Ejemplo n.º 1
0
  async def _roll(self, ctx, *dice):
    """rolls dice given pattern [Nd]S[(+|-)C]

    N: number of dice to roll
    S: side on the dice
    C: constant to add or subtract from each die roll
    """
    loop = asyncio.get_event_loop()

    roll = '\n'.join(await loop.run_in_executor(None, self.rolls, dice))
    message = ctx.message.author.mention + ':\n'
    if '\n' in roll:
      message += formatter.code(roll)
    else:
      message += formatter.inline(roll)
    await self.bot.say(message)
Ejemplo n.º 2
0
    async def _add(self, ctx, *, regex):
        """adds a new replacement
    Format `s/old/new/`
    """

        if ctx.message.author.id in self.permissions['rep-blacklist']:
            await self.bot.say(formatter.error('No ') + ':poi:')
            return

        #Find requested replacement
        rep = get_match(regex)

        #ensure that replace was found before proceeding
        if not rep:
            await self.bot.say(formatter.error('Could not find valid regex'))
            return

        p1 = formatter.escape_mentions(rep.group(2))
        p2 = formatter.escape_mentions(rep.group(4))

        #check regex for validity
        if not comp(p1, p2):
            await self.bot.say(formatter.error('regex is invalid'))
            return

        #make sure that there are no similar regexes in db
        for i in self.replacements:
            if similar(p1, i):
                r = '\"{}\" -> \"{}\"'.format(i, self.replacements[i][0])
                message = 'Similar regex already exists, delete or edit it\n{}'.format(
                    formatter.inline(r))
                await self.bot.say(formatter.error(message))
                return

        #make sure regex is not too broad
        if bad_re(p1):
            await self.bot.say(formatter.error('regex is too broad'))
            return

        #check that regex does not already exist
        if p1 in self.replacements:
            await self.bot.say(formatter.error('regex already exists'))
            return

        self.replacements[p1] = [p2, ctx.message.author.id]
        await self.bot.say(formatter.ok())
Ejemplo n.º 3
0
  async def choose(self, ctx, *, choices):
    """Chooses a value from a comma seperated list"""
    choices     = split(choices)
    choice      = random.choice(choices)
    choice_reps = {
       r'(?i)^(should)\s+I\s+'                         : r'You \1 ',
       r'(?i)^([wcs]hould|can|are|were|is)\s+(\S+)\s+' : r'\2 \1 ',
       r'\?$'                                          : '.',
       r'(?i)^am\s+I\s+'                               : 'Thou art ',
       r'(?i)\b(I|me)\b'                               : 'you',
       r'(?i)\bmy\b'                                   : 'your'
    }
    for r in choice_reps:
      choice = re.sub(r, choice_reps[r], choice)

    message  = ctx.message.author.mention + ':\n'
    message += formatter.inline(choice)
    await self.bot.say(message)
Ejemplo n.º 4
0
 async def question(self, ctx):
   """Answers a question with yes/no"""
   message = ctx.message.author.mention + ':\n'
   message += formatter.inline(random.choice(['yes', 'no']))
   await self.bot.say(message)