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

View file

@ -179,3 +179,13 @@ string x(string str, int n) {
for (i = 0; i < n; i++) res += str; for (i = 0; i < n; i++) res += str;
return res; 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; 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 #endif
#if HAS_PORT(HTTP_PORT, HTTP_PATH) || HAS_PORT(HTTPS_PORT, HTTP_PATH) #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; return 1;
#endif #endif
#ifdef PLACE_TOPIC_COMMAND #ifdef PLACE_TOPIC_COMMAND
// not used anymore, see _request_set_topic() instead
case "topic": case "topic":
case "topi": case "topi":
case "top": 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)) PT(("set(%O, %O, %O, %O, %O) called\n", source, mc, data, vars, b))
if (k = vars["_key"]) if (k = vars["_key"])
// pass on to a subhandler // 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;
sendmsg(source, "_warning_usage_place", "Usage: /place <variable> [<value>]");
return 1; return 1;
return 0;
} }
#ifdef PLACE_OWNED #ifdef PLACE_OWNED

View file

@ -129,47 +129,47 @@ _request_remove(source, mc, data, vars, b) {
// - public: anyone can enter // - public: anyone can enter
_request_privacy(source, mc, data, vars, b) { _request_privacy(source, mc, data, vars, b) {
P3((">> userthreads:_request_privace(%O, %O, %O, %O, %O)\n", source, mc, data, vars, b)) P3((">> userthreads:_request_privace(%O, %O, %O, %O, %O)\n", source, mc, data, vars, b))
string p = vars["_privacy"]; string value = vars["_value"];
if (p == "public" || p == "private") { if (value == "public" || value == "private") {
vSet("privacy", p); vSet("privacy", value);
save(); 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; return 1;
} }
#ifdef TWITTER #ifdef TWITTER
_request_twitter(source, mc, data, vars, b) { _request_set_twitter(source, mc, data, vars, b) {
string sw = vars["_switch"]; string value = vars["_value"];
if (sw == "on" || sw == "enabled" || sw == "1") { if (is_true(value)) {
unless (twitter) twitter = clone_object(NET_PATH "twitter/client")->load(source); unless (twitter) twitter = clone_object(NET_PATH "twitter/client")->load(source);
vSet("twitter", 1); vSet("twitter", 1);
save(); save();
} else if (sw == "off" || sw == "disabled" || sw == "0") { } else if (is_false(value)) {
if (twitter) twitter = 0; if (twitter) twitter = 0;
vSet("twitter", 0); vSet("twitter", 0);
save(); 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; return 1;
} }
#endif #endif
#ifdef IDENTICA #ifdef IDENTICA
_request_identica(source, mc, data, vars, b) { _request_set_identica(source, mc, data, vars, b) {
string sw = vars["_switch"]; string value = vars["_value"];
if (sw == "on" || sw == "enabled" || sw == "1") { if (is_true(value)) {
unless (identica) identica = clone_object(NET_PATH "identica/client")->load(source); unless (identica) identica = clone_object(NET_PATH "identica/client")->load(source);
vSet("identica", 1); vSet("identica", 1);
save(); save();
} else if (sw == "off" || sw == "disabled" || sw == "0") { } else if (is_false(value)) {
if (identica) identica = 0; if (identica) identica = 0;
vSet("identica", 0); vSet("identica", 0);
save(); 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; return 1;
} }
#endif #endif