-
Notifications
You must be signed in to change notification settings - Fork 0
/
dogebot.py
33 lines (28 loc) · 943 Bytes
/
dogebot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
from telegram.ext.dispatcher import run_async
import requests
import re
def get_url():
contents = requests.get('https://random.dog/woof.json').json()
url = contents['url']
return url
def get_image_url():
allowed_extension = ['jpg','jpeg','png']
file_extension = ''
while file_extension not in allowed_extension:
url = get_url()
file_extension = re.search("([^.]*)$",url).group(1).lower()
return url
@run_async
def bop(update, context):
url = get_image_url()
chat_id = update.message.chat_id
context.bot.send_photo(chat_id=chat_id, photo=url)
def main():
updater = Updater('il tuo token', use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('il tuo comando',bop))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()