ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/memoserv/list.C
Revision: 1.7
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * list.C: This file contains code for the Memoserv LIST function
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005 Atheme Development Group
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: list.C,v 1.6 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17 #include <account/myuser.h>
18 #include <account/mymemo.h>
19
20 static char const rcsid[] = "$Id: list.C,v 1.6 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("memoserv/list", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void ms_cmd_list (sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t const ms_list = { "LIST", N_(N_("Lists all of your memos.")), AC_NONE, 0, ms_cmd_list };
27
28 E cmdvec ms_cmdtree;
29 E helpvec ms_helptree;
30
31 bool
32 _modinit (module *m)
33 {
34 ms_cmdtree << ms_list;
35 help_addentry (ms_helptree, "LIST", "help/memoserv/list", NULL);
36
37 return true;
38 }
39
40 void
41 _moddeinit ()
42 {
43 ms_cmdtree >> ms_list;
44 help_delentry (ms_helptree, "LIST");
45 }
46
47 static void
48 ms_cmd_list (sourceinfo_t *si, int parc, char *parv[])
49 {
50 /* Misc structs etc */
51 mymemo_t *memo;
52 myuser_t::memo_vector::iterator mzit, mzit_end;
53 unsigned int i = 0;
54 char strfbuf[32];
55 struct tm tm;
56 char line[512];
57 char chan[CHANNELLEN];
58 char *p;
59
60 /* user logged in? */
61 if (si->smu == NULL)
62 {
63 command_fail (si, fault::noprivs, _("You are not logged in."));
64 return;
65 }
66
67 command_success_nodata (si, ngettext (N_("You have %d memo (%d new)."), N_("You have %d memos (%d new)."), si->smu->memos.size ()), si->smu->memos.size (), si->smu->memoct_new);
68
69 /* Check to see if any memos */
70 if (si->smu->memos.empty ())
71 return;
72
73 /* Go to listing memos */
74 command_success_nodata (si, " ");
75
76 for (mzit = si->smu->memos.begin (), mzit_end = si->smu->memos.end (); mzit != mzit_end; ++mzit)
77 {
78 memo = *mzit;
79 i++;
80 tm = *localtime (&memo->sent);
81
82 strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
83
84 snprintf (line, sizeof line, _("- %d From: %s Sent: %s"), i, memo->sender, strfbuf);
85 if (memo->status & MEMO_CHANNEL && *memo->text == '#')
86 {
87 strlcat (line, " ", sizeof line);
88 strlcat (line, _("To:"), sizeof line);
89 strlcat (line, " ", sizeof line);
90 strlcpy (chan, memo->text, sizeof chan);
91 p = strchr (chan, ' ');
92 if (p != NULL)
93 *p = '\0';
94 strlcat (line, chan, sizeof line);
95 }
96 if (!(memo->status & MEMO_READ))
97 {
98 strlcat (line, " ", sizeof line);
99 strlcat (line, _("[unread]"), sizeof line);
100 }
101 command_success_nodata (si, "%s", line);
102 }
103
104 return;
105 }