示例#1
0
 async def color(self, ctx, value: bool = True):
     guild = GuildDB.get_one(ctx.message.guild.id)
     if guild.vip:
         guild.color = value
         GuildDB.update_guild(guild)
         await ctx.send("Settings updated", delete_after=3)
     else:
         await ctx.send("You're not VIP. **Our color system is VIP only.** "
                        "If you want to become VIP, feel free to **join our support discord** and ask to become VIP.")
示例#2
0
async def is_immune(message):
    guild = GuildDB.get_one(message.guild.id)
    admins = GuildDB.get_admin_roles(guild)
    auth = message.author
    if message.guild is None:
        return False
    if auth == message.guild.owner:
        return True
    for role in auth.roles:
        if role.id in admins:
            return True
示例#3
0
 async def setting_update(self, ctx):
     for gguild in self.bot.guilds:
         guild = GuildDB.get_one(gguild.id)
         for role in gguild.roles:
             if GuildDB.exists_in_admin(role.id, ctx.guild.id):
                 GuildDB.remove_admin(role.id, ctx.guild.id)
             if role.permissions.administrator or role.permissions.manage_guild is True:
                 GuildDB.set_admin(role.id, gguild.id)
             elif role.permissions.ban_members or role.permissions.kick_members is True:
                 GuildDB.set_mod(role.id, gguild.id)
         GuildDB.update_guild(guild)
     await ctx.send("Done")
示例#4
0
async def is_admin_check(ctx):
    guild = GuildDB.get_one(ctx.guild.id)
    admins = GuildDB.get_admin_roles(guild)

    auth = ctx.message.author
    if ctx.guild is None:
        return False
    if auth == ctx.message.guild.owner:
        return True
    for role in auth.roles:
        if str(role.id) in admins:
            return True
示例#5
0
async def is_mod_check(ctx):
    guild = GuildDB.get_one(ctx.guild.id)
    mods = GuildDB.get_mod_roles(guild)
    admins = GuildDB.get_admin_roles(guild)

    auth = ctx.message.author
    if ctx.guild is None:
        return
    if auth == ctx.guild.owner:
        return True
    for role in auth.roles:
        if role.id in mods or role.id in admins:
            return True
示例#6
0
 async def update_names(self, ctx):
     for guild in self.bot.guilds:
         G = GuildDB.get_one(guild_id=guild.id)
         GuildDB.update_name(guild.id, guild.name)
         if guild.id in [
                 488765635439099914, 631811291568144384, 618414922556112916,
                 740622438282428416
         ]:
             for user in guild.members:
                 if not user.bot:
                     U = UserDB.get_one(user.id)
                     UserDB.update_name(
                         user.id, "{}#{}".format(user.name.lower(),
                                                 user.discriminator))
示例#7
0
    async def role(self, ctx, value, role: discord.Role = None):
        if not role:
            return
        guild = GuildDB.get_one(ctx.message.guild.id)
        if GuildDB.exists_in_admin(role.id, ctx.guild.id):
            GuildDB.remove_admin(role.id, ctx.guild.id)
        if value.lower() == 'mod':
            GuildDB.set_mod(role.id, ctx.message.guild.id)
        elif value.lower() == 'admin':
            GuildDB.set_admin(role.id, ctx.message.guild.id)
        else:
            return

        GuildDB.update_guild(guild)
        await ctx.send("Updating...", delete_after=3)
示例#8
0
    async def on_member_join(self, member):
        """

        :param member: The member who joined the guild
        """
        guild = GuildDB.get_one(member.guild.id)

        # Check if the user has already been muted to avoid any sanctions bypass
        if MuteDB.is_muted(member.id, member.guild.id):
            # Mute him again
            role = discord.utils.get(member.guild.roles, name="Muted")
            if not role:
                role = await member.guild.create_role(
                    name="Muted",
                    permissions=discord.Permissions.none(),
                    reason="Mute Role")
                for chan in member.guild.text_channels:
                    await chan.set_permissions(role, send_messages=False)
            await member.add_roles(role)
        if guild.logging:
            sanctions, time = await Checks().member_check(member)
            em = await Mod().check_embed(member, member.guild, sanctions, time)
            if guild.log_chan:
                channel = self.bot.get_channel(int(guild.log_chan))
                if isinstance(channel, discord.TextChannel):
                    try:
                        await channel.send(embed=em)
                    except discord.Forbidden:
                        return
