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))
                         ]]))
Example #2
0
 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")
Example #3
0
 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))
Example #4
0
 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)
Example #5
0
    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 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 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 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 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))
Example #10
0
        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)
Example #11
0
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)
Example #12
0
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)
Example #13
0
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"))
Example #15
0
    def rename(self, bot: Bot, update: Update, trainer: Trainer,
               database: Database):
        """Rename Pokemon"""
        trainer.load_values(database=database, values="lastcatched")
        poke = Pokemon(trainer.lastcatched)
        poke.load_values(database, "species_id")

        name = update.message.text[0:16].replace(" ", "")

        c = True

        for c in name:
            if (not (c.isupper() or c.islower())):
                c = False

        if c:
            poke.name = name
            trainer.menu_id = int(MenuId.MAIN_MENU)
            trainer.lastcatched = None
            trainer.update_values(database, "menu_id, lastcatched")
            poke.update_values(database, "name")
            bot.send_message(
                trainer.id,
                text=
                "You want to call your {1} {0}? Great! I think you will become good friends. Your {0} seems very strong! Click on the button bellow to show the Mainmenu."
                .format(poke.name, poke.species.name),
                reply_markup=InlineKeyboardMarkup([[
                    InlineKeyboardButton("Menu",
                                         callback_data=str(ButtonId.MAINMENU))
                ]]))

        else:
            bot.send_message(
                trainer.id,
                text=
                "Youuuu little rascal. There were bad character in this name, try it again."
            )