update to latest uniborg master

kate
udf 2018-06-22 16:26:32 +00:00
commit 39017da8dc
5 changed files with 11 additions and 25 deletions

View File

@ -8,6 +8,6 @@ from uniborg import Uniborg
logging.basicConfig(level=logging.INFO)
borg = Uniborg("stdborg", plugin_path="stdplugins")
borg = Uniborg("stdborg", plugin_path="stdplugins", connection_retries=None)
borg.run()
borg.run_until_disconnected()

View File

@ -144,7 +144,7 @@ async def reparse(event):
return
await borg(EditMessageRequest(
peer=await event.input_chat,
peer=await event.get_input_chat(),
id=event.message.id,
message=message,
no_webpage=not bool(event.message.media),

View File

@ -11,9 +11,10 @@ from uniborg import util
async def get_target_message(event):
if event.is_reply and (await event.reply_message).from_id == borg.uid:
return await event.reply_message
async for message in borg.iter_messages(await event.input_chat, limit=20):
if event.is_reply and (await event.get_reply_message()).from_id == borg.uid:
return await event.get_reply_message()
async for message in borg.iter_messages(
await event.get_input_chat(), limit=20):
if message.out:
return message
@ -22,7 +23,7 @@ async def await_read(chat, message):
chat = telethon.utils.get_peer_id(chat)
async def read_filter(read_event):
return (telethon.utils.get_peer_id(await read_event.input_chat) == chat
return (read_event.chat_id == chat
and read_event.is_read(message))
fut = borg.await_event(events.MessageRead(inbox=False), read_filter)
@ -44,7 +45,7 @@ async def delete(event):
return
target = await get_target_message(event)
if target:
chat = await event.input_chat
chat = await event.get_input_chat()
await await_read(chat, target)
await asyncio.sleep(.5)
if command == 'edit':

View File

@ -28,7 +28,7 @@ async def on_snip(event):
else:
media = None
await borg.send_message(await event.input_chat, snip['text'],
await borg.send_message(await event.get_input_chat(), snip['text'],
file=media,
reply_to=event.message.reply_to_msg_id)
@ -38,7 +38,7 @@ async def on_snip(event):
@borg.on(events.NewMessage(pattern=r'\.snips (\S+)', outgoing=True))
async def on_snip_save(event):
name = event.pattern_match.group(1)
msg = await event.reply_message
msg = await event.get_reply_message()
if msg:
snips.pop(name, None)
snip = {'type': TYPE_TEXT, 'text': msg.message or ''}

View File

@ -52,21 +52,6 @@ class Uniborg(TelegramClient):
self.me = await self.get_me()
self.uid = telethon.utils.get_peer_id(self.me)
async def _reconnect_nofail(self):
while True:
try:
await self.connect()
return
except ConnectionError:
pass
def run(self):
while True:
try:
self.run_until_disconnected()
except ConnectionError:
self.loop.run_until_complete(self._reconnect_nofail())
def load_plugin(self, shortname):
self.load_plugin_from_file(f"{self._plugin_path}/{shortname}.py")