示例#9
0
    async def add(self, ctx, name: str):
        guild = GuildDB.get_one(ctx.message.guild.id)

        if not guild.color:
            return

        role = discord.utils.get(ctx.guild.roles, name=name.lower())
        if not role and name.lower() in self.colors:
            pos = ctx.guild.me.roles[-1].position
            hexa = self.colors[name]
            hexa = hexa.lstrip('#')
            r = int(hexa[0:2], 16)
            g = int(hexa[2:4], 16)
            b = int(hexa[4:6], 16)

            color = discord.Colour.from_rgb(r, g, b)
            role = await ctx.guild.create_role(
                name=name,
                colour=color,
                reason=
                f"Color role submitted by {ctx.author.name}|{ctx.author.id}")

            await ctx.send("Created : " + role.name)
            await role.edit(position=pos)
        for x in ctx.author.roles:
            if x.name in self.colors:
                await ctx.author.remove_roles(x)
        await ctx.author.add_roles(role)
示例#10
0
    async def on_member_join(self, member):
        """

        :param member: The member who joined the guild
        """
        guild = GuildDB.get_one(member.guild.id)
        user = UserDB.get_one(member.id)

        # Check if the user has already been muted to avoid any sanctions bypass
        if UserDB.is_muted(guild, user):
            # Mute him again
            role = discord.utils.get(member.guild.roles, name="Muted")
            if not role:
                role = await member.guild.create_role(
                    name="Muted",
                    permissions=discord.Permissions.none(),
                    reason="Mute Role")
                for chan in member.guild.text_channels:
                    await chan.set_permissions(role, send_messages=False)
            await member.add_roles(role)

        # Check if the user is in the blacklist
        if BlacklistDB.is_blacklist(user):
            if GuildDB.has_blacklist(guild):
                # Ban the member
                await member.guild.ban(member, reason="Blacklist")
            try:
                await member.send(
                    "you're in the blacklist ! If you think it's an error, ask here --> "
                    "*****@*****.**")
            except discord.Forbidden:
                return

        if GuildDB.has_logging(guild):
            sanctions, time = await Checks().member_check(member)
            em = await Mod().check_embed(member, member.guild, sanctions, time)
            if guild.log_chan:
                channel = self.bot.get_channel(int(guild.log_chan))
                if isinstance(channel, discord.TextChannel):
                    try:
                        await channel.send(embed=em)
                    except discord.Forbidden:
                        return
示例#11
0
    async def get(self, ctx):

        guild = GuildDB.get_one(ctx.message.guild.id)

        if not guild.setup:
            await ctx.send("You must setup the bot before ! ")
            await ctx.invoke(self.setup)

        else:
            em = await Embeds().format_get_set_embed(ctx, guild.greet, guild.greet_chan, guild.blacklist, guild.logging,
                                                     guild.log_chan, guild.vip, guild.color, guild.stats_channels)
            await ctx.send(embed=em)
示例#12
0
    async def member_check(member: discord.Member):
        guild = GuildDB.get_one(member.guild.id)
        now = datetime.now()
        create = member.created_at

        strikes = SanctionsDB.get_sanctions_from_guild_user(
            member.guild.id, member.id)

        sanctions = len(strikes)
        time = (now - create).days

        return sanctions, time
示例#13
0
 async def log_send(self, ctx, guild_id, embed):
     guildY = GuildDB.get_one(guild_id)
     if guildY.logging:
         try:
             channel = self.bot.get_channel(int(guildY.log_chan))
         except discord.HTTPException:
             return
         try:
             await channel.send(embed=embed)
         except discord.Forbidden:
             return
     else:
         await ctx.send(embed=embed)
示例#14
0
    async def massban(self, ctx, *members: MemberID):
        try:
            for member_id in members:
                await ctx.guild.ban(discord.Object(id=member_id),
                                    reason="{} - massban".format(
                                        ctx.message.author))
        except Exception as e:
            return await ctx.send(e)

        guild = ctx.message.guild
        guildY = GuildDB.get_one(guild.id)

        if guildY.logging:
            channel = self.bot.get_channel(int(guildY.log_chan))
            await channel.send(f'{len(members)} users were banned')
        else:
            await ctx.send(f'{len(members)} users were banned')
示例#15
0
    async def on_member_join(self, member: discord.Member):
        """

        :param member: The member who joined the guild
        """

        guild = GuildDB.get_one(member.guild.id)

        if guild.greet:
            channel = self.bot.get_channel(int(guild.greet_chan))
            greet = random.choice(lists.greet)

            em = discord.Embed(timestamp=member.joined_at)
            em.set_author(name="Welcome", icon_url=member.avatar_url)
            em.set_footer(text=f'{member.name}')
            em.description = f"{greet}"
            await channel.send(embed=em)
