Esempio n. 1
0
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandInvokeError):
        if isinstance(error.original, discord.Forbidden):
            await ctx.reply(
                get_language_str(
                    get_server_config(ctx.guild.id, 'language', str), 6))
            return
    if not isinstance(
            error, (commands.CommandNotFound, commands.MissingPermissions,
                    commands.MissingRequiredArgument, commands.DisabledCommand,
                    commands.CheckFailure, commands.MemberNotFound)):
        if ctx.author.id == bot.owner_id:
            try:
                await ctx.reply(str(error))
            except discord.errors.HTTPException:
                pass  # probably unknown message, who knows.
        elif get_server_config(ctx.guild.id, 'share_error_logs', bool):
            dt_string = datetime.now().strftime("%d_%m_%Y %H %M %S")
            if not os.path.exists(f"data/errors/{type(error).__name__}/"):
                os.makedirs(f"data/errors/{type(error).__name__}/")
            open(
                f"data/errors/{type(error).__name__}/error_{dt_string}.txt",
                "w+",
                encoding="utf-8",
                newline="\n").write(
                    f"[{error}] while trying to invoke [{ctx.message.content}]"
                )
        else:
            error_file = io.BytesIO(bytes(str(error), 'utf-8'))
            await ctx.send(content=get_language_str(
                get_server_config(ctx.guild.id, 'language', str), 7),
                           file=discord.File(error_file, 'error.txt'))
Esempio n. 2
0
    async def mute_command(self, ctx, users: commands.Greedy[discord.Member],
                           *, timestamp):
        if get_server_config(ctx.guild.id, 'mute_role', int) == 0:
            await ctx.reply(get_language_str(ctx.guild.id, 85))
            return
        role = ctx.guild.get_role(
            get_server_config(ctx.guild.id, 'mute_role', int))
        if not users:
            await ctx.reply(
                get_language_str(ctx.guild.id,
                                 90).format(ctx.author.name,
                                            "No users specified."))
            return
        for user in users:
            if role in user.roles:
                await ctx.reply(
                    get_language_str(ctx.guild.id, 86).format(ctx.author.name))
                return
            else:
                pass

            await user.add_roles(role)

            try:
                str_dt_obj = add_mutes(ctx.guild.id, role.id, user.id,
                                       ctx.author.id, timestamp)
            except InvalidTimeParsed:
                await ctx.send(get_language_str(ctx.guild.id, 87))
                return
            except PastTimeError:
                await ctx.send(get_language_str(ctx.guild.id, 88))
                return
            except PresentTimeError:
                await ctx.send(get_language_str(ctx.guild.id, 89))
                return

            embed = discord.Embed(
                title="User muted",
                description=f"User: **{user}**\n"
                f"Time until the user will be unmuted: **{str_dt_obj}**\n"
                f"Muted by: **{ctx.author}**",
                color=random.choice(color_list))
            embed.set_thumbnail(url=user.avatar_url)
            embed.set_author(
                name=ctx.message.author.name,
                icon_url=ctx.message.author.avatar_url,
                url=f"https://discord.com/users/{ctx.message.author.id}/")

            await ctx.reply(embed=embed)
Esempio n. 3
0
async def command_check(ctx):
    if not ctx.guild:
        return True
    disabled_commands = get_server_config(ctx.guild.id, 'disabled_commands', list)
    disabled_cogs = get_server_config(ctx.guild.id, 'disabled_cogs', list)
    cog_disabled = False
    if ctx.command.cog:
        cog_disabled = ctx.command.cog.qualified_name in disabled_cogs
    command_disabled = str(ctx.command) in disabled_commands
    is_disabled = True
    if cog_disabled:
        is_disabled = False
    elif command_disabled:
        is_disabled = False
    return is_disabled  # What a mess.
Esempio n. 4
0
    async def setprefix_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        command_msg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        command_args = command_msg[len(prefix_used) + len(alias_used):]

        # Next, we check if the user actually passed some text
        if command_args == '':
            await ctx.reply(get_language_str(ctx.guild.id, 21))
            msg = await self.bot.wait_for('message', check=check)
            new_prefix = msg.content
        else:
            new_prefix = command_args.replace(' ', '')

        if not len(new_prefix) == 1:
            await ctx.reply(
                get_language_str(ctx.guild.id, 22).format(len(new_prefix)))
            return

        # Ask the user for confirmation
        msg = await ctx.send(
            get_language_str(ctx.guild.id, 23).format(new_prefix))

        if await wait_for_user(ctx, self.bot, msg):
            if get_server_config(ctx.guild.id, 'prefix', str) == new_prefix:
                await ctx.send(get_language_str(ctx.guild.id, 24))
                return
            write_server_config(ctx.guild.id, 'prefix', new_prefix)
            await ctx.reply(get_language_str(ctx.guild.id, 25))
            write_server_config(ctx.guild.id, 'asked_prefix', [])
            return
