Skip to content

Commit 00e2d91

Browse files
authored
Allows users to use KiwiIRC plugins to do stuff
1 parent 8ab4552 commit 00e2d91

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

files/kiwiirc-tags.c

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
Licence: GPLv3 or later
3+
Copyright Ⓒ 2022 Valerie Pond
4+
5+
Provides support for KiwiIRC-related tags
6+
*/
7+
/*** <<<MODULE MANAGER START>>>
8+
module
9+
{
10+
documentation "https://github.com/ValwareIRC/valware-unrealircd-mods/blob/main/kiwiirc-tags/README.md";
11+
troubleshooting "In case of problems, documentation or e-mail me at [email protected]";
12+
min-unrealircd-version "6.*";
13+
max-unrealircd-version "6.*";
14+
post-install-text {
15+
"The module is installed. Now all you need to do is add a loadmodule line:";
16+
"loadmodule \"third/kiwiirc-tags\";";
17+
"The module does not need any other configuration.";
18+
}
19+
}
20+
*** <<<MODULE MANAGER END>>>
21+
*/
22+
23+
#define MTAG_FILEUPLOAD "+kiwiirc.com/fileuploader"
24+
#define MTAG_CONFERENCE "+kiwiirc.com/conference"
25+
#define MTAG_TICTACTOE_OLD "+data" /* current */
26+
#define MTAG_TICTACTOE "+kiwiirc.com/ttt" /* supported in near future */
27+
#include "unrealircd.h"
28+
29+
ModuleHeader MOD_HEADER =
30+
{
31+
"third/kiwiirc-tags",
32+
"1.0",
33+
"Provides support for KiwiIRC's MessageTags",
34+
"Valware",
35+
"unrealircd-6",
36+
};
37+
int kiwiirc_tag(Client *client, const char *name, const char *value);
38+
void mtag_add_kiwiirc_tag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
39+
40+
MOD_INIT()
41+
{
42+
MessageTagHandlerInfo mtag;
43+
44+
MARK_AS_GLOBAL_MODULE(modinfo);
45+
46+
memset(&mtag, 0, sizeof(mtag));
47+
mtag.is_ok = kiwiirc_tag;
48+
mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
49+
mtag.name = MTAG_FILEUPLOAD;
50+
MessageTagHandlerAdd(modinfo->handle, &mtag);
51+
52+
memset(&mtag, 0, sizeof(mtag));
53+
mtag.is_ok = kiwiirc_tag;
54+
mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
55+
mtag.name = MTAG_CONFERENCE;
56+
MessageTagHandlerAdd(modinfo->handle, &mtag);
57+
58+
memset(&mtag, 0, sizeof(mtag));
59+
mtag.is_ok = kiwiirc_tag;
60+
mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
61+
mtag.name = MTAG_TICTACTOE_OLD;
62+
MessageTagHandlerAdd(modinfo->handle, &mtag);
63+
64+
memset(&mtag, 0, sizeof(mtag));
65+
mtag.is_ok = kiwiirc_tag;
66+
mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
67+
mtag.name = MTAG_TICTACTOE;
68+
MessageTagHandlerAdd(modinfo->handle, &mtag);
69+
70+
HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_kiwiirc_tag);
71+
72+
73+
return MOD_SUCCESS;
74+
}
75+
76+
MOD_LOAD()
77+
{
78+
return MOD_SUCCESS;
79+
}
80+
81+
MOD_UNLOAD()
82+
{
83+
return MOD_SUCCESS;
84+
}
85+
86+
int kiwiirc_tag(Client *client, const char *name, const char *value)
87+
{
88+
if (!strlen(value))
89+
{
90+
sendto_one(client, NULL, "FAIL * MESSAGE_TAG_TOO_SHORT %s :That message tag must contain a value.", name);
91+
return 0;
92+
}
93+
return 1;
94+
}
95+
96+
void mtag_add_kiwiirc_tag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
97+
{
98+
MessageTag *m;
99+
100+
if (IsUser(client))
101+
{
102+
m = find_mtag(recv_mtags, MTAG_FILEUPLOAD);
103+
if (m)
104+
{
105+
m = duplicate_mtag(m);
106+
AddListItem(m, *mtag_list);
107+
}
108+
m = find_mtag(recv_mtags, MTAG_CONFERENCE);
109+
if (m)
110+
{
111+
m = duplicate_mtag(m);
112+
AddListItem(m, *mtag_list);
113+
}
114+
m = find_mtag(recv_mtags, MTAG_TICTACTOE_OLD);
115+
if (m)
116+
{
117+
m = duplicate_mtag(m);
118+
AddListItem(m, *mtag_list);
119+
}
120+
m = find_mtag(recv_mtags, MTAG_TICTACTOE);
121+
if (m)
122+
{
123+
m = duplicate_mtag(m);
124+
AddListItem(m, *mtag_list);
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)