def room_say(message, fmt="text", notify=1, color="yellow", room="standup"): print "Saying in %s room: %s" % (room, message) Room.message(room_id=state["%s_room_id" % room], message=message, message_format=fmt, notify=notify, color=color, **{"from": settings.BOT_NAME})
def room_say(message, fmt="text", notify=1, color="yellow", room="standup"): print "Saying in %s room: %s" % (room, message) Room.message( room_id=state["%s_room_id" % room], message=message, message_format=fmt, notify=notify, color=color, **{"from": settings.BOT_NAME} )
def emit(self, record, room_id=None, sender=None, color=None): if not room_id: room_id = config.HIPCHAT_ROOMID if not sender: sender = config.HIPCHAT_SENDER if not color: color = 'red' try: message = {'room_id': room_id, 'from': sender, 'notify': 1, 'color': color, 'message': record.message} Room.message(**message) except: # swallow ALL errors here. print "error"
def emit(self, record, room_id=None, sender=None, color=None): if not room_id: room_id = config.HIPCHAT_ROOMID if not sender: sender = config.HIPCHAT_SENDER if not color: color = 'red' try: message = { 'room_id': room_id, 'from': sender, 'notify': 1, 'color': color, 'message': record.message } Room.message(**message) except: # swallow ALL errors here. print "error"
def create_room(room_name, set_topic=None): found_room = None for room in Room.list(): if room.name.lower() == room_name.lower(): found_room = room.room_id if found_room: if set_topic: print "updating room topic to %r" % set_topic Room.topic(room_id=found_room, topic=set_topic, **{"from": settings.BOT_NAME}) return found_room else: print "creating new room %s" % room_name room = Room.create( name=room_name, owner_user_id=state["bot_user_id"], topic=set_topic or "(go team!)", ) return room.room_id
def recent_users(): today = date.today() start = today - timedelta(days=settings.LOOK_BACK_DAYS) users = dict((u.user_id, u) for u in User.list()) seen = set() day = start user_order = list() while day <= today: kwargs = dict( date=day.strftime("%Y-%m-%d"), timezone=settings.BOT_TZ, ) try: day_talk = ( Room.history(room_id=state["team_room_id"], **kwargs) + Room.history(room_id=state["standup_room_id"], **kwargs) ) for message in day_talk: if message.sort != "message": continue from_info = getattr(message, "from") user_id = from_info["user_id"] if user_id in (u"api", state["bot_user_id"]): continue if user_id not in seen: logger.info("Added %s to the standup" % from_info["name"]) print "Added %s to the standup" % from_info["name"] seen.add(user_id) if user_id in user_order: del user_order[user_order.index(user_id)] user_order.append(user_id) except Exception, e: logger.warning( "error fetching history for %s: %r" % ( day.strftime("%Y-%m-%d"), e, ) ) day += timedelta(days=1)
def create_room(room_name, set_topic=None): found_room = None for room in Room.list(): if room.name.lower() == room_name.lower(): found_room = room.room_id if found_room: if set_topic: print "updating room topic to %r" % set_topic Room.topic( room_id=found_room, topic=set_topic, **{"from": settings.BOT_NAME} ) return found_room else: print "creating new room %s" % room_name room = Room.create( name=room_name, owner_user_id=state["bot_user_id"], topic=set_topic or "(go team!)", ) return room.room_id
def recent_users(): today = date.today() start = today - timedelta(days=settings.LOOK_BACK_DAYS) users = dict((u.user_id, u) for u in User.list()) seen = set() day = start user_order = list() while day <= today: kwargs = dict( date=day.strftime("%Y-%m-%d"), timezone=settings.BOT_TZ, ) try: day_talk = ( Room.history(room_id=state["team_room_id"], **kwargs) + Room.history(room_id=state["standup_room_id"], **kwargs)) for message in day_talk: if message.sort != "message": continue from_info = getattr(message, "from") user_id = from_info["user_id"] if user_id in (u"api", state["bot_user_id"]): continue if user_id not in seen: logger.info("Added %s to the standup" % from_info["name"]) print "Added %s to the standup" % from_info["name"] seen.add(user_id) if user_id in user_order: del user_order[user_order.index(user_id)] user_order.append(user_id) except Exception, e: logger.warning("error fetching history for %s: %r" % ( day.strftime("%Y-%m-%d"), e, )) day += timedelta(days=1)
def standup_loop(): while len(state["todo"]) and not terminate: recent_msgs = Room.history( room_id=state["standup_room_id"], timezone=settings.BOT_TZ, date="recent", ) for msg in recent_msgs: msg_date = parse(msg.date) if msg_date <= state["last_checked"]: continue from_info = getattr(msg, "from") if from_info["user_id"] in state["users"]: process_message(msg) state["last_checked"] = msg_date gevent.sleep(5) return standup_done()
exit() if hipchat_room_names == None: hipchat_room_names = [hipchat_room_name] my_username = "******" try: raw_hipchat_log=open('lucille.log') hipchat_log = json.load(raw_hipchat_log) raw_hipchat_log.close() except Exception: hipchat_log = {}; hipchat_rooms = [] for r in Room.list(): if r.name in hipchat_room_names: hipchat_rooms.append(r) if len(hipchat_rooms) == 0: print "no room found for digg" exit() GIPHY_REGEX = re.compile("\/giphy (.+)") EIGHTBALL_COMMAND_TERM = "8ball" EIGHTBALL_POSITIVE_RESPONSES = set(['It is decidedly so', 'Without a doubt', 'Yes definitely', 'It is certain', 'Most likely', 'You may rely on it', 'Yes', 'Outlook good', 'As I see it yes', 'Signs point to yes']) EIGHTBALL_NEGATIVE_RESPONSES = set(['Cannot predict now', 'Reply hazy try again', 'Ask again later', 'Better not tell you now', 'Concentrate and ask again']) EIGHTBALL_NEUTRAL_RESPONSES = set(['My reply is no', 'My sources say no', "Don't count on it", 'Very doubtful', 'Outlook not so good']) EIGHTBALL_RESPONSE_TO_KEYWORDS = {
global cfg_file cfg = ConfigObj(cfg_file) cfg['since'] = mktime(datetime.now().timetuple()) cfg.write() def is_since(m, since): dt = datetime.strptime(m.date[:-5], "%Y-%m-%dT%H:%M:%S") return dt >= since def notify(n, m): n.update(m.__getattribute__('from')['name'], m.message) n.show() sleep(3) cfg_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'hipchat.cfg') init_cfg() if not pynotify.init("hipchat"): sys.exit(1) n = pynotify.Notification("hipchat", "firing up") x={"room_id": hipchat.config.room_id, "date": hipchat.config.since.strftime("%Y-%m-%d"), "timezone": "Europe/London", "format": "json"} history=filter((lambda msg: is_since(msg, hipchat.config.since)), Room.history(**x)) map((lambda m: notify(n,m)), history) write_cfg()
exit() if hipchat_room_names == None: hipchat_room_names = [hipchat_room_name] my_username = "******" try: raw_hipchat_log = open('lucille.log') hipchat_log = json.load(raw_hipchat_log) raw_hipchat_log.close() except Exception: hipchat_log = {} hipchat_rooms = [] for r in Room.list(): if r.name in hipchat_room_names: hipchat_rooms.append(r) if len(hipchat_rooms) == 0: print "no room found for digg" exit() GIPHY_REGEX = re.compile("\/giphy (.+)") EIGHTBALL_COMMAND_TERM = "8ball" EIGHTBALL_POSITIVE_RESPONSES = set([ 'It is decidedly so', 'Without a doubt', 'Yes definitely', 'It is certain', 'Most likely', 'You may rely on it', 'Yes', 'Outlook good', 'As I see it yes', 'Signs point to yes' ])