Esempio n. 5
0
async def check_message(message):
    result = check_banword_filter(message.content, message.guild.id)
    penalty = result[0]
    if penalty != 0:
        try:
            await message.delete()
        except discord.errors.NotFound:
            pass  # oh well.
        if penalty != 1:
            try:
                offensive_word = result[1]
                do_warn = result[2]
                if penalty == 2:  # ban
                    await message.author.ban(
                        reason=f'Banned for saying word {offensive_word}\n'
                        f'Full message: {message.content}')
                if penalty == 3:  # kick
                    await message.author.kick(
                        reason=f'Kicked for saying word {offensive_word}\n'
                        f'Full message: {message.content}')
                if penalty == 4:  # mute
                    role = message.guild.get_role(
                        get_server_config(message.guild.id, 'mute_role', int))
                    await message.author.add_roles(role)
                    mute.add_mutes(message.guild.id, role.id,
                                   message.author.id, bot.user.id, "1 hour")
                if do_warn:  # warn
                    moderation.warn(
                        message.guild.id, message.author.id, bot.user.id,
                        bot.user.name, message.channel.id,
                        f'Warned for saying word {offensive_word}\n'
                        f'Full message: {message.content}')
            except discord.errors.Forbidden:
                await message.channel.send(
                    get_language_str(message.guild.id, 5))
Esempio n. 6
0
    async def banword_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        command_msg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        command_args = command_msg[len(prefix_used) + len(alias_used):]
        if command_args == '':
            await ctx.send(get_language_str(ctx.guild.id, 31))
            msg = await self.bot.wait_for('message', check=check)
            nonoword = msg.content
        else:
            nonoword = command_args
        no_no_words = get_server_config(ctx.guild.id, 'no_no_words', dict)
        nonoword = nonoword.lower().replace(" ", "")

        if nonoword in no_no_words:
            # it's already in, we have to delete it
            no_no_words.pop(nonoword)
            write_server_config(ctx.guild.id, 'no_no_words', no_no_words)
            to_send = 32
        else:
            # it's not in, we have to add it
            no_no_words[nonoword] = []
            write_server_config(ctx.guild.id, 'no_no_words', no_no_words)
            to_send = 33
        await ctx.send(get_language_str(ctx.guild.id, to_send))
Esempio n. 7
0
 async def toggleinactivity_command(self, ctx):
     if get_server_config(ctx.guild.id, 'inactivity_func', bool):
         write_server_config(ctx.guild.id, 'inactivity_func', False)
         await ctx.reply("Success, inactivity function is now turned off.")
     else:
         write_server_config(ctx.guild.id, 'inactivity_func', True)
         await ctx.reply("Success, inactivity function is now turned on.")
Esempio n. 8
0
    async def disablecog_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]
        if commandargs == '':
            await ctx.send('Which category would you like to disable?')
            msg = await self.bot.wait_for('message', check=check)
            togglethingy = msg.content
        else:
            togglethingy = commandargs.replace(' ', '')
        disabled_cogs = get_server_config(ctx.guild.id, 'disabled_cogs', list)
        cmdthingy = self.bot.get_cog(togglethingy)
        if not cmdthingy:
            await ctx.reply(
                "I could not find that cog. *Action cancelled.*\n"
                "*Tip: This command is case sensitive, make sure your category is capitalized correctly.*"
            )
            return

        if togglethingy in disabled_cogs:
            new_cogs = [x for x in disabled_cogs if x != togglethingy]
            write_server_config(ctx.guild.id, 'disabled_cogs', new_cogs)
            await ctx.reply("Success, this cog is now enabled.")
        else:
            disabled_cogs.append(togglethingy)
            write_server_config(ctx.guild.id, 'disabled_cogs', disabled_cogs)
            await ctx.reply("Success, this cog is now disabled.")
Esempio n. 9
0
 async def toggleflip_command(self, ctx):
     if get_server_config(ctx.guild.id, 'tableflip', bool):
         write_server_config(ctx.guild.id, 'tableflip', False)
         await ctx.reply(get_language_str(ctx.guild.id, 51))
     else:
         write_server_config(ctx.guild.id, 'tableflip', True)
         await ctx.reply(get_language_str(ctx.guild.id, 52))
