Example #1
0
async def drink_milk(ctx, user):
    users = get_users()

    users[user]['cdstate'] = 'off'

    dump_users(users)

    embed = discord.Embed(
        title=
        'You drank the milk carton. You feel power flowing through your veins.',
        description='Command cooldowns have been disabled.',
        color=discord.Color.green())
    await ctx.send('', embed=embed)
Example #2
0
async def on_command_error(ctx, error):
    embed = discord.Embed(title='', color=discord.Color.red())

    # if command has local error handler, return
    if hasattr(ctx.command, 'on_error'):
        return

    # get the original exception
    error = getattr(error, 'original', error)

    if isinstance(error, commands.CommandNotFound):
        embed.title = 'Invalid Command'
        await ctx.send('', embed=embed)
        return

    if isinstance(error, commands.BotMissingPermissions):
        missing = [
            perm.replace('_', ' ').replace('guild', 'server').title()
            for perm in error.missing_perms
        ]
        if len(missing) > 2:
            fmt = '{}, and {}'.format("**, **".join(missing[:-1]), missing[-1])
        else:
            fmt = ' and '.join(missing)
        _message = 'I need the **{}** permission(s) to run this command.'.format(
            fmt)
        embed.title = _message
        await ctx.send('', embed=embed)
        return

    if isinstance(error, commands.DisabledCommand):
        embed.title = 'This command has been disabled.'
        await ctx.send('', embed=embed)
        return

    if isinstance(error, commands.CommandOnCooldown):
        embed.title = 'This command is on cooldown, please retry in `{}s`.'.format(
            math.ceil(error.retry_after))
        await ctx.send('', embed=embed)
        return

    if isinstance(error, commands.MissingPermissions):
        missing = [
            perm.replace('_', ' ').replace('guild', 'server').title()
            for perm in error.missing_perms
        ]
        if len(missing) > 2:
            fmt = '{}, and {}'.format("**, **".join(missing[:-1]), missing[-1])
        else:
            fmt = ' and '.join(missing)
        _message = 'You need the **{}** permission(s) to use this command.'.format(
            fmt)
        embed.title = _message
        await ctx.send('', embed=embed)
        return

    if isinstance(error, commands.UserInputError):
        embed.title = 'Invalid Arguments.'
        await ctx.send('', embed=embed)
        return

    if isinstance(error, commands.NoPrivateMessage):
        try:
            await ctx.author.send(
                'This command cannot be used in direct messages.')
        except discord.Forbidden:
            pass
        return

    if isinstance(error, commands.CheckFailure):
        embed.title = 'You do not have permission to use this command.'
        await ctx.send('', embed=embed)
        return

    # ignore all other exception types, but print them to stderr
    print('Ignoring exception in command {}:'.format(ctx.command),
          file=sys.stderr)

    traceback.print_exception(type(error),
                              error,
                              error.__traceback__,
                              file=sys.stderr)
