mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Use XDG_DATA for plugins location
Removed plugins, now kept in separate reposutory profanity-plugins
This commit is contained in:
parent
667fcafe06
commit
3159824789
@ -1,14 +0,0 @@
|
||||
module ChatStart
|
||||
|
||||
@@contacts = [
|
||||
"\"Prof 2\"",
|
||||
"prof3@panesar"
|
||||
]
|
||||
|
||||
def self.prof_on_connect()
|
||||
@@contacts.each { | contact |
|
||||
Prof::send_line("/msg " + contact)
|
||||
}
|
||||
Prof::send_line("/win 1")
|
||||
end
|
||||
end
|
@ -1,53 +0,0 @@
|
||||
module RubyTest
|
||||
|
||||
def self.prof_init(version, status)
|
||||
Prof::cons_show("RubyTest: init, " + version + ", " + status)
|
||||
Prof::register_command("/ruby", 0, 1, "/ruby", "RubyTest", "RubyTest", cmd_ruby)
|
||||
Prof::register_timed(timer_test, 10)
|
||||
end
|
||||
|
||||
def self.prof_on_start()
|
||||
Prof::cons_show("RubyTest: on_start")
|
||||
end
|
||||
|
||||
def self.prof_on_connect(account_name, fulljid)
|
||||
Prof::cons_show("RubyTest: on_connect, " + account_name + ", " + fulljid)
|
||||
end
|
||||
|
||||
def self.prof_on_message_received(jid, message)
|
||||
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
|
||||
Prof::cons_alert
|
||||
return message + "[RUBY]"
|
||||
end
|
||||
|
||||
def self.prof_on_message_send(jid, message)
|
||||
Prof::cons_show("RubyTest: on_message_send, " + jid + ", " + message)
|
||||
Prof::cons_alert
|
||||
return message + "[RUBY]"
|
||||
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
|
||||
Prof::cons_alert
|
||||
Prof::notify("RubyTest: notify", 2000, "Plugins")
|
||||
Prof::send_line("/help")
|
||||
Prof::cons_show("RubyTest: sent \"/help\" command")
|
||||
}
|
||||
end
|
||||
|
||||
def self.timer_test()
|
||||
return Proc.new {
|
||||
Prof::cons_show("RubyTest: timer fired.")
|
||||
recipient = Prof::get_current_recipient
|
||||
if recipient
|
||||
Prof::cons_show(" current recipient = " + recipient)
|
||||
end
|
||||
Prof::cons_alert
|
||||
}
|
||||
end
|
||||
end
|
@ -1,12 +0,0 @@
|
||||
import prof
|
||||
import subprocess
|
||||
|
||||
def prof_init(version, status):
|
||||
prof.register_command("/ascii", 1, 1, "/ascii", "ASCIIfy a message", "ASCIIfy a message.", cmd_ascii)
|
||||
|
||||
def cmd_ascii(text):
|
||||
recipient = prof.get_current_recipient()
|
||||
if recipient:
|
||||
proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE)
|
||||
ascii_out = proc.communicate()[0].decode('utf-8')
|
||||
prof.send_line(u'\u000A' + ascii_out)
|
@ -1,60 +0,0 @@
|
||||
import prof
|
||||
import os
|
||||
import webbrowser
|
||||
import re
|
||||
|
||||
lastlink = {}
|
||||
|
||||
def prof_init(version, status):
|
||||
prof.register_command("/browser", 0, 1,
|
||||
"/browser [url]",
|
||||
"View a URL in the browser.",
|
||||
"View a URL in the browser, if no argument is supplied, " +
|
||||
"the last received URL will be used.",
|
||||
cmd_browser)
|
||||
|
||||
def prof_on_message_received(jid, message):
|
||||
global lastlink
|
||||
links = re.findall(r'(https?://\S+)', message)
|
||||
if (len(links) > 0):
|
||||
lastlink[jid] = links[len(links)-1]
|
||||
|
||||
def cmd_browser(url):
|
||||
global lastlink
|
||||
link = None
|
||||
|
||||
# use arg if supplied
|
||||
if (url != None):
|
||||
link = url
|
||||
else:
|
||||
jid = prof.get_current_recipient();
|
||||
|
||||
# check if in chat window
|
||||
if (jid != None):
|
||||
|
||||
# check for link from recipient
|
||||
if jid in lastlink.keys():
|
||||
link = lastlink[jid]
|
||||
else:
|
||||
prof.cons_show("No links found from " + jid);
|
||||
|
||||
# not in chat window
|
||||
else:
|
||||
prof.cons_show("You must supply a URL to the /browser command")
|
||||
|
||||
# open the browser if link found
|
||||
if (link != None):
|
||||
prof.cons_show("Opening " + link + " in browser")
|
||||
open_browser(link)
|
||||
|
||||
def open_browser(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)
|
@ -1,9 +0,0 @@
|
||||
import prof
|
||||
|
||||
user = "prof1@panesar"
|
||||
|
||||
def prof_on_start():
|
||||
global user
|
||||
prof.cons_show("")
|
||||
prof.cons_show("Enter password for " + user)
|
||||
prof.send_line("/connect " + user)
|
@ -1,97 +0,0 @@
|
||||
import prof
|
||||
import urllib2
|
||||
import json
|
||||
|
||||
#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
|
||||
score_url = None
|
||||
|
||||
summary = None
|
||||
|
||||
def prof_init(version, status):
|
||||
if score_url:
|
||||
prof.register_timed(get_scores, 60)
|
||||
prof.register_command("/cricket", 0, 0,
|
||||
"/cricket",
|
||||
"Get latest cricket score.",
|
||||
"Get latest cricket score.",
|
||||
cmd_cricket)
|
||||
|
||||
def prof_on_start():
|
||||
if score_url:
|
||||
get_scores()
|
||||
|
||||
def cmd_cricket():
|
||||
global score_url
|
||||
global summary
|
||||
new_summary = None
|
||||
|
||||
result_json = retrieve_scores_json()
|
||||
|
||||
if 'ms' in result_json.keys():
|
||||
new_summary = result_json['ms']
|
||||
|
||||
prof.cons_show("")
|
||||
prof.cons_show("Cricket score:")
|
||||
if 't1FI' in result_json.keys():
|
||||
prof.cons_show(" " + result_json['t1FI'])
|
||||
|
||||
if 't2FI' in result_json.keys():
|
||||
prof.cons_show(" " + result_json['t2FI'])
|
||||
|
||||
if 't1SI' in result_json.keys():
|
||||
prof.cons_show(" " + result_json['t1SI'])
|
||||
|
||||
if 't2SI' in result_json.keys():
|
||||
prof.cons_show(" " + result_json['t2SI'])
|
||||
|
||||
summary = new_summary
|
||||
prof.cons_show("")
|
||||
prof.cons_show(" " + summary)
|
||||
prof.cons_alert()
|
||||
|
||||
def get_scores():
|
||||
global score_url
|
||||
global summary
|
||||
notify = None
|
||||
new_summary = None
|
||||
change = False
|
||||
|
||||
result_json = retrieve_scores_json()
|
||||
|
||||
if 'ms' in result_json.keys():
|
||||
new_summary = result_json['ms']
|
||||
if new_summary != summary:
|
||||
change = True
|
||||
|
||||
if change:
|
||||
prof.cons_show("")
|
||||
prof.cons_show("Cricket score:")
|
||||
if 't1FI' in result_json.keys():
|
||||
notify = result_json['t1FI']
|
||||
prof.cons_show(" " + result_json['t1FI'])
|
||||
|
||||
if 't2FI' in result_json.keys():
|
||||
notify += "\n" + result_json['t2FI']
|
||||
prof.cons_show(" " + result_json['t2FI'])
|
||||
|
||||
if 't1SI' in result_json.keys():
|
||||
notify += "\n" + result_json['t1SI']
|
||||
prof.cons_show(" " + result_json['t1SI'])
|
||||
|
||||
if 't2SI' in result_json.keys():
|
||||
notify += "\n" + result_json['t2SI']
|
||||
prof.cons_show(" " + result_json['t2SI'])
|
||||
|
||||
summary = new_summary
|
||||
notify += "\n\n" + summary
|
||||
prof.cons_show("")
|
||||
prof.cons_show(" " + summary)
|
||||
prof.cons_alert()
|
||||
prof.notify(notify, 5000, "Cricket score")
|
||||
|
||||
def retrieve_scores_json():
|
||||
req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'})
|
||||
f = urllib2.urlopen(req)
|
||||
response = f.read()
|
||||
f.close()
|
||||
return json.loads(response);
|
@ -1,9 +0,0 @@
|
||||
import prof
|
||||
import platform
|
||||
|
||||
def prof_init(version, status):
|
||||
prof.register_command("/platform", 0, 0, "/platform", "Output system information.", "Output system information", cmd_platform)
|
||||
|
||||
def cmd_platform():
|
||||
result_summary = platform.platform()
|
||||
prof.cons_show(result_summary)
|
@ -1,40 +0,0 @@
|
||||
import prof
|
||||
|
||||
def prof_init(version, status):
|
||||
prof.cons_show("python-test: init, " + version + ", " + status)
|
||||
prof.register_command("/python", 0, 1, "/python", "python-test", "python-test", cmd_python)
|
||||
prof.register_timed(timer_test, 10)
|
||||
|
||||
def prof_on_start():
|
||||
prof.cons_show("python-test: on_start")
|
||||
|
||||
def prof_on_connect(account_name, fulljid):
|
||||
prof.cons_show("python-test: on_connect, " + account_name + ", " + fulljid)
|
||||
|
||||
def prof_on_message_received(jid, message):
|
||||
prof.cons_show("python-test: on_message_received, " + jid + ", " + message)
|
||||
prof.cons_alert()
|
||||
return message + "[PYTHON]"
|
||||
|
||||
def prof_on_message_send(jid, message):
|
||||
prof.cons_show("python-test: on_message_send, " + jid + ", " + message)
|
||||
prof.cons_alert()
|
||||
return message + "[PYTHON]"
|
||||
|
||||
def cmd_python(msg):
|
||||
if msg:
|
||||
prof.cons_show("python-test: /python command called, arg = " + msg)
|
||||
else:
|
||||
prof.cons_show("python-test: /python command called with no arg")
|
||||
prof.cons_alert()
|
||||
prof.notify("python-test: notify", 2000, "Plugins")
|
||||
prof.send_line("/vercheck")
|
||||
prof.cons_show("python-test: sent \"/vercheck\" command")
|
||||
|
||||
def timer_test():
|
||||
prof.cons_show("python-test: timer fired.")
|
||||
recipient = prof.get_current_recipient()
|
||||
if recipient:
|
||||
prof.cons_show(" current recipient = " + recipient)
|
||||
prof.cons_alert()
|
||||
|
@ -1,11 +0,0 @@
|
||||
all: test-c-plugin.so
|
||||
|
||||
%.so:%.o
|
||||
$(CC) -shared -fpic -lprofanity -o $@ $^
|
||||
|
||||
%.o:%.c
|
||||
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \
|
||||
-Wall -Wextra -lprofanity -pedantic -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) test-c-plugin.so
|
@ -1,91 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <profapi.h>
|
||||
|
||||
void
|
||||
cmd_c(char **args)
|
||||
{
|
||||
if (args[0] != NULL) {
|
||||
char *start = "c-test: /c command called, arg = ";
|
||||
char buf[strlen(start) + strlen(args[0]) + 1];
|
||||
sprintf(buf, "%s%s", start, args[0]);
|
||||
prof_cons_show(buf);
|
||||
} else {
|
||||
prof_cons_show("c-test: /c command called with no arg");
|
||||
}
|
||||
prof_cons_alert();
|
||||
prof_notify("c-test: notify", 2000, "Plugins");
|
||||
prof_send_line("/about");
|
||||
prof_cons_show("c-test: sent \"/about\" command");
|
||||
}
|
||||
|
||||
void
|
||||
timer_test(void)
|
||||
{
|
||||
prof_cons_show("c-test: timer fired.");
|
||||
char *recipient = prof_get_current_recipient();
|
||||
if (recipient != NULL) {
|
||||
char *start = " current recipient = ";
|
||||
char buf[strlen(start) + strlen(recipient) + 1];
|
||||
sprintf(buf, "%s%s", start, recipient);
|
||||
prof_cons_show(buf);
|
||||
}
|
||||
prof_cons_alert();
|
||||
}
|
||||
|
||||
void
|
||||
prof_init(const char * const version, const char * const status)
|
||||
{
|
||||
char *start = "c-test: init. ";
|
||||
char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1];
|
||||
sprintf(buf, "%s%s, %s", start, version, status);
|
||||
prof_cons_show(buf);
|
||||
prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c);
|
||||
prof_register_timed(timer_test, 10);
|
||||
}
|
||||
|
||||
void
|
||||
prof_on_start(void)
|
||||
{
|
||||
prof_cons_show("c-test: on_start");
|
||||
}
|
||||
|
||||
void
|
||||
prof_on_connect(const char * const account_name, const char * const fulljid)
|
||||
{
|
||||
char *start = "c-test: on_connect, ";
|
||||
char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1];
|
||||
sprintf(buf, "%s%s, %s", start, account_name, fulljid);
|
||||
prof_cons_show(buf);
|
||||
}
|
||||
|
||||
char *
|
||||
prof_on_message_received(const char * const jid, const char *message)
|
||||
{
|
||||
char *start = "c-test: on_message_received, ";
|
||||
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
|
||||
sprintf(buf, "%s%s, %s", start, jid, message);
|
||||
prof_cons_show(buf);
|
||||
prof_cons_alert();
|
||||
char *result = malloc(strlen(message) + 4);
|
||||
sprintf(result, "%s%s", message, "[C]");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char *
|
||||
prof_on_message_send(const char * const jid, const char *message)
|
||||
{
|
||||
char *start = "c-test: on_message_send, ";
|
||||
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
|
||||
sprintf(buf, "%s%s, %s", start, jid, message);
|
||||
prof_cons_show(buf);
|
||||
prof_cons_alert();
|
||||
char *result = malloc(strlen(message) + 4);
|
||||
sprintf(result, "%s%s", message, "[C]");
|
||||
|
||||
return result;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import prof
|
||||
import getpass
|
||||
|
||||
def prof_init(version, status):
|
||||
prof.register_command("/whoami", 0, 0, "/whoami", "Call shell whoami command.", "Call shell whoami command.", cmd_whoami)
|
||||
|
||||
def cmd_whoami():
|
||||
me = getpass.getuser()
|
||||
prof.cons_show(me)
|
@ -26,8 +26,10 @@ c_plugin_create(const char * const filename)
|
||||
ProfPlugin *plugin;
|
||||
void *handle = NULL;
|
||||
|
||||
// TODO use XDG for path
|
||||
GString *path = g_string_new("./plugins/");
|
||||
gchar *plugins_dir = plugins_get_dir();
|
||||
GString *path = g_string_new(plugins_dir);
|
||||
g_free(plugins_dir);
|
||||
g_string_append(path, "/");
|
||||
g_string_append(path, filename);
|
||||
|
||||
handle = dlopen (path->str, RTLD_NOW | RTLD_GLOBAL);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "config/preferences.h"
|
||||
#include "log.h"
|
||||
#include "plugins/callbacks.h"
|
||||
@ -173,3 +174,16 @@ plugins_shutdown(void)
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
|
||||
gchar *
|
||||
plugins_get_dir(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *plugins_dir = g_string_new(xdg_data);
|
||||
g_string_append(plugins_dir, "/profanity/plugins");
|
||||
gchar *result = strdup(plugins_dir->str);
|
||||
g_free(xdg_data);
|
||||
g_string_free(plugins_dir, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -52,5 +52,6 @@ char * plugins_on_message_send(const char * const jid, const char *message);
|
||||
void plugins_shutdown(void);
|
||||
gboolean plugins_run_command(const char * const cmd);
|
||||
void plugins_run_timed(void);
|
||||
gchar * plugins_get_dir(void);
|
||||
|
||||
#endif
|
||||
|
@ -39,7 +39,11 @@ python_env_init(void)
|
||||
python_check_error();
|
||||
// TODO change to use XDG spec
|
||||
GString *path = g_string_new(Py_GetPath());
|
||||
g_string_append(path, ":./plugins/");
|
||||
g_string_append(path, ":");
|
||||
gchar *plugins_dir = plugins_get_dir();
|
||||
g_string_append(path, plugins_dir);
|
||||
g_string_append(path, "/");
|
||||
g_free(plugins_dir);
|
||||
PySys_SetPath(path->str);
|
||||
python_check_error();
|
||||
g_string_free(path, TRUE);
|
||||
|
@ -44,7 +44,10 @@ ruby_env_init(void)
|
||||
ProfPlugin *
|
||||
ruby_plugin_create(const char * const filename)
|
||||
{
|
||||
GString *path = g_string_new("./plugins/");
|
||||
gchar *plugins_dir = plugins_get_dir();
|
||||
GString *path = g_string_new(plugins_dir);
|
||||
g_free(plugins_dir);
|
||||
g_string_append(path, "/");
|
||||
g_string_append(path, filename);
|
||||
rb_require(path->str);
|
||||
gchar *module_name = g_strndup(filename, strlen(filename) - 3);
|
||||
|
@ -680,6 +680,8 @@ _create_directories(void)
|
||||
g_string_append(chatlogs_dir, "/profanity/chatlogs");
|
||||
GString *logs_dir = g_string_new(xdg_data);
|
||||
g_string_append(logs_dir, "/profanity/logs");
|
||||
GString *plugins_dir = g_string_new(xdg_data);
|
||||
g_string_append(plugins_dir, "/profanity/plugins");
|
||||
|
||||
if (!mkdir_recursive(themes_dir->str)) {
|
||||
log_error("Error while creating directory %s", themes_dir->str);
|
||||
@ -690,10 +692,14 @@ _create_directories(void)
|
||||
if (!mkdir_recursive(logs_dir->str)) {
|
||||
log_error("Error while creating directory %s", logs_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(plugins_dir->str)) {
|
||||
log_error("Error while creating directory %s", plugins_dir->str);
|
||||
}
|
||||
|
||||
g_string_free(themes_dir, TRUE);
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
g_string_free(logs_dir, TRUE);
|
||||
g_string_free(plugins_dir, TRUE);
|
||||
|
||||
g_free(xdg_config);
|
||||
g_free(xdg_data);
|
||||
|
Loading…
Reference in New Issue
Block a user