Esempio n. 10
0
 async def toggleflip_command(self, ctx):
     if get_server_config(ctx.guild.id, 'tableflip', bool):
         write_server_config(ctx.guild.id, 'tableflip', False)
         await ctx.reply("Success, tableflip reactions are now turned off.")
     else:
         write_server_config(ctx.guild.id, 'tableflip', True)
         await ctx.reply("Success, tableflip reactions are now turned on.")
Esempio n. 11
0
    async def disablecmd_command(self, ctx, command_to_toggle: str):
        togglethingy = command_to_toggle.lower()

        disabled_commands = get_server_config(ctx.guild.id,
                                              'disabled_commands', list)
        cmdthingy = self.bot.get_command(togglethingy)
        if not cmdthingy:
            await ctx.reply(get_language_str(ctx.guild.id, 54))
            return
        togglethingy = cmdthingy.name
        if togglethingy == 'help':
            msg = await ctx.send(get_language_str(ctx.guild.id, 55))

            if await wait_for_user(ctx, self.bot, msg):
                pass
        if togglethingy in disabled_commands:
            new_commands = [x for x in disabled_commands if x != togglethingy]
            write_server_config(ctx.guild.id, 'disabled_commands',
                                new_commands)
            await ctx.reply(get_language_str(ctx.guild.id, 56))
        else:
            disabled_commands.append(togglethingy)
            write_server_config(ctx.guild.id, 'disabled_commands',
                                disabled_commands)
            await ctx.reply(get_language_str(ctx.guild.id, 57))
Esempio n. 12
0
    async def disablecog_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]
        if commandargs == '':
            await ctx.send(get_language_str(ctx.guild.id, 58))
            msg = await self.bot.wait_for('message', check=check)
            togglethingy = msg.content
        else:
            togglethingy = commandargs.replace(' ', '')
        disabled_cogs = get_server_config(ctx.guild.id, 'disabled_cogs', list)
        cmdthingy = self.bot.get_cog(togglethingy)
        if not cmdthingy:
            await ctx.reply(get_language_str(ctx.guild.id, 59))
            return

        if togglethingy in disabled_cogs:
            new_cogs = [x for x in disabled_cogs if x != togglethingy]
            write_server_config(ctx.guild.id, 'disabled_cogs', new_cogs)
            await ctx.reply(get_language_str(ctx.guild.id, 60))
        else:
            disabled_cogs.append(togglethingy)
            write_server_config(ctx.guild.id, 'disabled_cogs', disabled_cogs)
            await ctx.reply(get_language_str(ctx.guild.id, 61))
Esempio n. 13
0
 async def bwordpenalty_command(self, ctx, word: str, *args):
     matching_words = []
     penalties = []
     possible_penalties = ["warn", "kick", "mute", "ban"]
     no_no_words = get_server_config(ctx.guild.id, "no_no_words", dict)
     for banned_word in no_no_words:
         if banned_word.lower().replace(" ", "").startswith(word.lower()):
             matching_words.append(banned_word)
     if len(matching_words) != 1:
         await ctx.reply(
             get_language_str(ctx.guild.id,
                              127).format(len(matching_words)))
         return
     for arg in args:
         if arg.lower() in possible_penalties:
             penalties.append(arg)
     no_no_word = matching_words[0]
     word_penalties = no_no_words[no_no_word]
     if not penalties:
         await ctx.send(get_language_str(ctx.guild.id, 129))
         return
     for penalty in penalties:
         penalty = penalty.lower()
         if penalty in word_penalties:
             word_penalties = [x for x in word_penalties if x != penalty]
         else:
             word_penalties.append(penalty)
     no_no_words[no_no_word] = word_penalties
     write_server_config(ctx.guild.id, "no_no_words", no_no_words)
     await ctx.send(get_language_str(ctx.guild.id, 128))
Esempio n. 14
0
 async def toggleinactivity_command(self, ctx):
     if get_server_config(ctx.guild.id, 'inactivity_func', bool):
         write_server_config(ctx.guild.id, 'inactivity_func', False)
         await ctx.reply(get_language_str(ctx.guild.id, 29))
     else:
         write_server_config(ctx.guild.id, 'inactivity_func', True)
         await ctx.reply(get_language_str(ctx.guild.id, 30))