示例#16
0
    async def rank(self, ctx, user: discord.Member = None):
        if user is None:
            user = ctx.message.author

        userY = UserDB.get_one(user.id)
        guildY = GuildDB.get_one(ctx.message.guild.id)
        rankings = RankingsDB.get_user(userY, guildY)

        if not rankings:
            RankingsDB.create_ranking(userY, guildY)
            rankings = RankingsDB.get_user(user, guildY)

        rank = RankingsDB.get_rank(userY, guildY)

        em = discord.Embed()
        em.set_author(name=user.name, icon_url=user.avatar_url)
        em.add_field(name="**Rank**", value=f"{rank}", inline=False)
        em.add_field(name="**Level**", value=rankings["level"])
        em.add_field(name="**Progress**",
                     value="{} / {}".format(rankings['xp'], rankings['reach']))
        await ctx.send(embed=em)
示例#17
0
    async def on_member_remove(self, member):
        """

        :param member: The member who has left
        """

        guild = GuildDB.get_one(member.guild.id)

        if guild.greet:
            try:
                channel = member.guild.get_channel(int(guild.greet_chan))
            except discord.HTTPException:
                pass
            else:
                greet = random.choice(lists.leave)

                em = discord.Embed(timestamp=member.joined_at)
                em.set_author(name="Bye", icon_url=member.avatar_url)
                em.set_footer(text=f'{member.name}')
                em.description = f"{greet}"
                await channel.send(embed=em)
示例#18
0
    async def on_guild_join(self, guild):
        guildY = GuildDB.get_one(guild.id)

        for role in guild.roles:
            if GuildDB.exists_in_admin(role.id, guild.id):
                GuildDB.remove_admin(role.id, guild.id)
            if role.permissions.administrator or role.permissions.manage_guild is True:
                GuildDB.set_admin(role.id, guild.id)
            elif role.permissions.ban_members or role.permissions.kick_members is True:
                GuildDB.set_mod(role.id, guild.id)

        if guild.id == '264445053596991498':
            return
        try:
            await guild.owner.send(
                f"Thank you for adding the YumeBot to your guild!\n"
                f"In order to configure the YumeBot and to be able to use it fully"
                f" we ask you to make the command `--setting` in any channel of your guild **{guild.name}**"
                "Thank you for your understanding.\n\n"
                f"If you need help, do not hesitate to contact us on our discord: **invite.gg/yumenetwork**\n"
                f"__The YumeNetwork__")
        except discord.HTTPException:
            return
示例#19
0
    async def leaderboard(self, ctx):
        guild_y = GuildDB.get_one(ctx.message.guild.id)
        scoreboard = RankingsDB.get_scoreboard(guild_y)

        em = discord.Embed(
            description="ScoreBoard",
            color=discord.Colour.magenta()
        )

        x = 0
        for user in scoreboard:
            member: discord.Member = discord.utils.get(ctx.guild.members, id=int(user))
            if not isinstance(member, discord.Member):
                RankingsDB.reset_user(int(user), ctx.guild.id)

            else:
                member_ranking = RankingsDB.get_user(member.id, ctx.guild.id)
                x += 1
                total = member_ranking['total']
                em.add_field(name=f"**{x} - {member.name}**", value=f"Total xp : {total}",
                             inline=False)

        await ctx.send(embed=em)
示例#20
0
    async def leaderboard(self, ctx):
        guildY = GuildDB.get_one(ctx.message.guild.id)
        scoreboard = RankingsDB.get_scoreboard(guildY)

        em = discord.Embed(description="ScoreBoard",
                           color=discord.Colour.magenta())

        x = 0
        for user in scoreboard:
            member = discord.utils.get(ctx.guild.members, id=int(user))
            userY = UserDB.get_one(user)
            member_ranking = RankingsDB.get_user(userY, guildY)
            if member is None:
                RankingsDB.reset_user(userY, guildY)
            else:
                x += 1
                level = member_ranking['level']
                total = member_ranking['total']
                em.add_field(name=f"**{x} - {member.name}**",
                             value=f"Level : {level} \nTotal xp : {total}",
                             inline=False)

        await ctx.send(embed=em)
