예제 #1
0
    async def authenticate_member(self, member: Member, key: str) -> bool:
        collection = mongo.db[self.__MEMBER_COLLECTION]
        document = collection.find_one()

        if not document:
            document = {self.__AUTHENTICATION_FIELD: []}
            collection.insert(document)
        found = False
        for auth_data in document[self.__AUTHENTICATION_FIELD]:
            if auth_data[self.__KEY_FIELD] == key:
                name = auth_data[self.__NAME_FIELD]
                ra: RoleAuthority = RoleAuthority(self.guild)
                # try:
                await member.edit(nick=name)
                await member.add_roles(ra.student)
                await member.remove_roles(ra.un_authenticated)
                # except:
                #     logger.error("Error authenticating user {}".format(member.id))
                if self.__DISCORD_ID_FIELD in auth_data and auth_data[
                        self.__DISCORD_ID_FIELD] != member.id:
                    logger.error(
                        "Student tried to auth with a new account.  New ID: {}, Old ID: {}"
                        .format(member.id, auth_data[self.__DISCORD_ID_FIELD]))
                    return False
                auth_data[self.__DISCORD_ID_FIELD] = member.id

                found = True
                break

        collection.replace_one({"_id": document["_id"]}, document)
        return found
예제 #2
0
    async def is_invoked_by_message(message: Message, client: Client):

        if message.content.startswith("!accept"):
            ra: RoleAuthority = RoleAuthority(message.guild)
            if ra.ta_or_higher(message.author):
                ca: ChannelAuthority = ChannelAuthority(message.guild)
                if message.channel == ca.queue_channel:
                    return True
                else:
                    admonishment = await message.channel.send("{}, you must be in {} to accept a student.".format(
                        message.author.mention,
                        ca.queue_channel.mention
                    ))
                    await admonishment.delete(delay=7)
                    await message.delete()
                    return False
            else:
                admonishment = await message.channel.send("Silly {}, you're not a TA!".format(
                    message.author.mention
                ))
                await admonishment.delete(delay=7)
                await message.delete()
                return False

        return False
예제 #3
0
    async def is_invoked_by_message(message: Message, client: Client):

        if message.content.startswith("!reject"):
            ra: RoleAuthority = RoleAuthority(message.guild)

            # check if the sender has permission to issue this command
            if ra.ta_or_higher(message.author):
                ca: ChannelAuthority = ChannelAuthority(message.guild)
                malformed = False

                # Check to see if a there is a valid member id and message
                guild: Guild = message.guild;
                try:
                    # checks for at least 3 words
                    if len(message.content.split(" ")) < 3:
                        malformed = True
                    else:
                        member_id = int(message.content.split(" ")[1])
                        member_mentioned: Member = guild.get_member(member_id)
                        # checks if the supplied id is a valid id
                        if not member_mentioned:
                            malformed = True
                # if an exception is thrown above, then it's something real wonkey (like a non-int id)
                except:
                    malformed = True

                # tell them it's malformed and supply correct format
                if malformed:
                    admonishment = await message.channel.send(
                        "Reject must be of the form `!reject [integer userid] [message]`".format(
                            message.author.mention,
                            ca.queue_channel.mention
                        ))
                    await admonishment.delete(delay=7)
                    await message.delete()
                    return False
                # if it's well-formed and in the correct channel, we have success!
                if message.channel == ca.queue_channel:
                    return True
                else:
                    # else point them to the correct channel
                    admonishment = await message.channel.send("{}, you must be in {} to reject a student.".format(
                        message.author.mention,
                        ca.queue_channel.mention
                    ))
                    await admonishment.delete(delay=7)
                    await message.delete()
                    return False
            else:
                admonishment = await message.channel.send("Silly {}, you're not a TA!".format(
                    message.author.mention
                ))
                await admonishment.delete(delay=7)
                await message.delete()
                return False

        return False
예제 #4
0
 async def handle(self):
     sender: Member = self.message.author
     ra: RoleAuthority = RoleAuthority(self.guild)
     if ra.ta_or_higher(sender):
         await self.message.channel.send("{}, great and powerful course staff member! "
                                         "Go to {} to see all the ways I may serve you!".format(
             sender.mention, self.prefix + "tahelp.md"
         ))
     else:
         await self.message.channel.send("You can find a guide to using office hours here: {}".format(
             self.prefix + "student.md"
         ))
예제 #5
0
 async def is_invoked_by_message(message: Message, client: Client):
     ca: ChannelAuthority = ChannelAuthority(message.guild)
     if is_bot_mentioned(message, client) and ("setup" in message.content or "set up" in message.content):
         ra: RoleAuthority = RoleAuthority(message.guild)
         if ra.admin in message.author.roles:
             return True
         else:
             if ca.waiting_channel == None:
                 return True
             await message.channel.send("You can't run setup, " + message.author.mention)
             return False
     return False
예제 #6
0
    async def start_lab(self, message: Message) -> None:
        guild: Guild = message.guild
        ra: RoleAuthority = RoleAuthority(guild)
        # Make the category channel and make it inaccessible to unauthed nerds
        self.lab_category: CategoryChannel = await guild.create_category("Lab", overwrites={
            ra.un_authenticated: PermissionOverwrite(read_messages=False)
        })

        await self.lab_category.create_text_channel("General")
        await self.lab_category.create_voice_channel("Main Lecture")
        for i in range(1, 7):
            await self.lab_category.create_voice_channel("Small Group Chat " + str(i))

        self.update_channel(self.__LAB_CATEGORY_CHANNEL, self.lab_category)
