示例#1
0
    async def prefix_cmd(self, ctx, *, args=None):
        # Get specific server data
        if isinstance(ctx.channel, discord.TextChannel):
            data = await HandleData.retrieve_data(self, ctx.message.guild)
            lang_server = data[0]
            prefix_server = data[3]
        else:
            lang_server = "en"
            prefix_server = "+"
        cmd_tran = tran[cmd_name][lang_server]

        # Doesn't respond to bots
        if not ctx.message.author.bot == True:
            # Check user perms or owner
            if not(ctx.message.author.guild_permissions.administrator or is_owner(ctx)):
                return await ctx.send(cmd_tran["msg_perm_admin_user"].format(ctx.message.author.name))
            # No args given
            if not args:
                return await ctx.send(cmd_tran["msg_invalid_arg"].format(prefix_server))

            # Delete the prefix variations
            if any(x == args for x in ["delete", "reset", "remove", "suppr"]):
                # Prefix is already default
                if not prefix_server == "+":
                    await HandleData.change_prefix(self, ctx, "+")
                return await ctx.send(cmd_tran["msg_prefix_reset"])
            elif match_id(args):
                return await ctx.send(cmd_tran["msg_invalid_arg"].format(prefix_server))

            # Change the prefix with arguments
            await HandleData.change_prefix(self, ctx, args)
            await ctx.send(cmd_tran["msg_prefix_changed"].format(args))
示例#2
0
 def allow_type(cmd):
     if any(tran[cmd]["type"] == x for x in
            ["flc", "ism", "theswe", "sparse", "quentium"]):
         if tran[cmd][
                 "type"] == "flc" and ctx.guild.id == 371687157817016331:  # France Les Cités server ID
             return False
         if tran[cmd][
                 "type"] == "ism" and ctx.guild.id == 391272643229384705:  # Insoumis server ID
             return False
         if tran[cmd][
                 "type"] == "sparse" and ctx.guild.id == 798518855529005076:  # SparseSneakers server ID
             return False
         if tran[cmd][
                 "type"] == "theswe" and ctx.guild.id == 199189022894063627:  # TheSweMaster server ID
             return False
         if tran[cmd]["type"] == "quentium" and is_owner(ctx):
             return False
         return True
