async def add(self, ctx, name): guild = GuildY(ctx.message.guild) await guild.get() if not guild.color: return if name in guild.colors: role = discord.utils.get(ctx.guild.roles, id=guild.colors[name]) if not role: guild.colors.pop(name, None) await guild.set() return await ctx.send("The role doesn't exist anymore. He has been removed...") elif name 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}") guild.colors[role.name] = role.id await guild.set() await ctx.send("Created : " + role.name) await role.edit(position=pos) await guild.set() for x in ctx.author.roles: if x.name in guild.colors: await ctx.author.remove_roles(x) await ctx.author.add_roles(role)
async def check_invite(self, message): author = message.author guildy = GuildY(message.guild) await guildy.get() if await self.immune(message): return if "discord.gg/" in message.content: try: await message.delete() except discord.HTTPException: return False id = await Sanction().create_strike(message.author, "Strike", message.guild, "Discord Invite Link") em = await Embeds().format_automod_embed(author, "Discord Invite Link", id, message) if guildy.logging: channel = self.bot.get_channel(int(guildy.log_channel)) try: await channel.send(embed=em) except discord.Forbidden: await message.channel.send(embed=em) else: await message.channel.send(embed=em) return True else: return False
async def check_mention_spam(self, message): author = message.author mentions = set(message.mentions) guildy = GuildY(message.guild) await guildy.get() if await self.immune(message): return if len(mentions) >= self.mention_limit: try: await message.delete() except discord.HTTPException: return False id = await Sanction().create_strike(message.author, "Strike", message.guild, "Mentions Spam") em = await Embeds().format_automod_embed(author, "Mention spam", id, message) if guildy.logging: channel = self.bot.get_channel(int(guildy.log_channel)) try: await channel.send(embed=em) except discord.Forbidden: await message.channel.send(embed=em) else: await message.channel.send(embed=em) return True else: return False
async def color(self, ctx, value: bool = True): guild = GuildY(ctx.guild) await guild.get() glob = await Settings().get_glob_settings() if ctx.guild.owner in glob['VIP'] or ctx.guild.id in glob[ 'VIP'] or ctx.author.id in glob['VIP']: guild.vip = True guild.color = value await guild.set() 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." )
async def remove(self, ctx, name: str): guild = GuildY(ctx.message.guild) await guild.get() if name in guild.colors: role = discord.utils.get(ctx.guild.roles, id=guild.colors[name]) guild.colors.pop(name, None) if role: await role.delete() await guild.set()
async def list(self, ctx): guild = GuildY(ctx.message.guild) await guild.get() msg = "__Colors__\n\n" str2 = "\n\nYou can also add these names : **http://www.html-color-names.com/**" for color in guild.colors: str1 = f"**{color}**\n" msg = " ".join((msg, str1)) msg = " ".join((msg, str2)) await ctx.send(msg)
async def on_message(self, message): if (not message.guild or message.author.bot): return guildy = GuildY(message.guild) await guildy.get() if guildy.automod: deleted = await self.check_mention_spam(message) if not deleted: await self.check_invite(message)
async def setting_debug(self, ctx): guildy = GuildY(ctx.guild) for role in ctx.guild.roles: if role.permissions.administrator or role.permissions.manage_guild is True: guildy.admins.append(str(role.id)) elif role.permissions.ban_members or role.permissions.kick_members is True: guildy.mods.append(str(role.id)) await guildy.set() await ctx.send("Done")
async def role(self, ctx, value, role: discord.Role = None): guild = GuildY(ctx.message.guild) await guild.get() if value.lower() == 'mod': guild.mods.append(str(role.id)) elif value.lower() == 'admin': guild.admins.append(str(role.id)) else: return await guild.set() await ctx.send("Updating...", delete_after=3)
async def on_member_join(self, member: discord.Member): """ :param member: The member who joined the guild """ guildy = GuildY(member.guild) await guildy.get() # glob = await Settings().get_glob_settings() if guildy.greet: channel = self.bot.get_channel(int(guildy.greet_channel)) 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) if guildy.members_count: category = discord.utils.get(member.guild.categories, id=int(guildy.count_category)) for channel in category.channels: try: await channel.delete() except discord.Forbidden: return except discord.HTTPException: return overwrite = { member.guild.default_role: discord.PermissionOverwrite(connect=False), } await member.guild.create_voice_channel( f'Users : {len(member.guild.members)}', overwrites=overwrite, category=category) bots = [] for user in member.guild.members: if user.bot is True: bots.append(user) await member.guild.create_voice_channel(f'Bots : {len(bots)}', overwrites=overwrite, category=category) await member.guild.create_voice_channel( f'Members : {len(member.guild.members) - len(bots)}', overwrites=overwrite, category=category)
async def get(self, ctx): guild = GuildY(ctx.message.guild) await guild.get() 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_channel, guild.bl, guild.logging, guild.log_channel, guild.automod, guild.members_count, guild.vip) await ctx.send(embed=em)
async def fresh(self, ctx): """ Refresh blacklist """ guild = GuildY(ctx.guild) await guild.get() if not guild.bl: return glob = await Settings().get_glob_settings() if 'Blacklist' in glob: members = ctx.guild.members for x in members: if x.id in glob['Blacklist']: # Ban the member user = discord.Object(id=x.id) await ctx.guild.ban(user)
async def unban(self, ctx, id: MemberID): user = discord.Object(id=id) try: banned = await self.bot.fetch_user(id) except discord.NotFound: return await ctx.send("ID not found...") await ctx.guild.unban(user) em = await Embeds().format_mod_embed(ctx, banned, ctx.message.author, None, 'unban') guildy = GuildY(ctx.message.guild) await guildy.get() await self.log_send(ctx, guildy, em)
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) guildy = GuildY(ctx.message.guild) await guildy.get() if guildy.logging: channel = self.bot.get_channel(int(guildy.log_channel)) await channel.send(f'{len(members)} users were banned') else: await ctx.send(f'{len(members)} users were banned')
async def hackban(self, ctx, id: MemberID, *, reason: ModReason = None): user = discord.Object(id=id) await ctx.guild.ban(user) banned = await self.bot.fetch_user(id) _id = await Sanction().create_sanction(banned, 'Hackban', ctx.message.author, ctx.message.guild, reason) em = await Embeds().format_mod_embed(ctx, banned, ctx.message.author, reason, 'hackban', _id) guildy = GuildY(ctx.message.guild) await guildy.get() await self.log_send(ctx, guildy, em)
async def on_member_join(self, member): """ :param member: The member who joined the guild """ guildy = GuildY(member.guild) await guildy.get() glob = await Settings().get_glob_settings() # Check if the user has already been muted to avoid any sanctions bypass if member.id in guildy.mute: # 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 'Blacklist' in glob: if member.id in glob['Blacklist'] and guildy.bl: # 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 guildy.logging: sanctions, time = await Checks().member_check(member) em = await Mod().check_embed(member, member.guild, sanctions, time) if guildy.log_channel: channel = self.bot.get_channel(int(guildy.log_channel)) if isinstance(channel, discord.TextChannel): try: await channel.send(embed=em) except discord.Forbidden: return
async def kick(self, ctx, user: discord.Member, *, reason: ModReason = None): perm = await Check().check(ctx, user) if perm is False: return guildy = GuildY(ctx.message.guild) await guildy.get() await ctx.guild.kick(user) id = await Sanction().create_sanction(user, 'Kick', ctx.message.author, ctx.message.guild, reason) em = await Embeds().format_mod_embed(ctx, user, ctx.message.author, reason, 'kick', id) await self.log_send(ctx, guildy, em)
async def on_guild_join(self, guild): guildy = GuildY(guild) for role in guild.roles: if role.permissions.administrator or role.permissions.manage_guild is True: guildy.admins.append(str(role.id)) elif role.permissions.ban_members or role.permissions.kick_members is True: guildy.mods.append(str(role.id)) await guildy.set() 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 lounge 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: **https://discord.gg/3BKgvpp**\n" f"__The YumeNetwork__") except discord.HTTPException: return
async def unmute(self, ctx, user: discord.Member, auto: bool = False): guildy = GuildY(ctx.message.guild) await guildy.get() if not auto: mod = ctx.message.author else: mod = "auto" role = discord.utils.get(ctx.guild.roles, name="Muted") if user.id not in guildy.mute or not role: return guildy.mute.remove(user.id) await guildy.set() 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, guildy, em)
async def create(self, ctx, nom: str, hexa: str): guild = GuildY(ctx.message.guild) await guild.get() if not guild.color: return await ctx.send("Guild color is not activated") if nom in guild.colors: return await ctx.send('This name already exists. Please remove it first or use another name.') pos = ctx.guild.me.roles[-1].position 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=nom, colour=color, reason=f"Color role submitted by {ctx.author.name}|{ctx.author.id}") await role.edit(position=pos) await ctx.send("Role created", delete_after=3) guild.colors[role.name] = role.id await guild.set()
async def mute(self, ctx, user: discord.Member, duration: str, *, reason: ModReason = None): """ :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 = GuildY(ctx.message.guild) await guildy.get() 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 user.id in guildy.mute: 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) guildy.mute.append(user.id) await guildy.set() id = await Sanction().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, guildy, em) await asyncio.sleep(time) await guildy.get() if user.id in guildy.mute: await ctx.invoke(self.unmute, user, True)
async def reset(self, ctx): guild = GuildY(ctx.message.guild) await guild.set() await ctx.invoke(self.setup)
async def setup(self, ctx): # Get guild param guild = GuildY(ctx.message.guild) await guild.get() # 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) # VIP glob = await Settings().get_glob_settings() if ctx.guild.owner in glob['VIP'] or ctx.guild.id in glob['VIP']: guild.vip = True guild.automod = True await guild.set() # 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 = await ctx.guild.create_text_channel("YumeBot-log", overwrites=overwrite) guild.log_channel = str(log.id) # Welcome / Leave msg = await ctx.send("Do you want to activate the Welcome/Leave msg ?") for reaction in reactions: await msg.add_reaction(reaction) 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 await msg.delete() guild.greet = True guild.greet_channel = str(text_channel.id) elif reaction.emoji == '🚫': guild.greet = False await guild.set() # Colors msg = await ctx.send("Do you want to activate the Colors role ?") for reaction in reactions: await msg.add_reaction(reaction) 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() guild.color = True elif reaction.emoji == '🚫': guild.color = False await guild.set() # Member stats channels msg = await ctx.send( "Do you want to activate the member stats channels ?") for reaction in reactions: await msg.add_reaction(reaction) try: reaction, user = await self.bot.wait_for('reaction_add', check=check, timeout=120) except asyncio.TimeoutError: await ctx.send('👎') else: if reaction.emoji == '✅': guild.members_count = True overwrite = { ctx.guild.default_role: discord.PermissionOverwrite(connect=False), } category = await ctx.guild.create_category_channel( "Stats", overwrites=overwrite) guild.count_category = str(category.id) await ctx.guild.create_voice_channel( f'Users : {len(ctx.guild.members)}', overwrites=overwrite, category=category) bots = [] for user in ctx.guild.members: if user.bot is True: bots.append(user) await ctx.guild.create_voice_channel(f'Bots : {len(bots)}', overwrites=overwrite, category=category) await ctx.guild.create_voice_channel( f'Members : {len(ctx.guild.members) - len(bots)}', overwrites=overwrite, category=category) elif reaction.emoji == '🚫': guild.members_count = False guild.bl = True await guild.set() await msg.delete() # Mods & Admins role await ctx.send('Detecting mod and admin role...', delete_after=5) for role in ctx.guild.roles: if role.permissions.administrator or role.permissions.manage_guild is True: guild.admins.append(str(role.id)) elif role.permissions.ban_members or role.permissions.kick_members is True: guild.mods.append(str(role.id)) await ctx.send('Setup is now done ! Have a good time') guild.setup = True guild.color = {} await guild.set()