Debian Codegraph @

modules/chanserv/invite.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the CService INVITE functions.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "chanserv/invite", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void cs_cmd_invite(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t cs_invite = { "INVITE", N_("Invites you to a channel."),
21 AC_NONE, 1, cs_cmd_invite, { .path = "cservice/invite" } };
22
23 void _modinit(module_t *m)
24 {
25 service_named_bind_command("chanserv", &cs_invite);
26 }
27
28 void _moddeinit(module_unload_intent_t intent)
29 {
30 service_named_unbind_command("chanserv", &cs_invite);
31 }
32
33 static void cs_cmd_invite(sourceinfo_t *si, int parc, char *parv[])
34 {
35 char *chan = parv[0];
36 mychan_t *mc;
37
38 if (si->su == NULL)
39 {
40 command_fail(si, fault_noprivs, _("\2%s\2 can only be executed via IRC."), "INVITE");
41 return;
42 }
43
44 /* This command is not useful if the user is already in the channel,
45 * ignore it if it is a fantasy command so users can program bots to
46 * react on it without interference from ChanServ.
47 */
48 if (si->c != NULL)
49 return;
50
51 if (!chan)
52 {
53 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "INVITE");
54 command_fail(si, fault_needmoreparams, _("Syntax: INVITE <#channel>"));
55 return;
56 }
57
58 mc = mychan_find(chan);
59 if (!mc)
60 {
61 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan);
62 return;
63 }
64
65 if (metadata_find(mc, "private:close:closer"))
66 {
67 command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan);
68 return;
69 }
70
71 if (!chanacs_source_has_flag(mc, si, CA_INVITE))
72 {
73 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
74 return;
75 }
76
77 if (!mc->chan)
78 {
79 command_fail(si, fault_nosuch_target, _("\2%s\2 is currently empty."), mc->name);
80 return;
81 }
82
83 if (chanuser_find(mc->chan, si->su))
84 {
85 command_fail(si, fault_noprivs, _("You're already on \2%s\2."), mc->name);
86 return;
87 }
88
89 invite_sts(si->service->me, si->su, mc->chan);
90 logcommand(si, CMDLOG_DO, "INVITE: \2%s\2", mc->name);
91 command_success_nodata(si, _("You have been invited to \2%s\2."), mc->name);
92 }
93
94 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
95 * vim:ts=8
96 * vim:sw=8
97 * vim:noexpandtab
98 */