示例#3
0
    async def trigger_cmd(self, ctx, *, args=None):
        # Get specific server data
        if isinstance(ctx.channel, discord.TextChannel):
            data = await HandleData.retrieve_data(self, ctx.message.guild)
            lang_server = data[0]
            prefix_server = data[3]
        else:
            lang_server = "en"
            prefix_server = "+"
        cmd_tran = tran[cmd_name][lang_server]

        # Doesn't respond to bots
        if not ctx.message.author.bot == True:
            # Global embed
            embed = discord.Embed(color=0xBFFF11)

            # Check user perms or owner
            if not (ctx.message.author.guild_permissions.administrator
                    or is_owner(ctx)):
                # Allow trigger list without any permissions
                if not any(x in args.lower().split()
                           for x in ["list", "liste"]):
                    return await ctx.send(
                        cmd_tran["msg_perm_admin_user"].format(
                            ctx.message.author.name))
            # No args given
            if not args:
                embed.title = cmd_tran["msg_specify_trigger"].format(
                    prefix_server)
                return await ctx.send(embed=embed)

            # Get all triggers
            triggers = await HandleData.get_data(self, "triggers")

            # List server's triggers
            if any(x in args.lower().split() for x in ["list", "liste"]):
                # Check if server triggers exist and is not empty
                if any(x == str(ctx.guild.id)
                       for x in triggers.keys()) and triggers[str(
                           ctx.guild.id)]:
                    content = "\n- ".join(
                        [x for x in triggers[str(ctx.guild.id)].keys()])
                    embed.title = cmd_tran["msg_reactions_list"].format(
                        len(triggers[str(ctx.guild.id)].keys()))
                    embed.description = "- " + content
                else:
                    embed.title = cmd_tran["msg_no_reactions"]
                return await ctx.send(embed=embed)

            # Remove a trigger
            if any(x in args.lower().split()
                   for x in ["remove", "delete", "clear"]):
                # No triggers given
                if len(args.split()) == 1:
                    embed.title = cmd_tran[
                        "msg_specify_trigger_delete"].format(prefix_server)
                    return await ctx.send(embed=embed)

                # Find trigger between quotes
                if args.count("'") > 1 or args.count('"') > 1:
                    filter_args = re.findall(r"\"(.+?)\"|\'(.+?)\'", args)
                    raw_args = [
                        x[0] if x[0] != '' else x[1] for x in filter_args
                    ]
                    remove = raw_args[-1].lower()
                else:
                    remove = args.split()[-1].lower()
                # Trigger found
                if any(x.lower() == remove
                       for x in triggers[str(ctx.guild.id)].keys()):
                    # Delete the trigger
                    del triggers[str(ctx.guild.id)][remove]
                    self.data = triggers
                    # Save the triggers data
                    await HandleData.dump_data(self, "triggers")
                    embed.title = cmd_tran["msg_reaction_deleted"]
                    embed.description = f"**{remove}**"
                else:
                    embed.title = cmd_tran["msg_unknown_reaction"]
                return await ctx.send(embed=embed)

            # Delete all trigger from the server
            if any(x in args.lower().split()
                   for x in ["removeall", "deleteall", "clearall"]):
                del triggers[str(ctx.guild.id)]
                self.data = triggers
                await HandleData.dump_data(self, "triggers")
                embed.title = cmd_tran["msg_reaction_all_deleted"]
                return await ctx.send(embed=embed)

            # Add a trigger with two arguments
            if len(args.split()) == 2:
                if args.count("'") == 0 and args.count('"') == 0:
                    # Both arguments are valid and not between quotes
                    trigger = args.split()[0]
                    response = args.split()[1]
                else:
                    embed.title = cmd_tran["msg_not_enough_args"]
                    return await ctx.send(embed=embed)

            elif len(re.findall(r"\"(.+?)\"|\'(.+?)\'", args)) == 2:
                # If not all quotes required
                if args.count("'") < 4 and args.count('"') < 4:
                    embed.title = cmd_tran["msg_not_enough_args"]
                    return await ctx.send(embed=embed)

                # If one of two args is surrounded with quotes
                if args.count("'") % 2 == 0 or args.count('"') % 2 == 0:
                    filter_args = re.findall(r"\"(.+?)\"|\'(.+?)\'", args)
                    raw_args = [
                        x[0] if x[0] != '' else x[1] for x in filter_args
                    ]
                    # Get the trigger
                    trigger = raw_args[0]
                    # Displays all links even images in response (if only 1 image link, displays the preview directly)
                    response = raw_args[1]
                else:
                    embed.title = cmd_tran["msg_too_many_args"]
                    return await ctx.send(embed=embed)

            # Just one arg given
            elif len(args.split()) < 2 or len(
                    re.findall(r"\"(.+?)\"|\'(.+?)\'", args)) < 2:
                embed.title = cmd_tran["msg_not_enough_args"]
                return await ctx.send(embed=embed)
            # Multiple args given or no quotes to delimit
            else:
                embed.title = cmd_tran["msg_too_many_args"]
                return await ctx.send(embed=embed)

            # Is it the first trigger registered
            if any(x == str(ctx.guild.id) for x in triggers.keys()):
                # Trigger does not exist already
                if trigger.lower() in triggers[str(ctx.guild.id)].keys():
                    embed.title = cmd_tran["msg_trigger_exists"]
                    return await ctx.send(embed=embed)
                # Add a key
                triggers[str(ctx.guild.id)][trigger.lower()] = response
            else:
                # Create the key
                triggers[str(ctx.guild.id)] = {trigger.lower(): response}

            # Save the data in the file
            self.data = triggers
            await HandleData.dump_data(self, "triggers")
            embed.title = cmd_tran["msg_new_reaction"]
            # Send the trigger and the reply
            embed.add_field(name=cmd_tran["msg_trigger"],
                            value=trigger,
                            inline=True)
            embed.add_field(name=cmd_tran["msg_reply"],
                            value=response,
                            inline=True)
            await ctx.send(embed=embed)
