def weather(bot, channel, sender, args): weather_endpoint = "http://api.openweathermap.org/data/2.5/weather" geocoded = geocode(bot, channel, sender, args) if type(geocoded) != dict: bot.message(channel, geocoded) latlng = geocoded[u'geometry'][u'location'] args = { 'lat': str(latlng[u'lat']), 'lon': str(latlng[u'lng']), 'units': 'metric', 'APPID': bot.config['OpenWeatherMap']['key'] } response = requests.get(weather_endpoint, params=args) weather = response.json() bot.message( channel, "%s: The current weather in %s: %s || %s°C || Wind: %s m/s || Clouds: %s%% || Pressure: %s hpa" % (sender, geocoded[u'formatted_address'], weather['weather'][0]['description'], weather['main']['temp'], weather['wind']['speed'], weather['clouds']['all'], weather['main']['pressure']))
def lowest_karma(bot, channel, sender, args): """ Shows the lowest 5 users' karma scores """ k = get_multi_karma(bot, 5, False) bot.message( channel, ", ".join("{} ({:d})".format(item, amount) for item, amount in k))
def buttmaster(bot, channel, sender, args): if args and int(args[0]): top = get_multi_butts(bot, int(args[0]), True) bot.message(channel, ", ".join("%s (%d)" % (item, amount) for item, amount in top)) else: top = get_multi_butts(bot, 1, True)[0] bot.message(channel, "The buttmaster is %s, with %s butts" % (top[0], top[1]))
def ud(bot, channel, sender, args): """ Defines you a word """ definition = urbandictionary.define(" ".join(args))[0] bot.message(channel, "{}: {}".format( definition.word, definition.definition ))
def help(bot, channel, sender, args): """Shows all commands, or gets help for a specific command""" if args and args[0] in bot.commands.keys(): docstring = bot.commands[args[0]].__doc__ bot.message(channel, "Help for {0}: {1}".format(args[0], docstring)) else: bot.message(channel, "I know the following channel commands: {0}".format(", ".join(sorted(bot.commands.keys()))))
def weather(bot, channel, sender, args): weather_endpoint = "http://api.openweathermap.org/data/2.5/weather" geocoded = geocode(bot, channel, sender, args) if not isinstance(geocoded, dict): bot.message(channel, geocoded) latlng = geocoded[u'geometry'][u'location'] args = { 'lat': str(latlng[u'lat']), 'lon': str(latlng[u'lng']), 'units': 'metric', 'APPID': bot.config['OpenWeatherMap']['key'] } response = requests.get(weather_endpoint, params=args) current_weather = response.json() bot.message( channel, "{}: The current weather in {}: {} · {}°C · Wind: {} m/s · Clouds: {}% · Pressure: {} hpa" .format(sender, geocoded[u'formatted_address'], current_weather['weather'][0]['description'], current_weather['main']['temp'], current_weather['wind']['speed'], current_weather['clouds']['all'], current_weather['main']['pressure']))
def whereis_tbrb(bot, channel, sender, args): endpoint = "http://track-api.harryreeder.co.uk/ehpeeye" mapurl = "http://maps.googleapis.com/maps/api/staticmap?size=640x320&markers=size:large%7Ccolor:0xc0c0c0%7C" data = json.loads(requests.get(endpoint).text) response = "tbrb's last location was %s%s+%s" % (mapurl, data['loc']['latitude'], data['loc']['longitude']) bot.message(channel, response)
def ud(bot, channel, sender, args): """ Defines you a word """ definition = urbandictionary.define(" ".join(args))[0] bot.message(channel, "{}: {}".format( definition.word, definition.definition ))
def udrandom(bot, channel, sender, args): """ Defines you a random word from urban dictonary""" definition = urbandictionary.random() bot.message(channel, "{}: {}".format( definition[0].word, definition[0].definition ))
def link_title_parse_hook(bot, channel, sender, message): if not allowed_to_process(bot, channel): return elif "[edit]" in message: # Ignore edits for interpreting titles return for word in message.split(" "): for ignore in bot.config['Links']['ignore'].split(): if ignore in word.lower(): return try: if re.match(regex, word): r = requests.get(word) if r.status_code != 200: return r.encoding = 'utf-8' soup = BeautifulSoup(r.text, 'html.parser') raw_title = soup.title if raw_title: title = raw_title.text.strip() title = truncate_title(title) bot.message(channel, "🔗 {}".format(title)) except requests.exceptions.InvalidSchema: pass
def message_hook(bot, channel, sender, message): redis = None term = None reason = None m = re.match(r'^(.*)\+\+([ \t].*)*$', message) if m is not None: term, reason = m.groups() term = term.strip().lower() if term == sender.lower(): bot.message(channel, "Haha, nope!") decrement(bot, term) else: increment(bot, term) m = re.match(r'^(.*)--([ \t].*)*$', message) if m is not None: term, reason = m.groups() term = term.strip().lower() decrement(bot, term) if term: reason = reason.strip() redis = StrictRedis.from_url(bot.config['System']['redis_url']) amount = int( redis.hget(bot.config['System']['redis_prefix'] + "karma", term)) bot.message(channel, "%s now has %s karma %s" % (term, amount, reason))
def weather(bot, channel, sender, args): weather_endpoint = "http://api.openweathermap.org/data/2.5/weather" geocoded = geocode(bot, channel, sender, args) if type(geocoded) != dict: bot.message(channel, geocoded) latlng = geocoded[u'geometry'][u'location'] args = { 'lat': str(latlng[u'lat']), 'lon': str(latlng[u'lng']), 'units': 'metric', 'APPID': bot.config['OpenWeatherMap']['key'] } response = requests.get(weather_endpoint, params=args) weather = response.json() bot.message(channel, "%s: The current weather in %s: %s || %s°C || Wind: %s m/s || Clouds: %s%% || Pressure: %s hpa" % (sender, geocoded[u'formatted_address'], weather['weather'][0]['description'], weather['main']['temp'], weather['wind']['speed'], weather['clouds']['all'], weather['main']['pressure']))
def allow_sender(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if sender == redis.hget(bot.config['System']['redis_prefix'] + "lists:%s" % topic, "owner").decode('utf-8'): redis.sadd(bot.config['System']['redis_prefix'] + "lists:%s:senders" % topic, args[1]) bot.message(channel, "%s: You have now given %s the ability to broadcast to the topic '%s'" % (sender, args[1], topic)) else: bot.message(channel, "%s: You are not the owner of the topic '%s' and cannot add people to the senders list" % (sender, topic))
def karma_command(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) term = " ".join(args).lower() if args else sender.lower() try: amount = int(redis.hget(bot.config['System']['redis_prefix'] + "karma", term)) except TypeError: amount = "no" bot.message(channel, "%s has %s karma" % (term, amount))
def add_reaction(bot, channel, sender, args): """ Adds a reaction for a term - usage: $addreaction http://your.url.here your description here """ redis = StrictRedis.from_url(bot.config['System']['redis_url']) if len(args) == 1: bot.message(channel, "You did not specify a description") url = args[0] term = "_".join(args[1:]).lower() redis.sadd(bot.config['System']['redis_prefix'] + "reactions:" + term, url)
def unsubscribe(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if redis.sismember(bot.config['System']['redis_prefix'] + "lists", topic) and redis.sismember(bot.config['System']['redis_prefix'] + "lists:{}:subscribers".format(topic), sender): redis.srem(bot.config['System']['redis_prefix'] + "lists:{}:subscribers".format(topic), sender) bot.message(channel, "{}: You have now been unsubscribed from the topic '{}'".format(sender, topic)) else: bot.message(channel, "{}: Either that topic does not exist, or you are not a subscriber, and thus cannot unsubscribe from it!".format(sender))
def react(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) term = "_".join(args).lower() try: url = redis.srandmember(bot.config['System']['redis_prefix'] + "reactions:" + term).decode('utf-8') bot.message(channel, url) except TypeError: pass
def transfer_topic(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if sender == redis.hget(bot.config['System']['redis_prefix'] + "lists:{}".format(topic), "owner").decode('utf-8') and args[1]: redis.hset(bot.config['System']['redis_prefix'] + "lists:{}".format(topic), "owner", args[1]) bot.message(channel, "{}: You have now transferred ownership of the topic '{}' to {}".format(sender, topic, args[1])) else: bot.message(channel, "{}: You are not the owner of the topic '{}' and cannot transfer ownership of it.".format(sender, topic))
def subscribe(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if redis.sismember(bot.config['System']['redis_prefix'] + "lists", topic): redis.sadd(bot.config['System']['redis_prefix'] + "lists:{}:subscribers".format(topic), sender) bot.message(channel, "{}: You are now subscribed to the topic '{}'".format(sender, topic)) else: bot.message(channel, "{}: You cannot subscribe to a topic that doesn't exist!".format(sender))
def bot_info(bot, channel, sender, args): """Returns info about the bot, it's owner and where to report issues""" bot.message(channel, "%s: I am %s, a deployment of BotBot. My owner is %s. Any issues can be reported at %s" % ( sender, bot.config['IRC']['nick'], bot.config['System']['owner'], bot.config['System']['repo'] ))
def react(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) term = "_".join(args).lower() try: url = redis.srandmember(bot.config['System']['redis_prefix'] + "reactions:" + term).decode('utf-8') bot.message(channel, url) except TypeError: pass
def disallow_sender(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if sender == redis.hget(bot.config['System']['redis_prefix'] + "lists:{}".format(topic), "owner").decode('utf-8'): redis.srem(bot.config['System']['redis_prefix'] + "lists:{}:senders".format(topic), args[1]) bot.message(channel, "{}: You have now removed the ability to broadcast to the topic '{}' from {}".format(sender, topic, args[1])) else: bot.message(channel, "{}: You are not the owner of the topic '{}' and cannot add people to the senders list".format(sender, topic))
def karma_command(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) term = " ".join(args).lower() if args else sender.lower() try: amount = int( redis.hget(bot.config['System']['redis_prefix'] + "karma", term)) except TypeError: amount = "no" bot.message(channel, "%s has %s karma" % (term, amount))
def giphy(bot, channel, sender, args): """Usage: {bot.trigger}giphy [tag] - Finds a random gif, or returns a random gif tagged with [tag]""" params = (('api_key', giphy_api), ('q', " ".join(args)), ('limit', '25')) resp = requests.get(giphy_url, params=params).json() gif_url = resp['data'][random.randint(1, 25)]['images']['original']['webp'] bot.message(channel, gif_url)
def whereis_cazagen(bot, channel, sender, args): endpoint = "http://loc.cazagen.me/loc.json" mapurl = "http://maps.googleapis.com/maps/api/staticmap?size=640x320&markers=size:large%7Ccolor:0xc0c0c0%7C" data = requests.get(endpoint).json() last_updated = datetime.datetime.fromtimestamp(int(data['update'])) reported = last_updated.strftime('%Y/%m/%d %H:%M %Z') response = "Cameron's last location, reported on {}, was {}{}+{}".format(reported, mapurl, data['lat'], data['lon']) bot.message(channel, response)
def butts(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) who = " ".join(args).lower() if args else sender try: amount = int(redis.hget(bot.config['System']['redis_prefix'] + "buttmaster", who)) except TypeError: amount = "no" bot.message(channel, "%s has %s butts" % (who, amount))
def list_topics(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) subscribed_topics = [] topics = redis.smembers(bot.config['System']['redis_prefix'] + "lists") for topic in topics: topic = topic.decode('utf-8') if redis.sismember(bot.config['System']['redis_prefix'] + "lists:{}:subscribers".format(topic), sender): subscribed_topics.append(topic) bot.message(channel, "{}: You are subscribed to the following topics: {}".format(sender, ", ".join(subscribed_topics)))
def buttmaster(bot, channel, sender, args): if args and int(args[0]): top = get_multi_butts(bot, int(args[0]), True) bot.message( channel, ", ".join("%s (%d)" % (item, amount) for item, amount in top)) else: top = get_multi_butts(bot, 1, True)[0] bot.message(channel, "The buttmaster is %s, with %s butts" % (top[0], top[1]))
def karma_command(bot, channel, sender, args): """ Shows Karma for yourself, or optionally another user. Usage: {bot.trigger}karma [username] """ redis = StrictRedis.from_url(bot.config['System']['redis_url']) term = " ".join(args).lower() if args else sender.lower() try: amount = int( redis.hget(bot.config['System']['redis_prefix'] + "karma", term)) except TypeError: amount = "no" bot.message(channel, "{} has {} karma".format(term, amount))
def bunny_command(bot, channel, sender, args): uri = "https://api.bunnies.io/v2/loop/%s/?media=gif" part = "random" if args: try: part = str(int(args[0])) except ValueError: pass data = requests.get(uri % part).json() bot.message(channel, "https://bunnies.io/#%s - %s" % (data['id'], data['media']['gif']))
def dad_joke(bot, channel, sender, args): """Return a random dad - Usage: {bot.trigger}dadjoke""" endpoint = "https://icanhazdadjoke.com/" data = requests.get(endpoint, headers={ "Accept": "application/json" }).json() response = data['joke'] bot.message(channel, "{}: {}".format(sender, response))
def butts(bot, channel, sender, args): redis = StrictRedis.from_url(bot.config['System']['redis_url']) who = " ".join(args).lower() if args else sender try: amount = int( redis.hget(bot.config['System']['redis_prefix'] + "buttmaster", who)) except TypeError: amount = "no" bot.message(channel, "%s has %s butts" % (who, amount))
def link_title_parse_hook(bot, channel, sender, message): for word in message.split(" "): try: if rfc3987.match(word, rule='URI'): r = requests.get(word) soup = BeautifulSoup(r.text, 'html.parser') title = soup.head.title.text.strip() title = title.replace("\n", "") bot.message(channel, " :: {}".format(title)) except requests.exceptions.InvalidSchema: pass
def destroy_topic(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if sender == redis.hget(bot.config['System']['redis_prefix'] + "lists:{}".format(topic), "owner").decode('utf-8'): redis.srem(bot.config['System']['redis_prefix'] + "lists", topic) redis.delete(bot.config['System']['redis_prefix'] + "lists:{}".format(topic)) redis.delete(bot.config['System']['redis_prefix'] + "lists:{}:subscribers".format(topic)) redis.delete(bot.config['System']['redis_prefix'] + "lists:{}:senders".format(topic)) bot.message(channel, "{}: Topic '{}' was destroyed".format(sender, topic)) else: bot.message(channel, "{}: You are not the owner of the topic '{}' and thus cannot destroy it".format(sender, topic))
def butts(bot, channel, sender, args): """Usage: {bot.trigger}butts [nick] - Tells you how many butts (nick) has. Defaults to sender's nick""" redis = StrictRedis.from_url(bot.config['System']['redis_url']) who = " ".join(args).lower() if args else sender try: amount = int( redis.hget(bot.config['System']['redis_prefix'] + "buttmaster", who)) except TypeError: amount = "no" bot.message(channel, "{} has {} butts".format(who, amount))
def create_topic(bot, channel, sender, args): topic = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if not redis.sismember(bot.config['System']['redis_prefix'] + "lists", topic): redis.sadd(bot.config['System']['redis_prefix'] + "lists", topic) redis.hmset(bot.config['System']['redis_prefix'] + "lists:{}".format(topic), {"owner": sender}) redis.sadd(bot.config['System']['redis_prefix'] + "lists:{}:subscribers".format(topic), sender) redis.sadd(bot.config['System']['redis_prefix'] + "lists:{}:senders".format(topic), sender) bot.message(channel, "{}: New topic '{}' created, with yourself as the owner. You have also been subscribed to the topic by default.".format(sender, topic)) else: owner = redis.hget(bot.config['System']['redis_prefix'] + "lists:{}".format(topic), "owner").decode('utf-8') bot.message(channel, "{}: The topic '{}' already exists, and is owned by {}.".format(sender, topic, owner))
def buttmaster(bot, channel, sender, args): """Usage: {bot.trigger}buttmaster [n] - Tells you who the buttmaster is. Add a number to get a top N.""" if args and int(args[0]): top = get_multi_butts(bot, int(args[0]), True) bot.message( channel, ", ".join("{} {:d}".format(item, amount) for item, amount in top)) else: top = get_multi_butts(bot, 1, True)[0] bot.message( channel, "The buttmaster is {}, with {} butts".format(top[0], top[1]))
def excusetypes(bot, channel, sender, args): """Usage: {bot.trigger}excusetypes - Will return a list of valid excuse types""" redis = StrictRedis.from_url(bot.config['System']['redis_url']) excuse_types = redis.keys(bot.config['System']['redis_prefix'] + "excuses:*") excuse_types_string = ", ".join( [t.decode('utf-8').split(":", 1)[1] for t in excuse_types]) bot.message( channel, "I have the following excuse types: {}".format(excuse_types_string))
def shipit(bot, channel, sender, args): bot.message(channel, random.choice([ "http://shipitsquirrel.github.io/images/ship%20it%20squirrel.png", "http://media.tumblr.com/tumblr_lybw63nzPp1r5bvcto1_500.jpg", "http://i.imgur.com/DPVM1.png", "http://d2f8dzk2mhcqts.cloudfront.net/0772_PEW_Roundup/09_Squirrel.jpg", "http://www.cybersalt.org/images/funnypictures/s/supersquirrel.jpg", "http://www.zmescience.com/wp-content/uploads/2010/09/squirrel.jpg", "https://dl.dropboxusercontent.com/u/602885/github/sniper-squirrel.jpg", "http://1.bp.blogspot.com/_v0neUj-VDa4/TFBEbqFQcII/AAAAAAAAFBU/E8kPNmF1h1E/s640/squirrelbacca-thumb.jpg", "https://dl.dropboxusercontent.com/u/602885/github/soldier-squirrel.jpg", "https://dl.dropboxusercontent.com/u/602885/github/squirrelmobster.jpeg", ]))
def whereis_rikki(bot, channel, sender, args): endpoint = "http://rtrack.r2zer0.net/" mapurl = "http://maps.googleapis.com/maps/api/staticmap?size=640x320&markers=size:large%7Ccolor:0xc0c0c0%7C" data = json.loads(requests.get(endpoint).text) last_updated = datetime.datetime.fromtimestamp( int(data['timestamp']) / 1000) reported = last_updated.strftime('%Y/%m/%d %H:%M') response = "Rikki's last location, reported on %s, was %s%s+%s" % (reported, mapurl, data['latitude'], data['longitude']) bot.message(channel, response)
def slackwho(bot, channel, sender, args): """SlackWho will PM you a list of all users of the associated Slack Team""" slacker = Slacker(bot.config['Slack']['api_key']) users_response = slacker.users.list(presence=True) users = [user['name'] for user in users_response.body['members']] users.reverse() while users: outlist = [] try: for n in range(0, 10): outlist.append(users.pop()) except IndexError: pass output = "Slack Users: %s " % ", ".join(outlist) bot.message(sender, output)
def whereis(bot, channel, sender, args): """Where Is - Locates someone""" who = args[0].lower() targets = { 'rikki': whereis_rikki, 'r2zer0': whereis_rikki, 'rhiaro': whereis_amy, 'amy': whereis_amy, 'tbrb': whereis_tbrb, 'harry': whereis_tbrb } if who in targets.keys(): targets[who](bot, channel, sender, args) elif who == bot.nickname.lower(): bot.message(channel, "I am in the following places: " + ", ".join(bot.channels.keys())) else: bot.message(channel, "I do not know this '%s'. If they've got an open API reporting " "their location data, I'd love to know about it though!" % (who,))
def message_hook(bot, channel, sender, message): redis = None term = None if message.endswith("++"): term = message[:-2].lower() if term == sender.lower(): bot.message(channel, "Haha, nope!") decrement(bot, term) else: increment(bot, term) elif message.endswith("--"): term = message[:-2].lower() decrement(bot, term) if term: redis = StrictRedis.from_url(bot.config['System']['redis_url']) amount = int(redis.hget(bot.config['System']['redis_prefix'] + "karma", term)) bot.message(channel, "%s now has %s karma" % (term, amount))
def np(bot, channel, sender, args): """Now Playing - Gets the currently scrobbling track for a given last.fm user. Usage: np thebigredbutton""" from_redis = get_np_user(bot, sender) if args: user = args[0].strip() if len(args) > 1 and args[1] == "--save": set_np_user(bot, sender, user) elif from_redis: user = from_redis.decode('utf-8') else: user = sender network = pylast.LastFMNetwork( api_key=bot.config['LastFM']['key'], api_secret=bot.config['LastFM']['secret'] ) try: user = network.get_user(user) np = user.get_now_playing() if np: bot.message(channel, "[LastFM] %s is currently listening to '%s'" % (user.get_name(), np)) else: last_played = user.get_recent_tracks(limit=2) last_played = last_played[0] bot.message(channel, "[LastFM] %s is not currently scrobbling - " "They last listened to %s" % (user.get_name(), last_played.track)) except pylast.WSError: bot.message(channel, "[LastFM] I cannot find the user '%s'" % user)
def convert(bot, channel, sender, args): """ Converts units from one measurement to another. ie: !conv 100 cm inches """ amount = float(args[0]) unit_from = args[1] unit_to = args[2] try: ureg = pint.UnitRegistry() unit = ureg.Quantity(amount, unit_from) to = unit.to(unit_to) bot.message(channel, "{} {} || {} {}".format(amount, unit_from, to.magnitude, to.units)) except pint.errors.UndefinedUnitError as ex: bot.message(channel, str(ex)) except pint.errors.DimensionalityError as ex: bot.message(channel, str(ex))
def time(bot, channel, sender, args): '''Returns the time in a specified city''' timezone_endpoint = "https://maps.googleapis.com/maps/api/timezone/json" time_endpoint = "http://api.timezonedb.com/" geocoded = geocode(bot, channel, sender, args) if type(geocoded) != dict: bot.message(channel, geocoded) latlng = geocoded[u'geometry'][u'location'] timezoner_args = { 'sensor': 'false', 'location': str(latlng[u'lat']) + ',' + str(latlng[u'lng']), 'timestamp': pytime.time() } timezone_uri = timezone_endpoint + "?" + \ urllib.parse.urlencode(timezoner_args) timezone_response = requests.get(timezone_uri).text timezone = json.loads(timezone_response) tz = timezone[u'timeZoneId'] time_args = { 'key': 'BNQ3CH0R4TPN', 'zone': tz, 'format': 'json' } time_response = requests.get(time_endpoint, params=time_args).text localtime = json.loads(time_response) if localtime[u'status'] == u'FAIL': bot.message(channel, "%s: I was unable to find the time in %s" % (sender, datetime.datetime.utcfromtimestamp(localtime[u'timestamp']))) return timenow = datetime.datetime.utcfromtimestamp(localtime[u'timestamp']) bot.message(channel, "%s: It is currently %s in %s || Timezone: %s (%s)" % (sender, timenow.strftime("%H:%M"), geocoded[u'formatted_address'], tz, timezone[u'timeZoneName']))
def slacksetavatar(bot, sender, args): """SlackSetAvatar will set the avatar associated with your nickname. You can pass in either a URL or an E-Mail address (to use Gravatar)""" if args: inp = args[0] redis = StrictRedis.from_url(bot.config['System']['redis_url']) if inp.startswith("http://") or inp.startswith("https://"): # we're dealing with a direct url, store it redis.set(bot.config['System']['redis_prefix'] + "slack-avatar-" + sender, inp) bot.message(sender, "Ok, I've set that for you. Your avatar URL is: " + inp) return elif "@" in inp: # We're dealing with an email, let's treat it as gravatar url = "http://www.gravatar.com/avatar/" + hashlib.md5(inp.encode('utf-8').lower()).hexdigest() + "?s=200" redis.set(bot.config['System']['redis_prefix'] + "slack-avatar-" + sender, url) bot.message(sender, "Ok, I've set that for you. Your avatar URL is: " + url) return else: bot.message(sender, "Sorry, that wasn't recognised. I can support setting an email for gravatar " "or a direct url for an avatar")
def slackwhois(bot, channel, sender, args): """SlackWhois will return Username, Real Name (if available) and presence information about a given Slack user""" slacker = Slacker(bot.config['Slack']['api_key']) if not args: bot.message(channel, "%s: Please supply a user to look up" % sender) return users_response = slacker.users.list(presence=True) users = {user['name']: user for user in users_response.body['members']} if args[0] not in users: bot.message(channel, "%s: %s was not found in the slack team" % (sender, args[0])) return user = args[0] user = users[user] name_str = user['name'] if user['profile']['real_name']: name_str += " (%s)" % user['profile']['real_name'] bot.message(channel, "Slack User: %s, Presence: %s" % (name_str, user['presence']))
def message_hook(bot, channel, sender, message): if set(message) <= set(cyrillic_latin.keys()) and message.strip(): translit = ''.join(str(c) for c in map(lambda x: cyrillic_latin[x], message)) translate = translate_text(bot, message) bot.message(channel, '%s <%s> ~ %s' % (message, translit, translate))
def lowest_karma(bot, channel, sender, args): k = get_multi_karma(bot, 5, False) bot.message(channel, ", ".join("%s (%d)" % (item, amount) for item, amount in k))
def whereis_amy(bot, channel, sender, args): endpoint = "http://rhiaro.co.uk/where" data = json.loads(requests.get(endpoint).text) bot.message(channel, data['as:summary'] + " - https://rhiaro.co.uk/arrives")
def reload(bot, channel, sender, args): """Owner Command: Reload the bot""" if sender == bot.config['System']['owner']: bot.load_plugins() bot.message(channel, "Reloaded 👍")
def giphy(bot, channel, sender, args): tag = None if args: tag = " ".join(args) bot.message(channel, screensaver(tag=tag).fixed_height.url)