示例#21
0
    async def config(self, ctx, level: int, role: typing.Union[discord.Role,
                                                               int, str]):
        guild = GuildDB.get_one(ctx.guild.id)
        if isinstance(role, str):
            try:
                rolemention = discord.utils.get(ctx.guild.roles, name=role)
            except discord.NotFound:
                return await ctx.send(
                    "We can't find the role. Be sure to follow the syntax as in the exemple : **--level set 3 role_name**"
                )
        if isinstance(role, int):
            try:
                rolemention = discord.utils.get(ctx.guild.roles, id=role)
            except discord.NotFound:
                return await ctx.send(
                    "We can't find the role. Be sure to follow the syntax as in the exemple : **--level set 3 role_name**"
                )

        row = RoleDB.get_one_from_level(level, guild)
        if row:
            RoleDB.unset_level(row['level'], guild)
        RoleDB.set_level(role.id, guild, level)

        await ctx.send("Level setup", delete_after=2)
示例#22
0
    async def unmute(self, ctx, user: discord.Member, auto: bool = False):

        if not auto:
            mod = ctx.message.author
        else:
            mod = "auto"

        role = discord.utils.get(ctx.guild.roles, name="Muted")
        guild = ctx.message.guild
        guildY = GuildDB.get_one(guild.id)
        userY = UserDB.get_one(user.id)

        if not MuteDB.is_muted(userY, guildY) or not role:
            return

        MuteDB.unset_mute(userY, guildY)

        try:
            await user.remove_roles(role)
        except discord.HTTPException:
            return

        em = await Embeds().format_mod_embed(ctx, user, mod, None, 'unmute')
        await self.log_send(ctx, ctx.message.guild.id, em)
示例#23
0
    async def mute(self,
                   ctx,
                   user: discord.Member,
                   duration: str,
                   *,
                   reason: ModReason = None):
        """
        :param ctx: Command context
        :param user: The member to mute
        :param duration: The duration of the mute
        :param reason: the reason of the mute
        """

        perm = await Check().check(ctx, user)
        if perm is False:
            return

        guild = ctx.message.guild
        guildY = GuildDB.get_one(guild.id)
        userY = UserDB.get_one(user.id)

        unit = duration[-1]
        if unit == 's':
            time = int(duration[:-1])
        elif unit == 'm':
            time = int(duration[:-1]) * 60
        elif unit == 'h':
            time = int(duration[:-1]) * 3600
        elif unit == 'd':
            time = int(duration[:-1]) * 86400
        else:
            return await ctx.send('Invalid Unit! Use `s`, `m`, `h` or `d`.')

        if MuteDB.is_muted(userY, guildY):
            return await ctx.send('This user is already muted, you should '
                                  'unmute him first.')

        role = discord.utils.get(ctx.guild.roles, name="Muted")
        if not role:
            role = await ctx.guild.create_role(
                name="Muted",
                permissions=discord.Permissions.none(),
                reason="Mute Role")
            for chan in ctx.guild.text_channels:
                await chan.set_permissions(role, send_messages=False)
        await user.add_roles(role)

        MuteDB.set_mute(userY, guildY)

        id = await SanctionMethod().create_sanction(user, 'Mute',
                                                    ctx.message.author, guild,
                                                    reason, time)
        em = await Embeds().format_mod_embed(ctx, user, ctx.message.author,
                                             reason, 'mute', id, duration)

        await self.log_send(ctx, ctx.message.guild.id, em)

        await asyncio.sleep(time)

        if MuteDB.is_muted(userY, guildY):
            await ctx.invoke(self.unmute, user, True)
