Debian Codegraph @

modules/botserv/bottalk.c

raw
1 /*
2 * Copyright (c) 2016 Austin Ellis
3 * Copyright (c) 2009 Celestin, et al.
4 * Rights to this code are as documented in doc/LICENSE.
5 *
6 * This file contains a BService SAY and ACT which can make
7 * botserv bot talk in channel.
8 *
9 */
10
11 #include "atheme.h"
12
13 DECLARE_MODULE_V1
14 (
15 "botserv/bottalk", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 static void bs_cmd_say(sourceinfo_t *si, int parc, char *parv[]);
21 static void bs_cmd_act(sourceinfo_t *si, int parc, char *parv[]);
22
23 command_t bs_say = { "SAY", N_("Makes the bot say the given text on the given channel."), AC_AUTHENTICATED, 2, bs_cmd_say, { .path = "botserv/say" } };
24 command_t bs_act = { "ACT", N_("Makes the bot do the equivalent of a \"/me\" command."), AC_AUTHENTICATED, 2, bs_cmd_act, { .path = "botserv/act" } };
25
26 void _modinit(module_t *m)
27 {
28 service_named_bind_command("botserv", &bs_say);
29 service_named_bind_command("botserv", &bs_act);
30 }
31
32 void _moddeinit(module_unload_intent_t intent)
33 {
34 service_named_unbind_command("botserv", &bs_say);
35 service_named_unbind_command("botserv", &bs_act);
36 }
37
38 static void bs_cmd_say(sourceinfo_t *si, int parc, char *parv[])
39 {
40 char *channel = parv[0];
41 char *message = parv[1];
42 char saybuf[BUFSIZE];
43 metadata_t *bs;
44 user_t *bot;
45
46 if (!channel || !message)
47 {
48 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SAY");
49 command_fail(si, fault_needmoreparams, _("Syntax: SAY <#channel> <msg>"));
50 return;
51 }
52
53 channel_t *c = channel_find(channel);
54 mychan_t *mc = mychan_find(channel);
55
56 if (!mc)
57 {
58 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), channel);
59 return;
60 }
61
62 if (!c)
63 {
64 command_fail(si, fault_nosuch_target, _("\2%s\2 is currently empty."), channel);
65 return;
66 }
67
68 if (!(chanacs_source_flags(mc, si) & (CA_OP | CA_AUTOOP)))
69 {
70 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
71 return;
72 }
73
74 if (metadata_find(mc, "private:frozen:freezer"))
75 {
76 command_fail(si, fault_noprivs, _("\2%s\2 is frozen."), mc->name);
77 return;
78 }
79
80 if ((bs = metadata_find(mc, "private:botserv:bot-assigned")) != NULL)
81 bot = user_find_named(bs->value);
82 else
83 bot = NULL;
84 if (bot == NULL)
85 {
86 command_fail(si, fault_nosuch_key, _("\2%s\2 does not have a bot assigned."), mc->name);
87 return;
88 }
89
90 if (metadata_find(mc, "private:botserv:saycaller"))
91 {
92 snprintf(saybuf, BUFSIZE, "%s", get_source_name(si));
93 msg(bot->nick, channel, "(%s) %s", saybuf, message);
94 logcommand(si, CMDLOG_DO, "SAY:\2%s\2: \2%s\2", channel, message);
95 }
96 else
97 {
98
99 msg(bot->nick, channel, "%s", message);
100 logcommand(si, CMDLOG_DO, "SAY:\2%s\2: \2%s\2", channel, message);
101 }
102 }
103
104 static void bs_cmd_act(sourceinfo_t *si, int parc, char *parv[])
105 {
106 char *channel = parv[0];
107 char *message = parv[1];
108 char actbuf[BUFSIZE];
109 metadata_t *bs;
110 user_t *bot;
111
112 if (!channel || !message)
113 {
114 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "ACT");
115 command_fail(si, fault_needmoreparams, _("Syntax: ACT <#channel> <msg>"));
116 return;
117 }
118
119 channel_t *c = channel_find(channel);
120 mychan_t *mc = mychan_find(channel);
121
122 if (!mc)
123 {
124 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), channel);
125 return;
126 }
127
128 if (!c)
129 {
130 command_fail(si, fault_nosuch_target, _("\2%s\2 is currently empty."), channel);
131 return;
132 }
133
134 if (!(chanacs_source_flags(mc, si) & (CA_OP | CA_AUTOOP)))
135 {
136 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
137 return;
138 }
139
140 if (metadata_find(mc, "private:frozen:freezer"))
141 {
142 command_fail(si, fault_noprivs, _("\2%s\2 is frozen."), mc->name);
143 return;
144 }
145
146 if ((bs = metadata_find(mc, "private:botserv:bot-assigned")) != NULL)
147 bot = user_find_named(bs->value);
148 else
149 bot = NULL;
150 if (bot == NULL)
151 {
152 command_fail(si, fault_nosuch_key, _("\2%s\2 does not have a bot assigned."), mc->name);
153 return;
154 }
155 if (metadata_find(mc, "private:botserv:saycaller"))
156 {
157 snprintf(actbuf, BUFSIZE, "%s", get_source_name(si));
158 msg(bot->nick, channel, "\001ACTION (%s) %s\001", actbuf, message);
159 logcommand(si, CMDLOG_DO, "ACT:\2%s\2: \2%s\2", channel, message);
160 }
161 else
162 {
163
164 msg(bot->nick, channel, "\001ACTION %s\001", message);
165 logcommand(si, CMDLOG_DO, "ACT:\2%s\2: \2%s\2", channel, message);
166 }
167 }
168
169 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
170 * vim:ts=8
171 * vim:sw=8
172 * vim:noexpandtab
173 */
174
175