Esempio n. 1
0
async def remove_quote(ctx: discord.Message, client: discord.Client):
    # Checks if user is admin or bot owner
    if not (_checkrole.author_has_role(
            ctx,
            _mongoFunctions.get_settings(ctx.guild.id)['admin_role'])
            or _util.author_is_bot_owner(ctx)):
        replyEmbed = _embedMessage.create("RemoveQuote Reply",
                                          "Invalid Permissions", "red")
        await ctx.channel.send(embed=replyEmbed)
        return

    args = _util.parse_message(ctx.content)

    if len(args) != 3:
        await ctx.channel.send(embed=_embedMessage.create(
            "RemoveQuote Reply",
            "Invalid Syntax! You need two arguments for this function!", "red")
                               )
        return

    if len(args[1]) > embed_field_max_char:
        await ctx.channel.send(embed=_embedMessage.create(
            "RemoveQuote Reply",
            "Quote is too long! Please submit a quote that is 1024 characters or fewer",
            "red"))
        return

    embed = _embedMessage.create(
        "RemoveQuote Reply", "\"" + args[1] + "\" by: " + args[2] +
        " \n Removed by: " + ctx.author.mention, "blue")
    await ctx.channel.send(embed=embed)
    _mongoFunctions.delete_quote(ctx.guild.id, args[1], args[2])
Esempio n. 2
0
async def add_quote(ctx: discord.Message, client: discord.Client):
    if not _mongoFunctions.is_user_id_linked_to_verified_user_in_guild(
            ctx.guild.id, ctx.author.id) and _mongoFunctions.get_settings(
                ctx.guild.id)['verification_enabled']:
        replyEmbed = _embedMessage.create("AddQuote Reply",
                                          "Invalid Permissions", "red")
        await ctx.channel.send(embed=replyEmbed)
        return

    args = _util.parse_message(ctx.content)

    if len(args) != 3:
        await ctx.channel.send(embed=_embedMessage.create(
            "AddQuote Reply",
            "Invalid Syntax! You need two arguments for this function!\nEx: $addquote \"Life is Good\" Bedi",
            "red"))
        return

    if len(args[1]) > embed_field_max_char:
        await ctx.channel.send(embed=_embedMessage.create(
            "AddQuote Reply",
            "Quote is too long! Please submit a quote that is 1024 characters or fewer",
            "red"))
        return

    embed = _embedMessage.create(
        "AddQuote Reply",
        "| \"" + args[1] + "\" by: " + args[2] + " submitted by: " +
        ctx.author.mention + " \nReact to Approve\nApproved by: ", "blue")
    message = await ctx.channel.send(embed=embed)
    await message.add_reaction(
        discord.utils.get(ctx.guild.emojis,
                          name=_mongoFunctions.get_settings(
                              ctx.guild.id)['reaction_emoji']))
Esempio n. 3
0
async def get_birthdays(ctx: discord.Message, client: discord.Client):
    args = _util.parse_message(ctx.content)

    if len(args) != 2:
        await ctx.channel.send(embed=_embedMessage.create(
            "GetBirthdays Reply",
            "Invalid Syntax! You need one arguments for this function!", "red")
                               )
        return

    if int(args[1]) > 12 or int(args[1]) < 1:
        await ctx.channel.send(embed=_embedMessage.create(
            "GetBirthdays Reply", "Pick a month from 1 to 12", "red"))
        return

    message_embed = _embedMessage.create(
        "GetBirthdays Reply",
        "Here are the Birthdays for " + calendar.month_name[int(args[1])],
        "blue")

    user_documents = _mongoFunctions.get_birthdays_from_month(args[1])

    for document in user_documents:
        member = discord.utils.get(ctx.guild.members, id=document['user_id'])
        if member is None:
            continue

        # Adds birthday to embed, only including day and month
        _embedMessage.add_field(message_embed,
                                document['birth_date'].strftime("%B %d"),
                                member.mention, False)

    await ctx.channel.send(embed=message_embed)
