1 /*
2 * Copyright (c) 2009 Celestin, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains a BService INFO which can show
6 * botserv settings on channel or bot.
7 *
8 */
9
10 #include "atheme.h"
11 #include "botserv.h"
12
13 DECLARE_MODULE_V1
14 (
15 "botserv/info", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 static void bs_cmd_info(sourceinfo_t *si, int parc, char *parv[]);
21
22 command_t bs_info = { "INFO", N_("Allows you to see BotServ information about a channel or a bot."), AC_NONE, 1, bs_cmd_info, { .path = "botserv/info" } };
23
24 fn_botserv_bot_find *botserv_bot_find;
25 mowgli_list_t *bs_bots;
26
_modinit(module_t * m)27 void _modinit(module_t *m)
28 {
29 MODULE_TRY_REQUEST_SYMBOL(m, bs_bots, "botserv/main", "bs_bots");
30 MODULE_TRY_REQUEST_SYMBOL(m, botserv_bot_find, "botserv/main", "botserv_bot_find");
31
32 service_named_bind_command("botserv", &bs_info);
33 }
34
_moddeinit(module_unload_intent_t intent)35 void _moddeinit(module_unload_intent_t intent)
36 {
37 service_named_unbind_command("botserv", &bs_info);
38 }
39
40 /* ******************************************************************** */
41
bs_cmd_info(sourceinfo_t * si,int parc,char * parv[])42 static void bs_cmd_info(sourceinfo_t *si, int parc, char *parv[])
43 {
44 char *dest = parv[0];
45 mychan_t *mc = NULL;
46 botserv_bot_t* bot = NULL;
47 metadata_t *md;
48 int comma = 0, i;
49 char buf[BUFSIZE], strfbuf[BUFSIZE], *end;
50 time_t registered;
51 struct tm tm;
52 mowgli_node_t *n;
53 chanuser_t *cu;
54
55 if (parc < 1 || parv[0] == NULL)
56 {
57 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO");
58 command_fail(si, fault_needmoreparams, _("Syntax: INFO <#channel>"));
59 command_fail(si, fault_needmoreparams, _("Syntax: INFO <botnick>"));
60 return;
61 }
62
63 if (parv[0][0] == '#')
64 {
65 mc = mychan_find(dest);
66 }
67 else
68 {
69 bot = botserv_bot_find(dest);
70 }
71
72 if (bot != NULL)
73 {
74 command_success_nodata(si, _("Information for bot \2%s\2:"), bot->nick);
75 command_success_nodata(si, _(" Mask : %s@%s"), bot->user, bot->host);
76 command_success_nodata(si, _("Real name : %s"), bot->real);
77 registered = bot->registered;
78 tm = *localtime(®istered);
79 strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
80 command_success_nodata(si, _(" Created : %s (%s ago)"), strfbuf, time_ago(registered));
81 if (bot->private)
82 command_success_nodata(si, _(" Options : Private"));
83 else
84 command_success_nodata(si, _(" Options : None"));
85 command_success_nodata(si, _(" Used on : %zu channel(s)"), MOWGLI_LIST_LENGTH(&bot->me->me->channels));
86 if (has_priv(si, PRIV_CHAN_AUSPEX))
87 {
88 i = 0;
89 MOWGLI_ITER_FOREACH(n, bot->me->me->channels.head)
90 {
91 cu = (chanuser_t *)n->data;
92 command_success_nodata(si, _("%d: %s"), ++i, cu->chan->name);
93 }
94 }
95 }
96 else if (mc != NULL)
97 {
98 if (!(mc->flags & MC_PUBACL) && !chanacs_source_has_flag(mc, si, CA_ACLVIEW) && !has_priv(si, PRIV_CHAN_AUSPEX))
99 {
100 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
101 return;
102 }
103
104 command_success_nodata(si, _("Information for channel \2%s\2:"), mc->name);
105 if ((md = metadata_find(mc, "private:botserv:bot-assigned")) != NULL)
106 command_success_nodata(si, _(" Bot nick : %s"), md->value);
107 else
108 command_success_nodata(si, _(" Bot nick : not assigned yet"));
109 end = buf;
110 *end = '\0';
111 if (metadata_find(mc, "private:botserv:bot-handle-fantasy"))
112 {
113 end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", (comma) ? ", " : "", "Fantasy");
114 comma = 1;
115 }
116 if (metadata_find(mc, "private:botserv:no-bot"))
117 {
118 end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", (comma) ? ", " : "", "No bot");
119 comma = 1;
120 }
121 if (metadata_find(mc, "private:botserv:saycaller"))
122 {
123 end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", (comma) ? ", " : "", "Say Caller");
124 comma = 1;
125 }
126 command_success_nodata(si, _(" Options : %s"), (*buf) ? buf : "None");
127 }
128 else
129 {
130 command_fail(si, fault_nosuch_target, STR_INSUFFICIENT_PARAMS, "INFO");
131 command_fail(si, fault_nosuch_target, _("Syntax: INFO <#channel>"));
132 command_fail(si, fault_nosuch_target, _("Syntax: INFO <botnick>"));
133 }
134 }
135
136 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
137 * vim:ts=8
138 * vim:sw=8
139 * vim:noexpandtab
140 */
141
142
143