-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.py
112 lines (93 loc) · 3.93 KB
/
bot.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import os
from telegram.ext import Updater, CommandHandler
import pokepy
from modules import Type, Pic, Ability, Learnset, Random, Starter, AllInfo
import logging
START_TEXT = 'Hey! Pokedex here. Type /help to get list of commands'
ABOUT_TEXT = 'Bot made by Abhay Kshatriya (vegeto1806 on Telegram).\nThe source is available at https://github.com/kshatriya-abhay/pokebot'
HELP_TEXT = """
List of available commands:
/help - Get this list
/about - About the bot
Modules:
/pokedex - Gets the ability, type and learnset of a Pokemon
/ability - Get info about an ability/a Pokemon's all abilities
/learnset - Get Bulbapedia link to Learnset of a Pokemon
/pic - Get a Pokemon's sprite
/random - Get a random pokemon
/type - Get a Pokemon's type(s) and type weaknesses
/starter - Gets you your own unique starter pokemon
"""
# poke_client = pokepy.V2Client()
poke_client = pokepy.V2Client(cache='in_disk', cache_location=(os.getcwd()+'/.cache'))
def parse_args(args):
return '-'.join(args).lower()
def start(update, context):
update.message.reply_text(text = START_TEXT)
def about(update, context):
update.message.reply_text(text = ABOUT_TEXT)
def get_help(update, context):
update.message.reply_text(HELP_TEXT)
def all_info(update, context):
if len(context.args) >= 1:
query = parse_args(context.args)
response = ''
response = AllInfo.get_all_info(poke_client, query)
update.message.reply_text(response, parse_mode = 'Markdown')
else:
update.message.reply_text("Usage: /pokedex Pikachu")
def get_type(update, context):
if len(context.args) >= 1:
query = parse_args(context.args)
response = ''
response = Type.fetch_type(poke_client, query)
update.message.reply_text(response)
else:
update.message.reply_text("Usage: /type Pikachu")
def get_pic(update, context):
if len(context.args) >= 1:
query = parse_args(context.args)
flag, response, pic_title = Pic.fetch_pic(poke_client, query)
if flag:
context.bot.send_photo(chat_id=update.effective_chat.id, photo=response, caption=pic_title, reply_to_message_id=update.effective_message.message_id)
pass
else:
update.message.reply_text(response)
else:
update.message.reply_text("Usage: /pic Pikachu")
def ability(update, context):
if len(context.args) >= 1:
query = parse_args(context.args)
response = Ability.get_ability(poke_client, query)
update.message.reply_text(response, parse_mode = 'Markdown')
else:
update.message.reply_text("Usage: /ability Pikachu")
def learnset(update, context):
if len(context.args) >= 1:
query = parse_args(context.args)
response = Learnset.get_learnset(poke_client, query)
update.message.reply_text(response, parse_mode = 'Markdown')
else:
update.message.reply_text("Usage: /learnset Pikachu")
def get_random(update, context):
response = Random.get_random_pokemon(poke_client)
update.message.reply_text(response, parse_mode = 'Markdown')
def starter(update, context):
response = Starter.get_starter_pokemon(poke_client, update.message.from_user.id)
update.message.reply_text(response, parse_mode = 'Markdown')
if __name__ == "__main__":
TOKEN = open('API_TOKEN','r').read().replace('\n','')
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO)
updater = Updater(TOKEN, use_context=True)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CommandHandler('about', about))
updater.dispatcher.add_handler(CommandHandler('help', get_help))
updater.dispatcher.add_handler(CommandHandler('pokedex', all_info))
updater.dispatcher.add_handler(CommandHandler('type', get_type))
updater.dispatcher.add_handler(CommandHandler('pic', get_pic))
updater.dispatcher.add_handler(CommandHandler('ability', ability))
updater.dispatcher.add_handler(CommandHandler('learnset', learnset))
updater.dispatcher.add_handler(CommandHandler('random', get_random))
updater.dispatcher.add_handler(CommandHandler('starter', starter))
updater.start_polling()
updater.idle()