Skip to content

Commit 7798b75

Browse files
examknowjesopo
authored andcommitted
add support for bot mode spec
1 parent 519d9bc commit 7798b75

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

extensions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extension_LTLIBRARIES = \
4545
sno_globaloper.la \
4646
umode_noctcp.la \
4747
m_adminwall.la \
48+
m_botmode.la \
4849
m_echotags.la \
4950
m_extendchans.la \
5051
m_findforwards.la \

extensions/m_botmode.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (C) 2021 David Schultz <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17+
* USA
18+
*/
19+
20+
#include "stdinc.h"
21+
#include "capability.h"
22+
#include "client.h"
23+
#include "hook.h"
24+
#include "ircd.h"
25+
#include "send.h"
26+
#include "logger.h"
27+
#include "modules.h"
28+
#include "msgbuf.h"
29+
#include "numeric.h"
30+
#include "supported.h"
31+
#include "s_conf.h"
32+
#include "s_serv.h"
33+
#include "s_user.h"
34+
#include "s_newconf.h"
35+
36+
static char botmode_desc[] = "Provides support for the IRCv3 draft/bot spec";
37+
38+
static void h_bm_outbound_msgbuf(void *);
39+
static void h_bm_whois(void *);
40+
41+
static unsigned CLICAP_BOT;
42+
43+
mapi_cap_list_av2 botmode_caps[] = {
44+
{ MAPI_CAP_CLIENT, "draft/bot", NULL, &CLICAP_BOT },
45+
{ 0, NULL, NULL, NULL},
46+
};
47+
48+
mapi_hfn_list_av1 botmode_hfnlist[] = {
49+
{ "outbound_msgbuf", h_bm_outbound_msgbuf, HOOK_NORMAL },
50+
{ "doing_whois_global", h_bm_whois, HOOK_MONITOR },
51+
{ "doing_whois", h_bm_whois, HOOK_MONITOR },
52+
{ NULL, NULL, 0 }
53+
};
54+
55+
static void
56+
h_bm_outbound_msgbuf(void *data_)
57+
{
58+
hook_data *data = data_;
59+
struct MsgBuf *msgbuf = data->arg1;
60+
61+
if (data->client->umodes & user_modes['B'])
62+
{
63+
msgbuf_append_tag(msgbuf, "draft/bot", NULL, CLICAP_BOT);
64+
}
65+
}
66+
67+
static void
68+
h_bm_whois(void *data_)
69+
{
70+
hook_data_client *data = data_;
71+
if (data->target->umodes & user_modes['B'])
72+
{
73+
sendto_one_numeric(data->client, RPL_WHOISBOT,
74+
form_str(RPL_WHOISBOT), data->target->name, ServerInfo.network_name);
75+
}
76+
}
77+
78+
static int
79+
_modinit(void)
80+
{
81+
user_modes['B'] = find_umode_slot();
82+
construct_umodebuf();
83+
if (!user_modes['B'])
84+
{
85+
ierror("m_botmode: unable to allocate usermode slot for +B, unloading extension");
86+
return -1;
87+
}
88+
add_isupport("BOT", isupport_umode, "B");
89+
return 0;
90+
}
91+
92+
static void
93+
_moddeinit(void)
94+
{
95+
user_modes['B'] = 0;
96+
construct_umodebuf();
97+
delete_isupport("BOT");
98+
}
99+
100+
DECLARE_MODULE_AV2(botmode, _modinit, _moddeinit, NULL, NULL, botmode_hfnlist, botmode_caps, NULL, botmode_desc);

include/messages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#define NUMERIC_STR_331 ":%s 331 %s %s :No topic is set."
108108
#define NUMERIC_STR_332 ":%s 332 %s %s :%s"
109109
#define NUMERIC_STR_333 ":%s 333 %s %s %s %lld"
110+
#define NUMERIC_STR_335 "%s :is a bot on %s"
110111
#define NUMERIC_STR_338 "%s %s :actually using host"
111112
#define NUMERIC_STR_341 ":%s 341 %s %s %s"
112113
#define NUMERIC_STR_346 ":%s 346 %s %s %s %s %lu"

include/numeric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
#define RPL_NOTOPIC 331
161161
#define RPL_TOPIC 332
162162
#define RPL_TOPICWHOTIME 333
163+
#define RPL_WHOISBOT 335
163164
#define RPL_WHOISACTUALLY 338
164165

165166
#define RPL_INVITING 341

0 commit comments

Comments
 (0)