forked from uniborg/uniborg
update to latest uniborg master
This commit is contained in:
commit
39017da8dc
|
@ -8,6 +8,6 @@ from uniborg import Uniborg
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
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()
|
||||||
|
|
|
@ -144,7 +144,7 @@ async def reparse(event):
|
||||||
return
|
return
|
||||||
|
|
||||||
await borg(EditMessageRequest(
|
await borg(EditMessageRequest(
|
||||||
peer=await event.input_chat,
|
peer=await event.get_input_chat(),
|
||||||
id=event.message.id,
|
id=event.message.id,
|
||||||
message=message,
|
message=message,
|
||||||
no_webpage=not bool(event.message.media),
|
no_webpage=not bool(event.message.media),
|
||||||
|
|
|
@ -11,9 +11,10 @@ from uniborg import util
|
||||||
|
|
||||||
|
|
||||||
async def get_target_message(event):
|
async def get_target_message(event):
|
||||||
if event.is_reply and (await event.reply_message).from_id == borg.uid:
|
if event.is_reply and (await event.get_reply_message()).from_id == borg.uid:
|
||||||
return await event.reply_message
|
return await event.get_reply_message()
|
||||||
async for message in borg.iter_messages(await event.input_chat, limit=20):
|
async for message in borg.iter_messages(
|
||||||
|
await event.get_input_chat(), limit=20):
|
||||||
if message.out:
|
if message.out:
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ async def await_read(chat, message):
|
||||||
chat = telethon.utils.get_peer_id(chat)
|
chat = telethon.utils.get_peer_id(chat)
|
||||||
|
|
||||||
async def read_filter(read_event):
|
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))
|
and read_event.is_read(message))
|
||||||
fut = borg.await_event(events.MessageRead(inbox=False), read_filter)
|
fut = borg.await_event(events.MessageRead(inbox=False), read_filter)
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ async def delete(event):
|
||||||
return
|
return
|
||||||
target = await get_target_message(event)
|
target = await get_target_message(event)
|
||||||
if target:
|
if target:
|
||||||
chat = await event.input_chat
|
chat = await event.get_input_chat()
|
||||||
await await_read(chat, target)
|
await await_read(chat, target)
|
||||||
await asyncio.sleep(.5)
|
await asyncio.sleep(.5)
|
||||||
if command == 'edit':
|
if command == 'edit':
|
||||||
|
|
|
@ -28,7 +28,7 @@ async def on_snip(event):
|
||||||
else:
|
else:
|
||||||
media = None
|
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,
|
file=media,
|
||||||
reply_to=event.message.reply_to_msg_id)
|
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))
|
@borg.on(events.NewMessage(pattern=r'\.snips (\S+)', outgoing=True))
|
||||||
async def on_snip_save(event):
|
async def on_snip_save(event):
|
||||||
name = event.pattern_match.group(1)
|
name = event.pattern_match.group(1)
|
||||||
msg = await event.reply_message
|
msg = await event.get_reply_message()
|
||||||
if msg:
|
if msg:
|
||||||
snips.pop(name, None)
|
snips.pop(name, None)
|
||||||
snip = {'type': TYPE_TEXT, 'text': msg.message or ''}
|
snip = {'type': TYPE_TEXT, 'text': msg.message or ''}
|
||||||
|
|
|
@ -52,21 +52,6 @@ class Uniborg(TelegramClient):
|
||||||
self.me = await self.get_me()
|
self.me = await self.get_me()
|
||||||
self.uid = telethon.utils.get_peer_id(self.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):
|
def load_plugin(self, shortname):
|
||||||
self.load_plugin_from_file(f"{self._plugin_path}/{shortname}.py")
|
self.load_plugin_from_file(f"{self._plugin_path}/{shortname}.py")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue