Ejemplo n.º 1
0
async def rps(Bot, msg):
    valid = ["rock", "paper", "scissors"]
    mine = valid[randint(0, 2)]
    yours = strutils.parse_command(msg.content, 1)[1]
    result = ""
    if mine == yours:
        result = "It's a tie!"
    else:
        comb = mine + yours
        if comb in ["rockpaper", "scissorsrock", "paperscissors"]:
            result = strutils.format_response("{_mention} wins!", _msg=msg)
        else:
            result = "I win!"
    if yours in valid:
        await Bot.send_message(
            msg.channel,
            strutils.format_response(
                "**{_mention}** chooses **{yours}**, while I choose **{mine}**. {result}",
                yours=yours,
                mine=mine,
                _msg=msg,
                result=result))
    else:
        await Bot.send_message(
            msg.channel,
            "Your input was invalid. Please choose **rock**, **paper**, or **scissors.**"
        )
Ejemplo n.º 2
0
async def save(Bot, msg, overrideperms=False):
    if overrideperms or userutils.is_mod(msg.author):
        if not overrideperms:
            em = Embed(title="Saving Data...",
                       description="Saving...",
                       colour=0xd32323)
            msg = await msgutils.send_embed(Bot, msg, em)
            await asyncio.sleep(1)
        data = datautils.get_data()
        for k, v in data.items():
            with open('Data/%s.txt' % k, 'wb') as f:
                pickle.dump(v, f)
        if not overrideperms:
            em.description = "Complete!"
            msg = await msgutils.edit_embed(Bot, msg, embed=em)
            await asyncio.sleep(0.5)
            await Bot.delete_message(msg)
        return True
    else:
        em = Embed(
            title="Insufficient Permissions",
            description=strutils.format_response(
                "{_mention} does not have sufficient permissions to perform this task.",
                _msg=msg),
            colour=0xd32323)
        await msgutils.send_embed(Bot, msg, em)
        return False
Ejemplo n.º 3
0
async def quiz(Bot, msg):
    if not msg.server.id in bot_data['quiz_data']:
        bot_data['quiz_data'][msg.server.id] = [None, {}]
    else:
        for k in bot_data['quiz_data'][msg.server.id][1].keys():
            if not bot_data['quiz_data'][msg.server.id][1][k]:
                del bot_data['quiz_data'][msg.server.id][1][k]
    try:
        newmsg = strutils.strip_command(msg.content).split(" ")
    except IndexError:
        em = Embed(title="Missing subcommand", description=strutils.format_response("You must specify a subcommand!\nValid options include `cow quiz add` and `cow quiz take`.", _msg=msg), colour=0xff7830)
        await msgutils.send_embed(Bot, msg, em)
        return
    try:
        if not msg.author.id in quiz_users:
            quiz_users.append(msg.author.id)
            try:
                await quiz_handlers[newmsg[0]](Bot, msg)
            except KeyError:
                raise
            finally:
                quiz_users.remove(msg.author.id)
        else:
            await Bot.send_message(msg.channel, "You already have a quiz running!\nPlease cancel that command first.")
    except KeyError:
        em = Embed(title="ERROR", description="Unknown subcommand **%s**." % newmsg[0], colour=0xd32323)
        await Bot.send_message(msg.channel, embed=em)
Ejemplo n.º 4
0
async def addMooney(Bot, msg):
    if msg.author.id == "418827664304898048":
        try:
            amt = int(
                float(strutils.strip_command(msg.content).split(' ', 1)[0]) *
                100)
            give(amt, msg.mentions[0].id)
            em = Embed(title="Money Added",
                       description='{0:.2f}'.format(amt / 100) +
                       " mooney given to " + msg.mentions[0].mention,
                       colour=0xffd747)
            await msgutils.send_embed(Bot, msg, em)
        except (ValueError, TypeError):
            em = Embed(title="Invalid Amount",
                       description="Mooney to give must be a number.",
                       colour=0xd32323)
            await msgutils.send_embed(Bot, msg, em)
        except IndexError:
            em = Embed(
                title="Missing User",
                description="You must specify the user to give mooney to.",
                colour=0xd32323)
            await msgutils.send_embed(Bot, msg, em)
    else:
        em = Embed(
            title="Insufficient Permissions",
            description=strutils.format_response(
                "{_mention} does not have sufficient permissions to perform this task.",
                _msg=msg),
            colour=0xd32323)
        await msgutils.send_embed(Bot, msg, em)
