forked from uniborg/uniborg
Compare commits
No commits in common. "573f36bf57e3d95d3e36e6050fba5ff7c989f112" and "319eb84c5abc20827802652f2391ee0a890a3ca9" have entirely different histories.
573f36bf57
...
319eb84c5a
|
@ -45,14 +45,11 @@ def yaml_format(obj, indent=0):
|
|||
if not formatted.strip():
|
||||
continue
|
||||
result.append(' ' * (indent if has_multiple_items else 1))
|
||||
result.append(f'{k}:')
|
||||
if not formatted[0].isspace():
|
||||
result.append(' ')
|
||||
result.append(f'{formatted}')
|
||||
result.append(f'{k}: {formatted}')
|
||||
result.append('\n')
|
||||
result.pop()
|
||||
if has_multiple_items:
|
||||
indent -= 2
|
||||
result.append(' ' * indent)
|
||||
elif isinstance(obj, str):
|
||||
# truncate long strings and display elipsis
|
||||
result = repr(obj[:STR_LEN_MAX])
|
||||
|
@ -78,6 +75,7 @@ def yaml_format(obj, indent=0):
|
|||
result.append('\n')
|
||||
result.pop()
|
||||
indent -= 2
|
||||
result.append(' ' * indent)
|
||||
else:
|
||||
return repr(obj)
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
import asyncio
|
||||
from telethon import events, utils
|
||||
from telethon.tl import types
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
TYPE_TEXT = 0
|
||||
TYPE_PHOTO = 1
|
||||
|
@ -18,11 +16,10 @@ snips = storage.snips or {}
|
|||
|
||||
@borg.on(events.NewMessage(pattern=r'\.snip (\S+)', outgoing=True))
|
||||
async def on_snip(event):
|
||||
loop.create_task(event.delete())
|
||||
name = event.pattern_match.group(1)
|
||||
if name not in snips:
|
||||
return
|
||||
|
||||
await on_snip_save(event)
|
||||
else:
|
||||
snip = snips[name]
|
||||
if snip['type'] == TYPE_PHOTO:
|
||||
media = types.InputPhoto(snip['id'], snip['hash'], file_reference=b'')
|
||||
|
@ -35,15 +32,14 @@ async def on_snip(event):
|
|||
file=media,
|
||||
reply_to=event.message.reply_to_msg_id)
|
||||
|
||||
await event.delete()
|
||||
|
||||
|
||||
@borg.on(events.NewMessage(pattern=r'\.snips (\S+)', outgoing=True))
|
||||
async def on_snip_save(event):
|
||||
loop.create_task(event.delete())
|
||||
name = event.pattern_match.group(1)
|
||||
msg = await event.get_reply_message()
|
||||
if not msg:
|
||||
return
|
||||
|
||||
if msg:
|
||||
snips.pop(name, None)
|
||||
snip = {'type': TYPE_TEXT, 'text': msg.message or ''}
|
||||
if msg.media:
|
||||
|
@ -61,24 +57,27 @@ async def on_snip_save(event):
|
|||
snips[name] = snip
|
||||
storage.snips = snips
|
||||
|
||||
await event.delete()
|
||||
|
||||
|
||||
@borg.on(events.NewMessage(pattern=r'\.snipl', outgoing=True))
|
||||
async def on_snip_list(event):
|
||||
loop.create_task(event.delete())
|
||||
await event.respond('available snips: ' + ', '.join(snips.keys()))
|
||||
await event.delete()
|
||||
|
||||
|
||||
@borg.on(events.NewMessage(pattern=r'\.snipd (\S+)', outgoing=True))
|
||||
async def on_snip_delete(event):
|
||||
loop.create_task(event.delete())
|
||||
snips.pop(event.pattern_match.group(1), None)
|
||||
storage.snips = snips
|
||||
await event.delete()
|
||||
|
||||
|
||||
@borg.on(events.NewMessage(pattern=r'\.snipr (\S+)\s+(\S+)', outgoing=True))
|
||||
async def on_snip_rename(event):
|
||||
loop.create_task(event.delete())
|
||||
snip = snips.pop(event.pattern_match.group(1), None)
|
||||
if snip:
|
||||
snips[event.pattern_match.group(2)] = snip
|
||||
storage.snips = snips
|
||||
|
||||
await event.delete()
|
||||
|
|
Loading…
Reference in New Issue