示例#4
0
    async def autorole_cmd(self, ctx, *, args=None):
        # Get specific server data
        if isinstance(ctx.channel, discord.TextChannel):
            data = await HandleData.retrieve_data(self, ctx.message.guild)
            lang_server = data[0]
            autorole_server = data[2]
            prefix_server = data[3]
        else:
            lang_server = "en"
            autorole_server = None
            prefix_server = "+"
        cmd_tran = tran[cmd_name][lang_server]

        # Doesn't respond to bots
        if not ctx.message.author.bot == True:
            # Check user perms or owner
            if not (ctx.message.author.guild_permissions.manage_roles
                    or is_owner(ctx)):
                return await ctx.send(cmd_tran["msg_perm_roles_user"].format(
                    ctx.message.author.name))
            # Check bot perms
            if not ctx.message.channel.guild.me.guild_permissions.manage_roles:
                return await ctx.send(cmd_tran["msg_perm_roles_bot"])
            # No args given
            if not args:
                return await ctx.send(
                    cmd_tran["msg_invalid_arg"].format(prefix_server))

            # Remove the autorole
            if any(x == args.lower() for x in ["remove", "delete"]):
                await HandleData.change_autorole(self, ctx, None)
                return await ctx.send(cmd_tran["msg_role_deleted"])
            # See the autorole
            if any(x == args.lower() for x in ["show", "see"]):
                if autorole_server == None:
                    return await ctx.send(cmd_tran["msg_role_not_defined"])
                # Get the role object
                role = discord.utils.get(ctx.message.guild.roles,
                                         id=autorole_server)
                if role == None:
                    # Delete the role if it was deleted from the server
                    await HandleData.change_autorole(self, ctx, None)
                    return await ctx.send(cmd_tran["msg_unknown_role"])
                return await ctx.send(cmd_tran["msg_current_role"].format(
                    role.name))

            # If the role is any kind of ID
            if match_id(args):
                role = discord.utils.get(ctx.message.guild.roles,
                                         id=match_id(args))
            # Find the role using it's name
            else:
                for role in ctx.message.guild.roles:
                    # Match the argument with all roles names
                    if args.lower() == role.name.lower():
                        role = discord.utils.get(ctx.message.guild.roles,
                                                 name=role.name)
                        break
                else:
                    return await ctx.send(cmd_tran["msg_invalid_role"])

            # Modify the role in the config
            await HandleData.change_autorole(self, ctx, role.id)
            await ctx.send(cmd_tran["msg_role_set"].format(role.name))
示例#5
0
    async def role_cmd(self, ctx, *, role=None):
        # Get specific server data
        if isinstance(ctx.channel, discord.TextChannel):
            data = await HandleData.retrieve_data(self, ctx.message.guild)
        lang_server = "fr"
        cmd_tran = tran[cmd_name][lang_server]

        if not ctx.message.author.bot == True:
            if ctx.guild.id == 391272643229384705:  # Insoumis server ID
                list_roles = [
                    "Payday 2", "Diablo 3", "Gta 5", "The division",
                    "Fortnite", "CS GO", "Farming simulator", "Lol",
                    "Dead by daylight", "Destiny 2", "Quake", "left 4 dead 2",
                    "GRID 2", "Steep", "HL2DM", "Sea of Thieves",
                    "Monster Hunter"
                ]

            elif ctx.guild.id == 350156033198653441:  # TFI server ID
                list_roles = ["Chauffeur en Test", "Ami"]

            elif ctx.guild.id == 509028174013923339:  # Solumon server ID
                list_roles = ["Payday 2", "Joueur", "Gmod"]

            elif ctx.guild.id == 319533759894388736:  # Exos_Team server ID
                if any(x == ctx.message.author.id for x in is_owner(ctx)):
                    if not role:
                        return await ctx.message.delete()
                    role = discord.utils.get(ctx.message.guild.roles,
                                             name=role)
                    if role in ctx.message.author.roles:
                        return await ctx.message.author.remove_roles(role)
                    else:
                        return await ctx.message.author.add_roles(role)
            else:
                return await ctx.send(cmd_tran["msg_not_enabled"])

            # No role given
            if not role:
                return await ctx.send(cmd_tran["msg_specify_role"].format(
                    ", ".join(list_roles)))

            # List all the roles of the server
            if "list" in role.lower():  # List for english and french
                return await ctx.send(cmd_tran["msg_list_role"].format(
                    ", ".join(list_roles)))

            # Find the closest match of the arg compared to all roles
            lower_match = difflib.get_close_matches(
                role.lower(), [x.lower() for x in list_roles], n=1, cutoff=0)
            # List of close matches
            rolename = [x for x in list_roles if x.lower() == lower_match[0]]
            # Get the role object with the first match
            role = discord.utils.get(ctx.message.guild.roles, name=rolename[0])
            if not role:
                return await ctx.send(cmd_tran["msg_unknown_role"])
            # Role is in the available role list
            if any(x in role.name for x in list_roles):
                # If user already have the role, remove the role
                if role in ctx.message.author.roles:
                    await ctx.message.author.remove_roles(role)
                    await ctx.send(cmd_tran["msg_role_removed"].format(
                        role.name))
                # Add the role
                else:
                    await ctx.message.author.add_roles(role)
                    await ctx.send(cmd_tran["msg_role_added"].format(role.name)
                                   )
            else:
                await ctx.send(cmd_tran["msg_role_not_allowed"])