Exemple #1
0
async def cmd_mute(server, userid, channel, message):
    split_content = str(message.content).split()
    if len(message.mentions) < 1:
        await channel.send(
            f"{Lang.get('CMD_WRONG_SYNTAX', server.lang)}\r\n`{server.cmd_prefix}mute <users> (<time>)`"
        )
        return False
    time = -1
    if len(split_content) > len(message.mentions) + 1:
        time = int(split_content[-1])
    for mention in message.mentions:
        if mention.id not in server.members.keys():
            raise Exception(f'Cannot find user ({ mention.id }) in server')
            pass
        server.members[mention.id].lock.acquire()
        server.members[mention.id].muted = True
        if mention.voice is not None:
            await mention.edit(mute=True)
        if time > 0:
            server.members[mention.id].muted_until = datetime.now(
            ) + timedelta(seconds=time)
            await channel.send(
                Lang.get('CMD_MUTE_TIME',
                         server.lang).format(User.get_at_mention(mention.id),
                                             User.get_at_mention(userid),
                                             time))
        else:
            server.members[mention.id].muted_until = None
            await channel.send(
                Lang.get('CMD_MUTE',
                         server.lang).format(User.get_at_mention(mention.id),
                                             User.get_at_mention(userid)))
        server.members[mention.id].lock.release()
    return True
Exemple #2
0
 async def user_voice_moved(self, userid, before, after):
     user = self.members[userid]
     if after.id == self.afk_channel_id:
         user.lock.acquire()
         user.last_active_xp = None
         user.active_since = None
         user.lock.release()
         await self.print_admin_log(
             f'{User.get_at_mention(user.id)} ({ user.id }) moved from :sound:**{before.name}** and is now :zzz:**AFK**'
         )
         if user.afk_mentions is True:
             await self.print_bot_message(
                 Lang.get('USER_IS_AFK', self.lang).replace(
                     cfg.get_value('TEXTFILE_USER_MENTION'),
                     User.get_at_mention(user.id)))
     elif before.id == self.afk_channel_id:
         user.lock.acquire()
         user.last_active_xp = None
         user.active_since = datetime.datetime.now()
         user.lock.release()
         await self.print_admin_log(
             f'{User.get_at_mention(user.id)} ({user.id}) moved to :loud_sound:**{after.name}** and is no longer ~~**afk**~~'
         )
         if user.afk_mentions is True:
             await self.print_bot_message(
                 Lang.get('USER_NO_MORE_AFK', self.lang).replace(
                     cfg.get_value('TEXTFILE_USER_MENTION'),
                     User.get_at_mention(user.id)))
     else:
         await self.print_admin_log(
             f"{User.get_at_mention(user.id)} ({user.id}) moved from :sound:**{before.name}** to :loud_sound:**{after.name}**"
         )
Exemple #3
0
async def cmd_toggle_accept(server, userid, channel, message):
    server.use_accept_command = not server.use_accept_command
    accept = ':green_circle: ' + Lang.get('YES', server.lang)
    refuse = ':red_circle: ' + Lang.get('NO', server.lang)
    await channel.send(
        Lang.get('CMD_ACCEPT_TOGGLE', server.lang).format(
            accept if server.use_accept_command else refuse,
            server.cmd_prefix))
    return True
Exemple #4
0
async def cmd_set_perm(server, userid, channel, message):
    perks = str(message.content).split()[len(message.role_mentions) + 1:]
    if not Perks.is_valid([perk[1:] if perk.startswith(('+', '-')) else perk for perk in perks]):
        await channel.send(Lang.get('INVALID_PERK', server.lang))
        return False
    else:
        for role in message.role_mentions:
            remove_perks = [perk[1:] for perk in perks if perk.startswith('-')]
            add_perks = [perk.replace('+', '') for perk in perks if not perk.startswith('-') and perk.replace('+', '') not in remove_perks]
            if str(role.id) in server.group_perks.keys():
                old_perks = [perk for perk in server.group_perks[str(role.id)] if perk not in add_perks and perk not in remove_perks]
                add_perks = old_perks + add_perks
            server.group_perks[str(role.id)] = add_perks
        await channel.send(Lang.get('CMD_PERM_UPDATE', server.lang).format(' '.join([r.mention for r in message.role_mentions])))
        return True
Exemple #5
0
 async def user_voice_connected(self, userid, channel):
     await self.print_admin_log(
         f'{User.get_at_mention(userid)} ({userid}) connected to :loud_sound:**{channel.name}**'
     )
     if userid in self.members.keys():
         member = self.members[userid]
         member.lock.acquire()
         member.last_login = datetime.datetime.now()
         member.active_since = datetime.datetime.now()
         member.last_active_xp = None
         if member.check_daily_reward() is True:
             await self.print_bot_message(
                 Lang.get('DAILY_XP_REWARD_LOGIN', self.lang).replace(
                     cfg.get_value('TEXTFILE_USER_MENTION'),
                     User.get_at_mention(userid)).format(
                         cfg.get_value('DAILY_REWARD_XP')))
         member.lock.release()
         if self.members[userid].muted is True:
             await self.guild.get_member(userid).edit(mute=True)
         else:
             await self.guild.get_member(userid).edit(mute=False)
         if self.members[userid].deaf is True:
             await self.guild.get_member(userid).edit(deafen=True)
         else:
             await self.guild.get_member(userid).edit(deafen=False)
