1
0
Fork 0
mirror of git://git.psyced.org/git/psyced synced 2024-08-15 03:25:10 +00:00

added /place command for managing place settings like /set

usage: /place <key> [<value>]
key: e.g. topic, style, twitter, etc.
This commit is contained in:
Gabor Adam Toth 2010-02-28 17:44:02 +01:00
parent c2aa52adfa
commit e4ce000b32
4 changed files with 59 additions and 27 deletions

View file

@ -51,12 +51,19 @@ private volatile mapping _sigs = ([
"_request_nickname": ({ "_request_nick_local", 0, "_nick_local", "_INTERNAL_stuss" }),
// the real thing, maybe? method inheritance could even lead to here
// for all of the _request_set_something methods. good? bad?
"_request_place": ({ "_request_set", 0, "_key", "_value" }),
"_request_set": ({ "_request_set", 0, "_key", "_value" }),
// when called by _request_set(), value might be in _value
"_request_set_masquerade": ({ "_request_masquerade", 0, "_flag_masquerade" }),
"_request_set_owners": ({ "_request_owners", 0, "_list_owners" }), // _tab
"_request_set_public": ({ "_request_public", 0, "_flag_public" }),
"_request_set_style": ({ "_request_set_style", 0, "_uniform_style" }),
"_request_set_topic": ({ "_request_set_topic", 0, "_value" }),
"_request_topic": ({ "_request_set_topic", 0, "_value" }),
"_request_topi": ({ "_request_set_topic", 0, "_value" }),
"_request_top": ({ "_request_set_topic", 0, "_value" }),
"_request_to": ({ "_request_set_topic", 0, "_value" }),
"_request_t": ({ "_request_set_topic", 0, "_value" }),
// "INTERNAL" METHODS
// all of the following "fake" _request methods are just the psyced
// way to handle command name variations and shortcuts. never use this
@ -92,15 +99,15 @@ private volatile mapping _sigs = ([
#ifdef _flag_enable_module_microblogging
"_request_add": ({ "_request_add", 0, "_person" }),
"_request_remove": ({ "_request_remove", 0, "_person" }),
"_request_priv": ({ "_request_privacy", 0, "_privacy" }),
"_request_privacy": ({ "_request_privacy", 0, "_privacy" }),
"_request_set_priv": ({ "_request_set_privacy", 0, "_value" }),
"_request_set_privacy": ({ "_request_set_privacy", 0, "_value" }),
#ifdef TWITTER
"_request_tw": ({ "_request_twitter", 0, "_switch" }),
"_request_twitter": ({ "_request_twitter", 0, "_switch" }),
"_request_set_tw": ({ "_request_set_twitter", 0, "_value" }),
"_request_set_twitter": ({ "_request_set_twitter", 0, "_value" }),
#endif
#ifdef IDENTICA
"_request_ica": ({ "_request_identica", 0, "_switch" }),
"_request_identica": ({ "_request_identica", 0, "_switch" }),
"_request_set_ica": ({ "_request_set_identica", 0, "_value" }),
"_request_set_identica":({ "_request_set_identica", 0, "_value" }),
#endif
#endif
#ifdef EXPERIMENTAL

View file

@ -179,3 +179,13 @@ string x(string str, int n) {
for (i = 0; i < n; i++) res += str;
return res;
}
int is_true(string v) {
if (strlen(v) && regmatch(v, "^(?:on|yes|true|enabled|1)$")) return 1;
return 0;
}
int is_false(string v) {
if (strlen(v) && regmatch(v, "^(?:off|no|false|disabled|0)$")) return 1;
return 0;
}

View file

@ -462,6 +462,18 @@ showTopic(rcpt, verbose, mc) {
]) );
return 1;
}
_request_set_topic(source, mc, data, vars, b) {
string value = vars["_value"] || vars["_topic"];
if (strlen(value)) {
if (value == "-") value = 0;
sTopic(value, source, vars["_nick"]);
} else {
showTopic(source, 1, OFFICIAL);
}
return 1;
}
#endif
#if HAS_PORT(HTTP_PORT, HTTP_PATH) || HAS_PORT(HTTPS_PORT, HTTP_PATH)
@ -1838,6 +1850,7 @@ cmd(a, args, b, source, vars) {
return 1;
#endif
#ifdef PLACE_TOPIC_COMMAND
// not used anymore, see _request_set_topic() instead
case "topic":
case "topi":
case "top":
@ -2234,9 +2247,11 @@ _request_set(source, mc, data, vars, b) {
PT(("set(%O, %O, %O, %O, %O) called\n", source, mc, data, vars, b))
if (k = vars["_key"])
// pass on to a subhandler
if (call_signature(source, "_request_set"+ k, data, vars, b))
if (call_signature(source, "_request_set_"+ k, data, vars, b))
return 1;
return 0;
sendmsg(source, "_warning_usage_place", "Usage: /place <variable> [<value>]");
return 1;
}
#ifdef PLACE_OWNED
@ -2331,16 +2346,16 @@ _request_set_style(source, mc, data, vars, b) {
vSet("_uniform_style", value);
save();
} else if (value) {
sendmsg(source,
sendmsg(source,
"_error_illegal_scheme",
"That is not a valid [_scheme] URL for a file.",
"That is not a valid [_scheme] URL for a file.",
([ "_scheme" : "http" ]));
return 1;
return 1;
}
sendmsg(source, "_status_place_uniform_style",
"Style file [_uniform_style] is in use here.",
"Style file [_uniform_style] is in use here.",
([ "_uniform_style" :
v("_uniform_style") || "-" ]));
v("_uniform_style") || "-" ]));
return 1;
}
return 0;