示例#24
0
    async def setup(self, ctx):

        # Get guild param
        guild = GuildDB.get_one(ctx.message.guild.id)

        # Create check
        def check(reaction, user):
            return (user == ctx.message.author) and str(reaction.emoji)

        def msgcheck(m):
            return m.author == ctx.message.author

        # Check if already setup
        if guild.setup:
            return await ctx.send(
                "The setup has already been done. "
                "If you want to restore it you should use : **--setting reset**"
            )

        reactions = ['✅', '❌']  # Store reactions

        await ctx.send("Hey ! Let's setup your server ;) ", delete_after=3)

        # Create logging Channel
        guild.logging = True
        overwrite = {
            ctx.guild.default_role:
            discord.PermissionOverwrite(send_messages=False),
            ctx.guild.me:
            discord.PermissionOverwrite(send_messages=True)
        }

        log = discord.utils.get(ctx.guild.text_channels, name="yumebot-log")
        if not isinstance(log, discord.TextChannel):
            try:
                log = await ctx.guild.create_text_channel("yumebot-log",
                                                          overwrites=overwrite)
            except discord.Forbidden:
                await ctx.send("I don't have all the permissions required")

            except discord.HTTPException:
                print("HTTP Exception in setting yumebot-log")

            else:
                guild.log_chan = str(log.id)

        # Welcome / Leave
        msg = await ctx.send("Do you want to activate the Welcome/Leave msg ?")

        [await msg.add_reaction(reaction) for reaction in reactions]
        try:
            reaction, user = await self.bot.wait_for('reaction_add',
                                                     check=check,
                                                     timeout=120)
        except asyncio.TimeoutError:
            await ctx.send('👎', delete_after=3)
        else:
            if reaction.emoji == '✅':
                await msg.delete()
                msg = await ctx.send(
                    'Please mention a Channel !\nEx: `#general`')
                try:
                    m = await self.bot.wait_for('message',
                                                timeout=120,
                                                check=msgcheck)
                except asyncio.TimeoutError:
                    return await ctx.send('👎', delete_after=3)
                try:
                    text_channel = m.channel_mentions[0]
                except IndexError:
                    text_channel = ctx.message.channel

                guild.greet = True
                guild.greet_chan = str(text_channel.id)
            elif reaction.emoji == '❌':
                guild.greet = False
        await msg.delete()

        guild.color = False
        guild.blacklist = False
        print("send detecting")

        # Mods & Admins role
        await ctx.send('Detecting mod and admin role...', delete_after=5)
        for role in ctx.guild.roles:
            if GuildDB.exists_in_admin(role.id, ctx.guild.id):
                GuildDB.remove_admin(role.id, ctx.guild.id)
            if role.permissions.administrator or role.permissions.manage_guild is True:
                GuildDB.set_admin(role.id, ctx.message.guild.id)
            elif role.permissions.ban_members or role.permissions.kick_members is True:
                GuildDB.set_mod(role.id, ctx.message.guild.id)
        await ctx.send('Setup is now done ! Have a good time')

        guild.setup = True
        GuildDB.update_guild(guild)
示例#25
0
 async def reset(self, ctx):
     guild = GuildDB.get_one(ctx.message.guild.id)
     guild.setup = False
     GuildDB.update_guild(guild)
     await ctx.invoke(self.setup)
示例#26
0
    async def on_message(self, message: discord.Message):
        """

        :param message: The message that has been sent
        """
        user = message.author

        if user.bot is True or message.guild is None:
            return

        if message.guild.id == '264445053596991498':
            return

        bucket = self._cd.get_bucket(message)
        retry_after = bucket.update_rate_limit()
        if retry_after:
            return

        userY = UserDB.get_one(user.id)
        guildY = GuildDB.get_one(message.guild.id)
        rankings = RankingsDB.get_user(userY, guildY)

        if not rankings:
            RankingsDB.create_ranking(userY, guildY)
            rankings = RankingsDB.get_user(userY, guildY)

        if rankings['level'] < 3:
            gain = randint(2, 12)
        elif 3 <= rankings['level'] < 6:
            gain = randint(8, 20)
        elif 6 <= rankings['level'] < 10:
            gain = randint(12, 20)
        elif 10 <= rankings['level'] < 20:
            gain = randint(12, 22)
        else:
            gain = randint(15, 25)

        rankings['xp'] += gain
        rankings['total'] += gain

        if rankings['xp'] >= rankings['reach']:
            rankings['level'] += 1
            if rankings["level"] > 39:
                rankings['reach'] = round(rankings['reach'] * 1.02)
            if 39 >= rankings["level"] > 21:
                rankings['reach'] = round(rankings['reach'] * 1.05)
            elif 21 >= rankings["level"] > 10:
                rankings['reach'] = round(rankings['reach'] * 1.1)
            elif 10 >= rankings["level"] > 6:
                rankings['reach'] = round(rankings['reach'] * 1.3)
            else:
                rankings['reach'] = round(rankings['reach'] * 1.6)
            rankings['xp'] = 0

            try:
                await message.channel.send("{} is now level {}.".format(
                    user.name, rankings['level']),
                                           delete_after=2)
            except discord.HTTPException:
                pass
            RankingsDB.update_user(userY, guildY, rankings)
            row = RoleDB.get_one_from_level(rankings['level'], guildY)
            if row:
                try:
                    role = discord.utils.get(message.guild.roles,
                                             id=int(row["role_id"]))
                    await user.add_roles(role)
                except discord.HTTPException:
                    pass

        RankingsDB.update_user(userY, guildY, rankings)
示例#27
0
 async def on_guild_update(self, before, after):
     if before.name != after.name:
         name = "{}".format(after.name.lower())
         GuildDB.update_name(after.id, name)