async def unmute(self, ctx, user: discord.User = None): if user is None: return await Help.unmute(self, ctx) try: member, author_member = await member_check(self, ctx, user) except discord.NotFound: return await main.error_embed(ctx, 'Couldn\'t find that member') if member.top_role == author_member.top_role: await main.error_embed(ctx, f'You don\'t outrank {member.mention}') else: if self.bot.get_guild(main.ids(1)).get_role( main.ids(12)) not in member.roles: await main.error_embed(ctx, 'That member is not muted') else: await member.remove_roles( self.bot.get_guild(main.ids(1)).get_role(main.ids(12))) try: dm_channel = await member.create_dm() await main.dm_embed( 'Unmuted', 'You have been unmuted in the baritone discord', dm_channel) except (discord.Forbidden, discord.errors.HTTPException): pass channel = await self.bot.fetch_channel(main.ids(5)) await output(member, 'unmuted', channel, '', ctx, '', ctx) main.cur.execute('DELETE FROM rekt WHERE user_id=%s', (user.id, )) main.db.commit()
async def unban(self, ctx, user=None): if user is None: return await Help.unban(self, ctx) try: user_men = str(ctx.message.raw_mentions[0]) except IndexError: user_men = '' b_guild = self.bot.get_guild(main.ids(1)) if user_men != '': unban_user = self.bot.get_user( int(user_men)) # get the user if they mentioned elif (user.isdigit()) and (len(user) == 18): unban_user = self.bot.get_user(int(user)) else: unban_user = None if unban_user is None: await main.error_embed(ctx, 'The user you gave is invalid') else: try: await b_guild.unban(unban_user) await output(await self.bot.fetch_user(user), 'unbanned', await self.bot.fetch_channel(main.ids(5)), '', ctx, '', None) except discord.NotFound: await main.error_embed(ctx, 'That user is not banned')
def role_check(self, member, ig_roles): for y in ig_roles.strip('}{').split(','): if y != '': if self.bot.get_guild( main.ids(1)).get_role(int(y)) in self.bot.get_guild( main.ids(1)).get_member(member).roles: return True
async def on_message_edit(self, message_before, message_after): if message_after.author.discriminator != '0000': if message_after.content != '' and message_before.content != '': main.stat_update( r'UPDATE stats SET edited = edited + 1 WHERE user_id = %s', message_after.author.id) if message_before.author.id != main.ids(0): if str(message_before.channel.id) not in exempt_channels: if message_after.content != message_before.content: # prevent logging embeds loading if message_before.guild is None: jump = 'DMs**' else: jump = f'{message_after.channel.mention}** [(jump)](https://discord.com/channels/{message_after.guild.id}/{message_after.channel.id}/{message_after.id})' em_v = discord.Embed( color=int(main.values(1), 16), description=f'**Message edited in {jump}') em_v.add_field(name='Befored Edit:', value=message_before.content, inline=False) em_v.add_field(name='After Edit:', value=message_after.content, inline=False) em_v.set_footer( text= f'{message_after.author.name} | ID: {message_after.author.id}', icon_url=message_after.author.avatar_url) channel = await self.bot.fetch_channel(main.ids(3)) await channel.send(embed=em_v) print( f'{message_after.author.id} edited a message, Before: \"{message_before.content}\" After: \"{message_after.content}\"' )
async def optout(self, ctx, *, arg=None): b_guild = self.bot.get_guild(main.ids(1)) if arg is None: return await Help.optout(self, ctx) if arg == 'I am sure': channel = await self.bot.fetch_channel(main.ids(5)) try: dchannel = await ctx.author.create_dm() await main.dm_embed( 'Opted out', 'We appreciate you opting out. You have been banned from the server to prevent bypassing our moderation system.', dchannel) except (discord.Forbidden, discord.errors.HTTPException): pass print(f'{ctx.author.id} has been banned for reason: Opted out') await main.channel_embed( ctx, 'User Banned', f'{ctx.author.mention} has been banned for reason: \n```User {ctx.author} has opted out```' ) await main.log_embed( ctx, 'User Banned', f'{ctx.author.mention} has been banned for reason: \n```User {ctx.author} has opted out```', channel, ctx.author) await b_guild.ban(user=ctx.author, reason='Opted out and banned', delete_message_days=7) else: await main.channel_embed( ctx, 'Opt-Out', f'You will be **banned from this server** and **lose all your roles** by continuing. Are you sure you want to opt out? if yes, type `{main.values(0)}optout I am sure`' )
async def on_voice_state_update(self, member, before, after): if before.channel is None: # only reason its 'before' and 'is' is so that before is used and pycharm stops yelling at me b_role = discord.utils.get(member.guild.roles, id=main.ids(14)) await member.add_roles(b_role) print(f'{member.id} joined a voice channel and got the voice role') elif after.channel is None: b_role = discord.utils.get(member.guild.roles, id=main.ids(14)) await member.remove_roles(b_role) print( f'{member.id} left a voice channel and the voice role was removed' )
async def clear(self, ctx, num=None, num2=None): if num is None: return await Help.clear(self, ctx) try: user_men = str(ctx.message.raw_mentions[0]) except IndexError: user_men = '' if ctx.guild is None: await main.error_embed(ctx, 'You cannot use this command in DMs') else: if (user_men == '') and (len(num) != 18) and (num.isdigit()): # make sure a number is given and its not an ID int_num = int(num) if int_num > 0: await ctx.channel.purge(limit=int_num) channel = await self.bot.fetch_channel(main.ids(3)) await main.log_embed(None, 'Bulk messages deleted', f'{ctx.author.mention} cleared {int_num} messages in {ctx.channel.mention}', channel, ctx.author) print(f'{ctx.author.id} cleared {int_num} messages in {ctx.channel}') else: await main.error_embed(ctx, 'You need to give a positive non zero number') else: int_num2 = int(num2) if int_num2 > 0: limit = 0 if user_men != '': clear_member = self.bot.get_user(int(user_men)) # get the user if they mentioned elif (num.isdigit()) and (len(num) == 18): clear_member = self.bot.get_user(int(num)) # get the user if they gave an ID else: clear_member = ctx.guild.get_member_named(num) # get the member if they gave a name with/without discrimitor if clear_member is None: await main.error_embed(ctx, 'The user you gave is either invalid or the name you gave is not a member') else: async for message in ctx.channel.history(limit=None): limit += 1 if message.author == clear_member: int_num2 -= 1 if int_num2 == 0: break def member_check(m): return m.author == clear_member await ctx.channel.purge(limit=limit, check=member_check) try: await ctx.message.delete() # delete the command except discord.NotFound: # ignore error if it was already deleted pass channel = await self.bot.fetch_channel(main.ids(3)) await main.log_embed(ctx, 'Bulk messages deleted', f'{ctx.author.mention} cleared {num2} messages in {ctx.channel.mention} from {clear_member.mention}', channel, clear_member) print(f'{ctx.author.id} cleared {num2} messages in {ctx.channel.id} from {clear_member.id}') else: await main.error_embed(ctx, 'You need to give a positive non zero number')
async def on_message(self, message): if message.author.discriminator != '0000': main.stat_update( r'UPDATE stats SET messages = messages + 1 WHERE user_id = %s', message.author.id) if (message.guild is None) and (message.author.id != main.ids(0)) and (str( message.author.id) not in exempt_users): channel = self.bot.get_guild(main.ids(1)).get_channel( main.ids(4)) await main.log_embed(None, 'I have recieved a DM', message.content, channel, message.author) print(f'{message.author.id} dmed me \"{message.content}\"')
async def regex_respond(self, message): b_guild = self.bot.get_guild(main.ids(1)) main.cur.execute('SELECT * FROM response WHERE delete=false') match_regex = main.cur.fetchall() for x in match_regex: if re.search(x[0], message.content.lower()) is not None: main.stat_update( r'UPDATE stats SET triggered_responses = triggered_responses + 1 WHERE user_id = %s', message.author.id) if (b_guild.get_member(main.ids(0)) in message.mentions) or (message.content.startswith('!')): title = '' if x[1].lower() == 'none' else x[1] desc = '' if x[2].lower() == 'none' else x[2] await main.channel_embed(message.channel, title, desc) print( f'{message.author.id} manually triggered response #{x[5]}') if message.guild is not None: await message.delete() elif role_check(self, message.author.id, x[4]) is not True: title = '' if x[1].lower() == 'none' else x[1] desc = '' if x[2].lower() == 'none' else x[2] print(f'{message.author.id} triggered response #{x[5]}') em_v = discord.Embed(color=int(main.values(1), 16), title=title, description=desc) em_v.set_footer( text=f'{message.author.name} | ID: {message.author.id}', icon_url=message.author.avatar_url) auto_response = await message.channel.send(embed=em_v) await auto_response.add_reaction('🗑️') def check(dreaction, duser): try: return (auto_response.id == dreaction.message.id) and ( duser.id == message.author.id or staffr_check(self, duser.id) is True) except AttributeError: pass try: reaction, user = await self.bot.wait_for('reaction_add', timeout=1800, check=check) except asyncio.TimeoutError: pass else: if str(reaction) == '🗑️' and user.id != int(main.ids(0)): try: await auto_response.delete() except AttributeError: pass
async def mute(self, ctx, user: discord.User = None, mtime: TimeConverter = None, *, reason=None): if user is None: return await Help.mute(self, ctx) try: member, author_member = await member_check(self, ctx, user) except discord.NotFound: return await main.error_embed(ctx, 'Couldn\'t find that member') if member.top_role == author_member.top_role: await main.error_embed(ctx, f'You don\'t outrank {member.mention}') elif mtime is None: await main.error_embed( ctx, 'You need to give a reason or amount of time to mute') elif str(mtime).strip("')(").split(", '")[0] != '0' and reason is None: await main.error_embed(ctx, 'You need to give a reason') else: if self.bot.get_guild(main.ids(1)).get_role( main.ids(12)) in member.roles: await main.error_embed(ctx, 'That member is already muted') else: time_reason = str(mtime)[1:-2].split(', ') reason = '' if reason is None else reason if time_reason[0] == '0': reason_real, reason_time = time_reason[1][ 1:] + ' ' + reason, 'indefinitely' else: reason_real, reason_time = reason, f'for {time_reason[1][1:]}' await member.add_roles( self.bot.get_guild(main.ids(1)).get_role(main.ids(12))) try: dm_channel = await member.create_dm() await main.dm_embed( 'Muted', f'You have been muted in the baritone discord {reason_time}, reason: \n```{reason_real}```', dm_channel) except (discord.Forbidden, discord.errors.HTTPException): pass channel = await self.bot.fetch_channel(main.ids(5)) await output(member, 'muted', channel, f' {reason_time}', ctx, f'for reason: \n```{reason_real}```', ctx) main.cur.execute( 'INSERT INTO rekt(user_id, action, expiry, punisher) VALUES(%s, %s, %s, %s)', (member.id, 'muted', int(time_reason[0]), ctx.author.id)) main.db.commit()
async def releases(self, ctx): if await role_add(self, ctx, main.ids(13), 'You already have the Releases role', 'add') is True: await main.channel_embed( ctx, 'Releases role obtained', 'You will now be pinged when a new release is made!') print(f'{ctx.author.id} gave themselfs releases role')
async def unignore(self, ctx): if await role_add(self, ctx, main.ids(11), 'You don\'t have the Ignore role', 'remove') is True: await main.channel_embed( ctx, 'Ignored role removed', 'Your messages will now trigger the response regexes.') print(f'{ctx.author.id} removed ignore role')
async def on_message(self, message): if message.author.discriminator != '0000': if not message.content.lower().startswith( main.values(0)) and message.author.id != main.ids(0): if await regex_delete(self, message) is not True: await regex_respond(self, message) await att_paste(message)
async def serverinfo(self, ctx): b_guild = self.bot.get_guild(main.ids(1)) em_v = discord.Embed(color=int(main.values(1), 16), title=f'Server Information: {b_guild.name}') em_v.add_field(name='Owner:', value=f'{b_guild.owner} (ID: {b_guild.owner_id})', inline=False) em_v.add_field(name='Description:', value=b_guild.description, inline=False) em_v.add_field(name='Created:', value=b_guild.created_at.strftime( '%B %d, %Y at %I:%M:%S %p').lstrip('0').replace( ' 0', ' '), inline=False) em_v.add_field(name='Region:', value=b_guild.region, inline=False) em_v.add_field(name=f'Roles ({len(b_guild.roles)-1}):', value=(' '.join([str(r.mention) for r in b_guild.roles][1:]) + '\u200b'), inline=False) em_v.add_field(name='Text Channels:', value=str(len(b_guild.text_channels)), inline=True) em_v.add_field(name='Voice Channels:', value=str(len(b_guild.voice_channels)), inline=True) em_v.add_field(name='Members:', value=b_guild.member_count, inline=True) em_v.set_footer(text=f'ID: {b_guild.id}') em_v.set_thumbnail(url=b_guild.icon_url) await ctx.send(embed=em_v)
async def userinfo(self, ctx, user_id=None): b_guild = self.bot.get_guild(main.ids(1)) try: user_men = str(ctx.message.raw_mentions[0]) except IndexError: user_men = '' if user_id is None: return await Help.userinfo(self, ctx) if user_men != '': clear_member = await self.bot.fetch_user( int(user_men)) # get the user if they mentioned elif (user_id.isdigit()) and (len(user_id) == 18): clear_member = await self.bot.fetch_user( int(user_id)) # get the user if they gave an ID else: clear_member = b_guild.get_member_named( user_id ) # get the member if they gave a name with/without discrimitor if clear_member is None: await main.error_embed(ctx, 'The user you gave is invalid') else: if b_guild.get_member(clear_member.id) is not None: member = b_guild.get_member(clear_member.id) await varistuff(ctx, member, ismember=True) else: member = await self.bot.fetch_user(clear_member.id) await varistuff(ctx, member, ismember=False)
async def me(self, ctx): b_guild = self.bot.get_guild(main.ids(1)) member_check = b_guild.get_member(ctx.author.id) if member_check is not None: await varistuff(ctx, member_check, ismember=True) else: await varistuff(ctx, ctx.author, ismember=False)
async def defaultn(self, ctx): b_guild = self.bot.get_guild(main.ids(1)) await b_guild.me.edit(nick='Franky') await main.channel_embed( ctx, 'Nick set', 'Set the bot\'s nickname in this server to the default (Franky)') print(f'{ctx.author.id} set the nick to default')
async def emote(self, ctx, name=None, url=None): b_guild = self.bot.get_guild(main.ids(1)) if name is None: return await Help.emote(self, ctx) if len(ctx.message.attachments) > 0: if ctx.message.attachments[0].url.lower().endswith( ('.png', '.jpeg', '.jpg', '.gif')): await create_emote(ctx, name, ctx.message.attachments[0].url, b_guild) else: await main.error_embed( ctx, 'Invalid attachment, must be `.png` `.gif` `.jpeg` or `.jpg` or an image url' ) elif url is None: await main.error_embed( ctx, 'You need to either provide a link or attach a `.png` `.gif` `.jpeg` or `.jpg` to create an emote' ) else: if url.endswith(('.png', '.jpeg', '.jpg', '.gif')): await create_emote(ctx, name, url, b_guild) else: await main.error_embed( ctx, 'Url needs to end with `.png` `.gif` `.jpeg` or `.jpg`')
async def ignore(self, ctx): if await role_add(self, ctx, main.ids(11), 'You already have the Ignore role', 'add') is True: await main.channel_embed( ctx, 'Ignored role obtained', 'Your messages will not trigger the response regexes unless you ping me' ) print(f'{ctx.author.id} gave themselfs ignore role')
async def loops(self): log_channel = await self.bot.fetch_channel(main.ids(3)) async for message in log_channel.history(limit=1000): if (message.created_at + timedelta(hours=24)) < datetime.utcnow(): await message.delete() print('cleared logs older then 24 hours in the logs channel') main.cur.execute('SELECT * FROM rekt') for i in main.cur.fetchall(): if i[2] != 0: if i[2] - int(time()) <= 0: await unmute_embeds( self.bot.get_guild(main.ids(1)), await self.bot.fetch_channel(main.ids(5)), i) if datetime.utcnow().hour == 1 and datetime.utcnow( ).minute == 0 and datetime.utcnow().second <= 1: print('Dailies reset!') main.cur.execute('UPDATE stats SET daily = false')
async def unreleases(self, ctx): if await role_add(self, ctx, main.ids(13), 'You don\'t have the Releases role', 'remove') is True: await main.channel_embed( ctx, 'Releases role removed', 'You now will not be pinged when a new release is made .') print(f'{ctx.author.id} removed releases role')
async def nick(self, ctx, *, name=None): b_guild = self.bot.get_guild(main.ids(1)) if name is None: return await Help.nick(self, ctx) await b_guild.me.edit(nick=name) await main.channel_embed( ctx, 'Nick set', f'Set the bot\'s nickname in this server to `{name}`') print(f'{ctx.author.id} set the nick to {name}')
async def on_message_delete(self, message): if message.author.discriminator != '0000': main.stat_update( r'UPDATE stats SET deleted = deleted + 1 WHERE user_id = %s', message.author.id) if (message.author.id != main.ids(0)) and (str(message.channel.id) not in exempt_channels): channel = await self.bot.fetch_channel(main.ids(3)) if message.guild is None: del_channel = 'DMs' else: del_channel = message.channel.mention await main.log_embed( None, None, f'**Message deleted in {del_channel}** \n{message.content}', channel, message.author) print( f'{message.author.id} message was deleted: \"{message.content}\"' )
async def on_member_join(self, member): if member.name.startswith(('!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/')): await member.edit(nick=f'z{member.name}') print( f'{member.id} joined with a name that puts them to the top of the list, so z was added infront' ) channel = await self.bot.fetch_channel(main.ids(2)) await main.log_embed(None, 'User Joined', None, channel, member) main.cur.execute('SELECT user_id FROM rekt WHERE user_id=%s', (member.id, )) if main.cur.fetchone() is not None: await member.add_roles( self.bot.get_guild(main.ids(1)).get_role(main.ids(12))) print( f'{member.id} joined the server and was given the mute role because they are still muted' ) else: print(f'{member.id} joined the server')
async def ban_embeds(reasons): try: dm_channel = await member.create_dm() await main.dm_embed( 'Banned', f'You have been banned from the baritone discord for reason: \n```{reasons}```', dm_channel) except (discord.Forbidden, discord.errors.HTTPException): pass channel = await self.bot.fetch_channel(main.ids(5)) await output(member, 'banned', channel, '', ctx, f'for reason: \n```{reasons}```', ctx)
def staffr_check(self, mmember): for x in [ main.ids(8), main.ids(10), main.ids(7), main.ids(9), main.ids(6) ]: if self.bot.get_guild(main.ids(1)).get_role(x) in self.bot.get_guild( main.ids(1)).get_member(mmember).roles: return True
async def listun(self, ctx): main.cur.execute("SELECT ids FROM exempted WHERE type='channel'" ) # don't look at the lines below slist = [ self.bot.get_channel(int(line)) for line in [str(item[0]) for item in main.cur.fetchall()] ] klist = [(str(channel.id)) for channel in [ x for x in self.bot.get_guild(main.ids(1)).text_channels if x not in slist ]] await main.channel_embed(ctx, f'Unexempted Channels ({len(klist)})', f'<#{(">, <#".join(klist))}>')
async def role_add(self, ctx, role, role_words, action): b_guild = self.bot.get_guild(main.ids(1)) member_check = b_guild.get_member(ctx.author.id) b_role = discord.utils.get(b_guild.roles, id=role) if action == 'remove': if b_role not in member_check.roles: await main.error_embed(ctx, role_words) else: await member_check.remove_roles(b_role) return True elif action == 'add': if b_role in member_check.roles: await main.error_embed(ctx, role_words) else: await member_check.add_roles(b_role) return True
async def top_formatter(self, topp): desc, x = '', 0 for i in topp[:10]: x += 1 u_id, txp = int(str(i).split(' ')[1][:-1]), int( str(i).split(' ')[0][1:-1]) try: user = (await self.bot.get_guild(main.ids(1)).fetch_member(u_id)).name except discord.NotFound: try: user = (await self.bot.fetch_user(u_id)).name except discord.NotFound: user = u_id desc += f'**{x}.** {user} - `{txp}`\n' return desc
async def unmute_embeds(b_guild, modlog_channel, i): class RektAuthor: author = b_guild.get_member(i[3]) if b_guild.get_member(i[0]) is not None: try: dm_channel = await b_guild.get_member(i[0]).create_dm() await main.dm_embed( 'Unmuted', 'You have been unmuted in the baritone discord', dm_channel) except (discord.Forbidden, discord.errors.HTTPException): pass await main.log_embed( RektAuthor(), 'User Unmuted', f'{b_guild.get_member(i[0]).mention} has been unmuted', modlog_channel, b_guild.get_member(i[0])) await b_guild.get_member(i[0] ).remove_roles(b_guild.get_role(main.ids(12))) print(f'{i[0]} was unmuted automatically') main.cur.execute('DELETE FROM rekt WHERE user_id=%s', (i[0], )) main.db.commit()