Exemple #1
0
    async def sub(self, ctx, args):
        captain = None
        if not roles.is_admin(ctx.author):
            if self.match.status is MatchStatus.IS_CAPTAIN:
                await disp.SUB_ONLY_ADMIN.send(ctx)
                return
            captain = await get_check_captain(ctx,
                                              self.match,
                                              check_turn=False)
            if not captain:
                return

        if len(ctx.message.mentions) not in (1, 2):
            await disp.RM_MENTION_ONE.send(ctx)
            return

        subbed = Player.get(ctx.message.mentions[0].id)
        if not subbed:
            await disp.RM_NOT_IN_DB.send(ctx)
            return
        if not (subbed.match and subbed.match is self.match.proxy):
            await disp.SUB_NO.send(ctx)
            return
        if subbed.active and subbed.active.is_playing:
            subbed.active.team.captain.is_turn = True
            subbed.active.team.on_team_ready(False)

        # Can't have a swap command running at the same time
        self.factory.swap.on_clean()
        self.factory.bench.on_clean()

        if roles.is_admin(ctx.author):
            player = None
            if len(ctx.message.mentions) == 2:
                player = Player.get(ctx.message.mentions[1].id)
                if not player:
                    await disp.RM_NOT_IN_DB.send(ctx)
                    return
                elif player.match:
                    await disp.SUB_NO.send(ctx)
                    return
            await self.validator.force_confirm(ctx,
                                               subbed=subbed,
                                               force_player=player)
            return
        else:
            other_captain = self.match.teams[captain.team.id - 1].captain
            ctx = self.validator.arm(self.match.channel,
                                     captain,
                                     subbed=subbed)
            await disp.SUB_OK_CONFIRM.send(ctx, subbed.mention,
                                           other_captain.mention)
Exemple #2
0
def match_help(ctx):
    """ Returns match help embed
    """
    embed = Embed(colour=Color.blurple())
    embed.add_field(name='Match commands',
                    value='`=info` (`=i`) - Display the match status and team composition\n'
                          "`=squittal` - Display player data for integration in Chirtle's script",
                    inline=False)
    embed.add_field(name='Team Captain commands',
                    value='`=p @player` - Pick a player in your team\n'
                          '`=p VS`/`NC`/`TR` - Pick a faction\n'
                          '`=base` (`=b`) - Command for the base selection, use `=b help` to know more\n'
                          '`=ready` (`=rdy`) - To toggle the ready status of your team\n'
                          '`=sub @player` - Pick someone in queue to replace the player mentioned\n'
                          '`=swap @player1 @player2` - Swap the two players from one team to the other\n'
                          '`=bench`/`=unbench @player` - Bench or un-bench player from the match',
                    inline=False)
    if is_admin(ctx.author):
        embed.add_field(name="Staff commands",
                        value='`=clear` - Clear the match\n'
                              '`=captain @player` - Make @player a team captain\n'
                              '`=sub @player1 @player2` - Replace player1 by player2\n'
                              '`=check account/online` - Disable account or online check\n'
                              '`=channel freeze`/`unfreeze` - Prevent / Allow players to send messages',
                        inline=False)
    return embed
Exemple #3
0
def register_help(ctx):
    """ Returns register help embed
    """
    embed = Embed(
        colour=Color.blurple(),
        title='How to register?',
        description=f'You have to accept the rules in <#{cfg.channels["rules"]}> to register'
    )
    embed.add_field(name='If you don\'t have a Jaeger account',
                    value='`=r no account`\n',
                    inline=False)
    embed.add_field(name='If you have a Jaeger account',
                    value='`=r charName` - If your character names have faction suffixes '
                          '(charNameVS, charNameTR, charNameNC)\n'
                          '`=r charName1 charName2 charName3` - If your character names don\'t have faction suffixes',
                    inline=False)
    embed.add_field(name='Notify feature',
                    value='`=notify` - To join or leave the Notify feature\n'
                          f'When subscribed to Notify, you can be mentioned with <@&{cfg.roles["notify"]}> '
                          'when the queue is almost full',
                    inline=False)
    embed.add_field(name='Quit command',
                    value='`=quit` - To temporarily leave the channels\n'
                          f'You will be removed from the active POG channels. Accept the rules in <#{cfg.channels["rules"]}> to come back.',
                    inline=False)
    if is_admin(ctx.author):
        embed.add_field(name="Staff commands",
                        value='`=rename @player New Name` - Change the player name within the system\n'
                              '`=unregister @player` - Permanently remove player profile from the system\n'
                              '`=channel freeze`/`unfreeze` - Prevent / Allow players to send messages',
                        inline=False)
    return embed
