コード例 #1
0
    def __init__(self):
        super().__init__({
            'name': 'Calculator',
            'command': 'calc',
            'req_params': True,
        })

        self.client = wolframalpha.Client(config.get('tokens').get('wolfram'))
コード例 #2
0
ファイル: history.py プロジェクト: diath/AutoReiv
	def on_message(self, bot, msg):
		if msg.author.id == bot.user.id:
			return

		if msg.content.startswith('{}{}'.format(config.get('trigger'), self.command)):
			return

		self.db.execute('INSERT INTO history VALUES (?, ?, ?, ?);', (None, msg.author.name, int(time()), msg.clean_content))
		self.db.commit()
コード例 #3
0
ファイル: weather.py プロジェクト: diath/AutoReiv
	def callback(self, bot, msg, data):
		req = requests.get('http://api.openweathermap.org/data/2.5/weather?q={}&units=metric&APPID={}'.format(
			data.get('param'), config.get('tokens').get('weather')
		))
		if req.status_code != 200:
			yield from bot.reply(msg, 'Invalid reply from the server.')
		else:
			info = json.loads(req.text)
			if info.get('message'):
				yield from bot.reply(msg, '{}'.format(info.get('message')))
			else:
				yield from bot.reply(msg, '{} ({}) {}°C ({}, Humidity: {}%, Sunrise: {}, Sunset: {})'.format(
					info['name'], info['sys']['country'], floor(info['main']['temp']),
					capwords(info['weather'][0]['description']), info['main']['humidity'],
					ct(info['sys']['sunrise']), ct(info['sys']['sunset'])
				))
コード例 #4
0
ファイル: wordnik.py プロジェクト: diath/AutoReiv
	def callback(self, bot, msg, data):
		req = requests.get('http://api.wordnik.com/v4/word.json/{}/definitions?api_key={}&limit=3'.format(
			data.get('param'), config.get('tokens').get('wordnik')
		))
		if req.status_code != 200:
			yield from bot.reply(msg, 'Invalid reply from the server.')
		else:
			info = json.loads(req.text)
			if len(info) == 0:
				yield from bot.reply(msg, 'No definitions for {}.'.format(data.get('param')))
			else:
				message = 'Definitions for "{}":'.format(data.get('param'))
				for x in range(len(info)):
					message += '\n {}) {}'.format(x + 1, info[x]['text'])

				yield from bot.reply(msg, message)
コード例 #5
0
ファイル: wordnik.py プロジェクト: diath/AutoReiv
    def callback(self, bot, msg, data):
        req = requests.get(
            'http://api.wordnik.com/v4/word.json/{}/definitions?api_key={}&limit=3'
            .format(data.get('param'),
                    config.get('tokens').get('wordnik')))
        if req.status_code != 200:
            yield from bot.reply(msg, 'Invalid reply from the server.')
        else:
            info = json.loads(req.text)
            if not info:
                yield from bot.reply(
                    msg, 'No definitions for {}.'.format(data.get('param')))
            else:
                message = 'Definitions for "{}":'.format(data.get('param'))
                for (
                        index,
                        elem,
                ) in enumerate(info):
                    message += '\n {}) {}'.format(index + 1, elem.get('text'))

                yield from bot.reply(msg, message)
コード例 #6
0
ファイル: weather.py プロジェクト: diath/AutoReiv
 def callback(self, bot, msg, data):
     req = requests.get(
         'http://api.openweathermap.org/data/2.5/weather?q={}&units=metric&APPID={}'
         .format(data.get('param'),
                 config.get('tokens').get('weather')))
     if req.status_code != 200:
         yield from bot.reply(msg, 'Invalid reply from the server.')
     else:
         info = json.loads(req.text)
         if info.get('message'):
             yield from bot.reply(msg, '{}'.format(info.get('message')))
         else:
             yield from bot.reply(
                 msg,
                 '{} ({}) {}°C ({}, Humidity: {}%, Sunrise: {}, Sunset: {})'
                 .format(info['name'], info['sys']['country'],
                         floor(info['main']['temp']),
                         capwords(info['weather'][0]['description']),
                         info['main']['humidity'],
                         format_time(info['sys']['sunrise']),
                         format_time(info['sys']['sunset'])))
コード例 #7
0
ファイル: calculator.py プロジェクト: diath/AutoReiv
	def callback(self, bot, msg, data):
		if self.client is None:
			client = wolframalpha.Client(config.get('tokens').get('wolfram'))

		try:
			res = client.query(data.get('param'))
		except:
			yield from bot.reply(msg, 'Invalid reply from the server.')
		finally:
			if len(res.pods) == 0:
				yield from bot.reply(msg, 'No results found.')
			else:
				result = list(res.results)
				if len(result) != 0:
					result = result[0]
				else:
					if len(res.pods) > 1:
						result = res.pods[1]
					else:
						result = {'text': 'Unknown result'}

				yield from bot.reply(msg, '{}'.format(result.text))