<commit_before>import asyncio
from concurrent import futures
import os
import random
import re
from urllib.parse import parse_qs

import discord
from discord.ext import commands
from lxml import etree

from starwars import starroller, die_names


class RPG:
    def __init__(self, bot):
        self.bot = bot
        self.tarot_url = 'http://www.tarotlore.com/tarot-cards/{}/'

    @commands.command()
    async def choose(self, ctx, *options):
        """Choose between some options. Use quotes if they have spaces."""
        await ctx.send(random.choice(options))

    @commands.command()
    async def tarot(self, ctx, *suits):
        """Get a random tarot card."""
        async with ctx.typing():
            cards = []
            if not suits:
                suits = ('cups', 'swords', 'wands', 'pentacles', 'major')
            if 'minor' in suits:
                suits = suits + ('cups', 'swords', 'wands', 'pentacles')
            suits = set(suit.lower() for suit in suits)
            for root, dirs, files in os.walk('data/tarot'):
                if any(suit in root for suit in suits):
                    cards += [f'{root}/{card}' for card in files]
            card = random.choice(cards).replace('\\', '/')
            match = re.match(r'(?:\w+/)+[IVX0_]*([\w_]+)\.jpg', card)
            name = match.groups()[0].replace('_', ' ')
            url = self.tarot_url.format(name.lower().replace(' ', '-'))
            embed = discord.Embed()
            embed.title = name
            embed.url = url
            filename = card.replace('_', '').rpartition('/')[-1]
            embed.set_image(url=f'attachment://{filename}')
            await ctx.send(file=discord.File(f'{card}', filename),
                           embed=embed)

    @commands.command(aliases=['r'])
    async def roll(self, ctx, *, inp='1d20'):
        """Roll some dice!

        Can roll multiple dice of any size, with modifiers.
        Format: XdY([+-^v]Z)(xN)(s)(t)
        X is the number of dice
        Y is the number of sides
        + adds Z to the result
        - subtracts Z from the result<commit_msg>Handle bad input<commit_after>import asyncio
from concurrent import futures
import os
import random
import re
from urllib.parse import parse_qs

import discord
from discord.ext import commands
from lxml import etree

from starwars import starroller, die_names


class RPG:
    def __init__(self, bot):
        self.bot = bot
        self.tarot_url = 'http://www.tarotlore.com/tarot-cards/{}/'

    @commands.command()
    async def choose(self, ctx, *options):
        """Choose between some options. Use quotes if they have spaces."""
        await ctx.send(random.choice(options))

    @commands.command()
    async def tarot(self, ctx, *suits):
        """Get a random tarot card."""
        async with ctx.typing():
            cards = []
            if not suits:
                suits = ('cups', 'swords', 'wands', 'pentacles', 'major')
            if 'minor' in suits:
                suits = suits + ('cups', 'swords', 'wands', 'pentacles')
            suits = set(suit.lower() for suit in suits)
            for root, dirs, files in os.walk('data/tarot'):
                if any(suit in root for suit in suits):
                    cards += [f'{root}/{card}' for card in files]
            try:
                card = random.choice(cards).replace('\\', '/')
            except IndexError:
                await ctx.send('Please specify a valid suit, or no suit.')
                return
            match = re.match(r'(?:\w+\/)+[IVX0_]*([\w_]+)\.jpg', card)
            name = match.groups()[0].replace('_', ' ')
            url = self.tarot_url.format(name.lower().replace(' ', '-'))
            embed = discord.Embed()
            embed.title = name
            embed.url = url
            filename = card.replace('_', '').rpartition('/')[-1]
            embed.set_image(url=f'attachment://{filename}')
            await ctx.send(file=discord.File(f'{card}', filename),
                           embed=embed)

    @commands.command(aliases=['r'])
    async def roll(self, ctx, *, inp='1d20'):
        """Roll some dice!

        Can roll multiple dice of any size, with modifiers.
        Format: XdY([+-^v]Z)(xN)(s)(t)
        X is the number of dice
        Y is the number of sides
        + adds Z to the result
        - subtracts Z from the result
{'fraction_non_alphanumeric': 0.1416819012797075, 'fraction_numerical': 0.002742230347349177, 'mean_word_length': 2.0416956219596942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1471439', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1269, 'n_words': 380}