Exemple #4
0
    async def swap(self, ctx, args):
        captain = None
        if not roles.is_admin(ctx.author):
            captain = await get_check_captain(ctx,
                                              self.match,
                                              check_turn=False)
            if not captain:
                return

        if len(ctx.message.mentions) != 2:
            await disp.SWAP_MENTION_2.send(ctx)
            return

        players = list()
        for mention in ctx.message.mentions:
            p = Player.get(mention.id)
            if not p:
                await disp.RM_NOT_IN_DB.send(ctx)
                return
            if not (p.match and p.active and p.match is self.match.proxy):
                await disp.SWAP_NO.send(ctx, p.mention)
                return
            if p.active.is_playing:
                p.active.team.captain.is_turn = True
                p.active.team.on_team_ready(False)
            players.append(p.active)

        if players[0].team is players[1].team:
            await disp.SWAP_SAME_TEAM.send(ctx)
            return

        # Can't have a sub command running  at the same time
        self.factory.sub.on_clean()
        self.factory.bench.on_clean()

        if roles.is_admin(ctx.author):
            await self.validator.force_confirm(ctx,
                                               p_1=players[0],
                                               p_2=players[1])
            return
        else:
            other_captain = self.match.teams[captain.team.id - 1].captain
            ctx = self.validator.arm(self.match.channel,
                                     captain,
                                     p_1=players[0],
                                     p_2=players[1])
            await disp.SWAP_OK_CONFIRM.send(ctx, other_captain.mention)
Exemple #5
0
 async def __select_base(self, ctx, picker, base):
     if is_admin(ctx.author):
         await self.__validator.force_confirm(ctx, base=base)
         return
     other_captain = self.__match.teams[picker.team.id - 1].captain
     ctx = self.__validator.arm(ctx, picker, base=base)
     await disp.BASE_OK_CONFIRM.send(ctx, base.name, other_captain.mention)
     if self.is_base_booked(base):
         await disp.BASE_BOOKED.send(ctx, other_captain.mention, base.name)
Exemple #6
0
    async def bench(self, ctx, args, bench):
        captain = None
        if not roles.is_admin(ctx.author):
            captain = await get_check_captain(ctx, self.match, check_turn=False)
            if not captain:
                return

        if len(ctx.message.mentions) != 1:
            await disp.BENCH_MENTION.send(ctx)
            return

        p = Player.get(ctx.message.mentions[0].id)
        if not p:
            await disp.RM_NOT_IN_DB.send(ctx)
            return
        if not (p.match and p.active and p.match is self.match.proxy):
            await disp.BENCH_NO.send(ctx, p.mention)
            return
        if bench and p.active.is_benched:
            await disp.BENCH_ALREADY.send(ctx)
            return
        if not bench and not p.active.is_benched:
            await disp.BENCH_NOT.send(ctx)
            return
        if p.active.is_playing:
            p.active.team.captain.is_turn = True
            p.active.team.on_team_ready(False)

        player = p.active

        # Can't have another command running  at the same time
        self.factory.sub.on_clean()
        self.factory.swap.on_clean()

        if roles.is_admin(ctx.author):
            await self.validator.force_confirm(ctx, player=player, bench=bench)
            return
        else:
            other_captain = self.match.teams[captain.team.id - 1].captain
            ctx = self.validator.arm(self.match.channel, captain, player=player, bench=bench)
            if bench:
                await disp.BENCH_OK_CONFIRM.send(ctx, other_captain.mention)
            else:
                await disp.UNBENCH_OK_CONFIRM.send(ctx, other_captain.mention)
Exemple #7
0
def lobby_help(ctx):
    """ Returns lobby help embed
    """
    embed = Embed(colour=Color.blurple())
    embed.add_field(name='Lobby commands',
                    value='`=join` (`=j`) - Join the lobby\n'
                          '`=leave` (`=l`)  - Leave the lobby\n'
                          '`=queue` (`=q`)  - See the current lobby\n'
                          '`=reset` (`=rst`)  - Reset your queue timeout\n'
                          '`=info` (`=i`)  - Display the global information prompt',
                    inline=False)
    if is_admin(ctx.author):
        embed.add_field(name="Staff commands",
                        value='`=clear` - Clear the lobby\n'
                              '`=remove @player` - Remove player from lobby\n'
                              '`=channel freeze`/`unfreeze` - Prevent / Allow players to send messages\n'
                              '`=lobby save`/`get`/`restore` - Will save, get or restore the lobby from player IDs',
                        inline=False)
    return embed
