def restart_automatically(): Metasmoke.send_statistics() chatcommunicate.tell_rooms_with( "debug", "{}: Executing automatic scheduled reboot.".format( GlobalVars.location)) time.sleep(6) exit_mode("reboot")
def has_community_bumped_post(post_url, post_content): if GlobalVars.metasmoke_key is not None and GlobalVars.metasmoke_host is not None: try: ms_posts = Metasmoke.get_post_bodies_from_ms(post_url) if not ms_posts: return False return any(post['body'] == post_content for post in ms_posts) except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError): return False # MS is down, so assume it is not bumped return False
def autoflagged(msg): """ Determines whether a post was automatically flagged by Metasmoke :param msg: :return: A string """ post_data = get_report_data(msg) if not post_data: raise CmdException("That's not a report.") is_autoflagged, names = Metasmoke.determine_if_autoflagged(post_data[0]) if is_autoflagged: return "That post was automatically flagged, using flags from: {}.".format(", ".join(names)) else: return "That post was **not** automatically flagged by metasmoke."
def has_community_bumped_post(post_url, post_content): if GlobalVars.metasmoke_key is not None and GlobalVars.metasmoke_host is not None: try: ms_posts = Metasmoke.get_post_bodies_from_ms(post_url) if not ms_posts: return False latest_revision_date = max( [post['created_at'] for post in ms_posts]) for post in ms_posts: if post['created_at'] == latest_revision_date: if post['body'] == post_content: return True except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError): return False # MS is down, so assume it is not bumped return False
"SmokeDetector started in [standby mode](" + \ "https://charcoal-se.org/smokey/SmokeDetector-Statuses#standby-mode) " + \ "at [rev " +\ GlobalVars.commit_with_author +\ "](" + GlobalVars.bot_repository + "/commit/" +\ GlobalVars.commit['id'] +\ ") (running on " +\ GlobalVars.location +\ ")" GlobalVars.charcoal_hq = GlobalVars.wrap.get_room(GlobalVars.charcoal_room_id) if "standby" in sys.argv: GlobalVars.charcoal_hq.send_message(GlobalVars.standby_message) GlobalVars.standby_mode = True Metasmoke.send_status_ping() while GlobalVars.standby_mode: time.sleep(3) tavern_id = GlobalVars.meta_tavern_room_id GlobalVars.tavern_on_the_meta = GlobalVars.wrapm.get_room(tavern_id) GlobalVars.socvr = GlobalVars.wrapso.get_room(GlobalVars.socvr_room_id) def check_socket_connections(): if (datetime.utcnow() - GlobalVars.charcoal_hq.last_activity).total_seconds() >= 60 or\ (datetime.utcnow() - GlobalVars.socvr.last_activity).total_seconds() >= 60 or\ (datetime.utcnow() - GlobalVars.tavern_on_the_meta.last_activity).total_seconds() >= 60: os._exit(10)
def restart_automatically(): Metasmoke.send_statistics() os._exit(5)
GlobalVars.commit_with_author +\ "](" + GlobalVars.bot_repository + "/commit/" +\ GlobalVars.commit['id'] +\ ") (running on " +\ GlobalVars.location +\ ")" GlobalVars.standby_mode = "standby" in sys.argv chatcommunicate.init(username, password) Tasks.periodic(Metasmoke.send_status_ping, interval=60) Tasks.periodic(Metasmoke.check_last_pingtime, interval=30) if GlobalVars.standby_mode: chatcommunicate.tell_rooms_with("debug", GlobalVars.standby_message) Metasmoke.send_status_ping() while GlobalVars.standby_mode: time.sleep(3) chatcommunicate.join_command_rooms() # noinspection PyProtectedMember def check_socket_connections(): for client in chatcommunicate._clients.values(): if client.last_activity and (datetime.utcnow() - client.last_activity ).total_seconds() >= 60: os._exit(10)
ws = websocket.create_connection("ws://qa.sockets.stackexchange.com/") ws.send("155-questions-active") GlobalVars.charcoal_hq.join() GlobalVars.tavern_on_the_meta.join() GlobalVars.socvr.join() GlobalVars.charcoal_hq.watch_socket(watcher) GlobalVars.tavern_on_the_meta.watch_socket(watcher) GlobalVars.socvr.watch_socket(watcher) if "first_start" in sys.argv and GlobalVars.on_master: GlobalVars.charcoal_hq.send_message(GlobalVars.s) elif "first_start" in sys.argv and not GlobalVars.on_master: GlobalVars.charcoal_hq.send_message(GlobalVars.s_reverted) Metasmoke.send_status_ping() # This will call itself every minute or so while True: try: a = ws.recv() if a is not None and a != "": is_spam, reason, why = check_if_spam_json(a) if is_spam: t = Thread(target=GlobalVars.bodyfetcher.add_to_queue, args=(a, True)) t.start() else: t = Thread(target=GlobalVars.bodyfetcher.add_to_queue, args=(a, )) t.start() except Exception, e:
def restart_automatically(): Metasmoke.send_statistics() os._exit(1)
def restart_automatically(time_in_seconds): time.sleep(time_in_seconds) Metasmoke.send_statistics(False) # false indicates not to auto-repeat os._exit(1)
def is_code_privileged(site, user_id): if GlobalVars.code_privileged_users is None: Metasmoke.update_code_privileged_users_list() # For now, disable the moderator override on code/blacklist changes return (site, user_id) in GlobalVars.code_privileged_users
def restart_automatically(): Metasmoke.send_statistics() exit_mode("reboot")
GlobalVars.commit_with_author +\ "](" + GlobalVars.bot_repository + "/commit/" +\ GlobalVars.commit['id'] +\ ") (running on " +\ GlobalVars.location +\ ")" GlobalVars.standby_mode = "standby" in sys.argv chatcommunicate.init(username, password) Tasks.periodic(Metasmoke.send_status_ping, interval=60) Tasks.periodic(Metasmoke.check_last_pingtime, interval=30) if GlobalVars.standby_mode: chatcommunicate.tell_rooms_with("debug", GlobalVars.standby_message) Metasmoke.send_status_ping() while GlobalVars.standby_mode: time.sleep(3) chatcommunicate.init(username, password) # to rejoin rooms # noinspection PyProtectedMember def check_socket_connections(): for client in chatcommunicate._clients.values(): if client.last_activity and (datetime.utcnow() - client.last_activity).total_seconds() >= 60: os._exit(10) # noinspection PyProtectedMember
GlobalVars.socvr.join() GlobalVars.charcoal_hq.watch_socket(watcher) GlobalVars.tavern_on_the_meta.watch_socket(watcher) GlobalVars.socvr.watch_socket(watcher) for room in GlobalVars.specialrooms: if "watcher" in room: room["room"].join() room["room"].watch_socket(special_room_watcher) if "first_start" in sys.argv and GlobalVars.on_master: GlobalVars.charcoal_hq.send_message(GlobalVars.s) elif "first_start" in sys.argv and not GlobalVars.on_master: GlobalVars.charcoal_hq.send_message(GlobalVars.s_reverted) Metasmoke.send_status_ping() # This will call itself every minute or so metasmoke_ws_t = Thread(target=Metasmoke.init_websocket) metasmoke_ws_t.start() while True: try: a = ws.recv() if a is not None and a != "": is_spam, reason, why = check_if_spam_json(a) t = Thread(target=GlobalVars.bodyfetcher.add_to_queue, args=(a, True if is_spam else None)) t.start() except Exception, e: exc_type, exc_obj, exc_tb = sys.exc_info() now = datetime.utcnow() delta = now - UtcDate.startup_utc_date
"SmokeDetector started in [standby mode](" + \ GlobalVars.bot_repository + "/blob/master/StandbyMode.md) " + \ "at [rev " +\ GlobalVars.commit_with_author +\ "](" + GlobalVars.bot_repository + "/commit/" +\ GlobalVars.commit['id'] +\ ") (running on " +\ GlobalVars.location +\ ")" GlobalVars.charcoal_hq = GlobalVars.wrap.get_room(GlobalVars.charcoal_room_id) if "standby" in sys.argv: GlobalVars.charcoal_hq.send_message(GlobalVars.standby_message) GlobalVars.standby_mode = True Metasmoke.send_status_ping() while GlobalVars.standby_mode: time.sleep(3) tavern_id = GlobalVars.meta_tavern_room_id GlobalVars.tavern_on_the_meta = GlobalVars.wrapm.get_room(tavern_id) GlobalVars.socvr = GlobalVars.wrapso.get_room(GlobalVars.socvr_room_id) def check_socket_connections(): if (datetime.utcnow() - GlobalVars.charcoal_hq.last_activity).total_seconds() >= 60 or\ (datetime.utcnow() - GlobalVars.socvr.last_activity).total_seconds() >= 60 or\ (datetime.utcnow() - GlobalVars.tavern_on_the_meta.last_activity).total_seconds() >= 60: os._exit(10)