Esempio n. 15
0
    async def banword_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]
        if commandargs == '':
            await ctx.send('Which word would you like to ban?')
            msg = await self.bot.wait_for('message', check=check)
            nonoword = msg.content
        else:
            nonoword = commandargs.replace(' ', '')
        nonowords = get_server_config(ctx.guild.id, 'no_no_words', list)

        if nonoword in nonowords:
            # it's already in, we have to delete it
            new_nonowords = [x for x in nonowords if x != nonoword]
            write_server_config(ctx.guild.id, 'no_no_words', new_nonowords)
            await ctx.reply("Success, this word has been unbanned.")
        else:
            # it's not in, we have to add it
            nonowords.append(nonoword)
            write_server_config(ctx.guild.id, 'no_no_words', nonowords)
            await ctx.reply("Success, this word has been banned.")
Esempio n. 16
0
 async def anonymouslogs_command(self, ctx):
     if get_server_config(ctx.guild.id, 'share_error_logs', bool):
         write_server_config(ctx.guild.id, 'inactivity_func', False)
         await ctx.reply(get_language_str(ctx.guild.id, 47))
     else:
         write_server_config(ctx.guild.id, 'share_error_logs', True)
         await ctx.reply(get_language_str(ctx.guild.id, 48))
Esempio n. 17
0
def get_prefix(client, message):
    if message.guild:
        prefixes = get_server_config(message.guild.id, 'prefix', str)
    else:
        prefixes = ['', '!']
    # If the message was sent in a guild, get the guild's prefix. Else, just put either no prefix or the '!' prefix.

    # Allow users to @mention the bot instead of using a prefix when using a command. Also optional
    # Do `return prefixes` if you don't want to allow mentions instead of prefix.
    return commands.when_mentioned_or(*prefixes)(client, message)
Esempio n. 18
0
 async def anonymouslogs_command(self, ctx):
     if get_server_config(ctx.guild.id, 'share_error_logs', bool):
         write_server_config(ctx.guild.id, 'inactivity_func', False)
         await ctx.reply(
             "Success, anonymous error logs will no longer be automatically sent to the bot host."
         )
     else:
         write_server_config(ctx.guild.id, 'share_error_logs', True)
         await ctx.reply(
             "Success, anonymous error logs will now be automatically sent to the bot host."
         )
Esempio n. 19
0
    async def setprefix_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]

        # Next, we check if the user actually passed some text
        if commandargs == '':
            await ctx.reply(
                'What would you like to set the prefix as for this server?')
            msg = await self.bot.wait_for('message', check=check)
            new_prefix = msg.content
        else:
            new_prefix = commandargs.replace(' ', '')

        if not len(new_prefix) == 1:
            await ctx.reply("The prefix is longer than one character long. "
                            "You can only have one character as your prefix.\n"
                            f"*Requested prefix's length is {len(new_prefix)}*"
                            )
            return

        # Ask the user for confirmation
        await ctx.send(
            f"Are you sure you want to set `{new_prefix}` as your new server prefix?\n"
            f"Example: `{new_prefix}help`")
        replymsg = await self.bot.wait_for('message', check=check)
        reply = replymsg.content.lower()

        if reply in ('y', 'yes', 'confirm'):
            if get_server_config(ctx.guild.id, 'prefix', str) == new_prefix:
                await ctx.send(
                    "Hey wait a second, that's the same prefix as the current saved one! "
                    "*(Action cancelled. Not like it'd change anything if it weren't cancelled...)*"
                )
                return
            write_server_config(ctx.guild.id, 'prefix', new_prefix)
            await ctx.reply("Successfully changed server prefix.")
            write_server_config(ctx.guild.id, 'asked_prefix', [])
            return
        elif reply in ('n', 'no', 'cancel', 'flanksteak'):
            await ctx.send("Alright, action cancelled.")
            return
        else:
            await ctx.send(
                "I have no idea what that means. *Action cancelled.*")
