import json import re import requests import sys from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) ISSUE = re.compile('^#(\d*)| #(\d*)') URL = 'https://api.github.com/repos/%s/issues/{nb}' % sys.argv[1] sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): if msg['type'] != 'message': continue message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message'] match = ISSUE.search(text) if match: issue_nb = match.groups()[0] or match.groups()[1] resp = requests.get(URL.format(nb=issue_nb)) if resp.status_code == 200: msg = "{title} ({state}) - {html_url}".format(**resp.json) zen.send_privmsg(message['data']['channel'], msg)
import random import json from zenircbot_api import ZenIRCBot, load_config bot_config = load_config("../bot.json") zen = ZenIRCBot(bot_config["redis"]["host"], bot_config["redis"]["port"], bot_config["redis"]["db"]) zen.register_commands( "twsrs.py", [ { "name": "that's what she said", "description": ('Replies to "That\'s what she said" with quotes from ' "famous women"), } ], ) quote_list = open("twsrs_quotes.txt").readlines() def get_quote(): """get_quote""" index = random.randint(0, len(quote_list) - 1) quote = quote_list[index].strip() return quote sub = zen.get_redis_client().pubsub()
from datetime import datetime, timedelta from time import sleep import re from BeautifulSoup import BeautifulSoup from feedparser import parse from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) zen.register_commands('jira_feed.py', []) jira_config = load_config("./jira.json") jira_url = '%sbrowse/\\1' % jira_config['jira_url'] latest = None def strtodt(string): return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ') while True: feed = parse(jira_config['feed_url']) if latest is None: latest = strtodt(feed['entries'][0].updated) - timedelta(seconds=1) entries = [ entry for entry in feed['entries'] if strtodt(entry.updated) > latest ] for entry in entries:
import random import json from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) zen.register_commands('twsrs.py', [{'name': 'that\'s what she said', 'description': 'Replies to "That\'s what she said" with quotes from famous women'}]) quote_list = open('twsrs_quotes.txt').readlines() def get_quote(): """get_quote""" index = random.randint(0, len(quote_list) - 1) quote = quote_list[index].strip() return quote sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message']
import random import json from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) zen.register_commands('twsrs.py', [{ 'name': 'that\'s what she said', 'description': ('Replies to "That\'s what she said" with quotes from ' 'famous women') }]) quote_list = open('twsrs_quotes.txt').readlines() def get_quote(): """get_quote""" index = random.randint(0, len(quote_list) - 1) quote = quote_list[index].strip() return quote sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): message = json.loads(msg['data']) if message['version'] == 1:
from datetime import datetime, timedelta from time import sleep import re from BeautifulSoup import BeautifulSoup from feedparser import parse from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) zen.register_commands('jira_feed.py', []) jira_config = load_config("./jira.json") jira_url = '%sbrowse/\\1' % jira_config['jira_url'] latest = None def strtodt(string): return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ') while True: feed = parse(jira_config['feed_url']) if latest is None: latest = strtodt(feed['entries'][0].updated) - timedelta(seconds=1) entries = [entry for entry in feed['entries']
import json from zenircbot_api import ZenIRCBot, load_config import requests bot_config = load_config('../bot.json') admins = bot_config['servers'][0]['admin_nicks'] zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) commands = [ { 'name': '!funday', 'description': 'Gets a random funday monday from fundayroulette.com' } ] # zen.register_commands(__file__, commands) funday_url = 'http://fundayroulette.com/api/v1/funday/random/?format=json' def debug(data): return zen.send_privmsg('#pdxbots', str(data)) sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): debug(msg)
import json import re import requests import sys from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) ISSUE = re.compile('^#(\d*)| #(\d*)') URL = 'https://api.github.com/repos/%s/issues/{nb}' % sys.argv[1] sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): if msg['type'] != 'message': continue message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message'] match = ISSUE.search(text) if match: issue_nb = match.groups()[0] or match.groups()[1] resp = requests.get(URL.format(nb=issue_nb))
import json from zenircbot_api import ZenIRCBot, load_config import requests bot_config = load_config('../bot.json') admins = bot_config['servers'][0]['admin_nicks'] zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) commands = [{ 'name': '!funday', 'description': 'Gets a random funday monday from fundayroulette.com' }] # zen.register_commands(__file__, commands) funday_url = 'http://fundayroulette.com/api/v1/funday/random/?format=json' def debug(data): return zen.send_privmsg('#pdxbots', str(data)) sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): debug(msg) if msg['type'] == 'subscribe':