[srvx-commits] CVS: services/src helpserv.c,1.36,1.37 helpserv.help,1.10,1.11
Brought to you by:
entrope
|
From: Adrian D. <sai...@us...> - 2002-09-29 00:06:04
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv29754
Modified Files:
helpserv.c helpserv.help
Log Message:
Implement request-on-join
Index: helpserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/helpserv.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -r1.36 -r1.37
*** helpserv.c 24 Sep 2002 19:21:42 -0000 1.36
--- helpserv.c 29 Sep 2002 00:06:00 -0000 1.37
***************
*** 20,28 ****
/* TODO List for helpserv.c
- * - A feature suggestion was to let it also show the waiting users in the
- * help channel, in the order they joined, along with wait time (like
- * eggdrop's .channel command) (make whine message "n users waiting at least"
- * instead of "n requests open at least") (auto-close on part if no privmsg
- * even if persist says otherwise)
* - Request logging. Saxdb should make this fairly painless.
* - cmd_close should optionally take another argument (a reason/comment)
--- 20,23 ----
***************
*** 93,96 ****
--- 88,92 ----
#define KEY_NOTIFICATION "notification"
#define KEY_PRIVMSG_ONLY "privmsg_only"
+ #define KEY_REQ_ON_JOIN "req_on_join"
/* General */
***************
*** 179,188 ****
#define HSMSG_REQ_ASSIGNED_AGAIN "Your helper for request ID#%lu has been changed to %s (Current nick: %s)"
#define HSMSG_REQ_UNASSIGNED "Your helper for request ID#%lu has %s, so your request is no longer being handled by them. It has been placed near the front of the unhandled request queue, based on how long ago your request was opened."
! #define HSMSG_REQ_NEW "Your help request (ID#%lu) has been recorded, and a helper should contact you shortly."
! #define HSMSG_REQ_UNHANDLED_TIME "The first unhandled request has been waiting for %s."
#define HSMSG_REQ_NO_UNHANDLED "There are no other unhandled requests."
! #define HSMSG_REQ_PERSIST_QUIT "Anything else you tell me until you are helped (or you quit) will be recorded as well. If you disconnect, your request will be lost."
! #define HSMSG_REQ_PERSIST_PART "Anything else you tell me until you are helped (or you leave %s) will be recorded as well. If you part from %s, your request will be lost."
! #define HSMSG_REQ_PERSIST_HANDLE "Anything else you tell me until you are helped will be recorded as well."
#define HSMSG_REQ_FOUND_ANOTHER "Request ID#%lu has been closed. $S detected that you also have request ID#%lu open. If you send $S a message, it will be associated with that request."
--- 175,185 ----
#define HSMSG_REQ_ASSIGNED_AGAIN "Your helper for request ID#%lu has been changed to %s (Current nick: %s)"
#define HSMSG_REQ_UNASSIGNED "Your helper for request ID#%lu has %s, so your request is no longer being handled by them. It has been placed near the front of the unhandled request queue, based on how long ago your request was opened."
! #define HSMSG_REQ_NEW "Your message has been recorded and assigned request ID#%lu. A helper should contact you shortly."
! #define HSMSG_REQ_NEWONJOIN "Welcome to %s. You have been assigned request ID#%lu. A helper should contact you shortly."
! #define HSMSG_REQ_UNHANDLED_TIME "The oldest unhandled request has been waiting for %s."
#define HSMSG_REQ_NO_UNHANDLED "There are no other unhandled requests."
! #define HSMSG_REQ_PERSIST_QUIT "Everything you tell me until you are helped (or you quit) will be recorded. If you disconnect, your request will be lost."
! #define HSMSG_REQ_PERSIST_PART "Everything you tell me until you are helped (or you leave %s) will be recorded. If you part %s, your request will be lost."
! #define HSMSG_REQ_PERSIST_HANDLE "Everything you tell me until you are helped will be recorded."
#define HSMSG_REQ_FOUND_ANOTHER "Request ID#%lu has been closed. $S detected that you also have request ID#%lu open. If you send $S a message, it will be associated with that request."
***************
*** 414,417 ****
--- 411,415 ----
unsigned int privmsg_only : 1;
+ unsigned int req_on_join : 1;
time_t registered;
***************
*** 651,654 ****
--- 649,761 ----
}
+ static struct helpserv_request * create_request(struct userNode *user, struct helpserv_bot *hs, int from_join) {
+ struct helpserv_request *req = calloc(1, sizeof(struct helpserv_request));
+ char lbuf[3][MAX_LINE_SIZE], unh[INTERVALLEN];
+ struct helpserv_reqlist *reqlist, *hand_reqlist;
+ const unsigned int from_opserv=0;
+
+ assert(req);
+
+ req->id = ++hs->last_requestid;
+ sprintf(unh, "%lu", req->id);
+ dict_insert(hs->requests, strdup(unh), req);
+
+ if (hs->id_wrap) {
+ unsigned long i;
+ char buf[12];
+ if (hs->last_requestid < hs->id_wrap) {
+ for (i=hs->last_requestid; i < hs->id_wrap; i++) {
+ sprintf(buf, "%lu", i);
+ if (!dict_find(hs->requests, buf, NULL)) {
+ hs->last_requestid = i-1;
+ break;
+ }
+ }
+ }
+ if (hs->last_requestid >= hs->id_wrap) {
+ for (i=1; i < hs->id_wrap; i++) {
+ sprintf(buf, "%lu", i);
+ if (!dict_find(hs->requests, buf, NULL)) {
+ hs->last_requestid = i-1;
+ break;
+ }
+ }
+ if (i >= hs->id_wrap) {
+ log(HS_LOG, LOG_INFO, "%s has more requests than its id_wrap\n", hs->helpserv->nick);
+ }
+ }
+ }
+
+ req->hs = hs;
+ req->helper = NULL;
+ req->text = alloc_string_list(4);
+ req->user = user;
+ req->handle = user->handle_info;
+ req->opened = now;
+ req->updated = now;
+
+ if (!hs->unhandled) {
+ hs->unhandled = req;
+ req->next_unhandled = NULL;
+ } else {
+ /* Set req->next_unhandled temporarily to be the previous
+ * unhandled request, then set it null (last in list) */
+ for (req->next_unhandled = hs->unhandled; req->next_unhandled->next_unhandled; req->next_unhandled = req->next_unhandled->next_unhandled);
+ req->next_unhandled->next_unhandled = req;
+ req->next_unhandled = NULL;
+ }
+
+ if (!(reqlist = dict_find(helpserv_reqs_bynick_dict, user->nick, NULL))) {
+ reqlist = helpserv_reqlist_alloc();
+ dict_insert(helpserv_reqs_bynick_dict, user->nick, reqlist);
+ }
+ req->parent_nick_list = reqlist;
+ helpserv_reqlist_append(reqlist, req);
+
+ if (user->handle_info) {
+ if (!(hand_reqlist = dict_find(helpserv_reqs_byhand_dict, user->handle_info->handle, NULL))) {
+ hand_reqlist = helpserv_reqlist_alloc();
+ dict_insert(helpserv_reqs_byhand_dict, user->handle_info->handle, hand_reqlist);
+ }
+ req->parent_hand_list = hand_reqlist;
+ helpserv_reqlist_append(hand_reqlist, req);
+ } else {
+ req->parent_hand_list = NULL;
+ }
+
+ if (from_join) {
+ sprintf(lbuf[0], HSMSG_REQ_NEWONJOIN, hs->helpchan->name, req->id);
+ } else {
+ sprintf(lbuf[0], HSMSG_REQ_NEW, req->id);
+ }
+ if (req != hs->unhandled) {
+ intervalString(unh, now - hs->unhandled->opened);
+ sprintf(lbuf[1], HSMSG_REQ_UNHANDLED_TIME, unh);
+ } else {
+ sprintf(lbuf[1], HSMSG_REQ_NO_UNHANDLED);
+ }
+ switch (hs->persist_types[PERSIST_T_REQUEST]) {
+ case PERSIST_PART:
+ sprintf(lbuf[2], HSMSG_REQ_PERSIST_PART, hs->helpchan->name, hs->helpchan->name);
+ break;
+ case PERSIST_QUIT:
+ sprintf(lbuf[2], HSMSG_REQ_PERSIST_QUIT);
+ break;
+ default:
+ log(HS_LOG, LOG_ERROR, "%s has an invalid req_persist\n", hs->helpserv->nick);
+ case PERSIST_CLOSE:
+ if (user->handle_info) {
+ sprintf(lbuf[2], HSMSG_REQ_PERSIST_HANDLE);
+ } else {
+ sprintf(lbuf[2], HSMSG_REQ_PERSIST_QUIT);
+ }
+ break;
+ }
+ helpserv_message(hs, user, MSGTYPE_REQ_OPENED);
+ helpserv_msguser(user, "%s %s %s", lbuf[0], lbuf[1], lbuf[2]);
+
+ return req;
+ }
+
/* Handle a message from a user to a HelpServ bot. */
static void helpserv_usermsg(struct userNode *user, struct helpserv_bot *hs, char *text) {
***************
*** 710,715 ****
if (!req) {
- char lbuf[3][MAX_LINE_SIZE], unh[INTERVALLEN];
-
if ((hs->persist_types[PERSIST_T_REQUEST] == PERSIST_PART) && !GetUserMode(hs->helpchan, user)) {
helpserv_msguser(user, HSMSG_REQ_NOTIN_HELPCHAN, "You", "open", "you", hs->helpchan->name);
--- 817,820 ----
***************
*** 717,805 ****
}
! req = calloc(1, sizeof(struct helpserv_request));
!
! req->id = ++hs->last_requestid;
! sprintf(unh, "%lu", req->id);
! dict_insert(hs->requests, strdup(unh), req);
!
! if (hs->id_wrap) {
! if (hs->last_requestid >= hs->id_wrap) {
! unsigned long i;
! for (i=1; i < hs->id_wrap; i++) {
! char buf[12];
! sprintf(buf, "%lu", i);
! if (!dict_find(hs->requests, buf, NULL)) {
! hs->last_requestid = i-1;
! break;
! }
! }
! if (i >= hs->id_wrap) {
! log(HS_LOG, LOG_INFO, "%s has more requests than its id_wrap\n", hs->helpserv->nick);
! }
! }
! }
!
! req->hs = hs;
! req->helper = NULL;
! req->text = alloc_string_list(8);
! req->user = user;
! req->handle = user->handle_info;
! req->opened = now;
!
! if (!hs->unhandled) {
! hs->unhandled = req;
! req->next_unhandled = NULL;
! } else {
! /* Set req->next_unhandled temporarily to be the previous
! * unhandled request, then set it null (last in list) */
! for (req->next_unhandled = hs->unhandled; req->next_unhandled->next_unhandled; req->next_unhandled = req->next_unhandled->next_unhandled);
! req->next_unhandled->next_unhandled = req;
! req->next_unhandled = NULL;
! }
!
! if (!reqlist) {
! reqlist = helpserv_reqlist_alloc();
! dict_insert(helpserv_reqs_bynick_dict, user->nick, reqlist);
! }
! req->parent_nick_list = reqlist;
! helpserv_reqlist_append(reqlist, req);
!
! if (user->handle_info) {
! if (!hand_reqlist) {
! hand_reqlist = helpserv_reqlist_alloc();
! dict_insert(helpserv_reqs_byhand_dict, user->handle_info->handle, hand_reqlist);
! }
! req->parent_hand_list = hand_reqlist;
! helpserv_reqlist_append(hand_reqlist, req);
! } else {
! req->parent_hand_list = NULL;
! }
!
! sprintf(lbuf[0], HSMSG_REQ_NEW, req->id);
! if (req->next_unhandled) {
! intervalString(unh, now - req->next_unhandled->opened);
! sprintf(lbuf[1], HSMSG_REQ_UNHANDLED_TIME, unh);
! } else {
! sprintf(lbuf[1], HSMSG_REQ_NO_UNHANDLED);
! }
! switch (hs->persist_types[PERSIST_T_REQUEST]) {
! case PERSIST_PART:
! sprintf(lbuf[2], HSMSG_REQ_PERSIST_PART, hs->helpchan->name, hs->helpchan->name);
! break;
! case PERSIST_QUIT:
! sprintf(lbuf[2], HSMSG_REQ_PERSIST_QUIT);
! break;
! default:
! log(HS_LOG, LOG_ERROR, "%s has an invalid req_persist\n", hs->helpserv->nick);
! case PERSIST_CLOSE:
! if (user->handle_info) {
! sprintf(lbuf[2], HSMSG_REQ_PERSIST_HANDLE);
! } else {
! sprintf(lbuf[2], HSMSG_REQ_PERSIST_QUIT);
! }
! break;
! }
! helpserv_message(hs, user, MSGTYPE_REQ_OPENED);
! helpserv_msguser(user, "%s %s %s", lbuf[0], lbuf[1], lbuf[2]);
helpserv_page(PGSRC_STATUS, HSMSG_PAGE_NEW_REQUEST, req->id, user->nick, user->handle_info ? user->handle_info->handle : "not authed");
} else if (hs->intervals[INTERVAL_STALE_DELAY] && (req->updated < TIME_T_CAST(now - hs->intervals[INTERVAL_STALE_DELAY]))) {
--- 822,826 ----
}
! req = create_request(user, hs, 0);
helpserv_page(PGSRC_STATUS, HSMSG_PAGE_NEW_REQUEST, req->id, user->nick, user->handle_info ? user->handle_info->handle : "not authed");
} else if (hs->intervals[INTERVAL_STALE_DELAY] && (req->updated < TIME_T_CAST(now - hs->intervals[INTERVAL_STALE_DELAY]))) {
***************
*** 2669,2672 ****
--- 2690,2697 ----
}
+ static HELPSERV_OPTION(opt_req_on_join) {
+ OPTION_BINARY(hs->req_on_join, "Join opens request");
+ }
+
static HELPSERV_FUNC(cmd_set) {
helpserv_option_func_t *opt;
***************
*** 2678,2683 ****
opt_pagetype, opt_alert_page_type, opt_status_page_type,
opt_greeting, opt_openreq, opt_assignreq, opt_closereq,
! opt_idle_delay, opt_whine_delay, opt_whine_interval, opt_empty_interval, opt_stale_delay,
! opt_request_persistence, opt_helper_persistence, opt_notification, opt_id_wrap, opt_privmsg_only
};
--- 2703,2710 ----
opt_pagetype, opt_alert_page_type, opt_status_page_type,
opt_greeting, opt_openreq, opt_assignreq, opt_closereq,
! opt_idle_delay, opt_whine_delay, opt_whine_interval,
! opt_empty_interval, opt_stale_delay, opt_request_persistence,
! opt_helper_persistence, opt_notification, opt_id_wrap,
! opt_privmsg_only, opt_req_on_join
};
***************
*** 2954,2957 ****
--- 2981,2985 ----
if (hs->registrar) saxdb_write_string(ctx, KEY_REGISTRAR, hs->registrar);
saxdb_write_int(ctx, KEY_PRIVMSG_ONLY, hs->privmsg_only);
+ saxdb_write_int(ctx, KEY_REQ_ON_JOIN, hs->req_on_join);
/* End bot record */
***************
*** 3053,3056 ****
--- 3081,3086 ----
str = database_get_data(GET_RECORD_OBJECT(br), KEY_PRIVMSG_ONLY, RECDB_QSTRING);
hs->privmsg_only = str ? enabled_string(str) : 0;
+ str = database_get_data(GET_RECORD_OBJECT(br), KEY_REQ_ON_JOIN, RECDB_QSTRING);
+ hs->req_on_join = str ? enabled_string(str) : 0;
dict_foreach(users, user_read_helper, hs);
***************
*** 3131,3140 ****
if (user == req->user) {
! if (hs->persist_types[PERSIST_T_REQUEST] == PERSIST_PART) {
! helpserv_message(hs, user, MSGTYPE_REQ_DROPPED);
! helpserv_msguser(user, HSMSG_REQ_DROPPED_PART, chan->name, req->id);
!
! if (req->helper && (hs->notify >= NOTIFY_DROP)) helpserv_notify(req->helper, HSMSG_NOTIFY_REQ_DROP, req->id, "they have left the help channel");
dict_remove(hs->requests, iter_key(it));
break;
--- 3161,3171 ----
if (user == req->user) {
! if (hs->persist_types[PERSIST_T_REQUEST] == PERSIST_PART || !req->text->used /* Request on join with no text */) {
! if (req->text->used) {
! helpserv_message(hs, user, MSGTYPE_REQ_DROPPED);
! helpserv_msguser(user, HSMSG_REQ_DROPPED_PART, chan->name, req->id);
+ if (req->helper && (hs->notify >= NOTIFY_DROP)) helpserv_notify(req->helper, HSMSG_NOTIFY_REQ_DROP, req->id, "they have left the help channel");
+ }
dict_remove(hs->requests, iter_key(it));
break;
***************
*** 3342,3364 ****
}
! if ((botlist = dict_find(helpserv_bots_bychan_dict, chan->name, NULL))) {
! for (i=0; i < botlist->used; i++) {
! struct helpserv_bot *hs=botlist->list[i];
! helpserv_message(hs, user, MSGTYPE_GREETING);
! associate_requests_bybot(hs, user, 1);
! if (user->handle_info) {
! struct helpserv_user *hs_user;
! if ((hs_user = dict_find(hs->users, user->handle_info->handle, NULL))) {
! if (!hs_user->join_time) hs_user->join_time = now;
! if (hs_user->level >= HlHelper && hs->intervals[INTERVAL_EMPTY_INTERVAL]) {
! timeq_del(0, run_empty_interval, hs, TIMEQ_IGNORE_WHEN);
! helpserv_page(PGSRC_ALERT, HSMSG_PAGE_EMPTYNOMORE, user->nick, hs->helpchan->name);
! }
}
}
}
}
}
--- 3373,3411 ----
}
! if (!(botlist = dict_find(helpserv_bots_bychan_dict, chan->name, NULL))) return;
! for (i=0; i < botlist->used; i++) {
! struct helpserv_bot *hs=botlist->list[i];
! helpserv_message(hs, user, MSGTYPE_GREETING);
! associate_requests_bybot(hs, user, 1);
! if (user->handle_info) {
! struct helpserv_user *hs_user;
!
! if ((hs_user = dict_find(hs->users, user->handle_info->handle, NULL))) {
! if (!hs_user->join_time) hs_user->join_time = now;
!
! if (hs_user->level >= HlHelper && hs->intervals[INTERVAL_EMPTY_INTERVAL]) {
! timeq_del(0, run_empty_interval, hs, TIMEQ_IGNORE_WHEN);
! helpserv_page(PGSRC_ALERT, HSMSG_PAGE_EMPTYNOMORE, user->nick, hs->helpchan->name);
}
}
}
+
+ /* Make sure this is at the end (because of the continue) */
+ if (hs->req_on_join) {
+ struct helpserv_reqlist *reqlist;
+ unsigned int j;
+
+ if ((reqlist = dict_find(helpserv_reqs_bynick_dict, user->nick, NULL))) {
+ for (j=0; j < reqlist->used; j++) {
+ if (reqlist->list[i]->hs == hs) break;
+ }
+ if (j < reqlist->used) continue;
+ }
+
+ create_request(user, hs, 1);
+ }
}
}
***************
*** 3845,3848 ****
--- 3892,3896 ----
helpserv_define_option("IDWRAP", opt_id_wrap);
helpserv_define_option("PRIVMSGONLY", opt_privmsg_only);
+ helpserv_define_option("REQONJOIN", opt_req_on_join);
helpserv_bots_dict = dict_new();
Index: helpserv.help
===================================================================
RCS file: /cvsroot/srvx/services/src/helpserv.help,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** helpserv.help 11 Sep 2002 01:50:07 -0000 1.10
--- helpserv.help 29 Sep 2002 00:06:00 -0000 1.11
***************
*** 238,241 ****
--- 238,246 ----
"Helpers are not affected by this setting.",
"$uSee also:$u set");
+ "SET REQONJOIN" ("$bSET REQONJOIN$b",
+ "/msg $S SET REQONJOIN <Yes|No>",
+ "This sets if requests are automatically opened whenever someone joins the help channel. They contain no text by default.",
+ "Helpers are not affected by this setting.",
+ "$uSee also:$u set");
"SHOW" ("$bSHOW$b",
"/msg $S SHOW <reqid|nick|*account>",
|