Debian Codegraph @

modules/groupserv/set_channel.c

raw
1
2 /*
3 * Copyright (c) 2005 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains routines to handle the GroupServ HELP command.
7 *
8 */
9
10 #include "atheme.h"
11 #include "groupserv.h"
12
13 DECLARE_MODULE_V1
14 (
15 "groupserv/set_channel", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 static void gs_cmd_set_channel(sourceinfo_t *si, int parc, char *parv[]);
21
22 command_t gs_set_channel = { "CHANNEL", N_("Sets the official group channel."), AC_AUTHENTICATED, 2, gs_cmd_set_channel, { .path = "groupserv/set_channel" } };
23
24 static void gs_cmd_set_channel(sourceinfo_t *si, int parc, char *parv[])
25 {
26 mygroup_t *mg;
27 char *chan = parv[1];
28
29 if (!(mg = mygroup_find(parv[0])))
30 {
31 command_fail(si, fault_nosuch_target, _("Group \2%s\2 does not exist."), parv[0]);
32 return;
33 }
34
35 if (!groupacs_sourceinfo_has_flag(mg, si, GA_SET))
36 {
37 command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
38 return;
39 }
40
41 if (!chan || !strcasecmp("OFF", chan) || !strcasecmp("NONE", chan))
42 {
43 /* not in a namespace to allow more natural use of SET PROPERTY.
44 * they may be able to introduce spaces, though. c'est la vie.
45 */
46 if (metadata_find(mg, "channel"))
47 {
48 metadata_delete(mg, "channel");
49 logcommand(si, CMDLOG_SET, "SET:CHANNEL:NONE: \2%s\2", entity(mg)->name);
50 command_success_nodata(si, _("The official channel for \2%s\2 has been cleared."), parv[0]);
51 return;
52 }
53
54 command_fail(si, fault_nochange, _("A official channel for \2%s\2 was not set."), parv[0]);
55 return;
56 }
57
58 /* we'll overwrite any existing metadata */
59 metadata_add(mg, "channel", chan);
60
61 logcommand(si, CMDLOG_SET, "SET:CHANNEL: \2%s\2 \2%s\2", entity(mg)->name, chan);
62 command_success_nodata(si, _("The official channel of \2%s\2 has been set to \2%s\2."), parv[0], chan);
63 }
64
65 void _modinit(module_t *m)
66 {
67 use_groupserv_main_symbols(m);
68 use_groupserv_set_symbols(m);
69
70 command_add(&gs_set_channel, gs_set_cmdtree);
71 }
72
73 void _moddeinit(module_unload_intent_t intent)
74 {
75 command_delete(&gs_set_channel, gs_set_cmdtree);
76 }
77