Example #1
0
    async def set_registering_role(self, ctx, role_id):
        """
        Updates the registeringID for the guild.

        This command allows admins to update the role first given to users
        when they join the guild.
        """

        if not ctx.message.role_mentions:
            await ctx.send("Could not find a valid role. Please ensure you "
                           "have properly entered the role ID.")
            return

        guild = Guild.find(ctx.guild.id)
        if guild is None:
            await ctx.send("Failed to update role ID: guild was not found")
            return

        role = ctx.message.role_mentions[0]

        guild.registering_id = role.id
        guild.save()

        await ctx.send(f"Successfully updated registering role to {role.name}."
                       )
Example #2
0
    async def set_welcome_msg(self, ctx, *, content: str):
        """
        Updates the welcome message for the guild.

        This command allows admins to update the welcome message that
        users must react to when they wish to become members.
        """
        if len(content) == 0:
            await ctx.send("You must include a message.")
            return

        if await ut.get_confirmation(
                ctx.channel, ctx.author, self.bot,
                "You are about to set the servers welcome"
                f"message to\n ```{content}```\n"
                "Please react with a thumbs up "
                "to confirm."):
            message = await ctx.send(content)
            await message.add_reaction(u"\u2705")
            await message.add_reaction(u"\u274E")

            guild = Guild.find(ctx.guild.id)
            guild.welcome_message_id = message.id

            guild.save()
Example #3
0
 async def on_raw_reaction_add(self, payload):
     # Member is bot, or the emoji is not relevant,
     # or the message reacted to is not the role assignment message
     guild = Guild.find(payload.guild_id)
     if (payload.member.bot or str(payload.emoji) not in EMOJI_TO_ROLES
             or payload.message_id != guild.role_assignment_msg_id):
         return
     async with ut.RemoveReaction(self, payload):
         # Get the corresponding role name for the emoji
         role_name = EMOJI_TO_ROLES[str(payload.emoji)]
         # Get member's existing roles
         member_role_names = [str(role) for role in payload.member.roles]
         if role_name in member_role_names:
             return  # Return if the member is already assigned the role
         # Fetch the available roles from the server
         roles = await payload.member.guild.fetch_roles()
         # Get roles that are mutually exclusive
         mutex_roles = [role for role in roles if str(role) in MUTEX_ROLES]
         # Role to be assigned
         for role in roles:
             if str(role) == role_name:
                 role_to_be_assigned = role
                 break
         else:  # End of for loop means role was not found
             channel = await self.bot.fetch_channel(payload.channel_id)
             return await channel.send(
                 f"Role {role_name!r} does not exist. "
                 "Please report this issue to an admin.")
         # Removes existing mutually exclusive roles
         if role_to_be_assigned in mutex_roles:
             await payload.member.remove_roles(*mutex_roles)
         # Adds the required role
         await payload.member.add_roles(role_to_be_assigned)
    async def on_member_join(self, member):
        """Send user a welcome message."""
        if member.bot:
            return

        try:  # Avoid throwing errors on users with friend-only DMs.
            await member.create_dm()
            await member.dm_channel.send(
                f'Hey {member.name}, welcome to the (unofficial) University '
                f'of Sheffield Computer Science Discord!\n'
                'We like to know who we\'re talking to, so please change your '
                'nickname on the server to include your real name '
                'in some way.\n'
                'Apart from that, have fun on the server, get to know '
                'people and feel free to ask any questions about the course '
                'that you may have, '
                'we\'re all here to help each other!\n'
                'Many thanks,\n'
                'The Discord Server Admin Team\n\n'
                'As a note, all messages that you send '
                'on the server are logged.\n'
                'This is to help us in the case of messages that contain'
                'offensive content and need to be reported.\n'
                'If you would like your logged messages to be'
                'removed for any reason, please contact <@247428233086238720>.'
            )
        except discord.Forbidden:
            pass
        guild = Guild.find(member.guild.id)

        User.first_or_create(id=member.id, guild_id=guild.id)

        role_id = guild.registering_id
        await ut.add_role(member, role_id)
Example #5
0
    async def send_role_assignment_message(self, ctx):
        """
        Sends the role assignment message
        """
        guild = Guild.find(ctx.guild.id)
        message = await ctx.send(ROLE_ASSIGNMENT_MESSAGE)

        for emoji in EMOJI_TO_ROLES:
            await message.add_reaction(emoji)

        guild.role_assignment_msg_id = message.id
        guild.save()
Example #6
0
async def on_raw_reaction_add(payload):
    if payload.member.bot:
        return

    guild = Guild.find(payload.guild_id)
    expected_id = guild.welcome_message_id
    if payload.message_id == expected_id:
        message = await payload.member.guild.get_channel(payload.channel_id)\
            .fetch_message(payload.message_id)
        await message.remove_reaction(payload.emoji, payload.member)
        if payload.emoji.name == u"\u2705":
            registering_id = guild.registering_id
            member_id = guild.member_id

            await add_role(payload.member, member_id)
            await remove_role(payload.member, registering_id)

        elif payload.emoji.name == u"\u274E":
            await payload.member.guild.kick(payload.member,
                                            reason="Rejected T's&C's")
Example #7
0
    async def set_member_role(self, ctx, role_id):
        """
        Updates the memberID for the guild.

        This command allows admins to update the role given to users once
        they have 'accepted' the guilds rules.
        """

        if not ctx.message.role_mentions:
            await ctx.send("Could not find a valid role. Please ensure you "
                           "have properly entered the role ID.")
            return

        guild = Guild.find(ctx.guild.id)
        if guild is None:
            await ctx.send("Failed to update role ID: guild was not found")
            return

        role = ctx.message.role_mentions[0]

        guild.member_id = role.id
        guild.save()

        await ctx.send(f"Successfully updated member role to {role.name}.")