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 SET which can change
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/set_core", false, _modinit, _moddeinit,
16 	PACKAGE_STRING,
17 	"Rizon Development Group <http://dev.rizon.net>"
18 );
19 
20 static void bs_help_set(sourceinfo_t *si, const char *subcmd);
21 static void bs_cmd_set(sourceinfo_t *si, int parc, char *parv[]);
22 
23 command_t bs_set = { "SET", N_("Configures bot options."), AC_NONE, 3, bs_cmd_set, { .func =  bs_help_set } };
24 
25 mowgli_patricia_t *bs_set_cmdtree;
26 
_modinit(module_t * m)27 void _modinit(module_t *m)
28 {
29 	service_named_bind_command("botserv", &bs_set);
30 
31 	bs_set_cmdtree = mowgli_patricia_create(strcasecanon);
32 }
33 
_moddeinit(module_unload_intent_t intent)34 void _moddeinit(module_unload_intent_t intent)
35 {
36 	service_named_unbind_command("botserv", &bs_set);
37 
38 	mowgli_patricia_destroy(bs_set_cmdtree, NULL, NULL);
39 }
40 
41 /* ******************************************************************** */
42 
bs_help_set(sourceinfo_t * si,const char * subcmd)43 static void bs_help_set(sourceinfo_t *si, const char *subcmd)
44 {
45 	if (!subcmd)
46 	{
47 		command_success_nodata(si, _("***** \2%s Help\2 *****"), si->service->disp);
48 		command_success_nodata(si, _("Help for \2SET\2:"));
49 		command_success_nodata(si, " ");
50 		command_success_nodata(si, _("Configures different botserv bot options."));
51 		command_success_nodata(si, " ");
52 		command_help(si, bs_set_cmdtree);
53 		command_success_nodata(si, " ");
54 		command_success_nodata(si, _("For more specific help use \2/msg %s HELP SET \37command\37\2."), si->service->disp);
55 		command_success_nodata(si, _("***** \2End of Help\2 *****"));
56 	}
57 	else
58 		help_display_as_subcmd(si, si->service, "SET", subcmd, bs_set_cmdtree);
59 }
60 
bs_cmd_set(sourceinfo_t * si,int parc,char * parv[])61 static void bs_cmd_set(sourceinfo_t *si, int parc, char *parv[])
62 {
63 	char *dest;
64 	char *cmd;
65 	command_t *c;
66 
67 	if (parc < 3)
68 	{
69 		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SET");
70 		command_fail(si, fault_needmoreparams, _("Syntax: SET <destination> <setting> <parameters>"));
71 		return;
72 	}
73 
74 	dest = parv[0];
75 	cmd = parv[1];
76 	c = command_find(bs_set_cmdtree, cmd);
77 	if (c == NULL)
78 	{
79 		command_fail(si, fault_badparams, _("Invalid command. Use \2/%s%s help\2 for a command listing."), (ircd->uses_rcommand == false) ? "msg " : "", si->service->disp);
80 		return;
81 	}
82 
83 	parv[1] = dest;
84 	command_exec(si->service, si, c, parc - 1, parv + 1);
85 }
86 
87 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
88  * vim:ts=8
89  * vim:sw=8
90  * vim:noexpandtab
91  */
92