Ejemplo n.º 1
0
    async def ask(self, context, type=None):
        """
        Asks you a random question about your character or your world, to get the creative juices flowing.
        Initial questions taken from (novel-software).

        Examples:
            !ask c(haracter) - Asks you a question about your character
            !ask w(orld) - Asks you a question about your world
        """

        user = User(context.message.author.id, context.guild.id, context)

        # Check the arguments were all supplied and get a dict list of them and their values, after any prompts
        args = await self.check_arguments(context, type=type)
        if not args:
            return

        # Overwrite the variables passed in, with the values from the prompt and convert to lowercase
        type = args['type'].lower()

        if type in ('c', 'char', 'character'):
            options = lib.get_asset('q_char', user.get_guild())
        elif type in ('w', 'world'):
            options = lib.get_asset('q_world', user.get_guild())

        max = len(options) - 1
        rand = random.randint(1, max)
        question = options[rand]
        await context.send(f'[{rand}] {question}')
Ejemplo n.º 2
0
    async def reassure(self, context, who=None):
        """
        Reassures you that everything will be okay.

        Examples: !reassure
        """

        guild_id = context.guild.id

        # If no name passed through, default to the author of the command
        if who is None:
            mention = context.message.author.mention
        else:

            user = context.guild.get_member_named(who)

            # If we couldn't find the user, display an error
            if user is None:
                await context.send(
                    lib.get_string('err:nouser', guild_id) +
                    ' (There is a known issue with the reassure command, as well as the leaderboards in the Event and XP commands. We are waiting for Discord to respond to an email to get these fixed)'
                )
                return

            mention = user.mention

        # Load the JSON file with the quotes
        quotes = lib.get_asset('reassure', guild_id)

        max = len(quotes) - 1
        quote = quotes[random.randint(1, max)]

        # Send the message
        await context.send(mention + ', ' + format(quote))
Ejemplo n.º 3
0
    async def todo(self, context):
        """
        Displays current TODO list
        """
        user = User(context.message.author.id, context.guild.id, context)

        todo = lib.get_asset('todo', user.get_guild())

        output = '```ini\n'

        for type in todo.keys():

            output += '********** ' + lib.get_string(
                'todo:' + str(type), user.get_guild()) + ' **********\n'

            items = todo[type]
            if len(items):

                n = 1

                for item in items:
                    output += str(n) + '. ' + item + '\n'
                    n += 1
            else:
                output += '-'

            output += '\n\n'

        output += '```'

        return await context.send(output)
Ejemplo n.º 4
0
    async def reassure(self, context, who=None):
        """
        Reassures you that everything will be okay.

        Examples: !reassure
        """

        guild_id = context.guild.id

        # If no name passed through, default to the author of the command
        if who is None:
            who = context.message.author.name

        user = context.guild.get_member_named(who)

        # If we couldn't find the user, display an error
        if user is None:
            await context.send( lib.get_string('err:nouser', guild_id) )
            return

        # Load the JSON file with the quotes
        quotes = lib.get_asset('reassure', guild_id)

        max = len(quotes) - 1
        quote = quotes[random.randint(1, max)]

        # Send the message
        await context.send( user.mention + ', ' + format(quote) )
Ejemplo n.º 5
0
    async def reassure(self, context, who=None):
        """
        Reassures you that everything will be okay.

        Examples: !reassure
        """

        guild_id = context.guild.id

        # If no name passed through, default to the author of the command
        if who is None:
            mention = context.message.author.mention
        else:

            # We must now mention the user directly, as we can't easily lookup users any more
            if not who.startswith('<@!') or not who.endswith('>'):
                return await context.send(
                    lib.get_string('reassure:nomention', guild_id))

            mention = who

        # Load the JSON file with the quotes
        messages = lib.get_asset('reassure', guild_id)

        max = len(messages) - 1
        quote = messages[random.randint(1, max)]

        # Send the message
        await context.send(mention + ', ' + format(quote))
Ejemplo n.º 6
0
    async def quote(self, context):
        """
        A random motivational quote to inspire you.

        Examples: !quote
        """

        guild_id = context.guild.id

        # Load the JSON file with the quotes
        quotes = lib.get_asset('quotes', guild_id)

        max = len(quotes) - 1
        quote = quotes[random.randint(1, max)]

        # Send the message
        await context.send(
            format(quote['quote'] + ' - *' + quote['name'] + '*'))
Ejemplo n.º 7
0
    async def quote(self, context):
        """
        A random motivational quote to inspire you.

        Examples: !quote
        """
        if not Guild(context.guild).is_command_enabled('quote'):
            return await context.send(
                lib.get_string('err:disabled', context.guild.id))

        guild_id = context.guild.id

        # Load the JSON file with the quotes
        quotes = lib.get_asset('quotes', guild_id)

        max = len(quotes) - 1
        quote = quotes[random.randint(1, max)]

        # Send the message
        await context.send(
            format(quote['quote'] + ' - *' + quote['name'] + '*'))
Ejemplo n.º 8
0
    def generate(self, amount):

        generated_names = []

        # If the amount if higher than the max, set it to the max
        if amount > self.MAX_AMOUNT:
            amount = self.MAX_AMOUNT

        # If it's less than 1 for any reason, just use the default
        if amount is None or amount < 1:
            amount = self.DEFAULT_AMOUNT

        # # If the type is 'idea' or 'prompt', change the amount to 1, as that will take up too much space.
        # if self.type == 'idea' or self.type == 'prompt':
        #     amount = 1

        asset_file = 'gen_' + self.type
        source = lib.get_asset(asset_file, self.context.guild.id)
        retry_attempts = 0

        # If we loaded the asset source okay, then let's loop through and generate some responses
        if source:

            # Store all the name choices before we start the loop
            choices = source['names']

            def replace(match):

                match = match.group().replace('$', '')

                if match in choices.keys():

                    # Generate a choice
                    choice = random.choice(choices[match])

                    i = 0

                    # Make sure it's not the same as the last one.
                    # Only try a maximum of self.MAX_RETRIES times though, we don't want a situation where an infinite loop could happen
                    while len(
                            choice
                    ) > 2 and choice == self._last and i < self.MAX_RETRIES:
                        i += 1
                        choice = random.choice(choices[match])

                    self._last = choice
                    return choice
                else:
                    self._last = match
                    return match

            # Loop as many times as the amount we requested, and build up a generated name for each
            x = 0
            while x < amount:

                x += 1

                # Get the formats from the source data
                formats = source['formats']

                # Pick a random one to use
                format = random.choice(formats)

                # Variable to store the last chosen element, so we don't have the same thing twice in a row
                self._last = ''

                # Generate a name
                name = re.sub(r"\$([a-z0-9]+)", replace, format)

                # If we've already had this exact one, try again, up to self.MAX_RETRIES times
                if name in generated_names and retry_attempts < self.MAX_RETRIES:
                    x -= 1
                    retry_attempts += 1
                else:
                    # Add it to the return array
                    generated_names.append(name)
                    retry_attempts = 0

        # Sort the results alphabetically
        generated_names.sort()

        # Uppercase the first letter of each word, if it's anything but idea generation or prompt generatio
        if self.type != 'idea' and self.type != 'prompt':
            generated_names = map(lambda el: string.capwords(el),
                                  generated_names)

        # Generate the message
        message = lib.get_string('generate:message',
                                 self.context.guild.id).format(
                                     amount,
                                     lib.get_string(
                                         'generate:type:' + self.type,
                                         self.context.guild.id))

        return {'names': generated_names, 'message': message}