def trainercard(self, bot: Bot, update: Update, trainer: Trainer, database: Database): delete_message(bot, update) trainer.load_values( database=database, values="name, draws, wins, badges, looses, pokedollar") trainer.load_values(database=database, values="registeredsince") bot.send_message(trainer.id, """ ```Ⓣ Ⓡ Ⓐ Ⓘ Ⓝ Ⓔ Ⓡ - Ⓒ Ⓐ Ⓡ Ⓓ ═══════════════ Name: {0} TrainerID:{1} Pokédollar: {2}₱ ═══════════════ Registered Since: {3} ═══════════════ Badges: {4} ═══════════════ Wins: {5} Looses: {6} Draws: {7} ═══════════════```""".format(trainer.name, trainer.id, trainer.pokedollar, trainer.registeredsince.strftime('%Y-%m-%d'), trainer.badges, trainer.wins, trainer.looses, trainer.draws), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("⏪ Profile", callback_data=str( ButtonId.MENU_PROFILE)) ]]))
def start_wild(trainer: Trainer, species_id: int, level: int, database: Database) -> (bool, str): """ Starts a new fight between a trainer and a new wild pokemon, that will be spawned. The bot send a new battle message to the trainer :param database: pokemon database :param bot: telegram bot, which send the message :param trainer: trainer in the fight :param species_id: species of the wild pokemon :param level: level of the wild pokemon """ wild_pokemon = Pokemon.create_new(database, Data.all_species[species_id - 1], level) trainer_team = trainer.get_team(database, "id, currenthp") for p in trainer_team: if p.currenthp > 0: trainer_pokemon = p break else: return False, "Trainer in fight with no available pokemon!" trainer_pokemon.load_values( database, "hp_dv, attack_dv, defense_dv, special_dv, speed_dv, hp_exp, attack_exp, " "defense_exp, special_exp, speed_exp, species_id, currenthp, level, " "name") trainer.fight = Fight.create_new(database, wild_pokemon, trainer_pokemon) trainer.menu_id = int(MenuId.BATTLE) trainer.update_values(database, "fight, menu_id") return True, "Wild %s appeared!" % wild_pokemon.name
def invalid_invitation(self, bot, update, trainer, database): """Handes Invalid Invidation""" bot.send_message( update.message.chat_id, text="Invalid Invitationcode :( Maybe... IT WAS A TRAP?!") Trainer.create_new(database, trainer.id, update.message.from_user.first_name, 800)
def yes_name(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """Rename Message""" delete_message(bot, update) bot.send_message( trainer.id, text="Okay nice! How do you want to call your little friend?" " (Please only use normal character [A-Z, a-z], maximal 16 chars)") trainer.load_values(database=database, values="menu_id") trainer.menu_id = int(MenuId.ENTER_NAME) trainer.update_values(database, "menu_id")
def textcb(bot, update): # Get Data d = get_database() try: cid = update.message.from_user.id trainer = Trainer(cid) trainer.get_values(d, "id, menu_id") if trainer.menu_id == 2: renamestarter(bot, update, d, trainer) finally: free_database(d)
def heal_no(self, bot: Bot, update: Update, trainer: Trainer, database: Database): trainer.menu_id = MenuId.MAIN_MENU trainer.update_values(database, "menu_id") try: update.callback_query.message.delete() except TelegramError: bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text="Don't click that fast...", show_alert=False) bot.send_message( Trainer.id, "We hope to see you again! Write or click on /handler to show the handler" )
def search(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """sets earch MenuID and sends instructions""" delete_message(bot, update) dex_but = [[InlineKeyboardButton("⏪ Exit Search", callback_data = str(ButtonId.POKEDEX_EXIT_SEARCH))]] dex_keys = InlineKeyboardMarkup(dex_but) bot.send_message(trainer.id, "Here you can search for a Pokemon-Species-ID or a Pokemon-Species-Name." " So please send me a name or number from 1 to 151 now! Write " " \"exit\" to leave or click here: ", reply_markup = dex_keys) trainer.menu_id = int(MenuId.POKEDEX_SEARCH) trainer.update_values(database, "menu_id")
def handle(bot_p: Bot, update: Update, _cmd_handlers): with Database() as database: trainer = Trainer(update.message.from_user.id) menu_id = None if trainer.does_exist(database): trainer.load_values(values="menu_id", database=database) menu_id = trainer.menu_id if menu_id not in _cmd_handlers: return func = _cmd_handlers[menu_id] use_db = self.uses_db(func) if use_db: func(bot_p, update, trainer, database) if not use_db: func(bot_p, update, trainer)
def comcb(bot, update): d = get_database() try: query = update.callback_query data = query.data cid = query.from_user.id if data.find('box') != -1: result = "B O X \n====================\n" trainer = Trainer(cid) #trainer.load_values(d, "id") pokes = trainer.get_all_pkmn( d, "id, name, level, currenthp, gender, hp_exp, hp_dv, species_id, current_status" ) #all_pkmn id = 1 if pokes == []: result += "Nothing here...\n" for poke in pokes: #[startval:startval+19]: #poke.load_values(d, "name, level, currenthp, gender, hp_exp, hp_dv, species_id, current_status") result += """ ({0}) {1} [{5}] Lv. {2} \n HP: {3}/{4}\n""".format( id, poke.name, poke.level, poke.currenthp, poke.calculate_max_hp(), poke.gender) id += 1 result += """====================\n /binfo <boxnumber> to get more information about your Pokémon in the box /tinfo <boxnumber> to get more information about your Pokémon in tyour team /box2team <box id> move a pokemon from your box to your team /team2box <team idr> move a pokemon from your team to your box /change <from> <to> change the team id of your Pokémon /release <box id> release a pokemon /trade <box id> <user id> trade pokemon""" bot.send_message(cid, result) finally: free_database(d)
def daily_code(self, bot, update, trainer: Trainer, database: Database): """Compares and handles generated daily codes in database""" # TODO check Daily Code trainer.load_values(database, "pokedollar") trainer.pokedollar = trainer.pokedollar + 100 bot.send_message( update.message.chat_id, text= "You used a fancy secret code!\nNext link will be active tomorrow! :) " + "Thank you for playing! WE LOVE YOU!! WE LOVE EVERYBODY!!!! AGJDHKS!!!!\n" + "PS: Pokedollar are no Cryptocurrency!!! (Not Yet ;) ) " + "But you can send us some crypto with /donate to keep this project alive :) <3" ) trainer.update_values(database, "pokedollar")
def no_name(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """Dont want to Rename""" delete_message(bot, update) bot.send_message( trainer.id, text="Nice! Have fun with your new friend! You two seem very strong!" " Click on the button bellow to show the Mainmenu.", reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("Menu", callback_data=str(ButtonId.MAINMENU)) ]])) trainer.menu_id = int(MenuId.MAIN_MENU) trainer.lastcatched = None trainer.update_values(database, "menu_id, lastcatched")
def menu_pokemon(cls, bot: Bot, update: Update, trainer: Trainer, database: Database): team = trainer.get_team(database, "id, name, level") buttons = [] for i, t in enumerate(team): buttons.append([InlineKeyboardButton( t.name + " - lvl. " + str(t.level), callback_data=ButtonId.BATTLE_MENU_NEW_POKEMON + str(i))]) buttons.append([cls.button_back]) battle_message.edit_menu(bot, update.callback_query.message, InlineKeyboardMarkup(buttons))
def information_popup(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """displays information in a pop up""" trainer.load_values(database, "game_pos_x, game_pos_y, game_location_id") interact = False actual_location = get_map().get_location_by_id( trainer.game_location_id) text = "You're currently here: " + actual_location.name + "\n\n" + actual_location.description + "\n" + \ "_________\n🆗: Interact\n🔄: Warp to next location" bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=text, parse_mode=ParseMode.MARKDOWN, show_alert=True)
def send_actual_position(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """sends the loaded rpg piece""" trainer.load_values(database, "game_pos_x, game_pos_y, game_location_id") interact = False actual_location = get_map().get_location_by_id( trainer.game_location_id) actual_tile = actual_location.get_tile(trainer.game_pos_x, trainer.game_pos_y) sticker = None if actual_tile == WAYTYPE.NONE: # TODO log Error pass left = actual_location.can_walk(trainer.game_pos_x - 1, trainer.game_pos_y) right = actual_location.can_walk(trainer.game_pos_x + 1, trainer.game_pos_y) up = actual_location.can_walk(trainer.game_pos_x, trainer.game_pos_y - 1) down = actual_location.can_walk(trainer.game_pos_x, trainer.game_pos_y + 1) if actual_tile is None: # TODO Raise Error! trainer.load_values(database, "name") bot.send_message(trainer.id, "Hello "+ trainer.name+ "! Sadly there occured an error in this bot" + \ ":( Please go to your trainercard write down your trainer-ID and inform @kurodevs that you "+ \ " have an \"invalid position in the map\". We will fix it soon! "+\ "Thank you for using our bot! <3") raise PokemonBotError("Trainer: " + str(trainer.id) + " has no valid position in the map!") if actual_tile.type == WAYTYPE.FOREST: sticker = Stickerpacks.get_forrestpath(left, right, up, down) elif actual_tile.type == WAYTYPE.CAVE: sticker = Stickerpacks.get_cavepath(left, right, up, down) markup = self.create_markup(left, right, up, down, interact) delete_message(bot, update) bot.sendSticker(trainer.id, sticker=sticker, reply_markup=markup)
def heal_yes(self, bot: Bot, update: Update, trainer: Trainer, database: Database): delete_message(bot, update) pokeraw = trainer.get_team( database, "id, species_id, level, name, teamnr, currenthp, hp_dv, hp_exp" ) # blocktimer row_count = database.dict_cursor.rowcount healtime = row_count * 5 # "UPDATE trainer SET blocktimer = NOW() + INTERVAL %s MINUTE WHERE id = % s;", (healtime, cid,)) # trainer.set_attribute("blocktimer", "NOW() + INTERVAL {0} MINUTE".format(healtime)) trainer.blocktimer = dt.datetime.now() + dt.timedelta(minutes=healtime) # d.cmd("UPDATE pokemon SET currenthp = %s WHERE id = %s", (temppoke.calculate_max_hp(), temppoke.id,)) for poke in pokeraw: poke.currenthp = poke.calculate_max_hp() poke.update_values(database, "currenthp") # poke.set_attribute("currenthp", "{0}".format(poke.calculate_max_hp())) center_buttons = [[ InlineKeyboardButton("Pick up!", callback_data='pickuppkmn') ]] center_keys = InlineKeyboardMarkup(center_buttons) bot.send_message( Trainer.id, "Ok. We'll need your Pokémon. Come back in {0} minutes and pick up your Pokémon. You can't do anything while we are healing your Pokémon. Please take a seat in our waiting room..." .format(healtime), reply_markup=center_keys) trainer.menu_id = MenuId.CENTER_HEAL_BLOCKER trainer.update_values(database, "blocktimer") trainer.update_values(database, "menu_id")
def menu_fight(cls, bot: Bot, update: Update, trainer: Trainer, database: Database): trainer.load_values(database, "fight") trainer.fight.load_values(database, "trainerPokemon") trainer.fight.trainerPokemon.load_values(database, "move0, move1, move2, move3") bttns = [] for i in range(4): m = trainer.fight.trainerPokemon.get_move(i) if m is None: bttns.append(cls.button_none) else: m.load_values(database, "move_id, currentap") bttns.append(InlineKeyboardButton( "%s %d/%d" % (m.move.name, m.currentap, m.move.pp), callback_data=ButtonId.BATTLE_MENU_MOVE + str(i))) battle_message.edit_menu(bot, update.callback_query.message, InlineKeyboardMarkup( [[bttns[0], bttns[1]], [bttns[2], bttns[3]], [cls.button_back]]))
def move_chosen(database: Database, trainer: Trainer, bot: Bot, old_msg: Message, data: str): """ Handles the click on a move button. Therefor runs one round of the battle and updates the battle message. :param database: pokemon database :param trainer: trainer of the message :param bot: telegram bot :param old_msg: old telegram message, that will be updated :param data: callback data, describing which button was pressed """ trainer.load_values(database, "fight") trainer.fight.load_values( database, "trainerPokemon, wildPokemon, wild_attack, wild_defense, wild_special, " "wild_special, wild_speed, trainer_attack, trainer_defense, trainer_special, " "trainer_speed") msg = trainer.fight.run_turn(database, int(data[2])) battle_message.update(bot, old_msg, menu_main, trainer.fight.wildPokemon, trainer.fight.trainerPokemon, msg)
def choosed(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """Choose Pokemon""" data = update.callback_query.data species = int(data.replace(str(ButtonId.CHOOSE_STARTER), "")) poke = Pokemon.create_new(database, all_species[species], 5, trainer) delete_message(bot, update) bot.sendSticker(trainer.id, Stickerpacks.get_item(0)) bot.send_message(trainer.id, text="Nice, " + poke.name + " is your first Pokémon!\n" + poke.species.pokedextext + "\nDo you want to give your Pokémon a nickname?", reply_markup=self.return_rename_buttons()) trainer.menu_id = int(MenuId.CHOOSE_IF_RENAME) trainer.lastcatched = poke.id trainer.update_values(database, "menu_id, lastcatched") dexter = Pokedex(poke.id, trainer.id) dexter.create_new(database, poke.species.id, trainer)
def potions(self, bot: Bot, update: Update, trainer: Trainer, database: Database): trainer.load_values(database, "pokedollar") data = update.callback_query.data.replace(str(ButtonId.SHOP_POTIONS), "") delete_message(bot, update) num = self.num_calc(4, data) item = self.ShopItem() item.LoadPotionFromD(num, database) bot.sendSticker(trainer.id, Stickerpacks.get_potions(num), reply_markup=self.create_buttons( item, str(ButtonId.SHOP_POTIONS_MIN), str(ButtonId.SHOP_POTIONS_PLS), str(ButtonId.SHOP_POTIONS_BUY), num, trainer.pokedollar))
def button_handle(bot_p: Bot, update: Update): id = ButtonId.from_string(update.callback_query.data) if id not in self.buttonHandlers: return bttn_handlers = self.buttonHandlers[id] with Database() as database: trainer = Trainer(update.callback_query.from_user.id) menu_id = None if trainer.does_exist(database): trainer.load_values(values="menu_id", database=database) menu_id = trainer.menu_id if menu_id not in bttn_handlers: return func = bttn_handlers[menu_id] use_db = self.uses_db(func) if use_db: func(bot_p, update, trainer, database) if not use_db: func(bot_p, update, trainer)
def com(bot, update): """ if menu_id==3: Ask the player if the trainer wants to heal his Pokemonteam and prints the time the pokemon need to heal. Gets id and teamnr from database. Yes = menu_id -> 11 :param bot: bot-param :param update: update-param :return: nothing """ d = get_database() try: id = update.message.from_user.id trainer = Trainer(id) trainer.load_values(d, "menu_id") if trainer.menu_id == 3: center_buttons = [[ InlineKeyboardButton("Heal, please!", callback_data='heal_y'), InlineKeyboardButton("Nope.", callback_data='heal_n') ]] center_keys = InlineKeyboardMarkup(center_buttons) bot.send_message(id, """B E E P b o O o p B e E P...""") bot.send_message(id, """. . .""") bot.send_message(id, """W E L C O M E!""") box_buttons = [ [InlineKeyboardButton("Open Box", callback_data='center_box')], [ InlineKeyboardButton("Phone with Oak", callback_data='center_oak') ], ] box_keys = InlineKeyboardMarkup(box_buttons) bot.send_message(id, """C O M P U T E R M E N U""", reply_markup=box_keys) pass finally: free_database(d)
def search_for(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """searches for a pokemon""" input_data = update.message.text # Exit Search if input_data.upper() == "EXIT": trainer.menu_id = int(MenuId.MAIN_MENU) trainer.update_values(database, "menu_id") self.send_menu(bot, trainer) # If Input is a number elif input_data.isdigit(): dexnum = int(update.message.text) if dexnum > 151 or dexnum < 1: bot.send_message(trainer.id, "Invalid Dex number...") else: self.search_entry(database, bot, update, trainer.id, dexnum) # searches for a Name else: dexterraw = Pokedex.get_all(database, columns = "id, trainerid", where = "trainerid = " + str(trainer.id), order = "id") idar = {'null': None} for j in dexterraw: idar[Data.all_species[j.id - 1].name.upper()] = j.id input_dex = update.message.text.upper() keylist = [] for k in idar.keys(): keylist.append(str(k)) if input_dex in keylist: self.search_entry(database, bot, update, trainer.id, idar[input_dex]) else: bot.send_message(trainer.id, "There is no entry with " + input_dex + " Do this Pokémon really exist? Check your spelling and try it one more time!")
def tinfo(bot, update): """ :param bot: :param update: :return: """ d = get_database() try: data = update.message.text id = update.message.from_user.id trainer = Trainer(id) trainer.load_values(d, "menu_id") if trainer.menu_id == 3: pokes = trainer.get_team( d, "id, name, level, currenthp, gender, hp_exp, hp_dv, species_id, current_status" ) show_poke_info(bot, id, data, pokes) finally: free_database(d)
def balls(self, bot: Bot, update: Update, trainer: Trainer, database: Database): trainer.load_values(database, "pokedollar") data = update.callback_query.data.replace(str(ButtonId.SHOP_BALLS), "") delete_message(bot, update) num = self.num_calc(3, data) item = self.ShopItem() item.LoadBallsFromD(num, database) bot.sendSticker( trainer.id, Stickerpacks.get_balls(num), reply_markup=self.create_buttons( item, str(ButtonId.SHOP_BALLS_MIN), str(ButtonId.SHOP_BALLS_PLS), str(ButtonId.SHOP_BALLS_BUY), num, trainer.pokedollar)) #num, userinfo['pokedollar'], "balls"))
def start(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """Start cmd""" id = update.message.from_user.id name = update.message.from_user.first_name data = update.message.text invcode = data[7:] if trainer.does_exist(database): if data.find("fancycode") != -1: self.daily_code(bot, update, trainer, database) else: self.already_registered(bot, update, trainer) else: if invcode != None and invcode != " " and invcode != "" and int( invcode) != id: inviter = Trainer(int(invcode)) if inviter.does_exist(database): self.invite_code(bot, update, trainer, inviter, database) else: self.invalid_invitation(bot, update, trainer, database) else: Trainer.create_new(database, id, name, 800) self.register_user(bot, update, trainer, database)
def set_attribute(self, name, value): """ sets attribute :param name: Name of the attribute :param value: Value of the attribute """ if name == "id": self.species = value elif name == "trainerid": self.trainer = Trainer(value) else: setattr(self, name, value)
def heal(self, bot: Bot, update: Update, trainer: Trainer, database: Database): """ if menu_id==3: Ask the player if the trainer wants to heal his Pokemonteam and prints the time the pokemon need to heal. Gets id and teamnr from database. Yes = menu_id -> MenuId.POKEMON_CENTER """ pokemon = trainer.get_team(database, "id, teamnr") row_count = database.dict_cursor.rowcount healtime = row_count * minutes_to_heal center_buttons = [[ InlineKeyboardButton("Heal, please!", callback_data='heal_y'), InlineKeyboardButton("Nope.", callback_data='heal_n') ]] center_keys = InlineKeyboardMarkup(center_buttons) bot.send_message( id, "Welcome to our Pokémon Center! We heal your Pokémon back to perfect health! Shall we heal your Pokémon? We will need {0} minutes to heal every Pokémon in your team." .format(healtime), reply_markup=center_keys) trainer.menu_id = MenuId.POKEMON_CENTER trainer.update_values(database, "menu_id")
def invite_code(self, bot, update, invcode, trainer: Trainer, inviter: Trainer, database: Database): """Handles Invite Code""" inviter.load_values(database, "pokedollar") inviter.pokedollar = inviter.pokedollar + 400 inviter.update_values(database, "pokedollar") Trainer.create_new(database, id, update.message.from_user.first_name, 1200) bot.send_message( update.message.chat_id, text="Invited by {0}! You both got 400₱ as gift!".format( inviter.name)) logger.info("{0} with ID {1} was recuted by {2} with ID {3}".format( update.message.from_user.first_name, id, inviter.name, inviter.id))
def pokemon_team(self, bot: Bot, update: Update, trainer: Trainer, database: Database): delete_message(bot, update) team = trainer.get_team(database, "id, name, level, teamnr, currenthp, gender") msg = "" for p in team: poke = Pokemon(p.id) poke.load_values(database, "teamnr, name, level, currenthp") poke.load_values( database, "gender, hp_exp, hp_dv, species_id, current_status") msg += """ ({0}) {1} [{5}] Lv. {2} \n HP: {3}/{4}\n""".format( poke.teamnr, poke.name, poke.level, poke.currenthp, poke.calculate_max_hp(), poke.gender) bot.send_message(trainer.id, "Your Pokémon-Team:\n" + msg, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("⏪ Profile", callback_data=str( ButtonId.MENU_PROFILE)) ]]))
def pickuppkmn(self, bot: Bot, update: Update, trainer: Trainer, database: Database): trainer.get_values(database, "blocktimer") blocktime = trainer.blocktimer if blocktime <= dt.datetime.now(): bot.send_message( Trainer.id, text= """Thank you! Your Pokémon are fighting fit! We hope to see you again! Hehe... What? I'm not a s****t... Click or write /handler to show the handler!""" ) # d.cmd("UPDATE trainer SET blocktimer = NULL WHERE id = %s;", (cid,)) trainer.blocktime = None trainer.menu_id = 3 trainer.update_values(database, "menu_id, blocktimer") pass else: waitfor = blocktime - dt.datetime.now() minutes = (waitfor.days * 1440) + (waitfor.seconds / 60) + 1 # + waitfor.minute bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text="Wait for %d min..." % minutes, show_alert=False)