View file

@ -129,47 +129,47 @@ _request_remove(source, mc, data, vars, b) {
// - public: anyone can enter
_request_privacy(source, mc, data, vars, b) {
P3((">> userthreads:_request_privace(%O, %O, %O, %O, %O)\n", source, mc, data, vars, b))
string p = vars["_privacy"];
if (p == "public" || p == "private") {
vSet("privacy", p);
string value = vars["_value"];
if (value == "public" || value == "private") {
vSet("privacy", value);
save();
}
sendmsg(source, "_status_privacy", "Privacy is: [_privacy].", (["_privacy": v("privacy")]));
sendmsg(source, "_info_set_place_privacy", "Privacy is: [_value].", (["_value": v("privacy")]));
return 1;
}
#ifdef TWITTER
_request_twitter(source, mc, data, vars, b) {
string sw = vars["_switch"];
if (sw == "on" || sw == "enabled" || sw == "1") {
_request_set_twitter(source, mc, data, vars, b) {
string value = vars["_value"];
if (is_true(value)) {
unless (twitter) twitter = clone_object(NET_PATH "twitter/client")->load(source);
vSet("twitter", 1);
save();
} else if (sw == "off" || sw == "disabled" || sw == "0") {
} else if (is_false(value)) {
if (twitter) twitter = 0;
vSet("twitter", 0);
save();
}
sendmsg(source, "_status_twitter", "Twitter submission is [_status].", (["_status": v("twitter") ? "enabled" : "disabled"]));
sendmsg(source, "_info_set_place_twitter", "Twitter submission is [_status].", (["_status": v("twitter") ? "enabled" : "disabled"]));
return 1;
}
#endif
#ifdef IDENTICA
_request_identica(source, mc, data, vars, b) {
string sw = vars["_switch"];
if (sw == "on" || sw == "enabled" || sw == "1") {
_request_set_identica(source, mc, data, vars, b) {
string value = vars["_value"];
if (is_true(value)) {
unless (identica) identica = clone_object(NET_PATH "identica/client")->load(source);
vSet("identica", 1);
save();
} else if (sw == "off" || sw == "disabled" || sw == "0") {
} else if (is_false(value)) {
if (identica) identica = 0;
vSet("identica", 0);
save();
}
sendmsg(source, "_status_identica", "Identi.ca submission is [_status].", (["_status": v("identica") ? "enabled" : "disabled"]));
sendmsg(source, "_info_set_place_identica", "Identi.ca submission is [_status].", (["_status": v("identica") ? "enabled" : "disabled"]));
return 1;
}
#endif