Esempio n. 20
0
    async def disablecmd_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]
        if commandargs == '':
            await ctx.send('Which command would you like to disable?')
            msg = await self.bot.wait_for('message', check=check)
            togglethingy = msg.content.lower()
        else:
            togglethingy = commandargs.replace(' ', '').lower()
        disabled_commands = get_server_config(ctx.guild.id,
                                              'disabled_commands', list)
        cmdthingy = self.bot.get_command(togglethingy)
        if not cmdthingy:
            await ctx.reply(
                "I could not find that command. *Action cancelled.*")
            return
        if togglethingy == 'help':
            await ctx.send(
                "Umm, are you *sure* you want to toggle the help command?")
            replymsg = await self.bot.wait_for('message', check=check)
            reply = replymsg.content.lower()

            if reply in ('y', 'yes', 'confirm'):
                pass
            elif reply in ('n', 'no', 'cancel', 'flanksteak'):
                await ctx.send("Alright, action cancelled.")
                return
            else:
                await ctx.send(
                    "I have no idea what that means. *Action cancelled.*")
                return
        if togglethingy in disabled_commands:
            new_commands = [x for x in disabled_commands if x != togglethingy]
            write_server_config(ctx.guild.id, 'disabled_commands',
                                new_commands)
            await ctx.reply("Success, this command is now enabled.")
        else:
            disabled_commands.append(togglethingy)
            write_server_config(ctx.guild.id, 'disabled_commands',
                                disabled_commands)
            await ctx.reply("Success, this command is now disabled.")
Esempio n. 21
0
    async def mutedrole_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]

        # Next, we check if the user actually passed some text
        if commandargs == '':
            await ctx.send(get_language_str(ctx.guild.id, 41))
            msg = await self.bot.wait_for('message', check=check)
            new_role = msg.content
        else:
            new_role = commandargs

        replace = {' ': '', '<': '', '@': '', '&': '', '>': ''}
        for key, value in replace.items():
            new_role = new_role.replace(key, value)

        if new_role.isdigit():
            role = ctx.guild.get_role(int(new_role))
            if role is None:
                await ctx.reply(get_language_str(ctx.guild.id, 42))
                return
        else:
            role = discord.utils.get(ctx.guild.roles, name=new_role)
            if role is None:
                await ctx.reply(get_language_str(ctx.guild.id, 43))
                return

        # Checks if role is already the one that's already defined. If not, ask for confirmation
        if role.id == get_server_config(ctx.guild.id, 'mute_role', int):
            await ctx.send(get_language_str(ctx.guild.id, 44))
            return
        else:
            msg = await ctx.send(
                get_language_str(ctx.guild.id, 45).format(role.name))

        if await wait_for_user(ctx, self.bot, msg):
            write_server_config(ctx.guild.id, 'mute_role', role.id)
            await ctx.reply(
                get_language_str(ctx.guild.id, 46).format(role.name))
            return
Esempio n. 22
0
async def on_message(message):
    if message.guild:
        await check_message(message)
    if message.author.id == bot.user.id:
        return  # To prevent the bot itself from triggering things.
    if message.author.id in excluded_users:
        return
    global message_count
    if message.guild and get_server_config(message.guild.id, 'inactivity_func', bool) and \
            message.channel.id in get_server_config(message.guild.id, 'inactivity_channels', list):
        if message.channel.id in message_count:
            count = message_count[message.channel.id]
        else:
            count = 0
        message_count[message.channel.id] = count + 1
    if (message.content == bot_mention) or (message.content
                                            == bot_mention_mobile):
        if message.author.id not in get_server_config(message.guild.id,
                                                      'asked_prefix', list):
            # remind user about the prefix
            asked = get_server_config(message.guild.id, 'asked_prefix', list)
            asked.append(message.author.id)
            write_server_config(message.guild.id, 'asked_prefix', asked)
            await message.channel.send(
                get_language_str(message.guild.id, 4).format(
                    get_server_config(message.guild.id, 'prefix', str)))
        else:
            # taunt the user
            to_send = get_language_str(
                get_server_config(message.guild.id, 'language', str), 0)
            await message.channel.send(random.choice(to_send).format(message))
            return

    if '(╯°□°)╯︵ ┻━┻' in message.content and message.guild:
        if get_server_config(message.guild.id, 'tableflip', bool):
            async with message.channel.typing():
                lang = get_server_config(message.guild.id, 'language', str)
                to_send = get_language_str(lang, 2)
                to_send = random.choice(to_send)
                await asyncio.sleep(0.75)
                await message.channel.send(to_send.format(message))
Esempio n. 23
0
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandInvokeError):
        if isinstance(error.original, discord.Forbidden):
            await ctx.reply("Sorry, I do not have the permissions to do that.")
            return
    if not isinstance(error, (commands.CommandNotFound, commands.MissingPermissions, commands.MissingRequiredArgument,
                              commands.DisabledCommand, commands.CheckFailure, commands.MemberNotFound)):
        if get_server_config(ctx.guild.id, 'share_error_logs', bool):
            dt_string = datetime.now().strftime("%d_%m_%Y %H %M %S")
            if not os.path.exists(f"data/errors/{type(error).__name__}/"):
                os.makedirs(f"data/errors/{type(error).__name__}/")
            open(f"data/errors/{type(error).__name__}/error_{dt_string}.txt", "w+", encoding="utf-8",
                 newline="\n").write(
                f"[{error}] while trying to invoke [{ctx.message.content}]")
        else:
            errorio = io.BytesIO(bytes(str(error), 'utf-8'))
            await ctx.reply(content="Uh oh! I ran into an error.\n"
                                    "Because this server's configuration doesn't allow me to automatically save errors,"
                                    " you'll have to do it yourself.",
                            file=discord.File(errorio, 'error.txt'))
