def func_wrapper(stanza): stanza = ensure_unicode_stanza(stanza) recipient = xmpp.get_root_attrib(stanza, attrib) try: contat_jid = recipient.rsplit('/', 1)[0] except AttributeError: log.error('Recipient not valid.') return else_return log.info('Checking Sessions for {0}'.format(recipient)) state = ProfOmemoState() uninitialized_devices = state.devices_without_sessions(contat_jid) own_jid = ProfOmemoUser.account own_uninitialized = state.devices_without_sessions(own_jid) uninitialized_devices += own_uninitialized if not uninitialized_devices: log.info( 'Recipient {0} has all sessions set up.'.format(recipient)) return func(stanza) _query_device_list(contat_jid) _query_device_list(own_jid) log.warning('No Session found for user: {0}.'.format(recipient)) prof.notify('Failed to send last Message.', 5000, 'Profanity Omemo Plugin') return else_return
def func_wrapper(stanza): stanza = ensure_unicode_stanza(stanza) recipient = xmpp.get_root_attrib(stanza, attrib) try: contat_jid = recipient.rsplit('/', 1)[0] except AttributeError: log.error('Recipient not valid.') return else_return log.info('Checking Sessions for {0}'.format(recipient)) state = ProfOmemoState() uninitialized_devices = state.devices_without_sessions(contat_jid) own_jid = ProfOmemoUser.account own_uninitialized = state.devices_without_sessions(own_jid) uninitialized_devices += own_uninitialized if not uninitialized_devices: log.info('Recipient {0} has all sessions set up.'.format(recipient)) return func(stanza) _query_device_list(contat_jid) _query_device_list(own_jid) log.warning('No Session found for user: {0}.'.format(recipient)) prof.notify('Failed to send last Message.', 5000, 'Profanity Omemo Plugin') return else_return
def _cmd_python(msg): if msg: prof.cons_show("python-test: /python command called, arg = " + msg) else: prof.cons_show("python-test: /python command called with no arg") prof.cons_alert() prof.notify("python-test: notify", 2000, "Plugins") prof.send_line("/vercheck") prof.cons_show("python-test: sent \"/vercheck\" command")
def _notify(msg): if not msg: prof.cons_bad_cmd_usage("/python-test") return prof.win_create(plugin_win, _handle_win_input) prof.win_focus(plugin_win) prof.notify(msg, 5000, "python-test plugin") prof.win_show(plugin_win, "called -> prof.notify: " + msg)
def prof_on_contact_offline(barejid, resource, status): if _do_notify(barejid, "offline"): jid = barejid if prof.settings_boolean_get("presence_notify", "resource", False): jid = jid + "/" + resource message = "{jid} is offline".format(jid=jid) if status: message = message + ", \"{status}\"".format(status=status) prof.notify(message, 5000, "Presence") return
def prof_pre_chat_message_send(barejid, message): """ Called before a chat message is sent :returns: the new message to send, returning None stops the message from being sent """ plugin_enabled = _get_omemo_enabled_setting() if not plugin_enabled: return message if not ProfActiveOmemoChats.account_is_active(barejid): log.info('Chat not activated for {0}'.format(barejid)) return message omemo_state = ProfOmemoState() uninitialzed_devices = omemo_state.devices_without_sessions(barejid) if uninitialzed_devices: d_str = ', '.join([str(d) for d in uninitialzed_devices]) msg = 'Requesting bundles for missing devices {0}'.format(d_str) log.info(msg) prof.notify(msg, 5000, 'Profanity Omemo Plugin') for device in uninitialzed_devices: _query_bundle_info_for(barejid, device) own_jid = ProfOmemoUser.account own_uninitialized = omemo_state.devices_without_sessions(own_jid) if own_uninitialized: d_str = ', '.join([str(d) for d in own_uninitialized]) msg = 'Requesting own bundles for missing devices {0}'.format(d_str) log.info(msg) prof.notify(msg, 5000, 'Profanity Omemo Plugin') for device in own_uninitialized: _query_bundle_info_for(own_jid, device) return message
def prof_pre_chat_message_send(barejid, message): """ Called before a chat message is sent :returns: the new message to send, returning None stops the message from being sent """ plugin_enabled = _get_omemo_enabled_setting() if not plugin_enabled: return message if not ProfActiveOmemoChats.account_is_active(barejid): log.info('Chat not activated for {0}'.format(barejid)) return message omemo_state = ProfOmemoState() uninitialzed_devices = omemo_state.devices_without_sessions(barejid) if uninitialzed_devices: d_str = ', '.join([str(d) for d in uninitialzed_devices]) msg = 'Requesting bundles for missing devices {0}'.format(d_str) log.info(msg) prof.notify(msg, 5000, 'Profanity Omemo Plugin') for device in uninitialzed_devices: _query_bundle_info_for(barejid, device) own_jid = ProfOmemoUser.account own_uninitialized = omemo_state.devices_without_sessions(own_jid) if own_uninitialized: d_str = ', '.join([str(d) for d in own_uninitialized]) msg = 'Requesting own bundles for missing devices {0}'.format(d_str) log.info(msg) prof.notify(msg, 5000, 'Profanity Omemo Plugin') for device in own_uninitialized: _query_bundle_info_for(own_jid, device) return message
def _remind(): if enable_remind and job_list: notify_string = "" failing = job_list.num_in_state(STATE_FAILURE) unstable = job_list.num_in_state(STATE_UNSTABLE) if failing == 1: notify_string = notify_string + "1 failing build" if failing > 1: notify_string = notify_string + str(failing) + " failing builds" if failing > 0 and unstable > 0: notify_string = notify_string + "\n" if unstable == 1: notify_string = notify_string + "1 unstable build" if unstable > 1: notify_string = notify_string + str(unstable) + " unstable builds" if not notify_string == "": prof.notify(notify_string, 5000, "Jenkins")
def _remind(): if enable_remind and job_list: notify_string = "" failing = job_list.num_in_state(STATE_FAILURE) unstable = job_list.num_in_state(STATE_UNSTABLE) if failing == 1: notify_string = notify_string + "1 failing build" if failing > 1: notify_string = notify_string + str(failing) + " failing builds" if failing > 0 and unstable > 0: notify_string = notify_string + "\n" if unstable == 1: notify_string = notify_string + "1 unstable build" if unstable > 1: notify_string = notify_string + str(unstable) + " unstable builds" if not notify_string == "": prof.notify(notify_string, 5000, "Jenkins")
def _get_scores(): global _score_url global _summary notify = None new_summary = None change = False result_json = _retrieve_scores_json() if (result_json): if 'ms' in result_json.keys(): new_summary = result_json['ms'] if new_summary != _summary: change = True if change: prof.cons_show("") prof.cons_show("Cricket score:") if 't1FI' in result_json.keys(): notify = result_json['t1FI'] prof.cons_show(" " + result_json['t1FI']) if 't2FI' in result_json.keys(): notify += "\n" + result_json['t2FI'] prof.cons_show(" " + result_json['t2FI']) if 't1SI' in result_json.keys(): notify += "\n" + result_json['t1SI'] prof.cons_show(" " + result_json['t1SI']) if 't2SI' in result_json.keys(): notify += "\n" + result_json['t2SI'] prof.cons_show(" " + result_json['t2SI']) _summary = new_summary notify += "\n\n" + _summary prof.cons_show("") prof.cons_show(" " + _summary) prof.cons_alert() prof.notify(notify, 5000, "Cricket score")
def _get_scores(): global _score_url global _summary notify = None new_summary = None change = False result_json = _retrieve_scores_json() if (result_json): if 'ms' in result_json.keys(): new_summary = result_json['ms'] if new_summary != _summary: change = True if change: prof.cons_show("") prof.cons_show("Cricket score:") if 't1FI' in result_json.keys(): notify = result_json['t1FI'] prof.cons_show(" " + result_json['t1FI']) if 't2FI' in result_json.keys(): notify += "\n" + result_json['t2FI'] prof.cons_show(" " + result_json['t2FI']) if 't1SI' in result_json.keys(): notify += "\n" + result_json['t1SI'] prof.cons_show(" " + result_json['t1SI']) if 't2SI' in result_json.keys(): notify += "\n" + result_json['t2SI'] prof.cons_show(" " + result_json['t2SI']) _summary = new_summary notify += "\n\n" + _summary prof.cons_show("") prof.cons_show(" " + _summary) prof.cons_alert() prof.notify(notify, 5000, "Cricket score")
def _prof_callback(): global changes_list if poll_fail: if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show(win_tag, "Could not connect to jenkins, see the logs.") if poll_fail_message: prof.log_warning("Jenkins poll failed: " + str(poll_fail_message)) else: prof.log_warning("Jenkins poll failed") elif changes_list: for name in changes_list.get_in_state(STATE_QUEUED): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "cyan", name + " " + STATE_QUEUED) for name in changes_list.get_in_state(STATE_RUNNING): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "cyan", name + " " + STATE_RUNNING) for name, build_number in changes_list.get_in_state(STATE_SUCCESS): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed( win_tag, None, None, "green", name + " #" + str(build_number) + " " + STATE_SUCCESS) if enable_notify: prof.notify(name + " " + STATE_SUCCESS, 5000, "Jenkins") for name, build_number in changes_list.get_in_state(STATE_UNSTABLE): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed( win_tag, None, None, "yellow", name + " #" + str(build_number) + " " + STATE_UNSTABLE) if enable_notify: prof.notify(name + " " + STATE_UNSTABLE, 5000, "Jenkins") for name, build_number in changes_list.get_in_state(STATE_FAILURE): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed( win_tag, None, None, "red", name + " #" + str(build_number) + " " + STATE_FAILURE) if enable_notify: prof.notify(name + " " + STATE_FAILURE, 5000, "Jenkins") changes_list = None
def _prof_callback(): global changes_list if poll_fail: if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show(win_tag, "Could not connect to jenkins, see the logs.") if poll_fail_message: prof.log_warning("Jenkins poll failed: " + str(poll_fail_message)) else: prof.log_warning("Jenkins poll failed") elif changes_list: for name in changes_list.get_in_state(STATE_QUEUED): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "cyan", name + " " + STATE_QUEUED) for name in changes_list.get_in_state(STATE_RUNNING): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "cyan", name + " " + STATE_RUNNING) for name, build_number in changes_list.get_in_state(STATE_SUCCESS): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "green", name + " #" + str(build_number) + " " + STATE_SUCCESS) if enable_notify: prof.notify(name + " " + STATE_SUCCESS, 5000, "Jenkins") for name, build_number in changes_list.get_in_state(STATE_UNSTABLE): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "yellow", name + " #" + str(build_number) + " " + STATE_UNSTABLE) if enable_notify: prof.notify(name + " " + STATE_UNSTABLE, 5000, "Jenkins") for name, build_number in changes_list.get_in_state(STATE_FAILURE): if not prof.win_exists(win_tag): prof.win_create(win_tag, _handle_input) prof.win_show_themed(win_tag, None, None, "red", name + " #" + str(build_number) + " " + STATE_FAILURE) if enable_notify: prof.notify(name + " " + STATE_FAILURE, 5000, "Jenkins") changes_list = None
def cmd_pythontest(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None): if arg1 == "consalert": create_win() prof.win_focus(plugin_win) prof.cons_alert() prof.win_show(plugin_win, "called -> prof.cons_alert") elif arg1 == "consshow": if arg2 != None: create_win() prof.win_focus(plugin_win) prof.cons_show(arg2) prof.win_show(plugin_win, "called -> prof.cons_show: " + arg2) else: prof.cons_bad_cmd_usage("/python-test") elif arg1 == "consshow_t": if arg2 == None or arg3 == None or arg4 == None or arg5 == None: prof.cons_bad_cmd_usage("/python-test"); else: group = None if arg2 == "none" else arg2 key = None if arg3 == "none" else arg3 dflt = None if arg4 == "none" else arg4 message = arg5 create_win() prof.win_focus(plugin_win) prof.cons_show_themed(group, key, dflt, message) prof.win_show(plugin_win, "called -> prof.cons_show_themed: " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5) elif arg1 == "constest": res = prof.current_win_is_console() create_win() prof.win_focus(plugin_win) if res: prof.win_show(plugin_win, "called -> prof.current_win_is_console: true") else: prof.win_show(plugin_win, "called -> prof.current_win_is_console: false") elif arg1 == "winshow": if arg2 != None: create_win() prof.win_focus(plugin_win) prof.win_show(plugin_win, arg2) prof.win_show(plugin_win, "called -> prof.win_show: " + arg2) else: prof.cons_bad_cmd_usage("/python-test") elif arg1 == "winshow_t": if arg2 == None or arg3 == None or arg4 == None or arg5 == None: prof.cons_bad_cmd_usage("/python-test"); else: group = None if arg2 == "none" else arg2 key = None if arg3 == "none" else arg3 dflt = None if arg4 == "none" else arg4 message = arg5 create_win() prof.win_focus(plugin_win) prof.win_show_themed(plugin_win, group, key, dflt, message) prof.win_show(plugin_win, "called -> prof_win_show_themed: " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5) elif arg1 == "sendline": if arg2 != None: create_win() prof.win_focus(plugin_win) prof.send_line(arg2) prof.win_show(plugin_win, "called -> prof.send_line: " + arg2) else: prof.cons_bad_cmd_usage("/python-test") elif arg1 == "notify": if arg2 != None: create_win() prof.win_focus(plugin_win) prof.notify(arg2, 5000, "python-test plugin") prof.win_show(plugin_win, "called -> prof.notify: " + arg2) else: prof.cons_bad_cmd_usage("/python-test") elif arg1 == "get": if arg2 == None: prof.cons_bad_cmd_usage("/python-test") elif arg2 == "recipient": create_win() recipient = prof.get_current_recipient(); if recipient != None: prof.win_focus(plugin_win) prof.win_show(plugin_win, "called -> prof.get_current_recipient: " + recipient) else: prof.win_focus(plugin_win) prof.win_show(plugin_win, "called -> prof_get_current_recipient: <none>") elif arg2 == "room": create_win() room = prof.get_current_muc() if room != None: prof.win_focus(plugin_win) prof.win_show(plugin_win, "called -> prof_get_current_muc: " + room) else: prof.win_focus(plugin_win) prof.win_show(plugin_win, "called -> prof_get_current_muc: <none>") else: prof.cons_bad_cmd_usage("/python-test") elif arg1 == "log": if arg2 == None: prof.cons_bad_cmd_usage("/python-test") elif arg2 == "debug": if arg3 == None: prof.cons_bad_cmd_usage("/python-test") else: create_win() prof.win_focus(plugin_win) prof.log_debug(arg3) prof.win_show(plugin_win, "called -> prof.log_debug: " + arg3) elif arg2 == "info": if arg3 == None: prof.cons_bad_cmd_usage("/python-test") else: create_win() prof.win_focus(plugin_win) prof.log_info(arg3) prof.win_show(plugin_win, "called -> prof.log_info: " + arg3) elif arg2 == "warning": if arg3 == None: prof.cons_bad_cmd_usage("/python-test") else: create_win() prof.win_focus(plugin_win) prof.log_warning(arg3) prof.win_show(plugin_win, "called -> prof.log_warning: " + arg3) elif arg2 == "error": if arg3 == None: prof.cons_bad_cmd_usage("/python-test") else: create_win() prof.win_focus(plugin_win) prof.log_error(arg3) prof.win_show(plugin_win, "called -> prof.log_error: " + arg3) else: prof.cons_bad_cmd_usage("/python-test") elif arg1 == "count": create_win() prof.win_focus(plugin_win) prof.win_show(plugin_win, "Count: " + str(count)) else: prof.cons_bad_cmd_usage("/python-test")