async def uncap(self, ctx, mention): """Mod command: Remove the dunce cap from a mentioned user. Args: mention (User) The user to uncap. Returns: None """ if len(ctx.message.mentions) == 0: await ctx.send( "`!uncap`: The user to be uncapped must be @-mentioned as the first argument." ) return target_user = ctx.message.mentions[0] cap_role = find_role(ctx.guild, CONFIG['CapRole']) staff_channel = find_channel(ctx.guild, CONFIG['StaffChannel']) notifications_channel = find_channel(ctx.guild, CONFIG['NotificationsChannel']) if not cap_role: await ctx.send( '`!uncap`: There was an error attempting to uncap {}.'.format( target_user.mention)) return # Moderator uses !cap if is_admin(ctx.author) or is_mod(ctx.author): if not user_has_role(target_user, CONFIG['CapRole']): await ctx.send( 'Are you blind, {}? You can\'t uncap {} '.format( ctx.author.mention, target_user.display_name) + 'if they\'re not wearing the Dunce Cap!') else: await target_user.remove_roles(cap_role) await target_user.send('Your dunce cap is lifted.') await staff_channel.send('{} has been uncapped by {}!'.format( target_user.mention, ctx.author.mention)) await notifications_channel.send( '{} has been uncapped by {}!'.format( target_user.display_name, ctx.author.display_name)) return else: # Non-moderator attempts to use !uncap if not user_has_role(target_user, CONFIG['CapRole']): await ctx.send( '`!uncap`: How can you uncap someone who isn\'t ' + 'wearing a cap to begin with? Reconsider your life choices.' ) else: await ctx.send( '`!uncap`: You are not strong enough to discard the mighty cap.' )
async def on_member_join(member): welcome_channel = find_channel(member.guild, CONFIG['WelcomeChannel']) rules_channel = find_channel(member.guild, CONFIG['RulesChannel']) new_role = find_role(member.guild, CONFIG['NewRole']) await member.add_roles(new_role) await welcome_channel.send( 'Hello and welcome to the Megachannel, {0}! '.format( member.display_name) + 'Please make sure you read the {0} first '.format( rules_channel.mention) + '- they\'re short, simple, and easy to follow. ' + 'Once you have read and agreed to the rules, you will have access to ' + 'all the regular channels on the server!')
async def profile(self, ctx, mention): """Look up a user's profile, if they have made a post in #profiles. Args: mention (String: user mention) The user's profile to look up. Returns: None """ print('Context: {}'.format(ctx)) if user_has_role(ctx.author, CONFIG['ConfirmedRole']): if len(ctx.message.mentions) < 1 or len(ctx.message.mentions) > 1: await ctx.author.send('`!profile`: You must mention one user whose profile you wish to look up.') return target_user = ctx.message.mentions[0] print('User: {}'.format(target_user)) profiles_channel = find_channel(ctx.guild, CONFIG['ProfilesChannel']) profile = None async for message in profiles_channel.history(limit = 100 + len(ctx.guild.members)): if message.author == target_user: profile = message await ctx.send('You can find {}\'s profile at: {}'.format(target_user.display_name, message.jump_url)) return if not profile: await ctx.send('{} has not yet posted to {}.'.format(target_user.display_name, profiles_channel.mention)) else: await ctx.author.send('You must agree to the rules to view any profiles.')
async def agree(self, ctx): """Agree to the rules and join the server.""" member = ctx.author is_new = user_has_role(member, CONFIG['NewRole']) new_role = find_role(ctx.guild, CONFIG['NewRole']) confirmed_role = find_role(ctx.guild, CONFIG['ConfirmedRole']) profiles_channel = find_channel(ctx.guild, CONFIG['ProfilesChannel']) if is_new and CONFIG['WelcomeChannel'] in ctx.message.channel.name: await member.remove_roles(new_role) await send_notification(ctx.guild, 'Please welcome our newest member {0} to the Megachannel!'.format(member.mention)) await member.send('You have agreed to the rules of the Megachannel! Please make sure you check back often ' + 'to keep up-to-date with changes.' + '\n\nYou can now use any publicly-available channel; for example, you don\'t have to ' + 'be taking the course that corresponds to a course channel in order to chat there. ' + 'Feel free to head over to the {} channel '.format(profiles_channel.mention) + 'and introduce yourself - this is handy because the Megachannel has users who are in ' + 'different programs and courses who might not know each other! You can also add any ' + 'courses or game developer roles to yourself - type `!help` in a public channel ' + 'to see all available bot commands.' + '\n\nLastly, you may want to mute any channels you\'re not particularly interested in ' + 'as we can get into spirited discussions that can blow up your notifications.') await member.add_roles(confirmed_role) else: await member.send('You have already agreed to the rules on this server.')
async def crap(self, ctx, mention, *, reason='no reason'): """Admin command: Crap a mentioned user. Args: mention (User) The user to crap. Returns: None """ if not is_admin(ctx.author): await ctx.send('No.') return if len(ctx.message.mentions) == 0: await ctx.send("`!crap`: The user to be crapped must be @-mentioned as the first argument.") return target_user = ctx.message.mentions[0] crap_role = find_role(ctx.guild, CONFIG['CrapRole']) notifications_channel = find_channel(ctx.guild, CONFIG['NotificationsChannel']) if not crap_role: await ctx.send('`!crap`: There was an error attempting to crap {}.'.format(target_user.display_name)) return if user_has_role(target_user, CONFIG['CrapRole']): await ctx.send('`!crap`: {} has been double-crapped!'.format(target_user.display_name)) else: await target_user.add_roles(crap_role) await ctx.send('💩💩💩') await notifications_channel.send('{} has been crapped for {}'.format( target_user.display_name, reason))
async def unmonitor(self, ctx, mention): """Admin command: unmonitor a user. Args: ctx (Context) mention (Member) Returns: None """ target_user = ctx.message.mentions[0] if not is_admin(ctx.author): if ctx.author == target_user: notifications_channel = find_channel(ctx.guild, CONFIG['NotificationsChannel']) cap(ctx, ctx.author) await ctx.send("`!unmonitor`: This is an admin-only command. {} has been capped for trying to use it.".format(ctx.author.display_name)) await notifications_channel.send('{} was capped by the `!unmonitor` command!') return if len(ctx.message.mentions) == 0: await ctx.send("`!unmonitor`: The user to be monitored must be @-mentioned as the first argument.") return if target_user in CONFIG['DATA']['monitor']: unwatch(ctx, target_user) await ctx.send('`!unmonitor`: {} has been removed from watch.'.format(target_user.display_name)) CONFIG['DATA']['monitor'].remove(target_user) save_data(CONFIG['DATAFILE']) else: await ctx.send('`!unmonitor`: {} is not on watch.'.format(target_user.display_name))
async def uncrap(self, ctx, mention): """Admin command: Uncrap a mentioned user. Args: mention (User) The user to uncrap. Returns: None """ if not is_admin(ctx.author): await ctx.send('Nope.') return if len(ctx.message.mentions) == 0: await ctx.send("`!uncrap`: The user to be uncrapped must be @-mentioned as the first argument.") return target_user = ctx.message.mentions[0] crap_role = find_role(ctx.guild, CONFIG['CrapRole']) notifications_channel = find_channel(ctx.guild, CONFIG['NotificationsChannel']) if not crap_role: await ctx.send('`!uncrap`: There was an error attempting to uncrap {}.'.format(target_user.display_name)) return if user_has_role(target_user, CONFIG['CrapRole']): await target_user.remove_roles(crap_role) await ctx.send('🚫💩') await notifications_channel.send('{} has been uncrapped.'.format(target_user.display_name)) else: await ctx.send('`!uncrap`: {} doesn\'t appear to be crapped.'.format(target_user.display_name))
async def cap(self, ctx, mention, *, reason='N/A'): """Mod command: Dunce cap a mentioned user. Args: mention (User) The user to cap. Returns: None """ if len(ctx.message.mentions) == 0: await ctx.send( "`!cap`: The user to be capped must be @-mentioned as the first argument." ) return target_user = ctx.message.mentions[0] cap_role = find_role(ctx.guild, CONFIG['CapRole']) staff_channel = find_channel(ctx.guild, CONFIG['StaffChannel']) notifications_channel = find_channel(ctx.guild, CONFIG['NotificationsChannel']) if not cap_role: await ctx.send( '`!cap`: There was an error attempting to cap {}.'.format( target_user.mention)) return # Attempt to cap the Admin if is_admin(target_user): await ctx.author.add_roles(cap_role) await ctx.author.send( 'You have been dunce capped for attempting to dunce cap the admin. ' + 'While you are dunce capped, you will not be able to send messages, ' + 'but you will be able to add reactions to other users\' messages. ' + 'Your dunce cap will be removed after a certain amount of time.' ) await ctx.send( '{} has been capped for trying to cap {} - hoisted by your own petard!' .format(ctx.author.mention, target_user.mention)) await staff_channel.send( '{} has been capped for attempting to cap {}!'.format( ctx.author.mention, target_user.mention)) return # Moderator uses !cap if is_admin(ctx.author) or is_mod(ctx.author): if user_has_role(target_user, CONFIG['CapRole']): await ctx.send('`!cap`: {} is already capped!'.format( target_user.display_name)) else: await target_user.add_roles(cap_role) await ctx.send('WEE WOO WEE WOO') await target_user.send( 'You have been dunce capped for violating a rule. While you are ' + 'dunce capped, you will not be able to send messages, but you will ' + 'be able to add reactions to other users\' messages. The offending ' + 'violation must be remediated, and your dunce cap will be removed ' + 'after a certain amount of time.') await staff_channel.send( '{} has been dunce capped by {} for {}!'.format( target_user.mention, ctx.author.mention, reason)) await notifications_channel.send( '{} has been dunce capped by {}!'.format( target_user.display_name, ctx.author.display_name)) user = get_db_user(conn, cursor, target_user) if not user: cmd = '''INSERT INTO users VALUES (?, ?, 0, 0, 1)''' params = (target_user.id, target_user.name) else: cmd = '''UPDATE users SET times_capped = ? WHERE id == ?''' params = (user[4] + 1, target_user.id) cursor.execute(cmd, params) conn.commit() cmd = '''INSERT INTO notes VALUES (NULL, ?, ?, ?, ?, ?)''' params = (datetime.now(), target_user.id, target_user.name, 'cap', reason) cursor.execute(cmd, params) conn.commit() # Non-moderator uses !cap else: await ctx.send( '`!cap`: You are not worthy to wield the mighty cap.')