Esempio n. 24
0
    async def changelang_command(self, ctx, *, commandargs=None):
        # NOTICE: DO NOT TRANSLATE THIS COMMAND!
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        if not commandargs:
            await ctx.send("What would you like to change the language to?")
            msg = await self.bot.wait_for('message', check=check)
            commandargs = msg.content
        else:
            commandargs = commandargs.replace(' ', '')
        commandargs = commandargs.lower()

        if commandargs in get_all_languages():
            # language exists
            write_server_config(ctx.guild.id, 'language', commandargs)
            await ctx.reply(
                get_language_str(commandargs, 4).format(
                    get_server_config(ctx.guild.id, 'prefix', str)))
        else:
            # me no tabla whatever the hell kind of language they want to tell me
            await ctx.reply("Could not find that language, no changes made.")
Esempio n. 25
0
async def on_message(message):
    if message.guild:
        for item in get_server_config(message.guild.id, 'no_no_words', list):
            if item in message.content.lower():
                try:
                    await message.delete()
                except discord.errors.Forbidden:
                    await message.channel.send("Hey, you said something you were not supposed to say! "
                                               "Unfortunately for me (and probably fortunately for you), "
                                               "I don't have the permissions to delete your message.")
                # People expect the bot to work without even giving them the perms.
    if message.author.id == bot.user.id:
        return  # To prevent the bot itself from triggering things.
    global messagecount
    if message.guild and get_server_config(message.guild.id, 'inactivity_func', bool) and \
            message.channel.id in get_server_config(message.guild.id, 'inactivity_channels', list):
        if message.channel.id in messagecount:
            count = messagecount[message.channel.id]
        else:
            count = 0
        messagecount[message.channel.id] = count + 1
    bot_mention = f'<@!{bot.user.id}>'
    if message.content == bot_mention:
        if message.author.id in get_server_config(message.guild.id, 'asked_prefix', list):
            with open("data/quotes/salutes.json", encoding='utf-8', newline="\n") as f:
                data = json.load(f)
            await message.channel.send(random.choice(data).format(message))
            return
        else:
            await message.channel.send(f"My prefix here is `{get_server_config(message.guild.id, 'prefix', str)}`.")
            asked = get_server_config(message.guild.id, 'asked_prefix', list)
            asked.append(message.author.id)
            write_server_config(message.guild.id, 'asked_prefix', asked)
    if '(╯°□°)╯︵ ┻━┻' in message.content and message.guild:
        if get_server_config(message.guild.id, 'tableflip', bool):
            time.sleep(0.75)
            messages = json.load(open("data/quotes/tableflip.json", "r", encoding="utf-8", newline="\n"))
            to_send = random.choice(messages)
            await message.channel.send(to_send.format(message))
Esempio n. 26
0
    async def inactivitychannel_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        command_msg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        command_args = command_msg[len(prefix_used) + len(alias_used):]

        # Next, we check if the user actually passed some text
        if command_args == '':
            await ctx.send(get_language_str(ctx.guild.id, 34))
            msg = await self.bot.wait_for('message', check=check)
            new_channel = msg.content
        else:
            new_channel = command_args

        replace = {' ': '', '<': '', '#': '', '>': ''}
        for key, value in replace.items():
            new_channel = new_channel.replace(key, value)

        if new_channel.isdigit():
            channel = ctx.guild.get_channel(int(new_channel))
            if channel is None:
                await ctx.reply(get_language_str(ctx.guild.id, 35))
                return
        else:
            channel = discord.utils.get(self.bot.get_all_channels(),
                                        guild=ctx.guild,
                                        name=new_channel)
            if channel is None:
                await ctx.reply(get_language_str(ctx.guild.id, 36))
                return

        # Ask the user for confirmation
        if channel.id in get_server_config(ctx.guild.id, 'inactivity_channels',
                                           list):
            msg = await ctx.send(
                get_language_str(ctx.guild.id, 37).format(channel.id))
            remove = True
        else:
            msg = await ctx.send(
                get_language_str(ctx.guild.id, 38).format(channel.id))
            remove = False

        if await wait_for_user(ctx, self.bot, msg):
            if remove:
                new_list = [
                    x for x in get_server_config(ctx.guild.id,
                                                 'inactivity_channels', list)
                    if x != channel.id
                ]
                write_server_config(ctx.guild.id, 'inactivity_channels',
                                    new_list)
                await ctx.reply(
                    get_language_str(ctx.guild.id, 39).format(channel.id))
                return
            else:
                new_list = get_server_config(ctx.guild.id,
                                             'inactivity_channels', list)
                new_list.append(channel.id)
                write_server_config(ctx.guild.id, 'inactivity_channels',
                                    new_list)
                await ctx.reply(
                    get_language_str(ctx.guild.id, 40).format(channel.id))
                return