Esempio n. 4
0
async def get_quotes(ctx: discord.Message, client: discord.Client):
    args = _util.parse_message(ctx.content)
    if len(args) != 3 and len(args) != 2:
        await ctx.channel.send(embed=_embedMessage.create(
            "getQuote Reply",
            "Invalid Syntax! You need two arguments for this function!\nEx: $getQuotes Bedi 2",
            "red"))
        return
    try:
        person = str(args[1])
        if len(args) == 2:
            page = 1
        else:
            page = int(args[2])
        quotes = _mongoFunctions.find_quotes(ctx.guild.id, person, page)
        try:
            embed = _embedMessage.create("Quotes from: " + person,
                                         "Page: " + str(page), "green")
            for quote in quotes:
                value = (
                    quote["quote"][:(embed_field_max_char - 3)] +
                    '...') if len(quote["quote"]) > 1024 else quote["quote"]
                _embedMessage.add_field(embed_msg=embed,
                                        title_string=quote["name"],
                                        value_string=value,
                                        is_inline=False)
            await ctx.channel.send(embed=embed)
        except Exception as e:
            print(e)
            await ctx.channel.send(embed=_embedMessage.create(
                "GetQuotes Reply", "Error sending response", "red"))
    except:
        await ctx.channel.send(embed=_embedMessage.create(
            "GetQuotes Reply", "Invalid Syntax! You need integers", "red"))
Esempio n. 5
0
async def get_random_quote(ctx: discord.Message, client: discord.Client):
    args = _util.parse_message(ctx.content)

    quote = _mongoFunctions.random_quote_from_person(ctx.guild.id, args[1]) \
        if len(args) == 2 \
        else _mongoFunctions.random_quote(ctx.guild.id)

    await ctx.channel.send(
        embed=_embedMessage.create("GetRandomQuote Reply", quote, "blue"))
Esempio n. 6
0
async def say(ctx: discord.Message, client: discord.Client):
    # Checks if user is admin or bot owner
    if not (_checkrole.author_has_role(
            ctx,
            _mongoFunctions.get_settings(ctx.guild.id)['admin_role'])
            or _util.author_is_bot_owner(ctx)):
        replyEmbed = _embedMessage.create("Say Reply", "Invalid Permissions",
                                          "red")
        await ctx.channel.send(embed=replyEmbed)
        return

    global target_channel

    args = _util.parse_message(ctx.content)

    if len(args) != 4:
        await ctx.channel.send(embed=_embedMessage.create(
            "Say Reply",
            "Invalid Syntax! You need three arguments for this function!\nSyntax: say title content channel",
            "red"))
        return

    title = args[1]

    content = args[2]

    channel_mention = args[3]

    channels = client.get_all_channels()

    for channel in channels:
        if channel.mention == channel_mention:
            target_channel = channel
            break

    if target_channel is None:
        await ctx.channel.send(embed=_embedMessage.create(
            "Say Reply", "Channel not Found!", "red"))
        return

    try:
        await ctx.delete()
    except:
        print("Missing Manage Messages permission in {0} on server ID: {1}".
              format(channel.mention, str(ctx.guild.id)))

    if not _util.author_is_bot_owner(ctx):
        embed = _embedMessage.create(
            title, content +
            "\n\n This message was sent by {}".format(ctx.author.mention),
            "green")
    else:
        embed = _embedMessage.create(title, content, "green")

    await target_channel.send(embed=embed)
