commit e9e3da0a42773b6f2ad8b7b944428c221686bb4d Author: Davide Depau Date: Sun Jan 28 01:36:09 2018 +0100 Initial commit diff --git a/callmebyyourbot.py b/callmebyyourbot.py new file mode 100644 index 0000000..f926608 --- /dev/null +++ b/callmebyyourbot.py @@ -0,0 +1,62 @@ +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() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fa68d4d --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup + +setup( + name='Call Me By Your Bot', + version='0.1', + packages=['callmebyyourbot'], + url='https://github.com/Depaulicious/', + license='', + author='Davide Depau', + author_email='davide@depau.eu', + description='A Telegram bot that replies with a picture of Elio when #TeamElio is sent', + dependency_links=["https://github.com/Depaulicious/DepyTG/archive/wip.zip"], + requires=["DepyTG", "requests"] +)