Esempio n. 27
0
    async def mute_command(self, ctx, user: discord.Member, *, timestamp):
        if get_server_config(ctx.guild.id, 'mute_role', int) == 0:
            await ctx.reply(
                "The mute role hasn't been configured, please do so using the `muted_role` command. "
                "*Action cancelled.*")
            return
        role = ctx.guild.get_role(
            get_server_config(ctx.guild.id, 'mute_role', int))
        if role in user.roles:
            await ctx.reply(
                f"[{ctx.author.name}], relax. This user has already been "
                f"muted for now.")
            return
        else:
            pass

        regex = re.compile("\\s?(\\w+)([\\d]+\\s?\\w+)")
        try:
            new_string = str(" ".join(regex.match(timestamp).groups())) + "m"
        except AttributeError:
            new_string = timestamp

        dt_obj = cal.parseDT(datetimeString=new_string)
        now_dt = datetime.now()
        list_dt_obj = str(dt_obj[0]).split(":")
        list_now_dt = str(now_dt).split(":")

        str_now_dt = f'{list_now_dt[0]}:{list_now_dt[1]}'
        str_dt_obj = f'{list_dt_obj[0]}:{list_dt_obj[1]}'

        if dt_obj[1] == 0:
            await ctx.send(
                "Whoops, the time you inputted could not be parsed. *Action cancelled.*"
            )
            return
        elif dt_obj[0] <= now_dt:
            await ctx.send(
                "You can't set the time as the past, that just isn't logical. *Action cancelled.*"
            )
            return
        elif dt_obj[0] == now_dt or str_dt_obj == str_now_dt:
            await ctx.send("The time cannot be set as now. *Action cancelled.*"
                           )
            return

        await user.add_roles(role)

        with open("data/unmutes.json", "r+", newline='\n',
                  encoding='utf-8') as tempf:
            penalties = json.load(tempf)
            guild = ctx.guild
            mute_data = ([user.id, role.id, guild.id])
            if str_dt_obj not in penalties:
                penalties[str_dt_obj] = []
            penalties[str_dt_obj].append(mute_data)
            mute_index = len(penalties[str_dt_obj]) - 1
            if str(guild.id) not in penalties:
                penalties[str(guild.id)] = {}
            if str(user.id) in penalties[str(guild.id)]:
                penalties[str(guild.id)].pop(str(user.id))
            if not str(user.id) in penalties[str(guild.id)]:
                penalties[str(guild.id)][str(user.id)] = []
            penalties[str(guild.id)][str(
                user.id)] = [str_dt_obj, ctx.author.id, mute_index]
            tempf.seek(0)
            json.dump(penalties, tempf, indent=2)
            tempf.truncate()

        embed = discord.Embed(
            title="User muted",
            description=f"User: **{user}**\n"
            f"Time until the user will be unmuted: **{str_dt_obj}**\n"
            f"Muted by: **{ctx.author}**",
            color=random.choice(color_list))
        embed.set_thumbnail(url=user.avatar_url)
        embed.set_author(
            name=ctx.message.author.name,
            icon_url=ctx.message.author.avatar_url,
            url=f"https://discord.com/users/{ctx.message.author.id}/")

        await ctx.reply(embed=embed)
