Esempio n. 1
0
 async def on_rule_accept(player, interaction_id, interaction,
                          interaction_values):
     user = interaction.user
     if modules.loader.is_all_locked():
         raise modules.interactions.InteractionNotAllowed
     # reaction to the rule message?
     p = Player.get(user.id)
     if not p:  # if new player
         # create a new profile
         p = Player(user.id, user.name)
         await modules.roles.role_update(p)
         await modules.database.async_db_call(modules.database.set_element,
                                              "users", p.id, p.get_data())
         await disp.REG_RULES.send(
             ContextWrapper.channel(cfg.channels["register"]), user.mention)
     elif p.is_away:
         p.is_away = False
         await modules.roles.role_update(p)
         await p.db_update("away")
         await disp.AWAY_BACK.send(
             ContextWrapper.channel(cfg.channels["register"]), p.mention)
     else:
         i_ctx = InteractionContext(interaction)
         await disp.REG_RULES_ALREADY.send(i_ctx)
         await modules.roles.role_update(p)
Esempio n. 2
0
 async def run_player_check(self, interaction):
     if self.match.status is MatchStatus.IS_RUNNING:
         raise InteractionInvalid("Match is running!")
     i_ctx = InteractionContext(interaction)
     player = await get_check_player(i_ctx, self.match)
     if not player:
         raise InteractionNotAllowed
     return player
Esempio n. 3
0
 async def run_player_check(self, interaction):
     if self.match.status is MatchStatus.IS_RUNNING:
         raise InteractionInvalid("Match is running!")
     i_ctx = InteractionContext(interaction)
     captain = await get_check_captain(i_ctx, self.match, check_turn=self.check_turn)
     if not captain:
         raise InteractionNotAllowed
     return captain
Esempio n. 4
0
 async def volunteer(player, interaction_id, interaction,
                     interaction_values):
     if player.active:
         i_ctx = InteractionContext(interaction)
         await disp.CAP_ALREADY.send(i_ctx)
         raise interactions.InteractionNotAllowed
     if player not in self.p_list:
         # Should never happen
         raise interactions.InteractionInvalid(
             "player is valid but not in player list")
     await self.on_volunteer(player)
Esempio n. 5
0
 async def on_user_react(p, interaction_id, interaction,
                         interaction_values):
     user = interaction.user
     if user.id == player.id:
         ctx = ContextWrapper.channel(cfg.channels["lobby"])
         ctx.author = user
         reset_timeout(player)
         await disp.LB_REFRESHED.send(ctx)
     else:
         i_ctx = InteractionContext(interaction)
         await disp.LB_REFRESH_NO.send(i_ctx)
         raise interactions.InteractionNotAllowed
Esempio n. 6
0
 async def accept(captain, interaction_id, interaction, values):
     if captain is not self.expected:
         i_ctx = InteractionContext(interaction)
         await disp.CONFIRM_NOT_CAPTAIN.send(i_ctx,
                                             self.expected.mention)
         raise InteractionNotAllowed
     elif self.confirm_func:
         ctx = ContextWrapper.wrap(self.match.channel,
                                   author=interaction.user)
         kwargs = self.kwargs
         self.clean()
         await self.confirm_func(ctx, **kwargs)
     else:
         raise InteractionInvalid("no confirm function!")
Esempio n. 7
0
 async def on_answer(player, interaction_id, interaction,
                     interaction_values):
     i_ctx = InteractionContext(interaction)
     if player.active:
         await disp.CAP_ALREADY.send(i_ctx)
         raise interactions.InteractionNotAllowed
     if player not in self.captains:
         if interaction_id == 'accept':
             await disp.CAP_ACCEPT_NO.send(i_ctx)
         elif interaction_id == 'decline':
             await disp.CAP_DENY_NO.send(i_ctx)
         raise interactions.InteractionNotAllowed
     bl = await self.on_answer(player,
                               is_accept=(interaction_id == 'accept'))
     bl = bl and player is self.captains[i]
     if not bl:
         raise interactions.InteractionNotAllowed
Esempio n. 8
0
    async def run(self, interaction: Interaction):
        if self.__locked:
            return

        user = interaction.user
        player = None

        if await is_spam(user,
                         interaction.message.channel,
                         ctx=InteractionContext(interaction)):
            return

        self.__locked = True

        interaction_id = interaction.data['custom_id']
        interaction_values = interaction.data.get('values', None)

        try:
            if not self.__is_admin(user):
                player = await self.run_player_check(interaction)
            if not self.__callback:
                funcs = self.__f_dict[interaction_id]
            else:
                funcs = [self.__callback]
            for func in funcs:
                if is_coroutine(func):
                    await func(player, interaction_id, interaction,
                               interaction_values)
                else:
                    func(interaction_id, interaction, interaction_values)
                if self.__disable_after_use:
                    self.clean()
        except (InteractionNotAllowed, InteractionInvalid):
            pass
        except KeyError as e:
            log.warning(f"KeyError when processing interaction: {e}")
        except NotFound as e:
            log.warning(f"NotFound when processing interaction: {e}")
        finally:
            self.__locked = False
            unlock(user.id)