ref: Cleanup and rearrange files, update documentation

- Remove Ruby files since they aren't supported anymore
- Remove test and samples files
- Move all the "stable" plugins to `src` folder to follow standard conventions
- Update links and descriptions in the documentation
This commit is contained in:
2025-07-14 11:07:33 +02:00
parent 68800cf823
commit 325316c3b2
34 changed files with 26 additions and 3794 deletions

View File

@@ -1,10 +1,25 @@
profanity-plugins
=================
# CProof Plugins
* [Website documentation](https://profanity-im.github.io/plugins.html)
[Website documentation](https://jabber.space/guides/plugins/)
Building Profanity with plugin support
--------------------------------------
`Master` is a development branch compatible with the latest version of CProof.
## Installing plugins
Use the `/plugins install` command, e.g.
```bash
/plugins install ~/path-to/sounds.py
```
Alternatively, you can use URLs to raw files to install Python plugins. For example,
```bash
/plugins install https://git.jabber.space/devs/cproof-plugins/raw/branch/master/src/sounds.py
```
See the `/help plugins` command for further plugin management options.
## Building CProof with plugin support
Dependencies required:
@@ -19,41 +34,10 @@ For Python plugins the following is also required:
python-dev
```
Installing plugins
------------------
## Developing plugins
Use the `/plugins install` command, e.g.
```
/plugins install ~/projects-git/profanity-plugins/stable/say.py
```
See the `/help plugins` command for further plugin management options.
Branches
--------
* `0.5.0`: Maintenance branch compatible Profanity 0.5.0
* `0.5.1`: Maintenance branch compatible Profanity 0.5.1
* `master`: Development for Profanity 0.6.0 - 0.11.x
Developing plugins
------------------
API Documentation:
* [Python API](https://profanity-im.github.io/plugins/0.5.1/python/html/prof.html)
* [Python hooks](https://profanity-im.github.io/plugins/0.5.1/python/html/plugin.html)
* [C API](https://profanity-im.github.io/plugins/0.5.1/c/html/profapi_8h.html)
* [C hooks](https://profanity-im.github.io/plugins/0.5.1/c/html/profhooks_8h.html)
External plugins
------------------
* [moj](https://github.com/shinyblink/moj) - Replace emojis
* [profanity-copy-message-plugin](https://github.com/lonski/profanity-copy-message-plugin) - Copy messages to clipboard.
* [profanity-discord](https://github.com/colcrunch/profanity-discord) - Forward jabber pings on to discord through a webhook.
* [profanity-notifycmd](https://github.com/Neo-Oli/profanity-notifycmd) - Launch a custom shell command when you receive a message in profanity.
* [profanity-plugin-sanitise](https://github.com/nd2s/profanity-plugin-sanitise) - Clean incoming messages.
* [profanity-shortcuts-plugin](https://github.com/ReneVolution/profanity-shortcuts-plugin) - Store custom substitution shortcuts and use them in chats.
* [profanity-plugins by H3rnand3zzz](https://github.com/H3rnand3zzz/profanity-plugins) - Array of different **QoL** plugins.
* [profanity-plugins by Reimar](https://github.com/ReimarPB/profanity-plugins) - Collection of plugins
API Documentation is available on our website, [jabber.space](https://jabber.space/).
- [Python API](https://jabber.space/api-reference/python/prof/)
- [Python hooks](https://jabber.space/api-reference/python/plugin/)
- [C API](https://jabber.space/api-reference/c/profapi/)
- [C hooks](https://jabber.space/api-reference/c/profhooks/)

View File

@@ -1,16 +0,0 @@
module ChatStart
@@starts = {
"prof1@panesar" => [ "\"Prof 2\"", "prof3@panesar" ],
"prof2@panesar" => [ "prof1@panesar" ]
}
def self.prof_on_connect(account_name, fulljid)
if @@starts[account_name]
@@starts[account_name].each { | contact |
Prof::send_line("/msg " + contact)
}
Prof::send_line("/win 1")
end
end
end

View File

@@ -1,51 +0,0 @@
import prof
from chatterbotapi import ChatterBotFactory, ChatterBotType
factory = ChatterBotFactory()
bot = factory.create(ChatterBotType.CLEVERBOT)
# bot = factory.create(ChatterBotType.JABBERWACKY)
# bot = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
bot_session = {}
bot_state = False
def prof_post_chat_message_display(barejid, resource, message):
if bot_state:
if barejid not in bot_session:
bot_session[barejid] = bot.create_session()
response = bot_session[barejid].think(message)
prof.send_line("/msg " + barejid + " " + response)
def _cmd_chatterbot(state):
global bot_state
if state == "enable":
prof.cons_show("ChatterBot Activated")
bot_state = True
elif state == "disable":
prof.cons_show("ChatterBot Stopped")
bot_state = False
else:
if bot_state:
prof.cons_show("ChatterBot is running - current sessions:")
prof.cons_show(str(bot_session))
else:
prof.cons_show("ChatterBot is stopped - /chatterbot enable to activate.")
def prof_init(version, status, account_name, fulljid):
synopsis = [
"/chatterbot",
"/chatterbot enable|disable"
]
description = "ChatterBot, running with no args will show the current chatterbot status"
args = [
[ "enable", "Enable chatterbot" ],
[ "disable", "Disable chatterbot" ]
]
examples = []
prof.register_command("/chatterbot", 0, 1, synopsis, description, args, examples, _cmd_chatterbot)
prof.completer_add("/chatterbot", [ "enable", "disable" ])

View File

@@ -1,190 +0,0 @@
import re
import sys
import hashlib
if sys.version_info >= (3, 0):
from urllib.request import build_opener, HTTPCookieProcessor, urlopen
from urllib.parse import urlencode
import http.cookiejar as cookielib
else:
from urllib import urlencode, urlopen
from urllib2 import build_opener, HTTPCookieProcessor
import cookielib
import uuid
import xml.dom.minidom
"""
chatterbotapi
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
#################################################
# API
#################################################
class ChatterBotType:
CLEVERBOT = 1
JABBERWACKY = 2
PANDORABOTS = 3
class ChatterBotFactory:
def create(self, type, arg = None):
if type == ChatterBotType.CLEVERBOT:
return _Cleverbot('http://www.cleverbot.com', 'http://www.cleverbot.com/webservicemin', 35)
elif type == ChatterBotType.JABBERWACKY:
return _Cleverbot('http://jabberwacky.com', 'http://jabberwacky.com/webservicemin', 29)
elif type == ChatterBotType.PANDORABOTS:
if arg == None:
raise Exception('PANDORABOTS needs a botid arg')
return _Pandorabots(arg)
return None
class ChatterBot:
def create_session(self):
return None
class ChatterBotSession:
def think_thought(self, thought):
return thought
def think(self, text):
thought = ChatterBotThought()
thought.text = text
return self.think_thought(thought).text
class ChatterBotThought:
pass
#################################################
# Cleverbot impl
#################################################
class _Cleverbot(ChatterBot):
def __init__(self, baseUrl, serviceUrl, endIndex):
self.baseUrl = baseUrl
self.serviceUrl = serviceUrl
self.endIndex = endIndex
def create_session(self):
return _CleverbotSession(self)
class _CleverbotSession(ChatterBotSession):
def __init__(self, bot):
self.bot = bot
self.vars = {}
self.vars['start'] = 'y'
self.vars['icognoid'] = 'wsf'
self.vars['fno'] = '0'
self.vars['sub'] = 'Say'
self.vars['islearning'] = '1'
self.vars['cleanslate'] = 'false'
self.cookieJar = cookielib.CookieJar()
self.opener = build_opener(HTTPCookieProcessor(self.cookieJar))
self.opener.open(self.bot.baseUrl)
def think_thought(self, thought):
self.vars['stimulus'] = thought.text
data = urlencode(self.vars)
data_to_digest = data[9:self.bot.endIndex]
data_digest = hashlib.md5(data_to_digest.encode('utf-8')).hexdigest()
data = data + '&icognocheck=' + data_digest
url_response = self.opener.open(self.bot.serviceUrl, data.encode('utf-8'))
response = str(url_response.read())
response_values = re.split(r'\\r|\r', response)
#self.vars['??'] = _utils_string_at_index(response_values, 0)
self.vars['sessionid'] = _utils_string_at_index(response_values, 1)
self.vars['logurl'] = _utils_string_at_index(response_values, 2)
self.vars['vText8'] = _utils_string_at_index(response_values, 3)
self.vars['vText7'] = _utils_string_at_index(response_values, 4)
self.vars['vText6'] = _utils_string_at_index(response_values, 5)
self.vars['vText5'] = _utils_string_at_index(response_values, 6)
self.vars['vText4'] = _utils_string_at_index(response_values, 7)
self.vars['vText3'] = _utils_string_at_index(response_values, 8)
self.vars['vText2'] = _utils_string_at_index(response_values, 9)
self.vars['prevref'] = _utils_string_at_index(response_values, 10)
#self.vars['??'] = _utils_string_at_index(response_values, 11)
self.vars['emotionalhistory'] = _utils_string_at_index(response_values, 12)
self.vars['ttsLocMP3'] = _utils_string_at_index(response_values, 13)
self.vars['ttsLocTXT'] = _utils_string_at_index(response_values, 14)
self.vars['ttsLocTXT3'] = _utils_string_at_index(response_values, 15)
self.vars['ttsText'] = _utils_string_at_index(response_values, 16)
self.vars['lineRef'] = _utils_string_at_index(response_values, 17)
self.vars['lineURL'] = _utils_string_at_index(response_values, 18)
self.vars['linePOST'] = _utils_string_at_index(response_values, 19)
self.vars['lineChoices'] = _utils_string_at_index(response_values, 20)
self.vars['lineChoicesAbbrev'] = _utils_string_at_index(response_values, 21)
self.vars['typingData'] = _utils_string_at_index(response_values, 22)
self.vars['divert'] = _utils_string_at_index(response_values, 23)
response_thought = ChatterBotThought()
response_thought.text = _utils_string_at_index(response_values, 16)
return response_thought
#################################################
# Pandorabots impl
#################################################
class _Pandorabots(ChatterBot):
def __init__(self, botid):
self.botid = botid
def create_session(self):
return _PandorabotsSession(self)
class _PandorabotsSession(ChatterBotSession):
def __init__(self, bot):
self.vars = {}
self.vars['botid'] = bot.botid
self.vars['custid'] = uuid.uuid1()
def think_thought(self, thought):
self.vars['input'] = thought.text
data = urlencode(self.vars)
url_response = urlopen('http://www.pandorabots.com/pandora/talk-xml', data)
response = url_response.read()
response_dom = xml.dom.minidom.parseString(response)
response_thought = ChatterBotThought()
that_elements = response_dom.getElementsByTagName('that')
if that_elements is None or len(that_elements) == 0 or that_elements[0] is None:
return ''
that_elements_child_nodes = that_elements[0].childNodes
if that_elements_child_nodes is None or len(that_elements_child_nodes) == 0 or that_elements_child_nodes[0] is None:
return ''
that_elements_child_nodes_data = that_elements_child_nodes[0].data
if that_elements_child_nodes_data is None:
return ''
response_thought.text = that_elements_child_nodes_data.strip()
return response_thought
#################################################
# Utils
#################################################
def _utils_string_at_index(strings, index):
if len(strings) > index:
return strings[index]
else:
return ''

View File

@@ -1,531 +0,0 @@
"""
Manage jenkins jobs
Prerequisites:
The jenkinsapi module is required https://pypi.python.org/pypi/jenkinsapi
To install the module using pip:
sudo pip install jenkinsapi
The plugin polls the jenkins server at 'jenkins_url' every 'jenkins_poll_interval' seconds.
The results are checked by profanity every 'prof_cb_interval'.
New failures are reported in the jenkins window, and a desktop notification is sent.
The 'prof_remind_interval' specifies the time between reminder notifications of broken builds
"""
import prof
import os
import threading
import time
import webbrowser
import urllib2
import base64
import jenkinsapi
from jenkinsapi.jenkins import Jenkins
# Settings
jenkins_url = "http://localhost:8080"
username = None
password = None
jenkins_poll_interval = 5
prof_cb_interval = 5
prof_remind_interval = 10
enable_notify = True
enable_remind = True
# Global state
last_state = {}
STATE_SUCCESS = "SUCCESS"
STATE_UNSTABLE = "UNSTABLE"
STATE_FAILURE = "FAILURE"
STATE_QUEUED = "QUEUED"
STATE_RUNNING = "RUNNING"
STATE_NOBUILDS = "NOBUILDS"
STATE_UNKNOWN = "UNKNOWN"
win_tag = "Jenkins"
poll_fail = False
poll_fail_message = None
job_list = None
changes_list = None
def _help():
prof.win_show(win_tag, "Commands:")
prof.win_show(win_tag, " /jenkins help - Show this help")
prof.win_show(win_tag, " /jenkins jobs - List all jobs")
prof.win_show(win_tag, " /jenkins failing - List all failing jobs")
prof.win_show(win_tag, " /jenkins passing - List all passing jobs")
prof.win_show(win_tag, " /jenkins unstable - List all unstable jobs")
prof.win_show(win_tag, " /jenkins build [job] - Trigger build for job")
prof.win_show(win_tag, " /jenkins open [job] - Open job in browser")
prof.win_show(win_tag, " /jenkins log [job] - Show the latest build log")
prof.win_show(win_tag, " /jenkins remind on|off - Enable/disable reminder notifications")
prof.win_show(win_tag, " /jenkins notify on|off - Enable/disable build notifications")
prof.win_show(win_tag, " /jenkins settings - Show current settings")
def _settings():
prof.win_show(win_tag, "Jenkins settings:")
prof.win_show(win_tag, " Jenkins URL : " + jenkins_url)
prof.win_show(win_tag, " Jenkins poll interval : " + str(jenkins_poll_interval) + " seconds")
prof.win_show(win_tag, " Profanity update interval : " + str(prof_cb_interval) + " seconds")
prof.win_show(win_tag, " Reminder interval : " + str(prof_remind_interval) + " seconds")
prof.win_show(win_tag, " Notifications enabled : " + str(enable_notify))
prof.win_show(win_tag, " Reminders enabled : " + str(enable_remind))
def _safe_remove(jobname, state):
if jobname in last_state[state]:
last_state[state].remove(jobname)
def _set_state(jobname, state):
if not jobname in last_state[state]:
_safe_remove(jobname, STATE_SUCCESS)
_safe_remove(jobname, STATE_UNSTABLE)
_safe_remove(jobname, STATE_FAILURE)
_safe_remove(jobname, STATE_QUEUED)
_safe_remove(jobname, STATE_RUNNING)
_safe_remove(jobname, STATE_NOBUILDS)
_safe_remove(jobname, STATE_UNKNOWN)
last_state[state].append(jobname)
return True
else:
return False
def _open_job_url(url):
savout = os.dup(1)
saverr = os.dup(2)
os.close(1)
os.close(2)
os.open(os.devnull, os.O_RDWR)
try:
webbrowser.open(url, new=2)
finally:
os.dup2(savout, 1)
os.dup2(saverr, 2)
class JobList():
def __init__(self):
self.jobs = []
def add_job(self, name, build_number, state):
self.jobs.append((name, build_number, state))
def get_jobs(self, in_state=None):
if not in_state:
return self.jobs
else:
result = []
for name, build_number, state in self.jobs:
if state == in_state:
result.append((name, build_number, state))
return result
def get_job(self, jobname):
for name, build_number, state in self.jobs:
if name == jobname:
return name, build_number
return None
def contains_job(self, jobname):
for name, build_number, state in self.jobs:
if name == jobname:
return True
return False
def num_in_state(self, given_state):
count = 0
for name, build_number, state in self.jobs:
if state == given_state:
count = count + 1
return count
class JobUpdates():
def __init__(self):
self.states = {}
self.states[STATE_FAILURE] = []
self.states[STATE_SUCCESS] = []
self.states[STATE_UNSTABLE] = []
self.states[STATE_QUEUED] = []
self.states[STATE_RUNNING] = []
def add_update(self, state, name, build_number=None):
if build_number:
self.states[state].append((name, build_number))
else:
self.states[state].append(name)
def get_in_state(self, state):
return self.states[state]
def _process_build(name, build, new_job_list, new_changes_list):
if build.get_status() == STATE_FAILURE:
new_job_list.add_job(name, build.get_number(), STATE_FAILURE)
changed = _set_state(name, STATE_FAILURE)
if changed:
new_changes_list.add_update(STATE_FAILURE, name, build.get_number())
elif build.get_status() == STATE_SUCCESS:
new_job_list.add_job(name, build.get_number(), STATE_SUCCESS)
changed = _set_state(name, STATE_SUCCESS)
if changed:
new_changes_list.add_update(STATE_SUCCESS, name, build.get_number())
elif build.get_status() == STATE_UNSTABLE:
new_job_list.add_job(name, build.get_number(), STATE_UNSTABLE)
changed = _set_state(name, STATE_UNSTABLE)
if changed:
new_changes_list.add_update(STATE_UNSTABLE, name, build.get_number())
def _process_queued_or_running(name, job, new_job_list, new_changes_list):
if job.is_queued():
new_job_list.add_job(name, None, STATE_QUEUED)
changed = _set_state(name, STATE_QUEUED)
if changed:
new_changes_list.add_update(STATE_QUEUED, name)
elif job.is_running():
new_job_list.add_job(name, None, STATE_RUNNING)
changed = _set_state(name, STATE_RUNNING)
if changed:
new_changes_list.add_update(STATE_RUNNING, name)
def _jenkins_poll():
global poll_fail
global poll_fail_message
global job_list
global changes_list
job_ac = []
while True:
time.sleep(jenkins_poll_interval)
try:
j = Jenkins(jenkins_url, username, password)
except Exception, e:
poll_fail = True
poll_fail_message = str(e)
else:
poll_fail = False
poll_fail_message = None
new_job_list = JobList()
new_changes_list = JobUpdates()
for name, job in j.get_jobs():
if not job.is_queued_or_running():
build = job.get_last_build_or_none()
if build:
_process_build(name, build, new_job_list, new_changes_list)
else:
new_job_list.add_job(name, None, STATE_NOBUILDS)
else:
_process_queued_or_running(name, job, new_job_list, new_changes_list)
if not job_list:
job_ac.append(name)
if not job_list:
prof.completer_add("/jenkins build", job_ac)
prof.completer_add("/jenkins open", job_ac)
prof.completer_add("/jenkins log", job_ac)
job_list = new_job_list
changes_list = new_changes_list
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 _handle_input(win, line):
pass
def _list_jobs(jobs):
for name, build_number, state in jobs:
if state == STATE_SUCCESS:
prof.win_show_themed(win_tag, None, None, "green", " " + name + " #" + str(build_number) + " " + STATE_SUCCESS)
elif state == STATE_UNSTABLE:
prof.win_show_themed(win_tag, None, None, "yellow", " " + name + " #" + str(build_number) + " " + STATE_UNSTABLE)
elif state == STATE_FAILURE:
prof.win_show_themed(win_tag, None, None, "red", " " + name + " #" + str(build_number) + " " + STATE_FAILURE)
elif state == STATE_NOBUILDS:
prof.win_show(win_tag, " " + name + ", no builds")
else:
prof.win_show_themed(win_tag, None, None, "cyan", " " + name + " " + state)
def _build_job(job):
try:
request = urllib2.Request(jenkins_url + "/job/" + job + "/build");
if username:
basicauth = base64.encodestring("%s:%s" %(username, password)).replace("\n", "")
request.add_header("Authorization", "Basic %s" %basicauth);
request.add_data("")
urllib2.urlopen(request)
except Exception, e:
prof.win_show(win_tag, "Failed to build " + job + ", see the logs.")
prof.log_warning("Failed to build " + job + ": " + str(e))
else:
prof.win_show(win_tag, "Build request sent for " + job)
def _job_log(job):
name = job[0]
build_no = job[1]
if build_no:
try:
response = urllib2.urlopen(jenkins_url + "/job/" + name + "/" + str(build_no) + "/consoleText")
except Exception, e:
prof.win_show(win_tag, "Unable to fetch log for " + name + "#" + str(build_no) + ", see the logs.")
prof.log_warning("Unable to fetch log for " + name + "#" + str(build_no) + ": " + str(e))
else:
log_str = "Log for " + name + " #" + str(build_no) + ":\n" + response.read()
prof.win_show(win_tag, log_str)
else:
prof.win_show(win_tag, "No build found for " + name)
def _cmd_jenkins(cmd=None, arg=None):
global enable_remind
global enable_notify
if not prof.win_exists(win_tag):
prof.win_create(win_tag, _handle_input)
prof.win_focus(win_tag)
if cmd == "jobs":
if job_list and job_list.get_jobs():
prof.win_show(win_tag, "Jobs:")
_list_jobs(job_list.get_jobs())
else:
prof.win_show(win_tag, "No job data yet.")
elif cmd == "failing":
if job_list:
jobs_in_state = job_list.get_jobs(STATE_FAILURE)
if jobs_in_state:
prof.win_show(win_tag, "Failing jobs:")
_list_jobs(jobs_in_state)
else:
prof.win_show(win_tag, "No failing jobs.")
else:
prof.win_show(win_tag, "No job data yet.")
elif cmd == "passing":
if job_list:
jobs_in_state = job_list.get_jobs(STATE_SUCCESS)
if jobs_in_state:
prof.win_show(win_tag, "Passing jobs:")
_list_jobs(jobs_in_state)
else:
prof.win_show(win_tag, "No passing jobs.")
else:
prof.win_show(win_tag, "No job data yet.")
elif cmd == "unstable":
if job_list:
jobs_in_state = job_list.get_jobs(STATE_UNSTABLE)
if jobs_in_state:
prof.win_show(win_tag, "Unstable jobs:")
_list_jobs(jobs_in_state)
else:
prof.win_show(win_tag, "No unstable jobs.")
else:
prof.win_show(win_tag, "No job data yet.")
elif cmd == "build":
if not arg:
prof.win_show(win_tag, "You must supply a job argument.")
elif job_list and job_list.contains_job(arg):
_build_job(arg)
else:
prof.win_show(win_tag, "No such job: " + arg)
elif cmd == "open":
if not arg:
prof.win_show(win_tag, "You must supply a job argument.")
elif job_list and job_list.contains_job(arg):
_open_job_url(jenkins_url + "/job/" + arg)
else:
prof.win_show(win_tag, "No such job: " + arg)
elif cmd == "remind":
if not arg:
prof.win_show(win_tag, "You must specify either 'on' or 'off'.")
elif arg == "on":
enable_remind = True
prof.win_show(win_tag, "Reminder notifications enabled.")
elif arg == "off":
enable_remind = False
prof.win_show(win_tag, "Reminder notifications disabled.")
else:
prof.win_show(win_tag, "You must specify either 'on' or 'off'.")
elif cmd == "notify":
if not arg:
prof.win_show(win_tag, "You must specify either 'on' or 'off'.")
elif arg == "on":
enable_notify = True
prof.win_show(win_tag, "Build notifications enabled.")
elif arg == "off":
enable_notify = False
prof.win_show(win_tag, "Build notifications disabled.")
else:
prof.win_show(win_tag, "You must specify either 'on' or 'off'.")
elif cmd == "settings":
_settings()
elif cmd == "help":
_help()
elif cmd == "log":
if not arg:
prof.win_show(win_tag, "You must specify a job.")
else:
job = job_list.get_job(arg)
if job:
_job_log(job)
else:
prof.win_show(win_tag, "No job found: " + arg)
else:
prof.win_show(win_tag, "Unknown command.")
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 prof_init(version, status, account_name, fulljid):
last_state[STATE_SUCCESS] = []
last_state[STATE_UNSTABLE] = []
last_state[STATE_FAILURE] = []
last_state[STATE_QUEUED] = []
last_state[STATE_RUNNING] = []
last_state[STATE_NOBUILDS] = []
last_state[STATE_UNKNOWN] = []
jenkins_t = threading.Thread(target=_jenkins_poll)
jenkins_t.daemon = True;
jenkins_t.start()
prof.register_timed(_prof_callback, prof_cb_interval)
prof.register_timed(_remind, prof_remind_interval)
prof.completer_add(
"/jenkins", [
"help",
"jobs",
"failing",
"passing",
"unstable",
"build",
"open",
"log",
"remind",
"notify",
"settings"
]
);
prof.completer_add(
"/jenkins remind", [
"on",
"off"
]
);
prof.completer_add(
"/jenkins notify", [
"on",
"off"
]
);
synopsis = [
"/jenkins jobs|failing|passing|unstable",
"/jenkins build <job>",
"/jenkins open <job>",
"/jenkins log <job>",
"/jenkins remind on|off",
"/jenkins notify on|off",
"/jenkins settings"
]
description = "Monitor, run and view Jenkins jobs."
args = [
[ "jobs", "List all jobs" ],
[ "failing", "List all failing jobs" ],
[ "passing", "List all passing jobs" ],
[ "unstable", "List all unstable jobs" ],
[ "build <job>", "Trigger build for job" ],
[ "open <job>", "Open job in browser" ],
[ "log <job>", "Show the latest build log for job" ],
[ "remind on|off", "Enable/disable reminder notifications" ],
[ "notify on|off", "Enable/disable build notifications" ],
[ "settings", "Show current settings" ]
]
examples = [
"/kenkins failing",
"/kenkins build stabber-build",
"/kenkins remind off"
]
prof.register_command("/jenkins", 0, 2, synopsis, description, args, examples, _cmd_jenkins)
def prof_on_start():
prof.win_create(win_tag, _handle_input)
prof.win_show(win_tag, "Jenkins plugin started.")

View File

@@ -1,191 +0,0 @@
/*
* Copyright (C) 2020 Stefan Kropp <stefan@debxwoody.de>
*
* This file is part of profanity.
*
* profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with profanity. If not, see <http://www.gnu.org/licenses/>.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* !!! Status: Development / Testing !!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* File: microblog.c
*
* The microblog plugin can be used for Movim Users. If profanity gets a message
* "urn:xmpp:microblog:0", it will display the from, title and ID information of
* the blog post.
*
* Profanity will display a message like this, in the main Window:
*
* Blog from user@domain.tld - Title of the post (ID of the post)
*
* Compile:
*
* gcc -shared -fpic -g3 -O0 -Wextra -pedantic \
* -L/usr/lib/profanity -lprofanity `pkg-config --libs --cflags libxml-2.0` \
* -o microblog.so microblog.c
*
* Install:
*
* cp microblog.so \
* ~/.local/share/profanity/plugins/
*
* Documentation:
*
* https://profanity-im.github.io/plugins.html
*
*/
#define _GNU_SOURCE
#include <profapi.h>
#include <assert.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PLUGIN_NAME "microblog"
#define PLUGIN_VERSION "0.0.1-DEV"
#define XMPP_URN_MICROBLOG "urn:xmpp:microblog:0"
/**
* PubSubEvent is the struct with all data of the stanza, which should be
* displayed or processed by the plugin..
*/
typedef struct {
char *id; // id of the item
char *from; // jid from
char *title; // title of the item
} PubSubEvent;
// Enable or disable Plugin
static bool enabled = true;
/**
* Parse the char* stanza and return the information in event.
* The function will return true on success, otherwise false.
*/
bool parse(const char *stanza, PubSubEvent *event) {
bool result = false;
// stanza and event are mandatory
if (stanza == NULL || event == NULL || strlen(stanza) == 0) {
return result;
}
xmlDocPtr doc;
xmlNode *root_element = NULL;
doc = xmlReadMemory(stanza, strlen(stanza), NULL, NULL, 0);
if (doc == NULL) {
return result;
}
xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
xmlXPathRegisterNs(xpathCtx, BAD_CAST "ev",
BAD_CAST "http://jabber.org/protocol/pubsub#event");
xmlXPathRegisterNs(xpathCtx, BAD_CAST "a",
BAD_CAST "http://www.w3.org/2005/Atom");
xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(
"//message/ev:event/ev:items/attribute::node", xpathCtx);
if (xpathObj != NULL && xpathObj->nodesetval != NULL &&
xpathObj->nodesetval->nodeTab[0] != NULL) {
if (xpathObj->nodesetval->nodeTab[0]->children != NULL &&
xpathObj->nodesetval->nodeTab[0]->children->content != NULL) {
if (strcmp(xpathObj->nodesetval->nodeTab[0]->children->content,
XMPP_URN_MICROBLOG) == 0) {
xpathObj =
xmlXPathEvalExpression("//message/attribute::from", xpathCtx);
assert(xpathObj != NULL);
event->from =
strdup(xpathObj->nodesetval->nodeTab[0]->children->content);
xmlXPathFreeObject(xpathObj);
xpathObj = xmlXPathEvalExpression(
"//message/ev:event/ev:items/ev:item/a:entry/a:title", xpathCtx);
assert(xpathObj != NULL);
event->title =
strdup(xpathObj->nodesetval->nodeTab[0]->children->content);
xmlXPathFreeObject(xpathObj);
xpathObj = xmlXPathEvalExpression(
"//message/ev:event/ev:items/ev:item/attribute::id", xpathCtx);
assert(xpathObj != NULL);
event->id = strdup(xpathObj->nodesetval->nodeTab[0]->children->content);
xmlXPathFreeObject(xpathObj);
result = true;
}
}
}
if (xpathCtx) {
xmlXPathFreeContext(xpathCtx);
}
if (doc) {
xmlFreeDoc(doc);
}
return result;
}
void prof_init(const char *const version, const char *const status,
const char *const account_name, const char *const fulljid) {
char *s = NULL;
asprintf(&s, "Loaded Plugin %s %s", PLUGIN_NAME, PLUGIN_VERSION);
prof_cons_show(s);
free(s);
}
void prof_on_start(void) {}
void prof_on_shutdown(void) {}
void prof_on_unload(void) {
char *s = NULL;
asprintf(&s, "Unloading Plugin %s %s", PLUGIN_NAME, PLUGIN_VERSION);
prof_cons_show(s);
free(s);
}
int prof_on_message_stanza_receive(const char *const stanza) {
if (enabled) {
PubSubEvent event;
event.id = NULL;
event.from = NULL;
event.title = NULL;
if (parse(stanza, &event)) {
int size =
strlen(event.id) + strlen(event.from) + strlen(event.title) + 30;
char *message = calloc(size, sizeof(char));
snprintf(message, size, "Blog from %s - %s (%s)", event.from, event.title,
event.id);
prof_cons_show(message);
prof_cons_alert();
free(message);
free(event.id);
free(event.from);
free(event.title);
}
}
return 1;
}

View File

@@ -1,246 +0,0 @@
/*
* Copyright (C) 2020 Stefan Kropp <stefan@debxwoody.de>
*
* This file is part of profanity.
*
* profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with profanity. If not, see <http://www.gnu.org/licenses/>.
*
* File: c_plugin_example_01.c
*
* Example 1 for profanity c plugin.
*
* This example implements the hooks (callbacks) provides by profanity. The
* plugin writes name of function / the parameters of the hooks into a file.
*
* Compile:
*
* gcc -shared -fpic -g3 -O0 -Wextra -pedantic \
* -L/usr/lib/profanity -lprofanity \
* -o c_plugin_example_01.so c_plugin_example_01.c
*
* Install:
*
* cp c_plugin_example_01.so \
* ~/.local/share/profanity/plugins/c_plugin_example_01.so
*
* Documentation:
*
* https://profanity-im.github.io/plugins.html
*
*/
#include <profapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fp;
void prof_init(const char *const version, const char *const status,
const char *const account_name, const char *const fulljid) {
fp = fopen("profanity-c-plugins-example_01.log", "a");
fprintf(fp, "prof_init: %s %s %s %s\n", version, status, account_name,
fulljid);
fflush(fp);
}
void prof_on_start(void) {
fprintf(fp, "prof_on_start\n");
fflush(fp);
}
void prof_on_shutdown(void) {
fprintf(fp, "prof_on_shutdown\n");
fflush(fp);
}
void prof_on_unload(void) {
fprintf(fp, "prof_on_unload\n");
fflush(fp);
fclose(fp);
}
void prof_on_connect(const char *const account_name,
const char *const fulljid) {
fprintf(fp, "prof_on_connect: %s %s\n", account_name, fulljid);
fflush(fp);
}
void prof_on_disconnect(const char *const account_name,
const char *const fulljid) {
fprintf(fp, "prof_on_disconnect: %s %s\n", account_name, fulljid);
fflush(fp);
}
char *prof_pre_chat_message_display(const char *const barejid,
const char *const resource,
const char *message) {
fprintf(fp, "prof_pre_chat_message_display: %s %s %s\n", barejid, resource,
message);
fflush(fp);
return NULL;
}
void prof_post_chat_message_display(const char *const barejid,
const char *const resource,
const char *message) {
fprintf(fp, "prof_post_chat_message_display %s %s %s\n", barejid, resource,
message);
fflush(fp);
}
char *prof_pre_chat_message_send(const char *const barejid,
const char *message) {
fprintf(fp, "prof_pre_chat_message_send: %s %s\n", barejid, message);
fflush(fp);
return strdup(message);
}
void prof_post_chat_message_send(const char *const barejid,
const char *message) {
fprintf(fp, "prof_post_chat_message_send: %s %s\n", barejid, message);
fflush(fp);
}
char *prof_pre_room_message_display(const char *const barejid,
const char *const nick,
const char *message) {
fprintf(fp, "prof_pre_room_message_display: %s %s %s\n", barejid, nick,
message);
fflush(fp);
return NULL;
}
void prof_post_room_message_display(const char *const barejid,
const char *const nick,
const char *message) {
fprintf(fp, "prof_post_room_message_display: %s %s %s\n", barejid, nick,
message);
fflush(fp);
}
char *prof_pre_room_message_send(const char *const barejid,
const char *message) {
fprintf(fp, "prof_pre_room_message_send %s %s\n", barejid, message);
fflush(fp);
return strdup(message);
}
void prof_post_room_message_send(const char *const barejid,
const char *message) {
fprintf(fp, "prof_post_room_message_send: %s %s\n", barejid, message);
fflush(fp);
}
void prof_on_room_history_message(const char *const barejid,
const char *const nick,
const char *const message,
const char *const timestamp) {
fprintf(fp, "prof_on_room_history_message: %s %s %s %s\n", barejid, nick,
message, timestamp);
fflush(fp);
}
char *prof_pre_priv_message_display(const char *const barejid,
const char *const nick,
const char *message) {
fprintf(fp, "prof_pre_priv_message_display: %s %s %s\n", barejid, nick,
message);
fflush(fp);
return NULL;
}
void prof_post_priv_message_display(const char *const barejid,
const char *const nick,
const char *message) {
fprintf(fp, "prof_post_priv_message_display: %s %s %s\n", barejid, nick,
message);
fflush(fp);
}
char *prof_pre_priv_message_send(const char *const barejid,
const char *const nick, const char *message) {
fprintf(fp, "prof_pre_priv_message_send: %s %s %s\n", barejid, nick, message);
fflush(fp);
return strdup(message);
}
void prof_post_priv_message_send(const char *const barejid,
const char *const nick, const char *message) {
fprintf(fp, "prof_post_priv_message_send: %s %s %s\n", barejid, nick,
message);
fflush(fp);
}
char *prof_on_message_stanza_send(const char *const stanza) {
fprintf(fp, "prof_on_message_stanza_send: %d\n", strlen(stanza));
fflush(fp);
return NULL;
}
int prof_on_message_stanza_receive(const char *const stanza) {
fprintf(fp, "prof_on_message_stanza_receive: %d\n", strlen(stanza));
fflush(fp);
return 1;
}
char *prof_on_presence_stanza_send(const char *const stanza) {
fprintf(fp, "prof_on_presence_stanza_send: %s\n", stanza);
fflush(fp);
return NULL;
}
int prof_on_presence_stanza_receive(const char *const stanza) {
fprintf(fp, "prof_on_presence_stanza_receive: %d\n", strlen(stanza));
fflush(fp);
return 1;
}
char *prof_on_iq_stanza_send(const char *const stanza) {
fprintf(fp, "prof_on_iq_stanza_send: %d\n", strlen(stanza));
fflush(fp);
return NULL;
}
int prof_on_iq_stanza_receive(const char *const stanza) {
fprintf(fp, "prof_on_iq_stanza_receive: %d\n", strlen(stanza));
fflush(fp);
return 1;
}
void prof_on_contact_offline(const char *const barejid,
const char *const resource,
const char *const status) {
fprintf(fp, "prof_on_contact_offline: %s %s %s\n", barejid, resource, status);
fflush(fp);
}
void prof_on_contact_presence(const char *const barejid,
const char *const resource,
const char *const presence,
const char *const status, const int priority) {
fprintf(fp, "prof_on_contact_presence: %s %s %s %s %d\n", barejid, resource,
presence, status, priority);
fflush(fp);
}
void prof_on_chat_win_focus(const char *const barejid) {
fprintf(fp, "prof_on_chat_win_focus: %s\n", barejid);
fflush(fp);
}
void prof_on_room_win_focus(const char *const barejid) {
fprintf(fp, "prof_on_room_win_focus: %s\n", barejid);
fflush(fp);
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) 2020 Stefan Kropp <stefan@debxwoody.de>
*
* This file is part of profanity.
*
* profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with profanity. If not, see <http://www.gnu.org/licenses/>.
*
* File: c_plugin_example_02.c
*
* Example 2 for profanity c plugin. Define an own command which will be execute
* your own function. Load the plugin and try /help example2.
*
* Compile:
*
* gcc -shared -fpic -g3 -O0 -Wextra -pedantic \
* -L/usr/lib/profanity -lprofanity \
* -o c_plugin_example_02.so c_plugin_example_02.c
*
* Install:
*
* cp c_plugin_example_02.so \
* ~/.local/share/profanity/plugins/
*
* Documentation:
*
* https://profanity-im.github.io/plugins.html
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <profapi.h>
void cmd_callback(char **args) {
prof_cons_show("Hello! I'm Example 2.");
prof_cons_alert();
}
void prof_init(const char *const version, const char *const status,
const char *const account_name, const char *const fulljid) {
char *synopsis[] = {"/example2", NULL};
char *description = "Example 2 for profanity c plugin.";
char *args[][2] = {{NULL, NULL}};
char *examples[] = {NULL};
prof_register_command(synopsis[0], 0, 0, synopsis, description, args,
examples, cmd_callback);
}

View File

@@ -1,161 +0,0 @@
module RubyTest
def self.prof_init(version, status)
Prof::cons_show("RubyTest: init, " + version + ", " + status)
Prof::register_command("/ruby", 0, 1, "/ruby [arg]", "RubyTest", "RubyTest", cmd_ruby)
Prof::register_command("/rb_upper", 1, 1, "/rb_upper string", "RubyTest", "RubyTest", cmd_upper)
Prof::register_command("/rb_notify", 0, 0, "/rb_notify", "RubyTest", "RubyTest", cmd_notify)
Prof::register_command("/rb_vercheck", 0, 0, "/rb_vercheck", "RubyTest", "RubyTest", cmd_vercheck)
Prof::register_ac("/rb_complete", [ "aaaa", "bbbb", "bcbcbc" ])
Prof::register_ac("/rb_complete aaaa", [ "one", "two", "three", "four" ])
Prof::register_ac("/rb_complete bcbcbc", [ "james", "jim", "jane", "bob" ])
Prof::register_command("/rb_complete", 0, 2, "/rb_complete [arg1] [arg2]", "RubyTest", "RubyTest", cmd_ac)
Prof::register_timed(timer_test, 30)
end
def self.prof_on_start
Prof::cons_show("RubyTest: prof_on_start")
Prof::log_debug("RubyTest: logged debug");
Prof::log_info("RubyTest: logged info");
Prof::log_warning("RubyTest: logged warning");
Prof::log_error("RubyTest: logged error");
end
def self.prof_on_shutdown
Prof::log_info("RubyTest: prof_on_shutdown");
end
def self.prof_on_connect(account_name, fulljid)
Prof::cons_show("RubyTest: prof_on_connect, " + account_name + ", " + fulljid)
end
def self.prof_on_disconnect(account_name, fulljid)
Prof::cons_show("RubyTest: prof_on_disconnect, " + account_name + ", " + fulljid)
end
def self.prof_pre_chat_message_display(jid, message)
Prof::cons_show("RubyTest: prof_pre_chat_message_display, " + jid + ", " + message)
Prof::cons_alert
return message + "[RB_pre_chat_message_display]"
end
def self.prof_post_chat_message_display(jid, message)
Prof::cons_show("RubyTest: prof_post_chat_message_display, " + jid + ", " + message)
Prof::cons_alert
end
def self.prof_pre_chat_message_send(jid, message)
Prof::cons_show("RubyTest: prof_pre_chat_message_send, " + jid + ", " + message)
Prof::cons_alert
return message + "[RB_pre_chat_message_send]"
end
def self.prof_post_chat_message_send(jid, message)
Prof::cons_show("RubyTest: prof_post_chat_message_send, " + jid + ", " + message)
Prof::cons_alert
end
def self.prof_pre_room_message_display(room, nick, message)
Prof::cons_show("RubyTest: prof_pre_room_message_display, " + room + ", " + nick + ", " + message)
Prof::cons_alert
return message + "[RB_pre_room_message_display]"
end
def self.prof_post_room_message_display(room, nick, message)
Prof::cons_show("RubyTest: prof_post_room_message_display, " + room + ", " + nick + ", " + message)
Prof::cons_alert
end
def self.prof_pre_room_message_send(room, message)
Prof::cons_show("RubyTest: prof_pre_room_message_send, " + room + ", " + message)
Prof::cons_alert
return message + "[RB_pre_room_message_send]"
end
def self.prof_post_room_message_send(room, message)
Prof::cons_show("RubyTest: prof_post_room_message_send, " + room + ", " + message)
Prof::cons_alert
end
def self.prof_pre_priv_message_display(room, nick, message)
Prof::cons_show("RubyTest: prof_pre_priv_message_display, " + room + ", " + nick + ", " + message)
Prof::cons_alert
return message + "[RB_pre_priv_message_display]"
end
def self.prof_post_priv_message_display(room, nick, message)
Prof::cons_show("RubyTest: prof_post_priv_message_display, " + room + ", " + nick + ", " + message)
Prof::cons_alert
end
def self.prof_pre_priv_message_send(room, nick, message)
Prof::cons_show("RubyTest: prof_pre_priv_message_send, " + room + ", " + nick + ", " + message)
Prof::cons_alert
return message + "[RB_pre_priv_message_send]"
end
def self.prof_post_priv_message_send(room, nick, message)
Prof::cons_show("RubyTest: prof_post_priv_message_send, " + room + ", " + nick + ", " + message)
Prof::cons_alert
end
def self.cmd_ruby
return Proc.new { | msg |
if msg
Prof::cons_show("RubyTest: /ruby command called, arg = " + msg)
else
Prof::cons_show("RubyTest: /ruby command called with no arg")
end
}
end
def self.cmd_ac
return Proc.new { | arg1, arg2 |
Prof::cons_show("RubyTest: /rb_complete called")
}
end
def self.cmd_notify
return Proc.new {
Prof::notify("RubyTest: notify", 2000, "Plugins")
}
end
def self.cmd_vercheck
return Proc.new {
Prof::send_line("/vercheck")
Prof::cons_show("RubyTest: sent \"/vercheck\" command")
}
end
def self.timer_test
return Proc.new {
Prof::cons_show("RubyTest: timer fired.")
Prof::cons_alert
}
end
def self.cmd_upper
return Proc.new { | line |
win_tag = "Ruby Plygin"
if (Prof::win_exists(win_tag) == false)
Prof::win_create(win_tag, handle_upper)
end
Prof::win_focus(win_tag)
if (line)
handle_upper.call(win_tag, line)
end
}
end
def self.handle_upper
return Proc.new { | win, line |
upper = line.upcase
Prof::win_show(win, upper)
Prof::win_show_red(win, upper + " red")
Prof::win_show_yellow(win, upper + " yellow")
Prof::win_show_green(win, upper + " green")
Prof::win_show_cyan(win, upper + " cyan")
}
end
end

View File

@@ -1,23 +0,0 @@
module RubyThread
@counter = 0
def self.inc_counter()
while true
sleep(1)
@counter = @counter + 1
end
end
def self.cmd_rcount()
return Proc.new {
instance_eval {
Prof::cons_show("RCounter: " + @counter)
}
}
end
def self.prof_init(version, status)
Thread.new { self.inc_counter() }
Prof::register_command("/rcount", 0, 0, "/rcount", "Ruby threaded example", "Ruby threaded example", cmd_rcount)
end
end

View File

@@ -1,18 +0,0 @@
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINK_FLAGS := -fno-common -flat_namespace -bundle -undefined suppress
else
LINK_FLAGS := -shared -fpic
endif
all: enc_c.so
%.so:%.o
$(CC) $(LINK_FLAGS) -lprofanity -o $@ $^
%.o:%.c
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -g3 -O0 -std=c99 \
-Wextra -pedantic -c -o $@ $<
clean:
$(RM) enc_c.so

View File

@@ -1,220 +0,0 @@
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <profapi.h>
static char *chat_msg_hook = NULL;
static char *room_msg_hook = NULL;
void
cmd_enc(char **args)
{
if (args[0] && strcmp(args[0], "end") == 0) {
prof_encryption_reset(args[1]);
} else if (args[0] && (strcmp(args[0], "chat_title") == 0)) {
if (args[1] && (strcmp(args[1], "set") == 0)) {
prof_chat_set_titlebar_enctext(args[2], args[3]);
} else if (args[1] && (strcmp(args[1], "reset") == 0)) {
prof_chat_unset_titlebar_enctext(args[2]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
} else if (args[0] && (strcmp(args[0], "chat_ch") == 0)) {
if (args[1] && (strcmp(args[1], "set") == 0)) {
if (args[2] && (strcmp(args[2], "in") == 0)) {
prof_chat_set_incoming_char(args[3], args[4]);
} else if (args[2] && (strcmp(args[2], "out") == 0)) {
prof_chat_set_outgoing_char(args[3], args[4]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
} else if (args[1] && (strcmp(args[1], "reset") == 0)) {
if (args[2] && (strcmp(args[2], "in") == 0)) {
prof_chat_unset_incoming_char(args[3]);
} else if (args[2] && (strcmp(args[2], "out") == 0)) {
prof_chat_unset_outgoing_char(args[3]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
} else if (args[0] && (strcmp(args[0], "room_title") == 0)) {
if (args[1] && (strcmp(args[1], "set") == 0)) {
prof_room_set_titlebar_enctext(args[2], args[3]);
} else if (args[1] && (strcmp(args[1], "reset") == 0)) {
prof_room_unset_titlebar_enctext(args[2]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
} else if (args[0] && (strcmp(args[0], "room_ch") == 0)) {
if (args[1] && (strcmp(args[1], "set") == 0)) {
prof_room_set_message_char(args[2], args[3]);
} else if (args[1] && (strcmp(args[1], "reset") == 0)) {
prof_room_unset_message_char(args[2]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
} else if (args[0] && (strcmp(args[0], "chat_show") == 0)) {
prof_chat_show(args[1], args[2]);
} else if (args[0] && (strcmp(args[0], "chat_show_themed") == 0)) {
prof_chat_show_themed(args[1], "enc_c", "chat_msg", NULL, "c", args[2]);
} else if (args[0] && (strcmp(args[0], "room_show") == 0)) {
prof_room_show(args[1], args[2]);
} else if (args[0] && (strcmp(args[0], "room_show_themed") == 0)) {
prof_room_show_themed(args[1], "enc_c", "room_msg", NULL, "C", args[2]);
} else if (args[0] && (strcmp(args[0], "chat_msg") == 0)) {
if (chat_msg_hook) {
free(chat_msg_hook);
}
chat_msg_hook = strdup(args[1]);
} else if (args[0] && (strcmp(args[0], "room_msg") == 0)) {
if (room_msg_hook) {
free(room_msg_hook);
}
room_msg_hook = strdup(args[1]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
}
void
prof_init(const char * const version, const char * const status, const char *const account_name, const char *const fulljid)
{
char *synopsis[] = {
"/enc_c end <barejid>",
"/enc_c chat_title set <barejid> <text>",
"/enc_c chat_title unset <barejid>",
"/enc_c chat_ch set in <barejid> <ch>",
"/enc_c chat_ch reset in <barejid>",
"/enc_c chat_ch set out <barejid> <ch>",
"/enc_c chat_ch reset out <barejid>",
"/enc_c chat_show <barejid> <message>",
"/enc_c chat_show_themed <barejid> <message>",
"/enc_c room_title set <roomjid> <text>",
"/enc_c room_title unset <roomjid>",
"/enc_c room_ch set <roomjid> <ch>",
"/enc_c room_ch reset <roomjid>",
"/enc_c room_show <roomjid> <message>",
"/enc_c room_show_themed <roomjid> <message>",
"/enc_c chat_msg none",
"/enc_c chat_msg modify",
"/enc_c chat_msg block",
"/enc_c room_msg none",
"/enc_c room_msg modify",
"/enc_c room_msg block",
NULL
};
char *description = "Various enc things";
char *args[][2] = {
{ "end <barejid>", "User to end the session with" },
{ "chat_title set <barejid> <text>", "Set encryption text in titlebar for recipient" },
{ "chat_title reset <barejid>", "Reset encryption text in titlebar for recipient" },
{ "chat_ch set in <barejid> <ch>", "Set incoming char for recipient" },
{ "chat_ch reset in <barejid>", "Reset incoming char for recipient" },
{ "chat_ch set out <barejid> <ch>", "Set outgoing char for recipient" },
{ "chat_ch reset out <barejid>", "Reset outgoing char for recipient" },
{ "chat_show <barejid> <message>", "Show chat message" },
{ "chat_show_themed <barejid> <message>", "Show themed chat message" },
{ "room_title set <roomjid> <text>", "Set encryption text in titlebar for room" },
{ "room_title reset <roomjid>", "Reset encryption text in titlebar for room" },
{ "room_ch set <roomjid> <ch>", "Set char for room" },
{ "room_ch reset <roomjid>", "Reset char for room" },
{ "room_show <roomjid> <message>", "Show chat room message" },
{ "room_show_themed <roomjid> <message>", "Show themed chat room message" },
{ "chat_msg none", "Preserve chat messages" },
{ "chat_msg modify", "Modify chat messages" },
{ "chat_msg block", "Block chat messages" },
{ "room_msg none", "Preserve chat room messages" },
{ "room_msg modify", "Modify chat room messages" },
{ "room_msg block", "Block chat room messages" },
{ NULL, NULL }
};
char *examples[] = { NULL };
prof_register_command("/enc_c", 2, 5, synopsis, description, args, examples, cmd_enc);
char *cmd_ac[] = {
"end",
"chat_title",
"chat_ch",
"chat_show",
"chat_show_themed",
"room_title",
"room_ch",
"room_show",
"room_show_themed",
"chat_msg",
"room_msg",
NULL
};
prof_completer_add("/enc_c", cmd_ac);
char *chat_title_ac[] = { "set", "reset", NULL };
prof_completer_add("/enc_c chat_title", chat_title_ac);
char *chat_ch_ac[] = { "set", "reset", NULL };
prof_completer_add("/enc_c chat_ch", chat_ch_ac);
char *chat_ch_set_ac[] = { "in", "out", NULL };
prof_completer_add("/enc_c chat_ch set", chat_ch_set_ac);
char *chat_ch_reset_ac[] = { "in", "out", NULL };
prof_completer_add("/enc_c chat_ch reset", chat_ch_reset_ac);
char *room_title_ac[] = { "set", "reset", NULL };
prof_completer_add("/enc_c room_title", room_title_ac);
char *room_ch_ac[] = { "set", "reset", NULL };
prof_completer_add("/enc_c room_ch", room_ch_ac);
char *chat_msg_ac[] = { "none", "modify", "block", NULL };
prof_completer_add("/enc_c chat_msg", chat_msg_ac);
char *room_msg_ac[] = { "none", "modify", "block", NULL };
prof_completer_add("/enc_c room_msg", room_msg_ac);
}
char*
prof_pre_chat_message_send(const char * const barejid, const char *message)
{
if (chat_msg_hook && (strcmp(chat_msg_hook, "modify") == 0)) {
char buf[strlen("[c modified] ") + strlen(message) + 1];
sprintf(buf, "%s%s", "[c modified] ", message);
return strdup(buf);
} else if (chat_msg_hook && (strcmp(chat_msg_hook, "block") == 0)) {
prof_chat_show_themed(barejid, NULL, NULL, "bold_red", "!", "C plugin blocked message");
return NULL;
} else {
return strdup(message);
}
}
char*
prof_pre_room_message_send(const char * const roomjid, const char *message)
{
if (room_msg_hook && (strcmp(room_msg_hook, "modify") == 0)) {
char buf[strlen("[c modified] ") + strlen(message) + 1];
sprintf(buf, "%s%s", "[c modified] ", message);
return strdup(buf);
} else if (room_msg_hook && (strcmp(room_msg_hook, "block") == 0)) {
prof_room_show_themed(roomjid, NULL, NULL, "bold_red", "!", "C plugin blocked message");
return NULL;
} else {
return strdup(message);
}
}

View File

@@ -1,157 +0,0 @@
import prof
chat_msg_hook = None
room_msg_hook = None
def _cmd_enc(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
global chat_msg_hook
global room_msg_hook
if arg1 == "end":
prof.encryption_reset(arg2)
elif arg1 == "chat_title" and arg2 == "set":
prof.chat_set_titlebar_enctext(arg3, arg4)
elif arg1 == "chat_title" and arg2 == "reset":
prof.chat_unset_titlebar_enctext(arg3)
elif arg1 == "chat_ch" and arg2 == "set" and arg3 == "in":
prof.chat_set_incoming_char(arg4, arg5)
elif arg1 == "chat_ch" and arg2 == "reset" and arg3 == "in":
prof.chat_unset_incoming_char(arg4)
elif arg1 == "chat_ch" and arg2 == "set" and arg3 == "out":
prof.chat_set_outgoing_char(arg4, arg5)
elif arg1 == "chat_ch" and arg2 == "reset" and arg3 == "out":
prof.chat_unset_outgoing_char(arg4)
elif arg1 == "room_title" and arg2 == "set":
prof.room_set_titlebar_enctext(arg3, arg4)
elif arg1 == "room_title" and arg2 == "reset":
prof.room_unset_titlebar_enctext(arg3)
elif arg1 == "room_ch" and arg2 == "set":
prof.room_set_message_char(arg3, arg4)
elif arg1 == "room_ch" and arg2 == "reset":
prof.room_unset_message_char(arg3)
elif arg1 == "chat_show":
prof.chat_show(arg2, arg3)
elif arg1 == "chat_show_themed":
prof.chat_show_themed(arg2, "enc_py", "chat_msg", None, "p", arg3)
elif arg1 == "room_show":
prof.room_show(arg2, arg3)
elif arg1 == "room_show_themed":
prof.room_show_themed(arg2, "enc_py", "room_msg", None, "P", arg3)
elif arg1 == "chat_msg":
chat_msg_hook = arg2
elif arg1 == "room_msg":
room_msg_hook = arg2
else:
prof.cons_bad_cmd_usage("/enc_py")
def prof_init(version, status, account_name, fulljid):
synopsis = [
"/enc_py end <barejid>",
"/enc_py chat_title set <barejid> <text>",
"/enc_py chat_title unset <barejid>",
"/enc_py chat_ch set in <barejid> <ch>",
"/enc_py chat_ch reset in <barejid>",
"/enc_py chat_ch set out <barejid> <ch>",
"/enc_py chat_ch reset out <barejid>",
"/enc_py chat_show <barejid> <message>",
"/enc_py chat_show_themed <barejid> <message>",
"/enc_py room_title set <roomjid> <text>",
"/enc_py room_title unset <roomjid>"
"/enc_py room_ch set <roomjid> <ch>",
"/enc_py room_ch reset <roomjid>",
"/enc_py room_show <roomjid> <message>",
"/enc_py room_show_themed <roomjid> <message>"
"/enc_py chat_msg none",
"/enc_py chat_msg modify",
"/enc_py chat_msg block",
"/enc_py room_msg none",
"/enc_py room_msg modify",
"/enc_py room_msg block"
]
description = "Various enc things"
args = [
[ "end <barejid>", "User to end the session with" ],
[ "chat_title set <barejid> <text>", "Set encryption text in titlebar for recipient" ],
[ "chat_title reset <barejid>", "Reset encryption text in titlebar for recipient" ],
[ "chat_ch set in <barejid> <ch>", "Set incoming char for recipient" ],
[ "chat_ch reset in <barejid>", "Reset incoming char for recipient" ],
[ "chat_ch set out <barejid> <ch>", "Set outgoing char for recipient" ],
[ "chat_ch reset out <barejid>", "Reset outgoing char for recipient" ],
[ "chat_show <barejid> <message>", "Show chat message" ],
[ "chat_show_themed <barejid> <message>", "Show themed chat message" ],
[ "room_title set <roomjid> <text>", "Set encryption text in titlebar for room" ],
[ "room_title reset <roomjid>", "Reset encryption text in titlebar for room" ],
[ "room_ch set <roomjid> <ch>", "Set char for room" ],
[ "room_ch reset <roomjid>", "Reset char for room" ],
[ "room_show <roomjid> <message>", "Show chat room message" ],
[ "room_show_themed <roomjid> <message>", "Show themed chat room message" ],
[ "chat_msg none", "Preserve chat messages" ],
[ "chat_msg modify", "Modify chat messages" ],
[ "chat_msg block", "Block chat messages" ],
[ "room_msg none", "Preserve chat room messages" ],
[ "room_msg modify", "Modify chat room messages" ],
[ "room_msg block", "Block chat room messages" ]
]
examples = []
prof.register_command("/enc_py", 2, 5, synopsis, description, args, examples, _cmd_enc)
prof.completer_add("/enc_py", [
"end",
"chat_title",
"chat_ch",
"chat_show",
"chat_show_themed",
"room_title",
"room_ch",
"room_show",
"room_show_themed",
"chat_msg",
"room_msg"
])
prof.completer_add("/enc_py chat_title", [ "set", "reset" ])
prof.completer_add("/enc_py chat_ch", [ "set", "reset" ])
prof.completer_add("/enc_py chat_ch set", [ "in", "out" ])
prof.completer_add("/enc_py chat_ch reset", [ "in", "out" ])
prof.completer_add("/enc_py room_title", [ "set", "reset" ])
prof.completer_add("/enc_py room_ch", [ "set", "reset" ])
prof.completer_add("/enc_py chat_msg", [ "none", "modify", "block" ])
prof.completer_add("/enc_py room_msg", [ "none", "modify", "block" ])
def prof_pre_chat_message_send(barejid, message):
if chat_msg_hook == "modify":
return "[py modified] " + message
elif chat_msg_hook == "block":
prof.chat_show_themed(barejid, None, None, "bold_red", "!", "Python plugin blocked message")
return None
else:
prof.log_info("none")
return message
def prof_pre_room_message_send(roomjid, message):
if room_msg_hook == "modify":
return "[py modified] " + message
elif room_msg_hook == "block":
prof.room_show_themed(roomjid, None, None, "bold_red", "!", "Python plugin blocked message")
return None
else:
return message

View File

@@ -1,116 +0,0 @@
local luatest = {}
local function cmd_lua(msg)
if msg then
prof_cons_show("luatest: /lua command called, arg = " .. msg)
else
prof_cons_show("luatest: /lua command called with no arg")
end
prof_cons_alert()
prof_notify("luatest: notify", 8000, "Plugins")
prof_send_line("/account list")
prof_cons_show("luatest: sent \"/account list\" command")
end
local function timer_test()
prof_cons_show("luatest: timer fired.")
recipient = prof_get_current_recipient()
if recipient then
prof_cons_show(" current recipient = " .. recipient)
end
prof_cons_alert()
end
local function handle_bracket(win, line)
prof_win_show(win, "(" .. line .. ")")
prof_win_show_red(win, "Red")
prof_win_show_yellow(win, "Yellow")
prof_win_show_green(win, "Green")
prof_win_show_cyan(win, "Cyan")
end
local function cmd_bracket(line)
win_tag = "Parenthesise echo";
if prof_win_exists(win_tag) == false then
prof_win_create(win_tag, handle_bracket);
end
prof_win_focus(win_tag);
if line then
handle_bracket(win_tag, line)
end
end
function luatest.prof_init(version, status)
prof_cons_show("luatest: init, " .. version .. ", " .. status)
prof_register_command("/lua", 0, 1, "/lua", "luatest", "luatest", cmd_lua)
prof_register_command("/bracket", 0, 1, "/bracket", "Parenthesise input string", "Parenthesise input string", cmd_bracket);
prof_register_ac("/lcomplete", { "football", "footy", "tennis" })
prof_register_ac("/lcomplete football", { "goal", "out", "try", "given" })
prof_register_ac("/lcomplete tennis", { "test", "prod", "dev", "stage" })
prof_register_command("/lcomplete", 0, 2, "/lcomplete", "Lua completion", "Lua completion", cmd_bracket)
prof_register_timed(timer_test, 10)
end
function luatest.prof_on_start()
prof_cons_show("luatest: on_start")
prof_log_debug("luatest: logged debug");
prof_log_info("luatest: logged info");
prof_log_warning("luatest: logged warning");
prof_log_error("luatest: logged error");
end
function luatest.prof_on_connect(account_name, fulljid)
prof_cons_show("luatest: on_connect, " .. account_name .. ", " .. fulljid)
end
function luatest.prof_on_disconnect(account_name, fulljid)
prof_cons_show("luatest: on_disconnect, " .. account_name .. ", " .. fulljid)
prof_log_info("luatest: on_disconnect, " .. account_name .. ", " .. fulljid)
end
function luatest.prof_on_message_received(jid, message)
prof_cons_show("luatest: on_message_received, " .. jid .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_room_message_received(room, nick, message)
prof_cons_show("luatest: on_room_message_received, " .. room .. ", " .. nick .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_private_message_received(room, nick, message)
prof_cons_show("luatest: on_private_message_received, " .. room .. ", " .. nick .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_message_send(jid, message)
prof_cons_show("luatest: on_message_send, " .. jid .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_private_message_send(room, nick, message)
prof_cons_show("luatest: on_private_message_send, " .. room .. ", " .. nick .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_room_message_send(room, message)
prof_cons_show("luatest: on_room_message_send, " .. room .. ", " .. message)
prof_cons_alert()
return message .. "[LUA]"
end
function luatest.prof_on_shutdown()
prof_log_info("luatest: on_shutdown")
end
return luatest

View File

@@ -1,704 +0,0 @@
import prof
import threading
import time
plugin_win = "Python Test"
count = 0
ping_id = 1
count_thread = None
thread_stop = None
def _inc_counter():
global count
global thread_stop
while not thread_stop.is_set():
time.sleep(5)
count = count + 1
def _handle_win_input(win, line):
prof.win_show(win, "Input received: " + line)
def _consalert():
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.cons_alert()
prof.win_show(plugin_win, "called -> prof.cons_alert")
def _consshow(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.cons_show(msg)
prof.win_show(plugin_win, "called -> prof.cons_show: " + msg)
def _consshow_t(group, key, dflt, msg):
if not group or not key or not dflt or not msg:
prof.cons_bad_cmd_usage("/python-test")
return
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
groupval = None if group == "none" else group
keyval = None if key == "none" else key
dfltval = None if dflt == "none" else dflt
prof.cons_show_themed(groupval, keyval, dfltval, msg)
prof.win_show(plugin_win, "called -> prof.cons_show_themed: " + group + ", " + key + ", " + dflt + ", " + msg)
def _constest():
res = prof.current_win_is_console()
prof.win_create(plugin_win, _handle_win_input)
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")
def _winshow(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.win_show(plugin_win, msg)
prof.win_show(plugin_win, "called -> prof.win_show: " + msg)
def _winshow_t(group, key, dflt, msg):
if not group or not key or not dflt or not msg:
prof.cons_bad_cmd_usage("/python-test")
return
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
groupval = None if group == "none" else group
keyval = None if key == "none" else key
dfltval = None if dflt == "none" else dflt
prof.win_show_themed(plugin_win, groupval, keyval, dfltval, msg)
prof.win_show(plugin_win, "called -> prof_win_show_themed: " + group + ", " + key + ", " + dflt + ", " + msg)
def _sendline(line):
if not line:
prof.cons_bad_cmd_usage("/python-test")
return
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.send_line(line)
prof.win_show(plugin_win, "called -> prof.send_line: " + line)
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 _get(subject):
if subject == "recipient":
prof.win_create(plugin_win, _handle_win_input)
recipient = prof.get_current_recipient();
if recipient:
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 subject == "room":
prof.win_create(plugin_win, _handle_win_input)
room = prof.get_current_muc()
if room:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_current_muc: " + room)
nick = prof.get_room_nick(room)
if nick:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_room_nick('" + room + "'): " + nick)
else:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_current_muc: <none>")
elif subject == "nick":
prof.win_create(plugin_win, _handle_win_input)
nick = prof.get_current_nick()
if nick:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_current_nick: " + nick)
else:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_current_nick: <none>")
elif subject == "occupants":
prof.win_create(plugin_win, _handle_win_input)
occupants = prof.get_current_occupants()
if occupants:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_current_occupants:")
for occupant in occupants:
prof.win_show(plugin_win, occupant)
else:
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "called -> prof_get_current_occupants: <none>")
else:
prof.cons_bad_cmd_usage("/python-test")
def _log(level, msg):
if not level or not msg:
prof.cons_bad_cmd_usage("/python-test")
return
if level == "debug":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.log_debug(msg)
prof.win_show(plugin_win, "called -> prof.log_debug: " + msg)
elif level == "info":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.log_info(msg)
prof.win_show(plugin_win, "called -> prof.log_info: " + msg)
elif level == "warning":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.log_warning(msg)
prof.win_show(plugin_win, "called -> prof.log_warning: " + msg)
elif level == "error":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.log_error(msg)
prof.win_show(plugin_win, "called -> prof.log_error: " + msg)
else:
prof.cons_bad_cmd_usage("/python-test")
def _count():
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "Count: " + str(count))
def _ping(jid):
global ping_id
if not jid:
prof.cons_bad_cmd_usage("/python-test")
return
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
res = prof.send_stanza("<iq to='" + jid + "' id='pythonplugin-" + str(ping_id) + "' type='get'><ping xmlns='urn:xmpp:ping'/></iq>")
ping_id = ping_id + 1
if res:
prof.win_show(plugin_win, "Ping sent successfully")
else:
prof.win_show(plugin_win, "Error sending ping")
def _boolean(op, group, key, value_str):
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 value_str != "true" and value_str != "false":
prof.cons_bad_cmd_usage("/python-test")
return
if op == "get":
dflt = False
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
res = prof.settings_boolean_get(group, key, dflt)
if res:
prof.win_show(plugin_win, "Boolean setting: TRUE")
else:
prof.win_show(plugin_win, "Boolean setting: FALSE")
elif op == "set":
value = False
if value_str == "true":
value = True
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.settings_boolean_set(group, key, value)
prof.win_show(plugin_win, "Set [" + group + "] " + key + " to " + str(value))
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 _string_list(op, group, key, value):
if op != "get" and op != "add" and op !="remove" and op != "remove_all":
prof.cons_bad_cmd_usage("/python-test")
return
if op == "get":
if group == None or key == None:
prof.cons_bad_cmd_usage("/python-test")
return
res = prof.settings_string_list_get(group, key)
prof.win_focus(plugin_win)
if res is None:
prof.win_show(plugin_win, "No list found")
return
prof.win_show(plugin_win, "String list:")
for el in res:
prof.win_show(plugin_win, " " + el)
return
if op == "add":
if group == None or key == None or value == None:
prof.cons_bad_cmd_usage("/python-test")
return
prof.settings_string_list_add(group, key, value)
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "Added '" + value + "' to [" + group + "]" + " " + key)
return
if op == "remove":
if group == None or key == None or value == None:
prof.cons_bad_cmd_usage("/python-test")
return
res = prof.settings_string_list_remove(group, key, value)
prof.win_focus(plugin_win)
if res:
prof.win_show(plugin_win, "Removed '" + value + "' from [" + group + "]" + " " + key)
else:
prof.win_show(plugin_win, "Error removing string item from list")
return;
if op == "remove_all":
if group == None or key == None:
prof.cons_bad_cmd_usage("/python-test")
return
res = prof.settings_string_list_clear(group, key)
prof.win_focus(plugin_win)
if res:
prof.win_show(plugin_win, "Removed all items from [" + group + "]" + " " + key)
else:
prof.win_show(plugin_win, "Error removing list")
return
def _int(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 == "get":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
res = prof.settings_int_get(group, key, 0)
prof.win_show(plugin_win, "Integer setting: " + str(res))
elif op == "set":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.settings_int_set(group, key, int(value))
prof.win_show(plugin_win, "Set [" + group + "] " + key + " to " + str(value))
def _incoming(barejid, resource, message):
if not barejid or not resource or not message:
prof.cons_bad_cmd_usage("/python-test")
return
prof.incoming_message(barejid, resource, message)
def _completer(op, item):
if not item:
prof.cons_bad_cmd_usage("/python-test")
return
if op == "add":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.completer_add("/python-test", [item])
prof.win_show(plugin_win, "Added \"" + item + "\" to /python-test completer")
prof.completer_add("/python-test completer remove", [item])
elif op == "remove":
prof.win_create(plugin_win, _handle_win_input)
prof.win_focus(plugin_win)
prof.completer_remove("/python-test", [item])
prof.win_show(plugin_win, "Removed \"" + item + "\" to /python-test completer")
prof.completer_remove("/python-test completer remove", [item])
else:
prof.cons_bad_cmd_usage("/python-test")
def _cmd_pythontest(subcmd=None, arg1=None, arg2=None, arg3=None, arg4=None):
if subcmd == "consalert": _consalert()
elif subcmd == "consshow": _consshow(arg1)
elif subcmd == "consshow_t": _consshow_t(arg1, arg2, arg3, arg4)
elif subcmd == "constest": _constest()
elif subcmd == "winshow": _winshow(arg1)
elif subcmd == "winshow_t": _winshow_t(arg1, arg2, arg3, arg4)
elif subcmd == "sendline": _sendline(arg1)
elif subcmd == "notify": _notify(arg1)
elif subcmd == "get": _get(arg1)
elif subcmd == "log": _log(arg1, arg2)
elif subcmd == "count": _count()
elif subcmd == "ping": _ping(arg1)
elif subcmd == "boolean": _boolean(arg1, arg2, arg3, arg4)
elif subcmd == "string": _string(arg1, arg2, arg3, arg4)
elif subcmd == "string_list": _string_list(arg1, arg2, arg3, arg4)
elif subcmd == "int": _int(arg1, arg2, arg3, arg4)
elif subcmd == "incoming": _incoming(arg1, arg2, arg3)
elif subcmd == "completer": _completer(arg1, arg2)
else: prof.cons_bad_cmd_usage("/python-test")
def timed_callback():
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "timed -> timed_callback called")
def prof_init(version, status, account_name, fulljid):
global count
global ping_id
global thread_stop
count = 0
ping_id = 1
thread_stop = threading.Event()
count_thread = threading.Thread(target=_inc_counter)
count_thread.daemon = True
count_thread.start()
prof.disco_add_feature("urn:xmpp:profanity:python_test_plugin");
prof.win_create(plugin_win, _handle_win_input)
if account_name and fulljid:
prof.win_show(plugin_win, "fired -> prof_init: " + version + ", " + status + ", " + account_name + ", " + fulljid)
else:
prof.win_show(plugin_win, "fired -> prof_init: " + version + ", " + status)
synopsis = [
"/python-test consalert",
"/python-test consshow <message>",
"/python-test consshow_t <group> <key> <default> <message>",
"/python-test constest",
"/python-test winshow <message>",
"/python-test winshow_t <group> <key> <default> <message>",
"/python-test notify <message>",
"/python-test sendline <line>",
"/python-test get recipient|room|nick|occupants",
"/python-test log debug|info|warning|error <message>",
"/python-test count",
"/python-test ping <jid>",
"/python-test boolean get <group> <key>",
"/python-test boolean set <group> <key> <value>",
"/python-test string get <group> <key>",
"/python-test string set <group> <key> <value>",
"/python-test string_list get <group> <key>",
"/python-test string_list add <group> <key> <value>",
"/python-test string_list remove <group> <key> <value>",
"/python-test string_list remove_all <group> <key>",
"/python-test int get <group> <key>",
"/python-test int set <group> <key> <value>",
"/python-test incoming <barejid> <resource> <message>",
"/python-test completer add|remove <item>",
"/python-test file"
]
description = "Python test plugins. All commands focus the plugin window."
args = [
[ "consalert", "Highlight the console window in the status bar" ],
[ "consshow <message>", "Show the message in the console window" ],
[ "consshow_t <group> <key> <default> <message>", "Show the themed message in the console window. " ],
[ "constest", "Show whether the command was run in the console." ],
[ "winshow <message>", "Show the message in the plugin window" ],
[ "winshow_t <group> <key> <default> <message>", "Show the themed message in the plugin window. " ],
[ "notify <message>", "Send a desktop notification with message" ],
[ "sendline <line>", "Pass line to profanity to process" ],
[ "get recipient", "Show the current chat recipient, if in a chat window" ],
[ "get room", "Show the current room JID, if ina a chat room"],
[ "get nick", "Show nickname in current room, if ina a chat room"],
[ "get occupants", "Show occupants in current room, if ina a chat room"],
[ "log debug|info|warning|error <message>", "Log a message at the specified level" ],
[ "count", "Show the counter, incremented every 5 seconds by a worker thread" ],
[ "ping <jid>", "Send an XMPP ping to the specified Jabber ID" ],
[ "boolean get <group> <key>", "Get a boolean setting" ],
[ "boolean set <group> <key> <value>", "Set a boolean setting" ],
[ "string get <group> <key>", "Get a string setting" ],
[ "string set <group> <key> <value>", "Set a string setting" ],
[ "string_list get <group> <key>", "Get a string list setting" ],
[ "string_list add <group> <key> <value>", "Add a string to a string list setting" ],
[ "string_list remove <group> <key> <value>", "Remove a string from a string list setting" ],
[ "string_list remove_all <group> <key>", "Remove all strings from a string list setting" ],
[ "int get <group> <key>", "Get a integer setting" ],
[ "int set <group> <key> <value>", "Set a integer setting" ],
[ "incoming <barejid> <resource> <message>", "Show an incoming message." ],
[ "completer add <item>", "Add an autocomplete item to the /c-test command." ],
[ "completer remove <item>", "Remove an autocomplete item from the /c-test command." ],
[ "file", "Complete a file path." ]
]
examples = [
"/python-test sendline /about",
"/python-test log debug \"Test debug message\"",
"/python-test consshow_t c-test cons.show none \"This is themed\"",
"/python-test consshow_t none none bold_cyan \"This is bold_cyan\"",
"/python-test ping buddy@server.org"
]
prof.register_command("/python-test", 1, 5, synopsis, description, args, examples, _cmd_pythontest)
prof.completer_add("/python-test",
[
"consalert",
"consshow",
"consshow_t",
"constest",
"winshow",
"winshow_t",
"notify",
"sendline",
"get",
"log",
"count",
"ping",
"boolean",
"string",
"string_list",
"int",
"incoming",
"completer",
"file"
]
)
prof.completer_add("/python-test get",
[ "recipient", "room", "nick", "occupants" ]
)
prof.completer_add("/python-test log",
[ "debug", "info", "warning", "error" ]
)
prof.completer_add("/python-test boolean",
[ "get", "set" ]
)
prof.completer_add("/python-test string",
[ "get", "set" ]
)
prof.completer_add("/python-test string_list",
[ "get", "add", "remove", "remove_all" ]
)
prof.completer_add("/python-test int",
[ "get", "set" ]
)
prof.completer_add("/python-test completer",
[ "add", "remove" ]
)
prof.filepath_completer_add("/python-test file")
prof.register_timed(timed_callback, 5)
def prof_on_start():
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_start")
def prof_on_shutdown():
global thread_stop
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_shutdown")
thread_stop.set()
count_thread.join()
def prof_on_unload():
global thread_stop
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_unload")
thread_stop.set()
count_thread.join()
def prof_on_connect(account_name, fulljid):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_connect: " + account_name + ", " + fulljid)
def prof_on_disconnect(account_name, fulljid):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_disconnect: " + account_name + ", " + fulljid)
def prof_pre_chat_message_display(barejid, resource, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_chat_message_display: " + barejid + "/" + resource + ", " + message)
def prof_post_chat_message_display(barejid, resource, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_chat_message_display: " + barejid + "/" + resource + ", " + message)
def prof_pre_chat_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_chat_message_send: " + barejid + ", " + message)
return message
def prof_post_chat_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_chat_message_send: " + barejid + ", " + message)
def prof_pre_room_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_room_message_display: " + barejid + ", " + nick + ", " + message)
def prof_post_room_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_room_message_display: " + barejid + ", " + nick + ", " + message)
def prof_pre_room_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_room_message_send: " + barejid + ", " + message)
return message
def prof_post_room_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_room_message_send: " + barejid + ", " + message)
def prof_on_room_history_message(barejid, nick, message, timestamp):
prof.win_create(plugin_win, _handle_win_input)
if timestamp:
prof.win_show(plugin_win, "fired -> prof_on_room_history_message: " + barejid + ", " + nick + ", " + message + ", " + timestamp)
else:
prof.win_show(plugin_win, "fired -> prof_on_room_history_message: " + barejid + ", " + nick + ", " + message)
def prof_pre_priv_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_priv_message_display: " + barejid + ", " + nick + ", " + message)
def prof_post_priv_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_priv_message_display: " + barejid + ", " + nick + ", " + message)
def prof_pre_priv_message_send(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_priv_message_send: " + barejid + ", " + nick + ", " + message)
return message
def prof_post_priv_message_send(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_priv_message_send: " + barejid + ", " + nick + ", " + message)
def prof_on_message_stanza_send(stanza):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_message_stanza_send: " + stanza)
def prof_on_message_stanza_receive(stanza):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_message_stanza_receive: " + stanza)
return True
def prof_on_presence_stanza_send(stanza):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_presence_stanza_send: " + stanza)
def prof_on_presence_stanza_receive(stanza):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_presence_stanza_receive: " + stanza)
return True
def prof_on_iq_stanza_send(stanza):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_iq_stanza_send: " + stanza)
def prof_on_iq_stanza_receive(stanza):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_iq_stanza_receive: " + stanza)
return True
def prof_on_contact_offline(barejid, resource, status):
prof.win_create(plugin_win, _handle_win_input)
if status:
prof.win_show(plugin_win, "fired -> prof_on_contact_offline: " + barejid + "/" + resource + " \"" + status + "\"")
else:
prof.win_show(plugin_win, "fired -> prof_on_contact_offline: " + barejid + "/" + resource)
def prof_on_contact_presence(barejid, resource, presence, status, priority):
prof.win_create(plugin_win, _handle_win_input)
if status:
prof.win_show(plugin_win, "fired -> prof_on_contact_presence: " + barejid + "/" + resource + " " + presence + " " + str(priority) + " \"" + status + "\"")
else:
prof.win_show(plugin_win, "fired -> prof_on_contact_presence: " + barejid + "/" + resource + " " + presence + " " + str(priority))
def prof_on_chat_win_focus(barejid):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_chat_win_focus: " + barejid)
def prof_on_room_win_focus(barejid):
prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_room_win_focus: " + barejid)

View File

@@ -1,18 +0,0 @@
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINK_FLAGS := -fno-common -flat_namespace -bundle -undefined suppress
else
LINK_FLAGS := -shared -fpic
endif
all: test-c-plugin.so
%.so:%.o
$(CC) $(LINK_FLAGS) -lprofanity -o $@ $^
%.o:%.c
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -g3 -O0 -std=c99 \
-pedantic -c -o $@ $<
clean:
$(RM) test-c-plugin.so

File diff suppressed because it is too large Load Diff