/** * list.C: This file contains code for the Memoserv LIST function * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: list.C,v 1.7 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: list.C,v 1.7 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("memoserv/list", false, "The Ermyth Team "); static void ms_cmd_list (sourceinfo_t *si, int parc, char *parv[]); command_t const ms_list = { "LIST", N_(N_("Lists all of your memos.")), AC_NONE, 0, ms_cmd_list }; E cmdvec ms_cmdtree; E helpvec ms_helptree; bool _modinit (module *m) { ms_cmdtree << ms_list; help_addentry (ms_helptree, "LIST", "help/memoserv/list", NULL); return true; } void _moddeinit () { ms_cmdtree >> ms_list; help_delentry (ms_helptree, "LIST"); } static void ms_cmd_list (sourceinfo_t *si, int parc, char *parv[]) { /* Misc structs etc */ mymemo_t *memo; myuser_t::memo_vector::iterator mzit, mzit_end; unsigned int i = 0; char strfbuf[32]; struct tm tm; char line[512]; char chan[CHANNELLEN]; char *p; /* user logged in? */ if (si->smu == NULL) { command_fail (si, fault::noprivs, _("You are not logged in.")); return; } 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); /* Check to see if any memos */ if (si->smu->memos.empty ()) return; /* Go to listing memos */ command_success_nodata (si, " "); for (mzit = si->smu->memos.begin (), mzit_end = si->smu->memos.end (); mzit != mzit_end; ++mzit) { memo = *mzit; i++; tm = *localtime (&memo->sent); strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); snprintf (line, sizeof line, _("- %d From: %s Sent: %s"), i, memo->sender, strfbuf); if (memo->status & MEMO_CHANNEL && *memo->text == '#') { strlcat (line, " ", sizeof line); strlcat (line, _("To:"), sizeof line); strlcat (line, " ", sizeof line); strlcpy (chan, memo->text, sizeof chan); p = strchr (chan, ' '); if (p != NULL) *p = '\0'; strlcat (line, chan, sizeof line); } if (!(memo->status & MEMO_READ)) { strlcat (line, " ", sizeof line); strlcat (line, _("[unread]"), sizeof line); } command_success_nodata (si, "%s", line); } return; }