/** * topic.C: This file contains code for the ChanServ TOPIC functions. * * 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 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: topic.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include #include #include static char const rcsid[] = "$Id: topic.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("chanserv/topic", false, "The Ermyth Team "); static void cs_cmd_topic (sourceinfo_t *si, int parc, char *parv[]); static void cs_cmd_topicappend (sourceinfo_t *si, int parc, char *parv[]); static void cs_cmd_topicprepend (sourceinfo_t *si, int parc, char *parv[]); command_t const cs_topic = { "TOPIC", N_("Sets a topic on a channel."), AC_NONE, 2, cs_cmd_topic }; command_t const cs_topicappend = { "TOPICAPPEND", N_("Appends a topic on a channel."), AC_NONE, 2, cs_cmd_topicappend }; command_t const cs_topicprepend = { "TOPICPREPEND", N_("Prepends a topic on a channel."), AC_NONE, 2, cs_cmd_topicprepend }; E cmdvec cs_cmdtree; E helpvec cs_helptree; bool _modinit (module *m) { cs_cmdtree << cs_topic; cs_cmdtree << cs_topicappend; cs_cmdtree << cs_topicprepend; help_addentry (cs_helptree, "TOPIC", "help/chanserv/topic", NULL); help_addentry (cs_helptree, "TOPICAPPEND", "help/chanserv/topicappend", NULL); help_addentry (cs_helptree, "TOPICPREPEND", "help/chanserv/topicprepend", NULL); return true; } void _moddeinit () { cs_cmdtree >> cs_topic; cs_cmdtree >> cs_topicappend; cs_cmdtree >> cs_topicprepend; help_delentry (cs_helptree, "TOPIC"); help_delentry (cs_helptree, "TOPICAPPEND"); help_delentry (cs_helptree, "TOPICPREPEND"); } static void cs_cmd_topic (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *topic = parv[1]; mychan_t *mc; channel_t *c; char const *topicsetter; time_t prevtopicts; if (!chan || !topic) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPIC"); command_fail (si, fault::needmoreparams, _("Syntax: TOPIC <#channel> ")); return; } mc = mychan_t::find (chan); if (!mc) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); return; } c = channel_find (chan); if (!c) { command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan); return; } if (mc->find_metadata ("private:close:closer")) { command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); return; } if (!chanacs_source_has_flag (mc, si, CA_TOPIC)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } if (si->su != NULL) topicsetter = si->su->nick; else if (si->smu != NULL) topicsetter = si->smu->name; else topicsetter = "unknown"; prevtopicts = c->topicts; handle_topic (c, topicsetter, NOW, topic); phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topic); logcommand (si, CMDLOG_SET, "%s TOPIC", mc->name); if (!chanuser_find (c, si->su)) command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), topic, chan); } static void cs_cmd_topicappend (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *topic = parv[1]; mychan_t *mc; char topicbuf[BUFSIZE]; channel_t *c; char const *topicsetter; time_t prevtopicts; if (!chan || !topic) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICAPPEND"); command_fail (si, fault::needmoreparams, _("Syntax: TOPICAPPEND <#channel> ")); return; } mc = mychan_t::find (chan); if (!mc) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); return; } c = channel_find (chan); if (!c) { command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan); return; } if (!chanacs_source_has_flag (mc, si, CA_TOPIC)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } if (mc->find_metadata ("private:close:closer")) { command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); return; } topicbuf[0] = '\0'; if (c->topic) { strlcpy (topicbuf, c->topic, BUFSIZE); strlcat (topicbuf, " | ", BUFSIZE); strlcat (topicbuf, topic, BUFSIZE); } else strlcpy (topicbuf, topic, BUFSIZE); if (si->su != NULL) topicsetter = si->su->nick; else if (si->smu != NULL) topicsetter = si->smu->name; else topicsetter = "unknown"; prevtopicts = c->topicts; handle_topic (c, topicsetter, NOW, topicbuf); phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf); logcommand (si, CMDLOG_SET, "%s TOPICAPPEND", mc->name); if (!chanuser_find (c, si->su)) command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), c->topic, chan); } static void cs_cmd_topicprepend (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *topic = parv[1]; mychan_t *mc; char topicbuf[BUFSIZE]; channel_t *c; char const *topicsetter; time_t prevtopicts; if (!chan || !topic) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "TOPICPREPEND"); command_fail (si, fault::needmoreparams, _("Syntax: TOPICPREPEND <#channel> ")); return; } mc = mychan_t::find (chan); if (!mc) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); return; } c = channel_find (chan); if (!c) { command_fail (si, fault::nosuch_target, _("\2%s\2 is currently empty."), chan); return; } if (!chanacs_source_has_flag (mc, si, CA_TOPIC)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } if (mc->find_metadata ("private:close:closer")) { command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); return; } topicbuf[0] = '\0'; if (c->topic) { strlcpy (topicbuf, topic, BUFSIZE); strlcat (topicbuf, " | ", BUFSIZE); strlcat (topicbuf, c->topic, BUFSIZE); } else strlcpy (topicbuf, topic, BUFSIZE); if (si->su != NULL) topicsetter = si->su->nick; else if (si->smu != NULL) topicsetter = si->smu->name; else topicsetter = "unknown"; prevtopicts = c->topicts; handle_topic (c, topicsetter, NOW, topicbuf); phandler->topic_sts (c, topicsetter, NOW, prevtopicts, topicbuf); logcommand (si, CMDLOG_SET, "%s TOPICPREPEND", mc->name); if (!chanuser_find (c, si->su)) command_success_nodata (si, _("Topic set to \2%s\2 on \2%s\2."), c->topic, chan); }