Example #3
0
    async def hangman(self, ctx):
        """Description:
        Play hangman with up to 3 other people.
        
        Use:
        %shangman"""

        if self.playingHangman:
            embed = discord.Embed(title='There is already a hangman game going on!', description='Please wait until the current hangman game is finished.', color=discord.Color.red())
            await ctx.send('', embed=embed)
            return

        self.playingHangman = True

        players = [ctx.author.name]
        self.player_index = 1
        start_time = time.time()

        join_embed = discord.Embed(title='A hangman game is starting! React with :white_check_mark: to start the game.', description=f'React to this message with :nazar_amulet: to join the game. React with :door: to leave the game.\n(The game will be aborted in 30sec)\n\nPlayers: {players[0]}', color=discord.Color.blue())
        join_msg = await ctx.send('', embed=join_embed)
        await join_msg.add_reaction('✅')
        await join_msg.add_reaction('🧿')
        await join_msg.add_reaction('🚪')

        def check(reaction, user):
            if user.id != self.bot.user.id and user.id != ctx.author.id:
                if reaction.emoji == '🧿' and user.name not in players and len(players) <= 4:
                    join_embed.description += f', {players[self.player_index]}'
                    self.player_index += 1
                    players.append(user.name)
                    return True
                elif reaction.emoji == '🚪' and user.name in players:
                    players.remove(user.name)
                    return True
            elif user.id == ctx.author.id:
                if reaction.emoji == '✅':
                    return True
            return False

        try:
            reaction, _ = await self.bot.wait_for('reaction_add', timeout=30, check=check)
            
            while reaction.emoji != '✅':
                reaction, _ = await self.bot.wait_for('reaction_add', timeout=30 - (time.time() - start_time), check=check)
                await join_msg.edit(embed=join_embed)

        except asyncio.TimeoutError:
            embed = discord.Embed(title='The game has been aborted.', description=f'Use `{get_prefix(None, ctx)}hangman` to start another game.', color=discord.Color.red())
            await join_msg.edit(embed=embed)
            self.playingHangman = False
            return

        await ctx.author.send('Tell me what to make the hidden message.')

        def check_msg(message):
            return message.channel.type == discord.ChannelType.private and message.author.name == ctx.author.name

        while True:
            try:
                msg = await self.bot.wait_for('message', timeout=60, check=check_msg)
                message = msg.content

                if len(message) > 30:
                    await ctx.author.send('This message is too long. Try another one.')
                else:
                    break
            except asyncio.TimeoutError:
                embed = discord.Embed(title='Timeout', description='You didn\'t respond in time.', color=discord.Color.red())
                await ctx.send('', embed=embed)
                return

        await ctx.author.send('This message has been accepted.')
        
        hidden_word = ' '.join(['_' * len(word) for word in message.split()])
        hidden_str = ' '.join([r'\_ ' * len(word) for word in message.split()])

        hidden_embed = discord.Embed(title=hidden_str, description='Wrong Guesses: 0/5', color=discord.Color.blue())
        hidden_msg = await ctx.send('', embed=hidden_embed)

        def check_guess(msg):
            return len(msg.content) == 1 and msg.author.name in players

        guessed_letters = []
        wrong_guesses = 0

        end_result = ' '.join(list(message))

        while hidden_str != end_result:
            try:
                guess = await self.bot.wait_for('message', timeout=120, check=check_guess)

            except asyncio.TimeoutError:
                embed = discord.Embed(title='The game has been aborted.', description='Too much time has passed without a guess.', color=discord.Color.red())
                await hidden_msg.delete()
                await ctx.send('', embed=embed)
                self.playingHangman = False
                return
            
            guess = guess.content.lower()

            if guess not in guessed_letters:
                guessed_letters.append(guess)

                if guess in message.lower():
                    positions = []
                    appearances = 0
                    for char in message.lower():
                        if char == guess:
                            appearances += 1
                    
                    start = -1
                    for _ in range(appearances):
                        start = message.lower().find(guess, start + 1)
                        positions.append(start)
                    
                    hidden_word_list = list(hidden_word)

                    for pos in positions:
                        hidden_word_list[pos] = message[pos]

                    hidden_str = ''
                    for char in hidden_word_list:
                        if char == '_':
                            hidden_str += r'\_ '
                        else:
                            hidden_str += char + ' '

                    hidden_word = ''.join(hidden_word_list)
                    hidden_str = hidden_str[:-1]

                    await hidden_msg.delete()
                    hidden_embed.title = hidden_str

                    hidden_msg = await ctx.send('', embed=hidden_embed)

                else:
                    wrong_guesses += 1
                    
                    hidden_embed.description = f'Wrong Guesses: {wrong_guesses}/5'
                    await hidden_msg.delete()
                    hidden_msg = await ctx.send('', embed=hidden_embed)

                    if wrong_guesses == 5:
                        self.playingHangman = False

                        embed = discord.Embed(title='You lost!', description=f'The message was {message}', color=discord.Color.red())
                        await ctx.send('', embed=embed)
                        return
        
        embed = discord.Embed(title='You guessed the message! Good job! :thumbsup:', color=discord.Color.green())
        await ctx.send('', embed=embed)

        self.playingHangman = False
Example #4
0
async def enter_lottery(ctx, user, bot):
    amount_embed = discord.Embed(title='How many would you like to use?',
                                 color=discord.Color.blue())
    await ctx.send('', embed=amount_embed)

    try:
        msg = await bot.wait_for('message', timeout=10, check=check_lot_msg)

        amount = int(msg.content)

        if amount < 1:
            embed = discord.Embed(
                title='Error!',
                description='You can\'t use fewer than 1 tickets.',
                color=discord.Color.red())
            await ctx.send('', embed=embed)
            return

        users = get_users()

        if amount > users[ctx.author.name]['items']['Lottery Ticket'] + 1:
            embed = discord.Embed(
                title='Error!',
                description='You dont\'t have this many tickets.',
                color=discord.Color.red())
            await ctx.send('', embed=embed)
            users[ctx.author.name]['items']['Lottery Ticket'] += 1
            dump_users(users)
            return

        num_list = [random.randint(1, 200) for _ in range(amount)]

        if 69 in num_list:
            edit_user_milk(ctx.author.name, 100000)

            embed = discord.Embed(title='You won!',
                                  description='You have received 100000mu!',
                                  color=discord.Color.green())
            await ctx.send('', embed=embed)

        else:
            embed = discord.Embed(title='You lost.',
                                  description='Better luck next time.',
                                  color=discord.Color.red())
            await ctx.send('', embed=embed)

        users[ctx.author.name]['items']['Lottery Ticket'] -= (amount - 1)

        if users[ctx.author.name]['items']['Lottery Ticket'] == 0:
            del users[ctx.author.name]['items']['Lottery Ticket']

        dump_users(users)

    except asyncio.TimeoutError:
        embed = discord.Embed(title='Timed out.',
                              description='You didn\'t respond in time.',
                              color=discord.Color.red())
        await ctx.send('', embed=embed)
        users = get_users()
        users[ctx.author.name]['items']['Lottery Ticket'] += 1
        dump_users(users)
Example #5
0
async def eat_cookie(ctx, user):
    embed = discord.Embed(title='You ate the cookie. Nothing happened...',
                          color=discord.Color.blue())
    await ctx.send('', embed=embed)
Example #6
0
async def cant_be_used(ctx, user):
    embed = discord.Embed(title='Error!',
                          description='This item can\'t be used.',
                          color=discord.Color.red())
    await ctx.send('', embed=embed)