Initial commit
This commit is contained in:
commit
e9e3da0a42
2 changed files with 76 additions and 0 deletions
62
callmebyyourbot.py
Normal file
62
callmebyyourbot.py
Normal file
|
@ -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()
|
14
setup.py
Normal file
14
setup.py
Normal file
|
@ -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"]
|
||||
)
|
Loading…
Reference in a new issue