예제 #7
0
async def is_oh_command(client, message, type):
    ca: ChannelAuthority = ChannelAuthority(message.guild)
    if is_bot_mentioned(message, client) and \
            ("oh" in message.content.lower() and type in message.content.lower()):
        if message.channel == ca.queue_channel:
            ra: RoleAuthority = RoleAuthority(message.guild)
            if ra.ta_or_higher(message.author):
                return True
            else:
                await message.channel.send("You can't do this, " + message.author.mention)
                return False
        else:
            await message.channel.send("You have to be in " +
                                       ca.queue_channel.mention + " to {} office hours.".format(type))
            return False
    return False
예제 #8
0
    async def handle(self):
        qa: QueueAuthority = QueueAuthority(self.guild)
        if not qa.is_ta_on_duty(self.message.author.id):
            await self.message.channel.send("You must be on duty to accept a request!")
            return
        # get oldest queue item (and also remove it)
        session: OHSession = await qa.dequeue(self.message.author)
        if not session:
            msg = await self.message.channel.send("No one is in the queue.  Perhaps you're lonely?\n"
                                                  "https://giphy.com/gifs/30-rock-liz-lemon-jack-donaghy-VuWtVHkMjrz2w")
            await msg.delete(delay=7)
            await self.message.delete()
            return
        # create role for channel
        role: Role = await self.guild.create_role(name="{}'s OH session".format(command.name(session.member)), hoist=True)
        num_roles = len(self.guild.roles)
        # todo find bot role insert this underneath
        # await role.edit(position=num_roles-2)
        session.role = role
        await session.member.add_roles(session.role)
        await self.message.author.add_roles(session.role)

        # create channel
        ra: RoleAuthority = RoleAuthority(self.guild)
        session_category: CategoryChannel = await self.guild.create_category_channel(
            "Session for {}".format(command.name(session.member)),
            overwrites={
                role: PermissionOverwrite(read_messages=True, attach_files=True, embed_links=True),
                ra.student: PermissionOverwrite(read_messages=False),
                ra.un_authenticated: PermissionOverwrite(read_messages=False)
            })
        text_channel: TextChannel = await session_category.create_text_channel("Text Cat")
        await session_category.create_voice_channel("Voice chat")
        session.room = session_category
        # attach user ids and channel ids to OH room info in channel authority
        ca: ChannelAuthority = ChannelAuthority(self.guild)
        await session.announcement.delete()
        await self.message.delete()
        ca.add_oh_session(session)
        await text_channel.send("Hi, {} and {}!  Let the learning commence!  Type !close to end the session!".format(
            session.member.mention,
            session.ta.mention,
        ))
        logger.info("OH session for {} accepted by {}".format(
            command.name(session.member),
            command.name(self.message.author)))
예제 #9
0
async def is_lab_command(message: Message, client: Client, keyword: str):
    ca: ChannelAuthority = ChannelAuthority(message.guild)
    if is_bot_mentioned(message, client) and \
            ("{} lab".format(keyword) in message.content or "lab {}".format(keyword) in message.content):
        if ca.lab_running() and keyword == "start":
            await message.channel.send("A lab is already running, " + message.author.mention + \
                                       ", please wait for it to conclude or join in.")
            return False
        if message.channel == ca.queue_channel:
            ra: RoleAuthority = RoleAuthority(message.guild)
            if ra.ta_or_higher(message.author):
                return True
            else:
                await message.channel.send("You can't do this, " + message.author.mention)
                return False
        else:
            await message.channel.send("You have to be in " + ca.queue_channel.mention + " to request a lab start.")
            return False
    return False
예제 #10
0
    async def handle(self):
        qa: QueueAuthority = QueueAuthority(self.guild)
        # get oldest queue item (and also remove it)
        session: OHSession = await qa.dequeue(self.message.author)

        # create role for channel
        role: Role = await self.guild.create_role(name="{}'s OH session".format(name(session.member)), hoist=True)
        num_roles = len(self.guild.roles)
        # todo find bot role insert this underneath
        # await role.edit(position=num_roles-2)
        session.role = role
        await session.member.add_roles(session.role)
        await self.message.author.add_roles(session.role)

        # create channel
        ra: RoleAuthority = RoleAuthority(self.guild)
        session_category: CategoryChannel = await self.guild.create_category_channel(
            "Session for {}".format(name(session.member)),
            overwrites={
                role: PermissionOverwrite(read_messages=True, attach_files=True, embed_links=True),
                ra.student: PermissionOverwrite(read_messages=False),
                ra.un_authenticated: PermissionOverwrite(read_messages=False)
            })
        text_channel: TextChannel = await session_category.create_text_channel("Text Cat")
        await session_category.create_voice_channel("Voice chat")
        session.room = session_category
        # attach user ids and channel ids to OH room info in channel authority
        ca: ChannelAuthority = ChannelAuthority(self.guild)
        await session.announcement.delete()
        await self.message.delete()
        ca.add_oh_session(session)
        await text_channel.send("Hi, {} and {}!  Let the learning commence!  Type !close to end the session!".format(
            session.member.mention,
            session.ta.mention,
        ))
        logger.info("OH session for {} accepted by {}".format(
            name(session.member),
            name(self.message.author)))