Esempio n. 28
0
    async def inactivitychannel_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]

        # Next, we check if the user actually passed some text
        if commandargs == '':
            await ctx.send('What channel would you like to toggle?')
            msg = await self.bot.wait_for('message', check=check)
            new_channel = msg.content
        else:
            new_channel = commandargs

        replace = {' ': '', '<': '', '#': '', '>': ''}
        for key, value in replace.items():
            new_channel = new_channel.replace(key, value)

        if new_channel.isdigit():
            channel = ctx.guild.get_channel(int(new_channel))
            if channel is None:
                await ctx.reply(
                    "Uh oh, I could not get the channel you meant. Please try again. "
                    "If it still fails, please try directly inserting the channel's ID. *Action cancelled.*"
                )  # Freaking character limit, man.
                return
        else:
            channel = discord.utils.get(self.bot.get_all_channels(),
                                        guild=ctx.guild,
                                        name=new_channel)
            if channel is None:
                await ctx.reply(
                    "Whoops, I couldn't find the channel you meant. "
                    "Please try again by directly mentioning the channel you mean. *Action cancelled.*"
                )
                return

        # Ask the user for confirmation
        if channel.id in get_server_config(ctx.guild.id, 'inactivity_channels',
                                           list):
            await ctx.send(
                f"Are you sure you want to remove <#{channel.id}> from the inactivity channels?"
            )
            remove = True
        else:
            await ctx.send(
                f"Are you sure you want to add <#{channel.id}> to the inactivity channels?"
            )
            remove = False
        replymsg = await self.bot.wait_for('message', check=check)
        reply = replymsg.content.lower()

        if reply in ('y', 'yes', 'confirm'):
            if remove:
                new_list = [
                    x for x in get_server_config(ctx.guild.id,
                                                 'inactivity_channels', list)
                    if x != channel.id
                ]
                write_server_config(ctx.guild.id, 'inactivity_channels',
                                    new_list)
                await ctx.reply(
                    f"Successfully removed <#{channel.id}> from the inactivity channels."
                )
                return
            else:
                new_list = get_server_config(ctx.guild.id,
                                             'inactivity_channels', list)
                new_list.append(channel.id)
                write_server_config(ctx.guild.id, 'inactivity_channels',
                                    new_list)
                await ctx.reply(
                    f"Successfully added <#{channel.id}> to the inactivity channels."
                )
                return
        elif reply in ('n', 'no', 'cancel', 'flanksteak'):
            await ctx.send("Alright, action cancelled.")
            return
        else:
            await ctx.send(
                "I have no idea what that means. *Action cancelled.*")
Esempio n. 29
0
    async def mutedrole_command(self, ctx):
        def check(ms):
            return ms.channel == ctx.message.channel and ms.author == ctx.message.author

        commandmsg = ctx.message.content
        prefix_used = ctx.prefix
        alias_used = ctx.invoked_with
        commandargs = commandmsg[len(prefix_used) + len(alias_used):]

        # Next, we check if the user actually passed some text
        if commandargs == '':
            await ctx.send('Which role would you like to set the mute role as?'
                           )
            msg = await self.bot.wait_for('message', check=check)
            new_role = msg.content
        else:
            new_role = commandargs

        replace = {' ': '', '<': '', '@': '', '&': '', '>': ''}
        for key, value in replace.items():
            new_role = new_role.replace(key, value)

        if new_role.isdigit():
            role = ctx.guild.get_role(int(new_role))
            if role is None:
                await ctx.reply(
                    "Uh oh, I could not get the role you meant. Please try again. "
                    "If it still fails, please try directly inserting the role's ID. *Action cancelled.*"
                )
                return
        else:
            role = discord.utils.get(ctx.guild.roles, name=new_role)
            if role is None:
                await ctx.reply(
                    "Whoops, I couldn't find the role you meant. "
                    "Please try again by directly mentioning the role you mean. *Action cancelled.*"
                )
                return

        # Checks if role is already the one that's already defined. If not, ask for confirmation
        if role.id == get_server_config(ctx.guild.id, 'mute_role', int):
            await ctx.send(
                "Hey wait a second, that's the role that has already been defined as the mute role! "
                "*Action cancelled. I mean, it wouldn't change anything if it weren't cancelled...*"
            )
            return
        else:
            await ctx.send(
                f"Are you sure you want to set {role.name} as the mute role?")
        replymsg = await self.bot.wait_for('message', check=check)
        reply = replymsg.content.lower()

        if reply in ('y', 'yes', 'confirm'):
            write_server_config(ctx.guild.id, 'mute_role', role.id)
            await ctx.reply(f"Successfully set {role.name} as the muted role")
            return
        elif reply in ('n', 'no', 'cancel', 'flanksteak'):
            await ctx.send("Alright, action cancelled.")
            return
        else:
            await ctx.send(
                "I have no idea what that means. *Action cancelled.*")