Ejemplo n.º 1
0
 def get_new_context(self, ctx):
     self.__locked = True
     if self.__msg:
         self.clean()
     ctx = ContextWrapper.wrap(ctx)
     ctx.interaction_payload = self.__payload
     return ctx
Ejemplo n.º 2
0
 async def decline(captain, interaction_id, interaction, values):
     ctx = ContextWrapper.wrap(self.match.channel,
                               author=interaction.user)
     self.clean()
     if captain is self.expected:
         await disp.CONFIRM_DECLINE.send(ctx)
     else:
         await disp.CONFIRM_CANCELED.send(ctx)
Ejemplo n.º 3
0
 async def base_select(captain, interaction_id, interaction, values):
     author = interaction.user
     ctx = ContextWrapper.wrap(self.__match.channel, author=interaction.user)
     try:
         value = int(values[0])
     except (ValueError, IndexError):
         raise InteractionInvalid("invalid value!")
     base = self.find_by_id(value)
     if not base:
         raise InteractionInvalid("unknown base!")
     await self.__select_base(ctx, captain, base)
Ejemplo n.º 4
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!")
Ejemplo n.º 5
0
 async def on_answer(self, player, is_accept):
     if player is self.captains[0] and not player.active:
         i = 0
     elif player is self.captains[1] and not player.active:
         i = 1
     else:
         return False
     if is_accept:
         await self.add_captain(i, player)
     else:
         self.captains[i] = None
         ctx = ContextWrapper.wrap(self.match.channel, author=player)
         await disp.CAP_DENY_OK.send(ctx)
         self.auto_captain.restart()
         await self.get_new_auto(i)
     return True
Ejemplo n.º 6
0
async def is_spam(author, channel, ctx=None):
    a_id = author.id
    if a_id in __spam_list and __spam_list[a_id] > 0:
        if a_id in __last_requests and __last_requests[
                a_id] < tools.timestamp_now() - 30:
            log.info(
                f"Automatically unlocked id[{a_id}], name[{author.name}] from spam filter"
            )
            unlock(a_id)
    __last_requests[a_id] = tools.timestamp_now()
    if a_id not in __spam_list:
        __spam_list[a_id] = 1
        return False
    __spam_list[a_id] += 1
    if __spam_list[a_id] == 1:
        return False
    if __spam_list[a_id] % __SPAM_MSG_FREQUENCY == 0:
        if not ctx:
            ctx = ContextWrapper.wrap(channel, author=author)
        await disp.STOP_SPAM.send(ctx)
    return True
Ejemplo n.º 7
0
async def launch(ctx, id_list, tier):
    print("TIER 1")
    players = list()
    for p_id in id_list:
        player = Player.get(p_id)
        if not player:
            print(f"user {p_id}")
            user = await bot.fetch_user(p_id)
            player = Player(user.id, user.name)
            await db.async_db_call(db.set_element, "users", player.id,
                                   player.get_data())
            await player.register(None)
        players.append(player)

    for p in players:
        lobby.add_to_lobby(p)

    if tier == 1:
        return

    print("TIER 2")
    await asyncio.sleep(1)

    match = players[0].match

    while match.status is not MatchStatus.IS_CAPTAIN:
        await asyncio.sleep(1)

    cap_1_ctx = ContextWrapper.wrap(ctx.channel)
    cap_1_ctx.message = ctx.message
    cap_1_ctx.author = ctx.guild.get_member(players[0].id)
    await match.on_volunteer(players[0])

    cap_2_ctx = ContextWrapper.wrap(ctx.channel)
    cap_2_ctx.message = ctx.message
    cap_2_ctx.author = ctx.guild.get_member(players[1].id)
    await match.on_volunteer(players[1])

    if tier == 2:
        return

    print("TIER 3")
    while match.status is not MatchStatus.IS_PICKING:
        await asyncio.sleep(1)

    picked = ContextWrapper.user(players[2].id)
    cap_1_ctx.message.mentions.clear()
    cap_1_ctx.message.mentions.append(picked.author)

    await match.command.pick(cap_1_ctx, [""])

    if tier == 3:
        return

    print("TIER 4")

    while match.status is not MatchStatus.IS_FACTION:
        await asyncio.sleep(1)

    cap_2_ctx.message.mentions.clear()
    cap_1_ctx.message.mentions.clear()
    await match.command.pick(cap_2_ctx, ["VS"])
    await match.command.pick(cap_1_ctx, ["TR"])

    if tier == 4:
        return

    print("TIER 5")

    while match.status is not MatchStatus.IS_BASING:
        await asyncio.sleep(1)

    # We assume tester is an admin
    await match.command.base(ctx, ["ceres"])

    if tier == 5:
        return

    print("TIER 6")

    while match.status is not MatchStatus.IS_WAITING:
        await asyncio.sleep(1)

    match.change_check("online")
    match.change_check("account")

    await match.command.ready(cap_1_ctx)
    await match.command.ready(cap_2_ctx)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 async def _remove_msg(self, msg, view):
     try:
         ctx = ContextWrapper.wrap(msg)
         await ctx.edit(view=view)
     except NotFound:
         log.warning("NotFound exception when trying to remove message!")
Ejemplo n.º 10
0
 async def on_ready(captain, interaction_id, interaction,
                    interaction_values):
     ctx = ContextWrapper.wrap(self.match.channel,
                               author=interaction.user)
     ctx.cmd_name = "ready"
     await self.ready(ctx, captain)