62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
import sys, random
|
|
import traceback
|
|
from typing import Sequence, AnyStr
|
|
from depytg import types, methods, errors
|
|
|
|
PHOTOS = ('http://filmmakermagazine.com/wp-content/uploads/2017/10/t-call-me-by-your-name.jpg',)
|
|
|
|
|
|
def parse_message(token: AnyStr, msg: types.Message):
|
|
if not 'text' in msg:
|
|
return
|
|
|
|
if '#TeamElio' in msg.text:
|
|
send_photo = methods.sendPhoto(chat_id=msg.chat.id)
|
|
send_photo.reply_to_message_id = msg.message_id
|
|
send_photo.photo = random.choice(PHOTOS)
|
|
send_photo.caption = "#TeamElio"
|
|
send_photo(token)
|
|
|
|
|
|
def parse_update(token: AnyStr, update: types.Update) -> int:
|
|
print(update)
|
|
print()
|
|
for i in ('message', 'edited_message', 'channel_post', 'edited_channel_post'):
|
|
if i in update:
|
|
parse_message(token, update[i])
|
|
break
|
|
return update.update_id
|
|
|
|
|
|
def on_updates(token: AnyStr, updates: Sequence[types.Update]) -> int:
|
|
max_id = 0
|
|
for u in updates:
|
|
try:
|
|
upd_id = parse_update(token, u)
|
|
|
|
if upd_id > max_id:
|
|
max_id = upd_id
|
|
except errors.TelegramError:
|
|
traceback.print_exc(file=sys.stderr)
|
|
|
|
return max_id
|
|
|
|
|
|
def mainloop(token: AnyStr, offset: int = 0) -> int:
|
|
updates = methods.getUpdates(offset)(token)
|
|
return on_updates(token, updates)
|
|
|
|
|
|
def main():
|
|
token = sys.argv[1]
|
|
prev_offset = 0
|
|
|
|
try:
|
|
while True:
|
|
prev_offset = mainloop(token, prev_offset) + 1
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|