def _cmd_say(arg1=None, arg2=None): if arg1 == "on": prof.settings_string_set("say", "enabled", "on") prof.cons_show("Say plugin enabled") elif arg1 == "off": prof.settings_string_set("say", "enabled", "off") prof.cons_show("Say plugin disabled") elif arg1 == "active": prof.settings_string_set("say", "enabled", "active") prof.cons_show("Say plugin enabled for active window only") elif arg1 == "args": if arg2 == None: prof.cons_bad_cmd_usage("/say") else: prof.settings_string_set("say", "args", arg2) prof.cons_show("Say plugin arguments set to: " + arg2) elif arg1 == "clearargs": prof.settings_string_set("say", "args", "") prof.cons_show("Say plugin arguments cleared") elif arg1 == "test": if arg2 == None: prof.cons_bad_cmd_usage("/say") else: say(arg2) else: enabled = prof.settings_string_get("say", "enabled", "off") args = prof.settings_string_get("say", "args", "") prof.cons_show("Say plugin settings:") prof.cons_show("enabled : " + enabled) if args != "": prof.cons_show("args : " + args)
def _cmd_notifycmd(arg1=None, arg2=None): if arg1 == "on": prof.settings_string_set("notifycmd", "enabled", "on") prof.cons_show("Notifycmd plugin enabled") elif arg1 == "off": prof.settings_string_set("notifycmd", "enabled", "off") prof.cons_show("Notifycmd plugin disabled") elif arg1 == "active": prof.settings_string_set("notifycmd", "enabled", "active") prof.cons_show("Notifycmd plugin enabled for active window only") elif arg1 == "command": if arg2 == None: prof.cons_bad_cmd_usage("/notifycmd") else: prof.settings_string_set("notifycmd", "command", arg2) prof.cons_show("notifycmd plugin command set to: " + arg2) elif arg1 == "rooms": if arg2 == None: prof.cons_bad_cmd_usage("/notifycmd") else: prof.settings_string_set("notifycmd", "rooms", arg2) prof.cons_show( "notifycmd plugin notifications for rooms set to: " + arg2) else: enabled = prof.settings_string_get("notifycmd", "enabled", "on") rooms = prof.settings_string_get("notifycmd", "rooms", "mention") command = prof.settings_string_get("notifycmd", "command", "") prof.cons_show("Notifycmd plugin settings:") prof.cons_show("enabled : " + enabled) prof.cons_show("command : " + command) prof.cons_show("rooms : " + rooms)
def _cmd_say(arg1=None, arg2=None): if arg1 == "on": prof.settings_string_set("termuxnotify", "enabled", "on") prof.cons_show("Termuxnotify plugin enabled") elif arg1 == "off": prof.settings_string_set("termuxnotify", "enabled", "off") prof.cons_show("Termuxnotify plugin disabled") elif arg1 == "active": prof.settings_string_set("termuxnotify", "enabled", "active") prof.cons_show("Termuxnotify plugin enabled for active window only") elif arg1 == "vibrate": if arg2 == None: prof.cons_bad_cmd_usage("/termuxnotify") else: prof.settings_string_set("termuxnotify", "vibrate", arg2) prof.cons_show("termuxnotify plugin vibrate set to: " + arg2) elif arg1 == "rooms": if arg2 == None: prof.cons_bad_cmd_usage("/termuxnotify") else: prof.settings_string_set("termuxnotify", "rooms", arg2) prof.cons_show( "termuxnotify plugin notifications for rooms set to: " + arg2) else: enabled = prof.settings_string_get("termuxnotify", "enabled", "on") rooms = prof.settings_string_get("termuxnotify", "rooms", "off") vibrate = prof.settings_string_get("termuxnotify", "vibrate", "off") prof.cons_show("Termuxnotify plugin settings:") prof.cons_show("enabled : " + enabled) prof.cons_show("vibrate : " + vibrate) prof.cons_show("rooms : " + rooms)
def _cmd_say(arg1=None, arg2=None): if arg1 == "on": prof.settings_string_set("say", "enabled", "on") prof.cons_show("Say plugin enabled") elif arg1 == "off": prof.settings_string_set("say", "enabled", "off") prof.cons_show("Say plugin disabled") elif arg1 == "active": prof.settings_string_set("say", "enabled", "active") prof.cons_show("Say plugin enabled for active window only") elif arg1 == "args": if arg2 == None: prof.cons_bad_cmd_usage("/say") else: prof.settings_string_set("say", "args", arg2) prof.cons_show("Say plugin arguments set to: " + arg2) elif arg1 == "clearargs": prof.settings_string_set("say", "args", "") prof.cons_show("Say plugin arguments cleared") elif arg1 == "test": if arg2 == None: prof.cons_bad_cmd_usage("/say") else: say(arg2) else: enabled = prof.settings_string_get("say", "enabled", "off") args = prof.settings_string_get("say", "args", "") prof.cons_show("Say plugin settings:") prof.cons_show("enabled : " + enabled) if args != "": prof.cons_show("args : " + args)
def prof_post_room_message_display(barejid, nick, message): enabled = prof.settings_string_get("termuxnotify", "enabled", "on") rooms = prof.settings_string_get("termuxnotify", "rooms", "off") current_muc = prof.get_current_muc() if rooms == "on": if enabled == "on": termuxnotify(nick + " in " + barejid, message) elif enabled == "active" and current_muc == barejid: termuxnotify(nick, message) return message
def say(message): args = prof.settings_string_get("say", "args", "") if platform == "darwin": os.system("say " + args + " '" + message + "' 2>/dev/null") elif platform == "linux" or platform == "linux2": os.system("echo '" + message + "' | espeak " + args + " 2>/dev/null")
def say(message): args = prof.settings_string_get("say", "args", "") if platform == "darwin": os.system("say " + args + " '" + message + "' 2>/dev/null") elif platform == "linux" or platform == "linux2": os.system("echo '" + message + "' | espeak " + args + " 2>/dev/null")
def prof_post_chat_message_display(barejid, resource, message): enabled = prof.settings_string_get("say", "enabled", "off") current_recipient = prof.get_current_recipient() if enabled == "on" or (enabled == "active" and current_recipient == barejid): say(barejid + " says " + message) return message
def prof_post_chat_message_display(barejid, resource, message): enabled = prof.settings_string_get("say", "enabled", "off") current_recipient = prof.get_current_recipient() if enabled == "on" or (enabled == "active" and current_recipient == barejid): say(barejid + " says " + message) return message
def say(message): args = prof.settings_string_get("say", "args", "") if platform == "darwin": os.system("say " + args + " " + shlex.quote(message) + " 2>/dev/null") elif platform == "linux" or platform == "linux2": os.system("echo " + shlex.quote(message) + " | espeak " + args + " 2>/dev/null")
def _string(op, group, key, value): if op != "get" and op != "set": prof.cons_bad_cmd_usage("/python-test") return if group == None or key == None: prof.cons_bad_cmd_usage("/python-test") return if op == "set" and not value: prof.cons_bad_cmd_usage("/python-test") return if op == "get": prof.win_create(plugin_win, _handle_win_input) prof.win_focus(plugin_win) res = prof.settings_string_get(group, key, None) if res: prof.win_show(plugin_win, "String setting: " + res) else: prof.win_show(plugin_win, "String setting: None") elif op == "set": prof.win_create(plugin_win, _handle_win_input) prof.win_focus(plugin_win) prof.settings_string_set(group, key, value) prof.win_show(plugin_win, "Set [" + group + "] " + key + " to " + value)
def termuxnotify(sender, message): vibrate = prof.settings_string_get("termuxnotify", "vibrate", "off") os.system("termux-notification -t 'Profanity: {} says:' -c '{}'".format( secure(sender), secure(message))) if vibrate == "on": os.system("termux-vibrate -d 400") time.sleep(0.3) os.system("termux-vibrate -d 400")
def prof_post_priv_message_display(barejid, nick, message): enabled = prof.settings_boolean_get("sounds", "enabled", False) if not enabled: return soundfile = prof.settings_string_get("sounds", "private", None) if soundfile: _play_sound(soundfile)
def prof_post_room_message_display(barejid, nick, message): enabled = prof.settings_string_get("say", "enabled", "off") current_muc = prof.get_current_muc() if enabled == "on": say(nick + " in " + barejid + " says " + message) elif enabled == "active" and current_muc == barejid: say(nick + " says " + message) return message
def prof_post_room_message_display(barejid, nick, message): enabled = prof.settings_string_get("say", "enabled", "off") current_muc = prof.get_current_muc() if enabled == "on": say(nick + " in " + barejid + " says " + message) elif enabled == "active" and current_muc == barejid: say(nick + " says " + message) return message
def prof_post_room_message_display(barejid, nick, message): enabled = prof.settings_string_get("notifycmd", "enabled", "on") rooms = prof.settings_string_get("notifycmd", "rooms", "mention") current_muc = prof.get_current_muc() mynick = prof.get_room_nick(barejid) # Don't notify for ones own messages if nick != mynick: if rooms == "on": if enabled == "on": notifycmd(nick + " in " + barejid, message) elif enabled == "active" and current_muc == barejid: notifycmd(nick, message) elif rooms == "mention": if mynick in message: if enabled == "on": notifycmd(nick, message) elif enabled == "active" and current_muc == barejid: notifycmd(nick, message) return message
def prof_post_chat_message_display(barejid, resource, message): enabled = prof.settings_boolean_get("sounds", "enabled", False) if not enabled: return soundfile = prof.settings_string_get("sounds", "chat", None) if not soundfile: return _play_sound(soundfile)
def prof_pre_chat_message_send(barejid, message): enabled = prof.settings_string_get("autocorrector", "enabled", "on") if enabled == "off": return message else: replacements = prof.settings_string_list_get("autocorrector", "replacements") for replacement in replacements: repl = replacement.split(':') message = message.replace(repl[0], repl[1]) return message
def notifycmd(sender, message): command = prof.settings_string_get("notifycmd", "command", "") # replace markers with complex strings first to avoid "%%mittens"=>"(%%)mittens"=>"(%m)ittens"=>"<message>ittens" but rather do "(%%)mittens"=>"%mittens" command = command.replace("%%", "{percentreplace}") command = command.replace("%s", "${senderreplace}") command = command.replace("%m", "${messagereplace}") command = command.replace("{percentreplace}", "%") command = "set -f;senderreplace=\"{}\";messagereplace=\"{}\";{}".format( secure(sender), secure(message), command) p = Popen(['sh', '-c', command])
def _cmd_autocorrector(arg1=None, arg2=None): if arg1 == "on": prof.settings_string_set("autocorrector", "enabled", "on") prof.cons_show("autocorrector plugin enabled") elif arg1 == "off": prof.settings_string_set("autocorrector", "enabled", "off") prof.cons_show("autocorrector plugin disabled") elif arg1 == "clearall": prof.settings_string_list_clear("autocorrector", "replacements") prof.cons_show("autocorrector plugin replacement list cleared.") elif arg1 == "showlist": replacements = prof.settings_string_list_get("autocorrector", "replacements") prof.cons_show("Replacement string list:") for replacement in replacements: prof.cons_show(replacement) elif arg1 == "add": if arg2 == None: prof.cons_bad_cmd_usage("/autocorrector") else: if len(arg2.split(':')) == 2: prof.settings_string_list_add("autocorrector", "replacements", arg2) prof.cons_show("Replacement String added.") else: prof.cons_show( "Invalid replacement String. Please use the following format to specify replacements: pattern:replacement." ) elif arg1 == "rm": if arg2 == None: prof.cons_bad_cmd_usage("/autocorrector") else: if len(arg2.split(':')) == 2: prof.settings_string_list_remove("autocorrector", "replacements", arg2) prof.cons_show("Replacement String removed.") else: prof.cons_show( "Invalid replacement String. Please use the following format to specify replacements: pattern:replacement." ) else: enabled = prof.settings_string_get("autocorrector", "enabled", "on") if enabled == "off": prof.cons_show("autocorrector inactive.") else: prof.cons_show("autocorrector active.")
def _show_settings(): prof.cons_show("") prof.cons_show("Presence notify plugin settings:") mode = prof.settings_string_get("presence_notify", "mode", "all") prof.cons_show("Mode: {mode}".format(mode=mode)) resource = prof.settings_boolean_get("presence_notify", "resource", False) if resource: prof.cons_show("Resource: ON") else: prof.cons_show("Resource: OFF") ignored_list = prof.settings_string_list_get("presence_notify", "ignored") if ignored_list and len(ignored_list) > 0: prof.cons_show("Ignored:") for contact in ignored_list: prof.cons_show(" {barejid}".format(barejid=contact))
def prof_post_room_message_display(barejid, nick, message): my_nick = prof.get_room_nick(barejid) if not my_nick: return if my_nick == nick: return; enabled = prof.settings_boolean_get("sounds", "enabled", False) if not enabled: return soundfile = prof.settings_string_get("sounds", "room", None) if not soundfile: return roomlist = prof.settings_string_list_get("sounds", "rooms") if roomlist and (barejid not in roomlist): return _play_sound(soundfile)
def _do_notify(barejid, presence): ignored = prof.settings_string_list_get("presence_notify", "ignored") if ignored and barejid in ignored: return False mode = prof.settings_string_get("presence_notify", "mode", "all") if mode == "all": return True elif mode == "online": if barejid in online: if presence == "offline": online.remove(barejid) return True else: return False else: if presence != "offline": online.add(barejid) return True else: return False else: # off return False
def _get_omemo_message_char(): return prof.settings_string_get( SETTINGS_GROUP, 'message_char', OMEMO_DEFAULT_MESSAGE_CHAR)
def _cmd_sounds(arg1=None, arg2=None, arg3=None): if not arg1: prof.cons_show("") enabled = prof.settings_boolean_get("sounds", "enabled", False) chatsound = prof.settings_string_get("sounds", "chat", None) roomsound = prof.settings_string_get("sounds", "room", None) privatesound = prof.settings_string_get("sounds", "private", None) roomlist = prof.settings_string_list_get("sounds", "rooms") if chatsound or roomsound or privatesound: if enabled: prof.cons_show("Sounds: ON") else: prof.cons_show("Sounds: OFF") if chatsound: prof.cons_show(" Chat : " + chatsound) if roomsound: prof.cons_show(" Room : " + roomsound) if roomlist and len(roomlist) > 0: for room in roomlist: prof.cons_show(" " + room) else: prof.cons_show(" All rooms") if privatesound: prof.cons_show(" Private : " + privatesound) else: prof.cons_show("No sounds set.") return if arg1 == "on": prof.settings_boolean_set("sounds", "enabled", True) prof.cons_show("Sounds enabled") return if arg1 == "off": prof.settings_boolean_set("sounds", "enabled", False) prof.cons_show("Sounds disabled") return if arg1 == "set": if arg2 == "chat": prof.settings_string_set("sounds", "chat", arg3) prof.cons_show("Set chat sound: " + arg3) elif arg2 == "room": prof.settings_string_set("sounds", "room", arg3) prof.cons_show("Set room sound: " + arg3) elif arg2 == "private": prof.settings_string_set("sounds", "private", arg3) prof.cons_show("Set private sound: " + arg3) else: prof.cons_bad_cmd_usage("/sounds") return if arg1 == "clear": if arg2 == "chat": prof.settings_string_set("sounds", "chat", "") prof.cons_show("Removed chat sound.") elif arg2 == "room": prof.settings_string_set("sounds", "room", "") prof.cons_show("Removed room sound.") elif arg2 == "private": prof.settings_string_set("sounds", "private", "") prof.cons_show("Removed private sound.") else: prof.cons_bad_cmd_usage("/sounds") return if arg1 == "rooms": if arg2 == "add": if not arg3: prof.cons_bad_cmd_usage("/sounds") else: prof.settings_string_list_add("sounds", "rooms", arg3) prof.cons_show("Sounds enabled for room: " + arg3) elif arg2 == "remove": if not arg3: prof.cons_bad_cmd_usage("/sounds") else: prof.settings_string_list_remove("sounds", "rooms", arg3) roomlist = prof.settings_string_list_get("sounds", "rooms") if roomlist and len(roomlist) > 0: prof.cons_show("Sounds disabled for room: " + arg3) else: prof.cons_show("Empty room list for sounds, playing in all rooms.") elif arg2 == "clear": prof.settings_string_list_clear("sounds", "rooms") prof.cons_show("Cleared sounds room list, playing in all rooms.") else: prof.cons_bad_cmd_usage("/sounds") return prof.cons_bad_cmd_usage("/sounds")
def _get_omemo_message_char(): return prof.settings_string_get(SETTINGS_GROUP, 'message_char', OMEMO_DEFAULT_MESSAGE_CHAR)