Пример #1
0
 async def dog(self, ctx):
     ''' Get a dog '''
     p = Phrasebook(ctx, self.bot)
     try:
         r = requests.get('https://dog.ceo/api/breeds/image/random')
     except ConnectionError:
         await self.bot.say(
             p.pickPhrase('web', 'timeout', 'Dog Picture',
                          'https://dog.ceo/api'))
         return
     await self.bot.say(p.pickPhrase('trump', 'dog', r.json()['message']))
Пример #2
0
	async def rate(self, ctx):
		''' Rates content using a complex algorithm '''
		p = Phrasebook(ctx, self.bot)
		r = random.randrange(9)
		ms = ""
		for i in range(0,8):
			if i <= r:
				ms = ms + '★'
			else:
				ms = ms + '☆'

		await self.bot.say(p.pickPhrase('roller', 'rate', ms))
		await self.bot.delete_message(ctx.message)
Пример #3
0
    async def mycat(self, ctx):
        ''' Display a cat, generated just for you '''
        p = Phrasebook(ctx, self.bot)
        name = ctx.message.author.name
        if not os.path.isfile('./dat/mycat/' + parse.quote(name) + '.png'):
            await self.bot.say(p.pickPhrase('trump', 'mycat_dl'))
            imgpath = parse.quote(name) + '.png'
            urllib.request.urlretrieve( \
            parse.urlunparse(('http', 'robohash.org', imgpath, '', 'set=set4', '')), \
            './dat/mycat/' + imgpath
            )

        await self.bot.send_file(ctx.message.channel,
                                 './dat/mycat/' + parse.quote(name) + '.png')
Пример #4
0
 async def cat(self, ctx):
     ''' Get a cat '''
     p = Phrasebook(ctx, self.bot)
     try:
         r = requests.get('http://thecatapi.com/api/images/get?format=xml')
     except ConnectionError:
         await self.bot.say(
             p.pickPhrase('web', 'timeout', 'Cat Picture',
                          'http://thecatapi.com'))
         return
     doc = etree.fromstring(r.text)
     source = doc.findtext('data/images/image/source_url')
     lnk = doc.findtext('data/images/image/url')
     await self.bot.say(p.pickPhrase('trump', 'cat', lnk, source))
Пример #5
0
	async def roll(self, ctx, *dice):
		die = ''
		for d in dice:
			die = die + str(d)
		p = Phrasebook(ctx, self.bot)
		msg = ctx.message.author.name + ' rolls ' + str(die) + '\n'
		res = 0
		try:
			dieRoll = Expression(die)
			res = dieRoll.run()
			await self.bot.say(p.pickPhrase('roller', 'out', str(res)))
		except ExpressionSyntaxError:
			await self.bot.say(p.pickPhrase('roller', 'invalid', str(die)))
			return
		except ExpressionVariableError:
			await self.bot.say(p.pickPhrase('roller', 'invalid', str(die)))
			return
Пример #6
0
async def cabbages(ctx):
    ''' Displays the current number of cabbages '''
    p = Phrasebook(ctx, bot)
    global cabbageNumber
    global cabbageStealer
    global cabbageTheftTime
    print('User ' + str(ctx.message.author) +
          ' requested cabbage count (currently ' + str(cabbageNumber) + ')')
    if datetime.now().hour < 5:
        await bot.say(p.pickPhrase('cabbage', 'checkLate'))
        return
    if cabbageNumber == 0:
        await bot.say(
            p.pickPhrase('cabbage', 'checkOut', cabbageStealer,
                         timeStrSince(cabbageTheftTime)))
    else:
        await bot.say(p.pickPhrase('cabbage', 'check', cabbageNumber))
Пример #7
0
async def takeCabbage(ctx):
    ''' Take a cabbage for yourself

Be careful, though: once the cabbages are gone, they're gone until I restart. '''
    p = Phrasebook(ctx, bot)
    global cabbageNumber
    global cabbageStealer
    global cabbageTheftTime
    print('User ' + str(ctx.message.author) + ' took cabbage (now ' +
          str(cabbageNumber - 1) + ')')
    if cabbageNumber > 1:
        cabbageNumber = cabbageNumber - 1
        if cabbageNumber > 100:
            await bot.say(p.pickPhrase('cabbage', 'takePlenty', cabbageNumber))
        else:
            await bot.say(p.pickPhrase('cabbage', 'take', cabbageNumber))
    elif cabbageNumber == 1:
        cabbageNumber = 0
        await bot.say(p.pickPhrase('cabbage', 'takeLast'))
        cabbageStealer = ctx.message.author
        cabbageTheftTime = datetime.now()
    else:
        await bot.say(
            p.pickPhrase('cabbage', 'checkOut', cabbageStealer.name,
                         timeStrSince(cabbageTheftTime)))
Пример #8
0
 async def trump(self, ctx, *target):
     ''' Get presidential insight '''
     p = Phrasebook(ctx, self.bot)
     try:
         if (target):
             s = ''
             for t in target:
                 s = s + t + ' '
             r = requests.get(
                 'https://api.whatdoestrumpthink.com/api/v1/quotes/personalized?q='
                 + parse.quote(s.rstrip()))
         else:
             r = requests.get(
                 'https://api.whatdoestrumpthink.com/api/v1/quotes/random')
     except ConnectionError:
         await self.bot.say(
             p.pickPhrase('web', 'timeout', 'Presidential Quote',
                          'https://api.whatdoestrumpthink.com'))
         return
     await self.bot.say(
         p.pickPhrase('trump', 'trump',
                      (r.json()['message']) + '\n\n  -- Donald J. Trump'))
Пример #9
0
    async def demote(self, ctx, user):
        p = Phrasebook(ctx, self.bot)
        admin = AdminFramework(ctx.message.server)
        if not admin.check(ctx.message.author):
            await self.bot.say(p.pickPhrase('admin', 'notauthorized'))
            return

        mem = ctx.message.server.get_member_named(user)
        if not mem:
            await self.bot.say(p.pickPhrase('admin', 'notfound', user))
        else:
            await self.bot.say(p.pickPhrase('admin', 'confirmdemote', \
             mem.name, mem.discriminator, mem.id)\
            )
            msg = await self.bot.wait_for_message(author=ctx.message.author)
            if msg and 'yes' in msg.content.lower(
            ) or 'confirm' in msg.content.lower():
                admin.demote(mem)
                await self.bot.say(p.pickPhrase('admin', 'demote',
                                                mem.mention))
            else:
                await self.bot.say(p.pickPhrase('admin', 'abort'))
Пример #10
0
 async def wakemeup(self, ctx):
     p = Phrasebook(ctx, self.bot)
     await self.bot.say(p.pickPhrase('poll', 'wakemeup'))
Пример #11
0
 async def saveme(self, ctx):
     p = Phrasebook(ctx, self.bot)
     await self.bot.say(p.pickPhrase('poll', 'saveme'))
Пример #12
0
async def intro(ctx):
    ''' Test Command '''
    p = Phrasebook(ctx, bot)
    await bot.say(p.pickPhrase('core', 'intro1'))
    await bot.say(p.pickPhrase('core', 'intro2'))