Ejemplo n.º 1
0
  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.')
Ejemplo n.º 2
0
  async def role(self, ctx, role):
    """Add a role to yourself so you can be mentioned by the role.

    Args:
      role (String)
        See !roles for a list of current roles.

    Returns:
      None
    """
    if not user_has_role(ctx.author, CONFIG['ConfirmedRole']):
      await ctx.send('`!role`: You cannot use this command until you have agreed to the rules.')
      return

    if role == 'programmers':
      role = 'developers'

    if role not in CONFIG['Roles']:
      await ctx.send("`!role`: `{}` is not an active role.".format(role))
      return

    target_role = find_role(ctx.guild, role)
    if not target_role:
      await ctx.send("`!role`: `{}` could not be found. Please check the spelling and punctuation.".format(role))
      return

    if target_role in ctx.author.roles:
      await ctx.author.remove_roles(target_role)
      await send_notification(ctx.guild, "{} has removed themselves from `{}`.".format(
                                                      ctx.author.mention, target_role))
    else:
      await ctx.author.add_roles(target_role)
      await send_notification(ctx.guild, "{} has added themselves to `{}`.".format(ctx.author.mention, target_role))
      await ctx.author.send('The {0} role was added. You will now be notified '.format(target_role) + 'when someone mentions `@{0}`.'.format(target_role))
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
 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))
Ejemplo n.º 5
0
    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.'
                )
Ejemplo n.º 6
0
 async def addchannel(self, ctx, name, category):
   """Admin command: Create a new channel with the correct permissions.
   
   Args:
     name (String)
       The name of the new channel.
     
     category(String)
       The name of one of the existing categories to place the new channel in.
   
   Returns:
     None
   """
   if not is_admin(ctx.author):
     await ctx.send('`!addchannel`: Only admins may use this command.')
     return
   
   if not name:
     await ctx.send('`!addchannel`: You must specify a name for the new channel.')
     return
   
   if not category:
     await ctx.send('`!addchannel`: You must specify a category for the new channel.')
     return
     
   channel_list = ctx.guild.text_channels
   
   for channel in channel_list:
     if channel.name == name:
       await ctx.send('`!addchannel`: A channel with this name already exists.')
       return
   
   category_list = ctx.guild.categories
   target_category = None
   
   for cat in category_list:
     if cat.name == category:
       target_category = cat
   
   if not target_category:
     await ctx.send('`!addchannel`: This category could not be found.')
     return
       
   new_channel = await ctx.guild.create_text_channel(name, 
                                                     category=target_category)
   
   if not isinstance(new_channel, discord.TextChannel):
     await ctx.send('`!addchannel`: Unable to add new channel.')
   
   cap_role = find_role(ctx.guild, CONFIG['CapRole'])
   
   await new_channel.set_permissions(cap_role, send_messages=False)
   
   if not new_channel.overwrites_for(cap_role):
     await ctx.send('`!addchannel`: Cap role overwrite not effective.')
   
   await ctx.send('`!addchannel`: {} created in {}!'.format(name, category))
Ejemplo n.º 7
0
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!')
Ejemplo n.º 8
0
    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.')