]> jfr.im git - irc/evilnet/x3.git/commitdiff
CANCEL command
authorsirvulcan <redacted>
Tue, 20 Jun 2006 05:14:00 +0000 (05:14 +0000)
committersirvulcan <redacted>
Tue, 20 Jun 2006 05:14:00 +0000 (05:14 +0000)
ChangeLog
src/mod-memoserv.c
src/mod-memoserv.help

index 31dc1483e39f4fd9a9372da55fe1ceb096a311e0..f49ef317c100780e6e3cf16cfa093f8e45fabea0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
 /***********************************************************************
  X3 ChangeLog
 
+2006-06-20  Neil Spierling <sirvulcan@gmail.com>
+
+       * src/mod-memoserv.c: Added CANCEL command for cancelling memos
+       that you have sent, aslong as they have not been read yet.
+
+       * src/mod-memoserv.help: CANCEL entry plus tweaked some read
+       recipient to read reciept stuff.
+
 2006-06-20  Neil Spierling <sirvulcan@gmail.com>
 
        * src/mod-memoserv.c: Redid the db stuff, it now writes users
index 1f0204c1018e003209710a9088634ec56e3157e2..75a5367d333a4a1c07a8a88b4f740314a8fcd08c 100644 (file)
 #define KEY_MESSAGE "msg"
 #define KEY_READ "read"
 #define KEY_RECIEPT "reciept"
+#define KEY_ID "id"
 
 static const struct message_entry msgtab[] = {
     { "MSMSG_CANNOT_SEND", "You cannot send to account $b%s$b." },
-    { "MSMSG_MEMO_SENT", "Message sent to $b%s$b." },
+    { "MSMSG_MEMO_SENT", "Message sent to $b%s$b (ID# %d)." },
     { "MSMSG_NO_MESSAGES", "You have no messages." },
     { "MSMSG_MEMOS_FOUND", "Found $b%d$b matches.\nUse /msg $S READ <ID> to read a message." },
     { "MSMSG_CLEAN_INBOX", "You have $b%d$b or more messages, please clean out your inbox.\nUse /msg $S READ <ID> to read a message." },
@@ -70,6 +71,10 @@ static const struct message_entry msgtab[] = {
     { "MSMSG_BAD_MESSAGE_ID", "$b%s$b is not a valid message ID (it should be a number between 0 and %u)." },
     { "MSMSG_NO_SUCH_MEMO", "You have no memo with that ID." },
     { "MSMSG_MEMO_DELETED", "Memo $b%d$b deleted." },
+    { "MSMSG_MEMO_CANCEL_NUMBER", "You must specify a number id" },
+    { "MSMSG_MEMO_DONT_OWN", "You did not send memo# %d" },
+    { "MSMSG_MEMO_READ", "Memo# %d has already been read, you cannot cancel it." },
+    { "MSMSG_MEMO_CANT_LOCATE", "Could not locate memo# %d" },
     { "MSMSG_EXPIRY_OFF", "I am currently not expiring messages. (turned off)" },
     { "MSMSG_EXPIRY", "Messages will be expired when they are %s old (%d seconds)." },
     { "MSMSG_MESSAGES_EXPIRED", "$b%lu$b message(s) expired." },
@@ -103,6 +108,7 @@ struct memo {
     struct memo_account *sender;
     char *message;
     time_t sent;
+    unsigned long id;
     unsigned int is_read : 1;
     unsigned int reciept : 1;
 };
@@ -133,6 +139,8 @@ static struct {
 #define OPTION_FUNC(NAME) int NAME(struct userNode *user, struct handle_info *hi, UNUSED_ARG(unsigned int override), unsigned int argc, char *argv[])
 typedef OPTION_FUNC(option_func_t);
 
+unsigned long memo_id;
+
 extern struct string_list *autojoin_channels;
 const char *memoserv_module_deps[] = { NULL };
 static struct module *memoserv_module;
@@ -211,7 +219,7 @@ expire_memos(UNUSED_ARG(void *data))
 }
 
 static struct memo*
-add_memo(time_t sent, struct memo_account *recipient, struct memo_account *sender, char *message)
+add_memo(time_t sent, struct memo_account *recipient, struct memo_account *sender, char *message, int nfrom_read)
 {
     struct memo *memo;
 
@@ -219,6 +227,11 @@ add_memo(time_t sent, struct memo_account *recipient, struct memo_account *sende
     if (!memo)
         return NULL;
 
+    if (nfrom_read) {
+        memo_id++;
+        memo->id = memo_id;
+    }
+
     memo->recipient = recipient;
     memoList_append(&recipient->recvd, memo);
     memo->sender = sender;
@@ -328,7 +341,7 @@ static MODCMD_FUNC(cmd_send)
         inc = 3;
 
     message = unsplit_string(argv + inc, argc - inc, NULL);
-    memo = add_memo(now, ma, sender, message);
+    memo = add_memo(now, ma, sender, message, 1);
     if (reciept == 1)
         memo->reciept = 1;
 
@@ -339,7 +352,7 @@ static MODCMD_FUNC(cmd_send)
             send_message(other, cmd->parent->bot, "MSMSG_NEW_MESSAGE", user->nick);
     }
 
-    reply("MSMSG_MEMO_SENT", ma->handle->handle);
+    reply("MSMSG_MEMO_SENT", ma->handle->handle, memo_id);
     return 1;
 }
 
@@ -437,7 +450,8 @@ static MODCMD_FUNC(cmd_read)
 
             sprintf(content, "%s has read your memo dated %s.", ma->handle->handle, posted);
 
-            memo = add_memo(now, sender, ma, content);
+            memo = add_memo(now, sender, ma, content, 1);
+            reply("MSMSG_MEMO_SENT", memo->sender->handle, memo_id);
 
             if (sender->flags & MEMO_NOTIFY_NEW) {
                 struct userNode *other;
@@ -478,6 +492,48 @@ static MODCMD_FUNC(cmd_delete)
     return 1;
 }
 
+static MODCMD_FUNC(cmd_cancel)
+{
+    unsigned long id;
+    unsigned int ii;
+    dict_iterator_t it;
+    struct memo *memo;
+    struct memo_account *ma;
+
+    if (isdigit(argv[1][0])) {
+        id = strtoul(argv[1], NULL, 0);
+    } else {
+        reply("MSMSG_MEMO_CANCEL_NUMBER");
+        return 0;
+    }
+
+    for (it = dict_first(memos); it; it = iter_next(it)) {
+        ma = iter_data(it);
+        for (ii = 0; ii < ma->recvd.used; ++ii) {
+            memo = ma->recvd.list[ii];
+
+            if (id == memo->id) {
+                if (!strcasecmp(memo->sender->handle->handle, user->handle_info->handle)) {
+                    if (memo->is_read) {
+                        reply("MSMSG_MEMO_READ", id);
+                        return 0;
+                    } else {
+                        delete_memo(memo);
+                        reply("MSMSG_MEMO_DELETED", id);
+                        return 1;
+                    }
+                } else {
+                    reply("MSMSG_MEMO_DONT_OWN", id);
+                    return 0;
+                }
+            }
+        }
+    }
+
+    reply("MSMSG_MEMO_CANT_LOCATE", id);
+    return 0;
+}
+
 static MODCMD_FUNC(cmd_expire)
 {
     unsigned long old_expired = memosExpired;
@@ -722,6 +778,7 @@ memoserv_memo_read(const char *key, struct record_data *hir)
     char *str;
     struct handle_info *sender, *recipient;
     struct memo *memo;
+    unsigned long id;
     time_t sent;
 
     if (hir->type != RECDB_OBJECT) {
@@ -736,6 +793,14 @@ memoserv_memo_read(const char *key, struct record_data *hir)
 
     sent = atoi(str);
 
+    if (!(str = database_get_data(hir->d.object, KEY_ID, RECDB_QSTRING))) {
+        log_module(MS_LOG, LOG_ERROR, "ID sent not present in memo %s; skipping", key);
+        return 0;
+    }
+    id = strtoul(str, NULL, 0);
+    if (id > memo_id)
+      memo_id = id;
+
     if (!(str = database_get_data(hir->d.object, KEY_RECIPIENT, RECDB_QSTRING))) {
         log_module(MS_LOG, LOG_ERROR, "Recipient not present in memo %s; skipping", key);
         return 0;
@@ -757,13 +822,15 @@ memoserv_memo_read(const char *key, struct record_data *hir)
         return 0;
     }
 
-    memo = add_memo(sent, memoserv_get_account(recipient), memoserv_get_account(sender), str);
+    memo = add_memo(sent, memoserv_get_account(recipient), memoserv_get_account(sender), str, 0);
     if ((str = database_get_data(hir->d.object, KEY_READ, RECDB_QSTRING)))
         memo->is_read = 1;
 
     if ((str = database_get_data(hir->d.object, KEY_RECIEPT, RECDB_QSTRING)))
         memo->reciept = 1;
 
+    memo->id = id;
+
     return 0;
 }
 
@@ -800,11 +867,11 @@ static int
 memoserv_write_memos(struct saxdb_context *ctx, struct memo *memo)
 {
     char str[7];
-    unsigned int id = 0;
 
-    saxdb_start_record(ctx, inttobase64(str, id++, sizeof(str)), 0);
+    saxdb_start_record(ctx, inttobase64(str, memo->id, sizeof(str)), 0);
 
     saxdb_write_int(ctx, KEY_SENT, memo->sent);
+    saxdb_write_int(ctx, KEY_ID, memo->id);
     saxdb_write_string(ctx, KEY_RECIPIENT, memo->recipient->handle->handle);
     saxdb_write_string(ctx, KEY_FROM, memo->sender->handle->handle);
     saxdb_write_string(ctx, KEY_MESSAGE, memo->message);
@@ -910,6 +977,7 @@ memoserv_init(void)
     modcmd_register(memoserv_module, "list",   cmd_list,   1, MODCMD_REQUIRE_AUTHED, NULL);
     modcmd_register(memoserv_module, "read",   cmd_read,   2, MODCMD_REQUIRE_AUTHED, NULL);
     modcmd_register(memoserv_module, "delete", cmd_delete, 2, MODCMD_REQUIRE_AUTHED, NULL);
+    modcmd_register(memoserv_module, "cancel", cmd_cancel, 2, MODCMD_REQUIRE_AUTHED, NULL);
     modcmd_register(memoserv_module, "expire", cmd_expire, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
     modcmd_register(memoserv_module, "expiry", cmd_expiry, 1,                        0, NULL);
     modcmd_register(memoserv_module, "status", cmd_status, 1,                        0, NULL);
index 9cf004bf466340d9af27b34515d48a49767b45a3..648f77227461192e90349e5853b2de54549af3f0 100644 (file)
@@ -10,6 +10,7 @@
         "  $bREAD$b    - Reads a message.",
         "  $bDELETE$b  - Deletes a message.",
         "  $bLIST$b    - Lists your messages.",
+        "  $bCANCEL$b  - Cancels a message you have sent.",
         "  $bSET$b     - Sets certain options in relation with $S.",
         "  $bEXPIRY$b  - Displays when old unread messages will be deleted.",
         "  $bSTATUS$b  - Displays a few details about $S's status.",
          "Runs an expire process through $S's messages, deleting any messages that are over date.",
          "$uSee Also:$u expiry");
 
+"CANCEL" ("/msg $S CANCEL <id>",
+         "Cancels the messaged marked with <id> as long as you have sent the message.");
+
 "SEND" ("/msg $S SEND <nick|*account> <-flags> <message>",
-        "Sends a message to an user. Flags can be $br$b to request a read recipient.",
+        "Sends a message to an user. Flags can be $br$b to request a read recipient. Take note of the ID number if you wish to cancel the message in the future. The ID number is required in the CANCEL command.",
         "You may use *Account instead of Nick as the name argument; the * makes $S use the name of an account directly (useful if the user is not online).",
         "$uSee also:$u read, list");