Esempio n. 7
0
async def quotes_reaction_handler(
        reaction_payload: discord.RawReactionActionEvent,
        message: discord.Message):
    # if isinstance(reaction.emoji, str):
    # i think this means its a discord emoji
    # await reaction.message.channel.send("string")

    if reaction_payload.emoji.is_custom_emoji:
        # await reaction.message.channel.send("emoji")
        # print(reaction.emoji.name)
        # emojis from this server

        if reaction_payload.emoji.id == discord.utils.get(
                message.guild.emojis,
                name=_mongoFunctions.get_settings(
                    message.guild.id)['reaction_emoji']).id:
            if reaction_payload.member.mention not in message.embeds[
                    0].description:
                embed = _embedMessage.create(
                    "AddQuote Reply", message.embeds[0].description + " " +
                    reaction_payload.member.mention, "blue")
                await message.edit(embed=embed)

            reaction_object = None

            for reaction in message.reactions:
                if reaction.emoji.id == reaction.emoji.id:
                    reaction_object = reaction
                    break

            if reaction_object.count >= _mongoFunctions.get_settings(
                    message.guild.id)['required_quote_reactions']:
                args = _util.parse_message(message.embeds[0].description)
                quote = args[1]
                quotedPerson = args[3]
                res = _mongoFunctions.insert_quote(guild_id=message.guild.id,
                                                   quoted_person=quotedPerson,
                                                   quote=quote)

                contentArr = message.embeds[0].description.split(" ")
                newContent = " ".join(contentArr[1:])

                if res:
                    embed = _embedMessage.create("Quote Reply",
                                                 "Approved: " + newContent,
                                                 "blue")
                    await message.edit(embed=embed)
                else:
                    embed = _embedMessage.create(
                        "Quote Reply",
                        "Failed to Connect to DB: " + newContent, "blue")
                    await message.edit(embed=embed)
Esempio n. 8
0
async def say(ctx, client):
    if not (_checkrole.author_has_role(
            ctx, _mongoFunctions.get_admin_role(ctx.guild.id))
            or _util.author_is_bot_owner(ctx)):
        replyEmbed = _embedMessage.create("Say Reply", "Invalid Permissions",
                                          "red")
        await ctx.channel.send(embed=replyEmbed)
        return

    global target_channel

    args = _util.parse_message(ctx.content)

    if len(args) != 4:
        await ctx.channel.send(embed=_embedMessage.create(
            "Say Reply",
            "Invalid Syntax! You need three arguments for this function!",
            "red"))
        return

    title = args[1]

    content = args[2]

    channel_mention = args[3]

    channels = client.get_all_channels()

    for channel in channels:
        if channel.mention == channel_mention:
            target_channel = channel
            break

    if target_channel is None:
        await ctx.channel.send(embed=_embedMessage.create(
            "Say Reply", "Channel not Found!", "red"))
        return

    await ctx.delete()
    await target_channel.send(
        embed=_embedMessage.create(title, content, "green"))

    return
Esempio n. 9
0
async def set_settings(ctx: discord.Message, client: discord.Client,
                       response_message: discord.Message,
                       stop_embed: discord.embeds, check):
    while True:
        await response_message.edit(embed=_embedMessage.create(
            "Setup Reply", "Should Due Dates be Enabled (y/n)?", "blue"))
        try:
            due_dates_message = await client.wait_for('message',
                                                      timeout=wait_timeout,
                                                      check=check)
        except asyncio.TimeoutError:
            await response_message.edit(embed=_embedMessage.create(
                "Setup Reply", "You took too long to respond.", "red"))
            return
        else:
            due_dates_string = due_dates_message.content.lower()
            if due_dates_string == 'next':
                break
            if due_dates_string == 'stop':
                await ctx.channel.send(embed=stop_embed)
                return
            if due_dates_string in ('yes', 'y', 'true', 't', '1', 'enable',
                                    'on'):
                _mongoFunctions.update_setting(ctx.guild.id,
                                               "due_dates_enabled", True)

            else:
                _mongoFunctions.update_setting(ctx.guild.id,
                                               "due_dates_enabled", False)
            break

    if _mongoFunctions.get_settings(ctx.guild.id)["due_dates_enabled"]:
        while True:
            await response_message.edit(embed=_embedMessage.create(
                "Setup Reply",
                "Which streams require due dates? (Must be integers separated by spaces."
                "E.g. 4 8)", "blue"))
            try:
                streams_message = await client.wait_for('message',
                                                        timeout=wait_timeout,
                                                        check=check)
            except asyncio.TimeoutError:
                await response_message.edit(embed=_embedMessage.create(
                    "Setup Reply", "You took too long to respond.", "red"))
                return
            else:
                streams_string = streams_message.content
                if streams_string.lower() == 'next':
                    break
                if streams_string.lower() == 'stop':
                    await ctx.channel.send(embed=stop_embed)
                    return
                streams = streams_string.split(' ')
                _mongoFunctions.update_setting(ctx.guild.id, "streams",
                                               streams)
                break

        while True:
            await response_message.edit(embed=_embedMessage.create(
                "Setup Reply",
                "What are the term's courses. (Or other deadline categories). "
                "(Must be strings separated by spaces. "
                "Use quotes around courses made of multiple words) "
                "E.g. \"MATH 115\" Physics)", "blue"))
            try:
                courses_message = await client.wait_for('message',
                                                        timeout=wait_timeout,
                                                        check=check)
            except asyncio.TimeoutError:
                await response_message.edit(embed=_embedMessage.create(
                    "Setup Reply", "You took too long to respond.", "red"))
                return
            else:
                courses_string = courses_message.content
                if courses_string.lower() == 'next':
                    break
                if courses_string.lower() == 'stop':
                    await ctx.channel.send(embed=stop_embed)
                    return
                courses = _util.parse_message(courses_string)
                _mongoFunctions.update_setting(ctx.guild.id, "courses",
                                               courses)
                break

        while True:
            await response_message.edit(embed=_embedMessage.create(
                "Setup Reply", "What are the due date types. "
                "(Must be strings separated by spaces. "
                "E.g. Assignment Test Quiz Exam Project Other)", "blue"))
            try:
                due_date_types_message = await client.wait_for(
                    'message', timeout=wait_timeout, check=check)
            except asyncio.TimeoutError:
                await response_message.edit(embed=_embedMessage.create(
                    "Setup Reply", "You took too long to respond.", "red"))
                return
            else:
                due_date_types_string = due_date_types_message.content
                if due_date_types_string.lower() == 'next':
                    break
                if due_date_types_string.lower() == 'stop':
                    await ctx.channel.send(embed=stop_embed)
                    return
                due_date_types = due_date_types_string.split(' ')
                _mongoFunctions.update_setting(ctx.guild.id, "due_date_types",
                                               due_date_types)
                break