Ejemplo n.º 5
0
async def setmod(Bot, msg):
    if (bot_data['quiz_data'][msg.server.id][0] and bot_data['quiz_data'][msg.server.id][0] not in msg.author.roles) and not msg.channel.permissions_for(msg.author).manage_messages:
        em = Embed(title="Insufficient Permissions", description=strutils.format_response("{_mention} does not have sufficient permissions to perform this task.", _msg=msg), colour=0xd32323)
        await msgutils.send_embed(Bot, msg, em)
        return
    try:
        bot_data['quiz_data'][msg.server.id][0] = msg.role_mentions[0]
        await Bot.send_message(msg.channel, "Quiz moderator role has succesfully been set to "+msg.role_mentions[0].mention+".")
    except IndexError:
        await Bot.send_message(msg.channel, "Please mention a role.")
Ejemplo n.º 6
0
async def purge(Bot, msg):
    perms = msg.channel.permissions_for(msg.author)
    if perms.manage_messages or msg.author.id == "418827664304898048":
        num = int(strutils.parse_command(msg.content, 1)[1].split(' ')[0]) + 1
        if num < 2:
            await Bot.send_message("There is no reason to delete 0 messages!")
        deletechunks = []

        def check(message):
            return not msg.mentions or msg.mentions[0].id == message.author.id

        try:
            await Bot.purge_from(msg.channel, limit=num, check=check)
            m = await Bot.send_message(
                msg.channel,
                strutils.format_response(
                    "**{_mention}** has cleared the last **{_number}** messages!",
                    _msg=msg,
                    _number=num - 1))
        except HTTPException:
            m = await Bot.send_message(
                msg.channel,
                strutils.format_response(
                    "You cannot bulk delete messages that are over 14 days old!!"
                ))

        await asyncio.sleep(2)
        await Bot.delete_message(m)
    else:
        em = Embed(
            title="Insufficient Permissions",
            description=strutils.format_response(
                "{_mention} does not have sufficient permissions to perform this task.",
                _msg=msg),
            colour=0xd32323)
        await msgutils.send_embed(Bot, msg, em)
Ejemplo n.º 7
0
async def add(Bot, msg):
    if (bot_data['quiz_data'][msg.server.id][0] and bot_data['quiz_data'][msg.server.id][0] not in msg.author.roles) and not msg.channel.permissions_for(msg.author).manage_messages:
        em = Embed(title="Insufficient Permissions", description=strutils.format_response("{_mention} does not have sufficient permissions to perform this task.", _msg=msg), colour=0xd32323)
        await msgutils.send_embed(Bot, msg, em)
        return
    question = strutils.strip_command(msg.content).split(" ", 1)[1]
    em = Embed(title="Add Quiz Question", description="Question:\n"+question, colour=0xff7830)
    desc = ''
    if len(bot_data['quiz_data'][msg.server.id][1]) > 0:
        for k,v in bot_data['quiz_data'][msg.server.id][1].items():
            desc+='\n'+k
    else:
        desc = '\nNone'
    em.add_field(name="Question Category", value="Available Categories:"+desc+"\n\nIf your desired category is not listed, you may add one below.\n\nIf you want to cancel, type `cancel`.", inline=False)
    qmsg = await msgutils.send_embed(Bot, msg, em)

    cat = await getquestioncategory(Bot, msg, qmsg, em, add=True)
    if not cat:
        return
    em.set_field_at(0, name="Question Category", value=cat, inline=False)
    quest = await editquestion(Bot, msg, qmsg, em, cat, question)
    bot_data['quiz_data'][msg.server.id][1][cat].append(quest)