Exemple #8
0
    async def base(self, ctx, args):
        bl = self.match.status in (MatchStatus.IS_PLAYING,
                                   MatchStatus.IS_STARTING)
        bl = bl or (self.match.status is MatchStatus.IS_WAITING
                    and self.match.round_no > 1)
        if bl:
            if len(args) != 0:
                await disp.BASE_NO_CHANGE.send(ctx)
                return
            base = self.match.base
            await disp.BASE_SELECTED.send(ctx,
                                          base.name,
                                          base=base,
                                          is_booked=False)
            return

        # Check player status
        captain, msg = get_check_captain_sync(ctx,
                                              self.match,
                                              check_turn=False)
        # If player doesn't have the proper status
        if msg:
            if len(args) == 0:
                # If player just want to get base status, we give him
                await self.match.base_selector.show_base_status(ctx)
                msg.close()
                return
            elif not roles.is_admin(ctx.author):
                await msg
                return
            msg.close()

        if self.match.teams[0].is_playing or self.match.teams[1].is_playing:
            if len(args) == 0:
                await self.match.base_selector.show_base_status(ctx)
                return
            else:
                for tm in self.match.teams:
                    tm.captain.is_turn = True
                    tm.on_team_ready(False)

        await self.match.base_selector.process_request(ctx, captain, args)
Exemple #9
0
def auto_help(ctx, is_dm=False):
    """ Return help embed depending on current channel """
    if is_dm:
        return dm_help(ctx)
    if ctx.channel_id == cfg.channels['register']:
        return register_help(ctx)
    if ctx.channel_id == cfg.channels['lobby']:
        return lobby_help(ctx)
    if ctx.channel_id in cfg.channels['matches']:
        return match_help(ctx)
    if ctx.channel_id == cfg.channels['muted']:
        if ctx.author and is_admin(ctx.author):
            return timeout_help(ctx)
        else:
            return muted_help(ctx)
    if ctx.channel_id == cfg.channels['staff']:
        return admin_help(ctx)
    if ctx.channel_id == cfg.channels['usage']:
        return usage_help(ctx)
    return default_help(ctx)
Exemple #10
0
 async def cog_check(self, ctx):
     return roles.is_admin(ctx.author)
Exemple #11
0
async def on_message(client, message):

    # if bot, do nothing
    if message.author == client.user:
        return

    # if dm, send in staff
    if isinstance(message.channel, DMChannel):
        await on_dm(message)
        return

    # If message not in the bot's area of action
    if message.channel.id not in cfg.channels_list:
        return

    if len(message.content) == 0:
        return

    if message.content == cfg.emojis['info']:
        message.content = "=info"

    if message.content[0] != cfg.general["command_prefix"]:
        return

    # If bot is locked
    if is_all_locked():
        if not is_admin(message.author):
            return
        # Admins can still use bot when locked

    # Save actual author
    actual_author = message.author

    # Check if too many requests from this user:
    if await spam_checker.is_spam(message.author, message.channel):
        return

    try:
        # Make the message lower-case:
        if not message.content.lower().startswith("=rename"):
            message.content = message.content.lower()

        message.content = message.content.replace(",", " ").replace(
            "/", " ").replace(";", " ")

        # Split on whitespaces
        args = message.content.split()

        new_args = list()
        for arg in args:
            if '@' in arg:
                continue
            try:
                arg_int = int(arg)
            except ValueError:
                pass
            else:
                if arg_int >= 21154535154122752:  # minimum number for discord id
                    member = message.channel.guild.get_member(arg_int)
                    if member:
                        message.mentions.append(member)
                        continue
                    try:
                        member = await message.channel.guild.fetch_member(
                            arg_int)
                    except NotFound:
                        message.mentions.append(FakeMember(arg_int))
                        continue
                    if member:
                        message.mentions.append(member)
                        continue

            new_args.append(arg)

        message.content = " ".join(new_args)

        # Check for =as command
        if is_admin(message.author) and message.content[0:3] == "=as":
            try:
                message.author = message.mentions[0]
                del message.mentions[0]
                i = message.content[1:].index('=')
                message.content = message.content[i + 1:]
            except (ValueError, IndexError):
                ctx = ContextWrapper.wrap(message.channel,
                                          author=actual_author)
                await disp.WRONG_USAGE.send(ctx, "as")
                spam_checker.unlock(actual_author.id)
                return

        await client.process_commands(message)  # if not spam, processes

        # Call finished, we can release user
        await sleep(0.5)
    finally:
        spam_checker.unlock(actual_author.id)
Exemple #12
0
 def __is_admin(self, user):
     return self.__is_admin_allowed and is_admin(user)