Esempio n. 10
0
async def confirm(ctx: discord.Message, client: discord.Client):
    if not _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']:
        replyEmbed = _embedMessage.create(
            "Confirm Reply", "Verification is not enabled on this server!",
            "red")
        await ctx.channel.send(embed=replyEmbed)
        return

    # Verified users can't run $confirm. They are already verified (duh)
    if _mongoFunctions.is_user_id_linked_to_verified_user_in_guild(
            ctx.guild.id, ctx.author.id):
        replyEmbed = _embedMessage.create("Confirm Reply",
                                          "Invalid Permissions", "red")
        await ctx.channel.send(embed=replyEmbed)
        return

    message_contents = _util.parse_message(ctx.content)

    if len(message_contents) != 2:
        await ctx.channel.send(embed=_embedMessage.create(
            "Confirm Reply",
            "The syntax is invalid! Make sure it is in the format $confirm <confirmcode>",
            "red"))
        return

    uw_id = _mongoFunctions.get_uw_id_from_pending_user_id(
        ctx.guild.id, ctx.author.id)

    if uw_id is None:
        await ctx.channel.send(embed=_embedMessage.create(
            "Confirm Reply", "You have not run $verify yet!", "red"))
        return

    unique_key = message_contents[1]
    if unique_key == _email.verificationCodes.get(ctx.author.id):
        # Removing this stuff since V2 API is deprecated

        # department = uw_driver.directory_people_search(uw_id)['department']

        # if department == "ENG/Mechanical & Mechatronics":
        #     await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name = "Tron"))
        # else:
        #     await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name = "Not Tron"))

        await ctx.author.add_roles(
            discord.utils.get(ctx.guild.roles,
                              name=_mongoFunctions.get_settings(
                                  ctx.guild.id)['verified_role']))
        _mongoFunctions.add_user_to_verified_users(
            ctx.guild.id, ctx.author.id, _hashingFunctions.hash_user_id(uw_id))
        _mongoFunctions.remove_user_from_pending_verification_users(
            ctx.guild.id, ctx.author.id)
        reply_embed = _embedMessage.create("Confirm reply",
                                           "You have been verified", "blue")
        await ctx.channel.send(embed=reply_embed)
        await ctx.author.send(embed=reply_embed)

    else:
        await ctx.channel.send(
            embed=_embedMessage.create("Confirm reply", "Invalid Code!", "red")
        )