def callback(data): if len(key) == 0: return bot = data.get('bot', 0) word = data.get('arg', '') target = data.get('target', '') if len(word) == 0: nvsk.privmsg(bot, target, '[Wordnik] Please specify the word.') return req = requests.get('http://api.wordnik.com/v4/word.json/{}/definitions?api_key={}&limit=3' .format(word, key)) if req.status_code != 200: nvsk.privmsg(bot, target, '[Wordnik] Invalid reply from the server.') return info = json.loads(req.text) if len(info) == 0: nvsk.privmsg(bot, target, '[Wordnik] No definitions for {}.'.format(word)) return nvsk.privmsg(bot, target, '[Wordnik] Definitions for {}:'.format(word)) for x in range(len(info)): nvsk.privmsg(bot, target, '{}) {}'.format(x + 1, info[x]['text'].encode('utf-8')))
def callback(data): bot = data.get('bot', 0) video = data.get('matches', '')[1].split('=')[1] target = data.get('target', '') req = requests.get('http://gdata.youtube.com/feeds/api/videos/{}?alt=json&v=2'.format(video)) if req.status_code != 200: nvsk.privmsg(bot, target, '[YouTube] Invalid reply from the server.') return info = json.loads(req.text)['entry'] nvsk.privmsg(bot, target, '[YouTube] {} (Author: {}, Views: {:,}, Length: {})'.format( info['title']['$t'], info['author'][0]['name']['$t'], int(info['yt$statistics']['viewCount']), duration(info['media$group']['yt$duration']['seconds'])))
def callback(data): bot = data.get('bot', 0) arg = data.get('arg', '') target = data.get('target', '') if arg.find(',') != -1: choices = [choice.strip(' ') for choice in arg.split(',')] nvsk.privmsg(bot, target, '[Roll] {}'.format(random.choice(choices))) return elif arg.find('-') != -1: arg = arg.split('-') if len(arg) == 2: result = random.randint(int(arg[0]), int(arg[1])) nvsk.privmsg(bot, target, '[Roll] {}'.format(result)) return result = rdice.match(arg) if result: count = int(result.group(1)) faces = int(result.group(2)) if count > 10 or faces > 36: nvsk.privmsg(bot, target, '[Roll] You can roll only up to 10 dice with up to 36 faces.') return total = [] for x in range(count): total.append(random.randint(1, faces)) nvsk.privmsg(bot, target, '[Roll] {} ({} total)'.format( ', '.join([str(x) for x in total]), sum(total) ))
def callback(data): bot = data.get("bot", 0) target = data.get("target", "") query = data.get("arg", "") if len(query) == 0: nvsk.privmsg(bot, target, "[Wikipedia] Please specify the search query.") return summary = wikipedia.summary(query, sentences=3).encode("utf-8") if len(summary) > 250: summary = summary[:250] summary += "..." nvsk.privmsg( bot, target, "[Wikipedia] {} (More at https://wikipedia.org/wiki/{})".format( summary.replace("\n", ""), query.replace(" ", "%20") ), )
def callback(data): bot = data.get('bot', 0) target = data.get('target', '') matches = data.get('matches', []) if len(matches) == 0: return hash = re.findall('imgur\.com/(?:gallery/)?([\w\d]{5,7})', matches[0]) if len(hash) == 0: return req = requests.get('http://imgur.com/gallery/{}.json'.format(hash[0])) if req.status_code != 200: nvsk.privmsg(bot, target, '[imgur] Invalid reply from the server.') return info = json.loads(req.text) if info['status'] != 200 or info['success'] != True: nvsk.privmsg(bot, target, '[imgur] Invalid reply from the API.') return info = info['data']['image'] nvsk.privmsg(bot, target, '[imgur] {} {} ({} points, {} upvotes, {} downvotes)'.format( '[\x034NSFW\x03]' if info['nsfw'] else '[\x033SFW\x03]', info['title'], info['points'], info['ups'], info['downs']))
def callback(data): if client is None: return bot = data.get('bot', 0) target = data.get('target', '') query = data.get('arg', '') if len(query) == 0: nvsk.privmsg(bot, target, '[Calculator] Please specify the search query.') return try: res = client.query(query) except: return if len(res.pods) == 0: nvsk.privmsg(bot, target, '[Calculator] No results found.') return 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'} nvsk.privmsg(bot, target, '[Calculator] {}'.format(result.text.encode('utf-8')))
def callback(data): bot = data.get("bot", 0) term = data.get("arg", "") target = data.get("target", "") if len(term) == 0: nvsk.privmsg(bot, target, "[UrbanDictionary] Please specify the search term.") return req = requests.get("http://api.urbandictionary.com/v0/define?page=0&term={}".format(term)) if req.status_code != 200: nvsk.privmsg(bot, target, "[UrbanDictionary] Invalid reply from the server.") return info = json.loads(req.text).get("list") if not info or len(info) == 0: nvsk.privmsg(bot, target, "[UrbanDictionary] No definitions found.") return nvsk.privmsg(bot, target, "[UrbanDictionary] Definitions for {}:".format(term)) for x in range(min(len(info), 3)): nvsk.privmsg(bot, target, "{}) {}".format(x + 1, info[x]["definition"].encode("utf-8")))
def callback(data): nick = data.get('nick', '') ident = data.get('ident', '') host = data.get('host', '') arg = data.get('arg', '') args = data.get('args', []) bot = data.get('bot', 0) target = data.get('target', '') command = data.get('command', '') if not nvsk.isWhitelisted(bot, '{}!{}@{}'.format(nick, ident, host)): nvsk.privmsg(bot, target, '[Admin] You are not authorized to execute this command.') return if command == 'eval': if not EVAL: nvsk.privmsg(bot, target, '[Admin] This command needs to be explicitly enabled in Scripts/Admin.py file') else: try: result = eval(arg) except Exception as e: result = e.message if result: nvsk.privmsg(bot, target, '[Eval] {}'.format(result)) return data = FUNCS.get(command) if not data: return if len(args) < data[1]: nvsk.privmsg(bot, target, 'Not enough arguments.') return if data[1] == 0: data[0]() return if data[2]: data[0](bot, target, *args) else: data[0](bot, *args)
def callback(data): bot = data.get('bot', 0) location = data.get('arg', '') target = data.get('target', '') if len(location) == 0: nvsk.privmsg(bot, target, '[Weather] Please specify the location.') return req = requests.get('http://api.openweathermap.org/data/2.5/weather?q={}&units=metric'.format(location)) if req.status_code != 200: nvsk.privmsg(bot, target, '[Weather] Invalid reply from the server.') return info = json.loads(req.text) if info.get('message'): nvsk.privmsg(bot, target, '[Weather] {}'.format(info.get('message'))) return nvsk.privmsg(bot, target, '[Weather] {} ({}) {}°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'])))
def callback(data): bot = data.get('bot', 0) title = data.get('arg', '') target = data.get('target', '') if len(title) == 0: nvsk.privmsg(bot, target, '[IMDb] Please specify the movie title.') return req = requests.get('http://omdbapi.com/?t={}'.format(title)) if req.status_code != 200: nvsk.privmsg(bot, target, '[IMDb] Invalid reply from the server.') return info = json.loads(req.text) if info.get('Error'): nvsk.privmsg(bot, target, '[IMDb] {}'.format(info.get('Error'))) return nvsk.privmsg(bot, target, '[IMDb] {} ({}) ({}), more at http://imdb.com/title/{}'.format( info['Title'].encode('utf-8'), info['Year'].encode('utf-8'), info['Genre'].encode('utf-8'), info['imdbID'].encode('utf-8')))
def callback(data): bot = data.get('bot', 0) query = data.get('arg', '') target = data.get('target', '') if len(query) == 0: nvsk.privmsg(bot, target, '[YouTube] Please specify your search query.') return req = requests.get('http://gdata.youtube.com/feeds/api/videos/?v=2&alt=jsonc&max-results=3&q={}'.format(query)) if req.status_code != 200: nvsk.privmsg(bot, target, '[YouTube] Invalid reply from the server.') return info = json.loads(req.text) if info['data']['totalItems'] == 0: nvsk.privmsg(bot, target, '[YouTube] No results found.') results = [] for result in info['data']['items']: results.append('https://youtu.be/{} ({})'.format(result['id'], result['title'].encode('utf-8'))) nvsk.privmsg(bot, target, '[YouTube] Results: {}'.format(', '.join(results)))
def callback(data): bot = data.get('bot', 0) target = data.get('target', '') commands = nvsk.getCommands() nvsk.privmsg(bot, target, 'Available commands: {}'.format(commands))