[srvx-commits] CVS: services/src helpserv.c,1.29,1.30
Brought to you by:
entrope
|
From: Adrian D. <sai...@us...> - 2002-08-31 04:21:30
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv24704
Modified Files:
helpserv.c
Log Message:
Implement smart_get_request(), used by cmd_close, cmd_show, cmd_pickup and cmd_addnote. Permits use of ID#, nick, or *account when using commands.
Update TODO list to include what I hope to complete for 1.2's release
Index: helpserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/helpserv.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** helpserv.c 24 Aug 2002 19:11:59 -0000 1.29
--- helpserv.c 31 Aug 2002 04:21:27 -0000 1.30
***************
*** 22,39 ****
* - 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)
! * Wishlist for helpserv.c
* - cmd_close should optionally take another argument (a reason/comment)
! * - Let HelpServ accept "close nick|*handle", and make it work if there's
! * only one request open to the target. complain and list request IDs if
! * there are more than one.
* - Make HelpServ send unassigned request count to helpers as they join the
* channel
* - FAQ responses
* - Get cmd_statsreport to sort by time
- * - A lot of the stuff (especially when talking to users) should be privmsg
- * instead of notice, even if their handle is set otherwise
- * - Allow helpers to switch to help mode (I'm not entirely sure the use of
- * this)
* - Something for users to use a subset of commands... like closing their
* own request(s), viewing what they've sent so far, and finding their
--- 22,37 ----
* - 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)
! * - Statistical analysis of time
! * - Setting to send all contact with users in privmsg (including greeting)
! * Wishlist for helpserv.c
* - Make HelpServ send unassigned request count to helpers as they join the
* channel
* - FAQ responses
* - Get cmd_statsreport to sort by time
* - Something for users to use a subset of commands... like closing their
* own request(s), viewing what they've sent so far, and finding their
***************
*** 161,166 ****
/* Requests */
! #define HSMSG_REQ_INVALID "$b%s$b is not a valid request ID."
#define HSMSG_REQ_NOT_YOURS "Request $b%lu$b is not assigned to you; it is currently %s%s."
#define HSMSG_REQ_CLOSED "Request $b%lu$b has been closed."
#define HSMSG_REQ_NO_UNASSIGNED "There are no unassigned requests."
--- 159,165 ----
/* Requests */
! #define HSMSG_REQ_INVALID "$b%s$b is not a valid request ID, or there are no requests for that nick or account."
#define HSMSG_REQ_NOT_YOURS "Request $b%lu$b is not assigned to you; it is currently %s%s."
+ #define HSMSG_REQ_FOUNDMANY "The user you entered had multiple requests. The oldest one is being used."
#define HSMSG_REQ_CLOSED "Request $b%lu$b has been closed."
#define HSMSG_REQ_NO_UNASSIGNED "There are no unassigned requests."
***************
*** 558,561 ****
--- 557,645 ----
}
+ /* Searches for a request by number, nick, or account (num|nick|*account).
+ * As there can potentially be >1 match, it takes a reqlist. The return
+ * value is the "best" request found (explained in the comment block below).
+ *
+ * If num_results is not NULL, it is set to the number of potentially matching
+ * requests.
+ * If hs_user is not NULL, requests assigned to this helper will be given
+ * preference (oldest assigned, falling back to oldest if there are none).
+ */
+ static struct helpserv_request * smart_get_request(struct helpserv_bot *hs, struct helpserv_user *hs_user, const char *needle, int *num_results) {
+ struct helpserv_reqlist *reqlist, resultlist;
+ struct helpserv_request *req, *oldest=NULL, *oldest_assigned=NULL;
+ struct userNode *user;
+ unsigned int i;
+
+ if (num_results) *num_results = 0;
+
+ if (*needle == '*') {
+ /* This test (handle) requires the least processing, so it's first */
+ if (!(reqlist = dict_find(helpserv_reqs_byhand_dict, needle+1, NULL))) return NULL;
+ helpserv_reqlist_init(&resultlist);
+ for (i=0; i < reqlist->used; i++) {
+ req = reqlist->list[i];
+ if (req->hs == hs) {
+ helpserv_reqlist_append(&resultlist, req);
+ if (num_results) (*num_results)++;
+ }
+ }
+ } else if (!needle[strspn(needle, "0123456789")]) {
+ /* The string is 100% numeric - a request id */
+ if (!(req = dict_find(hs->requests, needle, NULL))) return NULL;
+ if (num_results) *num_results = 1;
+ return req;
+ } else if ((user = GetUserH(needle))) {
+ /* And finally, search by nick */
+ if (!(reqlist = dict_find(helpserv_reqs_bynick_dict, needle, NULL))) return NULL;
+ helpserv_reqlist_init(&resultlist);
+
+ for (i=0; i < reqlist->used; i++) {
+ req = reqlist->list[i];
+ if (req->hs == hs) {
+ helpserv_reqlist_append(&resultlist, req);
+ if (num_results) (*num_results)++;
+ }
+ }
+ /* If the nick didn't have anything, try their handle */
+ if (!resultlist.used && user->handle_info) {
+ char star_handle[NICKSERV_HANDLE_LEN+2];
+
+ helpserv_reqlist_clean(&resultlist);
+ sprintf(star_handle, "*%s", user->handle_info->handle);
+
+ return smart_get_request(hs, hs_user, star_handle, num_results);
+ }
+ } else {
+ return NULL;
+ }
+
+ if (resultlist.used == 0) {
+ helpserv_reqlist_clean(&resultlist);
+ return NULL;
+ } else if (resultlist.used == 1) {
+ req = resultlist.list[0];
+ helpserv_reqlist_clean(&resultlist);
+ return req;
+ }
+
+ /* In case there is >1 request returned, use the oldest one assigned to
+ * the helper executing the command. Otherwise, use the oldest request.
+ * This may not be the intended result for cmd_pickup (first unhandled
+ * request may be better), or cmd_reassign (first handled request), but
+ * it's close enough, and there really aren't supposed to be multiple
+ * requests per person anyway; they're just side effects of authing. */
+
+ for (i=0; i < resultlist.used; i++) {
+ req=resultlist.list[i];
+ if (!oldest || req->opened < oldest->opened) oldest = req;
+ if (hs_user && (!oldest_assigned || (req->helper == hs_user && req->opened < oldest_assigned->opened))) oldest_assigned = req;
+ }
+
+ helpserv_reqlist_clean(&resultlist);
+
+ return oldest_assigned ? oldest_assigned : oldest;
+ }
+
/* Handle a message from a user to a HelpServ bot. */
static void helpserv_usermsg(struct userNode *user, struct helpserv_bot *hs, char *text) {
***************
*** 1174,1188 ****
struct helpserv_request *req, *newest=NULL;
struct helpserv_reqlist *nick_list, *hand_list;
unsigned long old_req;
unsigned int i;
REQUIRE_PARMS(2);
! if (!(req = dict_find(hs->requests, argv[1], NULL))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
! if (!req->helper || (req->helper->handle != user->handle_info)) {
helpserv_notice(user, HSMSG_REQ_NOT_YOURS, req->id, (req->helper ? "assigned to " : "unassigned"), (req->helper ? req->helper->handle->handle : ""));
return 0;
--- 1258,1278 ----
struct helpserv_request *req, *newest=NULL;
struct helpserv_reqlist *nick_list, *hand_list;
+ struct helpserv_user *hs_user=GetHSUser(hs, user->handle_info);
unsigned long old_req;
unsigned int i;
+ int num_requests=0;
REQUIRE_PARMS(2);
! assert(hs_user);
!
! if (!(req = smart_get_request(hs, hs_user, argv[1], &num_requests))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
! if (num_requests > 1) helpserv_notice(user, HSMSG_REQ_FOUNDMANY);
!
! if (hs_user->level < HlManager && req->helper != hs_user) {
helpserv_notice(user, HSMSG_REQ_NOT_YOURS, req->id, (req->helper ? "assigned to " : "unassigned"), (req->helper ? req->helper->handle->handle : ""));
return 0;
***************
*** 1193,1198 ****
helpserv_page(PGSRC_STATUS, HSMSG_PAGE_CLOSE_REQUEST, req->id, req->user ? req->user->nick : "an offline user", req->handle ? req->handle->handle : "not authed", user->nick);
! req->helper->closed[0]++;
! req->helper->closed[1]++;
/* Set these to keep track of the lists after the request is gone, but
--- 1283,1288 ----
helpserv_page(PGSRC_STATUS, HSMSG_PAGE_CLOSE_REQUEST, req->id, req->user ? req->user->nick : "an offline user", req->handle ? req->handle->handle : "not authed", user->nick);
! hs_user->closed[0]++;
! hs_user->closed[1]++;
/* Set these to keep track of the lists after the request is gone, but
***************
*** 1416,1427 ****
static HELPSERV_FUNC(cmd_show) {
struct helpserv_request *req;
REQUIRE_PARMS(2);
! if (!(req = dict_find(hs->requests, argv[1], NULL))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
helpserv_notice(user, HSMSG_REQ_INFO_1, req->id);
helpserv_show(from_opserv, hs, user, req);
--- 1506,1523 ----
static HELPSERV_FUNC(cmd_show) {
struct helpserv_request *req;
+ struct helpserv_user *hs_user=GetHSUser(hs, user->handle_info);
+ int num_requests=0;
REQUIRE_PARMS(2);
! assert(hs_user);
!
! if (!(req = smart_get_request(hs, hs_user, argv[1], &num_requests))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
+ if (num_requests > 1) helpserv_notice(user, HSMSG_REQ_FOUNDMANY);
+
helpserv_notice(user, HSMSG_REQ_INFO_1, req->id);
helpserv_show(from_opserv, hs, user, req);
***************
*** 1431,1441 ****
static HELPSERV_FUNC(cmd_pickup) {
struct helpserv_request *req;
REQUIRE_PARMS(2);
! if (!(req = dict_find(hs->requests, argv[1], NULL))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
return helpserv_assign(from_opserv, hs, user, user, req);
}
--- 1527,1544 ----
static HELPSERV_FUNC(cmd_pickup) {
struct helpserv_request *req;
+ struct helpserv_user *hs_user=GetHSUser(hs, user->handle_info);
+ int num_requests=0;
REQUIRE_PARMS(2);
! assert(hs_user);
!
! if (!(req = smart_get_request(hs, hs_user, argv[1], &num_requests))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
+
+ if (num_requests > 1) helpserv_notice(user, HSMSG_REQ_FOUNDMANY);
+
return helpserv_assign(from_opserv, hs, user, user, req);
}
***************
*** 1443,1456 ****
static HELPSERV_FUNC(cmd_reassign) {
struct helpserv_request *req;
- struct helpserv_user *target, *hs_user;
struct userNode *targetuser;
REQUIRE_PARMS(3);
! if (!(req = dict_find(hs->requests, argv[1], NULL))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
if (!(targetuser = GetUserH(argv[2]))) {
helpserv_notice(user, MSG_NICK_UNKNOWN, argv[2]);
--- 1546,1565 ----
static HELPSERV_FUNC(cmd_reassign) {
struct helpserv_request *req;
struct userNode *targetuser;
+ struct helpserv_user *target;
+ struct helpserv_user *hs_user=GetHSUser(hs, user->handle_info);
+ int num_requests=0;
REQUIRE_PARMS(3);
! assert(hs_user);
!
! if (!(req = smart_get_request(hs, hs_user, argv[1], &num_requests))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
+ if (num_requests > 1) helpserv_notice(user, HSMSG_REQ_FOUNDMANY);
+
if (!(targetuser = GetUserH(argv[2]))) {
helpserv_notice(user, MSG_NICK_UNKNOWN, argv[2]);
***************
*** 1468,1472 ****
}
- hs_user = GetHSUser(hs, user->handle_info);
if ((hs->persist_types[PERSIST_T_HELPER] == PERSIST_PART) && !GetUserMode(hs->helpchan, user) && (hs_user->level < HlManager)) {
helpserv_notice(user, HSMSG_REQ_NOTIN_HELPCHAN, targetuser->nick, "be assigned", "they", hs->helpchan->name);
--- 1577,1580 ----
***************
*** 1481,1491 ****
char text[MAX_LINE_SIZE], timestr[MAX_LINE_SIZE], *note;
struct helpserv_request *req;
REQUIRE_PARMS(3);
! if (!(req = dict_find(hs->requests, argv[1], NULL))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
note = unsplit_string(argv+2, argc-2, NULL);
--- 1589,1605 ----
char text[MAX_LINE_SIZE], timestr[MAX_LINE_SIZE], *note;
struct helpserv_request *req;
+ struct helpserv_user *hs_user=GetHSUser(hs, user->handle_info);
+ int num_requests=0;
REQUIRE_PARMS(3);
! assert(hs_user);
!
! if (!(req = smart_get_request(hs, hs_user, argv[1], &num_requests))) {
helpserv_notice(user, HSMSG_REQ_INVALID, argv[1]);
return 0;
}
+
+ if (num_requests > 1) helpserv_notice(user, HSMSG_REQ_FOUNDMANY);
note = unsplit_string(argv+2, argc-2, NULL);
|