Пример #1
0
    def test_badArgs(self):
        msg = "I couldn't understand your command!\n\nIf you need more help with this command, send `!help [[!help]]`."
        self.assertEqual(h.badArgs(err.CustomCommandException("help", "")),
                         msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "Make sure the command you want help with is surrounded by double brackets. "
            + "If you want a list of all commands, don't send any brackets. " +
            "If you need more help with this command, send `!help [[!help]]`.")
        self.assertEqual(h.badArgs(err.BadArgumentException("help")), msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "I need a command to search for. " +
            "If you want a list of all commands, don't send any brackets. " +
            "If you need more help with this command, send `!help [[!help]]`.")
        self.assertEqual(h.badArgs(err.EmptyArgumentException("help")), msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "I need at least two things to choose from. " +
            "If you need more help with this command, send `!help [[!choose]]`."
        )
        self.assertEqual(h.badArgs(err.TooFewArgumentsException("choose")),
                         msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "I can only search for one command at a time. " +
            "If you need more help with this command, send `!help [[!help]]`.")
        self.assertEqual(h.badArgs(err.TooManyArgumentsException("help")), msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "I don't have the command you're searching for. " +
            "If you want a list of all commands, send `!help` with no arguments. "
            +
            "If you need more help with this command, send `!help [[!help]]`.")
        self.assertEqual(
            h.badArgs(err.CustomCommandException("help", "bad_command")), msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "I can only convert integers to binary. " +
            "If you need more help with this command, send `!help [[!binary]]`."
        )
        self.assertEqual(h.badArgs(err.BadValueException("binary")), msg)

        msg = (
            "I couldn't understand your command!\n\n" +
            "I can only convert numbers 0-65535 to binary. " +
            "If you need more help with this command, send `!help [[!binary]]`."
        )
        self.assertEqual(h.badArgs(err.BadNumberException("binary")), msg)

        msg = "I couldn't understand your command!\n\nIf you need more help with this command, send `!help [[!]]`."
        self.assertEqual(h.badArgs(err.CustomCommandException("", "")), msg)
Пример #2
0
async def announce(message):
    if message.author.guild_permissions.administrator:
        try:
            reminder = useful.makeDateReminder(message, announcement=True)

            await message.channel.send(useful.confirmReminder(message, reminder))

            def pred(msg):
                return (msg.author == message.author and
                        msg.channel == message.channel and
                        (msg.content.upper().startswith('!YES') or msg.content.upper().startswith('!NO')))

            try:
                reply = await globs.client.wait_for('message', check=pred, timeout=30)
                if reply.content.upper().startswith('!YES'):
                    await message.channel.send(useful.startReminder(reminder))
                elif reply.content.upper().startswith('!NO'):
                    await message.channel.send("Ok, I will discard that reminder.")
                    
            except asyncio.TimeoutError:
                await message.channel.send("%s, you took too long to respond so I discarded your reminder."
                                              % message.author.mention)
        except errors.Error as e:
            await message.channel.send(helpers.badArgs(e))
            
    else:
        await message.channel.send("Sorry, only administrators can use that command!")
Пример #3
0
async def remind(message, time=False):
    try:
        if time:
            reminder = useful.makeDurationReminder(message)
        else:
            reminder = useful.makeDateReminder(message)

        await message.channel.send(useful.confirmReminder(message, reminder))

        def pred(msg):
            return (msg.author == message.author and
                    msg.channel == message.channel and
                    (msg.content.upper().startswith('!YES') or msg.content.upper().startswith('!NO')))

        try:
            reply = await globs.client.wait_for('message', check=pred, timeout=30)
            if reply.content.upper().startswith('!YES'):
                await message.channel.send(useful.startReminder(reminder))
            elif reply.content.upper().startswith('!NO'):
                await message.channel.send("Ok, I will discard that reminder.")
                
        except asyncio.TimeoutError:      
            await message.channel.send("%s, you took too long to respond so I discarded your reminder."
                                      % message.author.mention)

    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #4
0
async def magic(message):
    try:
        for c in useful.fetchCard(message):
            if c.empty():
                await message.channel.send(c.description)
            else:
                await message.channel.send("", embed=discord.Embed.from_dict(c.asDict()))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #5
0
async def game(message):
    try:
        a = useful.fetchGame(message)
        if a.empty():
            await message.channel.send(a.description)
        else:
            await message.channel.send("", embed=discord.Embed.from_dict(a.asDict()))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
async def help(message):
    try:
        m = information.sendHelp(message)
        if m.empty():
            await message.channel.send(m.description)
        else:
            await message.channel.send("Here are my commands:",
                                       embed=discord.Embed.from_dict(
                                           m.asDict()))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #7
0
async def poll(message):
    try:
        poll = useful.makePoll(message)
        
        if helpers.isPollRunning(poll): #Only begin a poll if not already one in channel
            await message.channel.send(c.POLL_ALREADY_RUNNING)
        elif message.guild.me.permissions_in(message.channel).add_reactions == False:
            await message.channel.send(c.CANT_ADD_REACTIONS)

        else:
            reactions = []
            sentMsg = await message.channel.send(poll.body)
            poll.messageId = sentMsg.id
            helpers.addToActivePolls(poll)

            def pred(msg):
                return (msg.author == message.author and
                        msg.channel == message.channel and
                        msg.content.upper().startswith('!END'))

            if globs.props['poll_pin']:
                try:
                    await sentMsg.pin(
                        reason="Poll started by %s: '%s'" % (poll.author, poll.question))
                except discord.errors.Forbidden: #Can't pin
                    pass

            for o in poll.options:
                await sentMsg.add_reaction(o)

            try:
                reply = await globs.client.wait_for(
                    'message', check=pred, timeout = globs.props['poll_run_duration'] * 3600)
            except asyncio.TimeoutError:
                pass

            fetchedMsg = await message.channel.fetch_message(poll.messageId) #Update message information
            await message.channel.send(useful.finishPoll(fetchedMsg,poll))

            try:
                await fetchedMsg.unpin(
                    reason="Poll by %s finished: '%s'" % (poll.author, poll.question))
            except discord.errors.Forbidden: #Can't unpin
                pass
            
            helpers.removeFromActivePolls(poll)
            
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #8
0
async def hexadec(message):
    try:
        await message.channel.send(useful.toHex(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #9
0
async def calc(message):
    try:
        await message.channel.send(useful.calc(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #10
0
async def binary(message):
    try:
        await message.channel.send(useful.toBin(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #11
0
async def roll(message):
    try:
        await message.channel.send(useful.rollDice(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #12
0
async def rps(message):
    try:
        await message.channel.send(fun.playRps(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #13
0
async def rate(message):
    try:
        await message.channel.send(fun.rateSomething(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))
Пример #14
0
async def choose(message):
    try:
        await message.channel.send(fun.choose(message))
    except errors.Error as e:
        await message.channel.send(helpers.badArgs(e))