Exemple #6
0
    async def cmd_router(self, msg, userid, channel):
        content = str(msg.content)
        commands = [
            ToggleAcceptCmd, AcceptGroupCmd, AcceptCmd, VersionCmd, HelpCmd,
            CommandsCmd, AfkCmd, StopAfkCmd, WarnsCmd, WarnCmd, PrefixCmd,
            PermCmd, MuteCmd, UnmuteCmd, DeafenCmd, UndeafenCmd, LangCmd,
            XpCmd, TFTCmd, ForceSaveCmd, DailyRewardCmd, DailyRewardAliasCmd,
            DiceCmd
        ]

        found_valid_command = False
        for cmd in commands:
            if content == self.cmd_prefix + cmd.name or content.startswith(
                    self.cmd_prefix + cmd.name + ' '):
                found_valid_command = True
                if await cmd.run_cmd(self, userid, channel, msg) is True:
                    await self.print_admin_log(
                        f"{User.get_at_mention(userid)} used **{self.cmd_prefix}{cmd.name}** command (||{msg.content}||)"
                    )
                else:
                    await self.print_admin_log(
                        f"{User.get_at_mention(userid)} tried to use **{self.cmd_prefix}{cmd.name}** command but failed (||{msg.content}||)"
                    )
                break
        if not found_valid_command and content.startswith(self.cmd_prefix):
            await channel.send(embed=simple_embed(value=Lang.get(
                'UNKNOWN_CMD', self.lang).format(content, self.cmd_prefix),
                                                  color=COLOR.LIGHT_RED))
async def cmd_stop_afk(server, userid, channel,
                       message):  # stop afk mentions (but keep admin logs)
    user = server.members[userid]
    user.afk_mentions = False
    await channel.send(
        Lang.get('CMD_STOPAFK',
                 server.lang).replace(cfg.get_value('TEXTFILE_USER_MENTION'),
                                      User.get_at_mention(user.id)))
    return True
Exemple #8
0
async def cmd_user_xp_get_self(server, userid, channel, message):
    if userid not in server.members.keys():
        raise Exception(
            f'Cannot self display user xp ({userid}) : user id not found in this guild'
        )
    await channel.send(
        Lang.get('CMD_XP_SELF',
                 server.lang).format(User.get_at_mention(userid),
                                     server.members[userid].xp))
    return True
Exemple #9
0
 async def run_cmd(self, server, userid, channel, message):
     if not self.can_execute(server, userid):
         await channel.send(embed=simple_embed(value=Lang.get(
             'MISSING_PERM', server.lang).replace(
                 cfg.get_value('TEXTFILE_USER_MENTION'),
                 User.get_at_mention(userid)),
                                               color=COLOR.RED))
         return False
     else:
         return await self.action(server, userid, channel, message)
Exemple #10
0
def grant_connected_user_daily_reward(server, member):
    global bot_loop
    member.lock.acquire()
    if member.active_since is not None and member.check_daily_reward() is True:
        asyncio.run_coroutine_threadsafe(
            server.print_bot_message(
                Lang.get('DAILY_XP_REWARD_ACTIVE', server.lang).replace(
                    cfg.get_value('TEXTFILE_USER_MENTION'),
                    User.get_at_mention(member.id)).format(
                        cfg.get_value('DAILY_REWARD_XP'))), bot_loop)
    member.lock.release()
Exemple #11
0
async def cmd_accept_group_set(server, userid, channel, message):
    if len(message.role_mentions) < 1:
        await channel.send(
            f"{Lang.get('CMD_WRONG_SYNTAX', server.lang)}\r\n`{server.cmd_prefix}acceptgroup <group>`"
        )
        return False
    server.accept_rank = message.role_mentions[0].name
    await channel.send(
        Lang.get('CMD_ACCEPT_GROUP_SET',
                 server.lang).format(message.role_mentions[0].mention,
                                     server.cmd_prefix))
    return True
async def cmd_daily_reward(server, userid, channel, message):
    if userid in server.members.keys():
        member = server.members[userid]
        now = datetime.now()
        daily_time = 86400 - (now - member.last_daily_reward).total_seconds()
        seconds = floor(daily_time % 60)
        minutes = floor(daily_time / 60)
        hours = floor(minutes / 60)
        minutes = minutes % 60
        display = f"{str(hours) + Lang.get('HOURS', server.lang) + ' ' if hours > 0 else ''}{str(minutes) + Lang.get('MINUTES', server.lang) + ' ' if minutes > 0 else ''}{str(seconds) + Lang.get('SECONDS', server.lang) + ' ' if seconds > 0 else ''}"
        await channel.send(
            Lang.get('NEXT_DAILY_XP_REWARD',
                     server.lang).format(User.get_at_mention(userid), display))
        return True
    return False
Exemple #13
0
async def cmd_unmute(server, userid, channel, message):
    split_content = str(message.content).split()
    if len(message.mentions) < 1:
        await channel.send(Lang.get('CMD_WRONG_SYNTAX', server.lang))
        await channel.send(f"`{server.cmd_prefix}unmute <users>`")
        return False
    for mention in message.mentions:
        if mention.id not in server.members.keys():
            raise Exception(f'Cannot find user ({ mention.id }) in server')
            pass
        server.members[mention.id].lock.acquire()
        server.members[mention.id].muted = False
        server.members[mention.id].muted_until = None
        if mention.voice is not None:
            await mention.edit(mute=False)
        await channel.send(
            f"{User.get_at_mention(mention.id)} has been unmuted by {User.get_at_mention(userid)}"
        )
        server.members[mention.id].lock.release()
    return True
Exemple #14
0
async def cmd_set_lang(server, userid, channel, message):
    splited_message = str(message.content).split()
    new_lang = splited_message[1].lower()
    server.lang = new_lang
    await channel.send(Lang.get('CMD_LANG_SET', server.lang).format(new_lang))
    return True
Exemple #15
0
async def cmd_get_lang(server, userid, channel, message):
    await channel.send(
        Lang.get('CMD_LANG_GET', server.lang).format(server.lang))
    return True