Skip to content

Commit c253322

Browse files
authored
reduced-moderation.c (#77)
Requested by Mahjong This works just like +m (moderated) except ops and above will still see messages from non-voiced users, and nobody else in that channel. In addition, the user will not receive an error about the message being lost.
1 parent 78e2f5b commit c253322

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

files/reduced-moderation.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Licence: GPLv3
3+
Copyright Ⓒ 2022 Valerie Pond
4+
5+
Permissions: By using this module, you agree that it is Free, and you are allowed to make copies
6+
and redistrubite this at your own free will, so long as in doing so, the original author and license remain in-tact.
7+
8+
9+
Reduced moderation: Requested by Mahjong
10+
11+
*/
12+
/*** <<<MODULE MANAGER START>>>
13+
module
14+
{
15+
documentation "https://github.com/ValwareIRC/valware-unrealircd-mods/blob/main/reduced-moderation/README.md";
16+
troubleshooting "In case of problems, documentation or e-mail me at [email protected]";
17+
min-unrealircd-version "6.*";
18+
max-unrealircd-version "6.*";
19+
post-install-text {
20+
"The module is installed. Now all you need to do is add a loadmodule line:";
21+
"loadmodule \"third/reduced-moderation\";";
22+
"And /REHASH the IRCd.";
23+
"The module does not need any other configuration.";
24+
}
25+
}
26+
*** <<<MODULE MANAGER END>>>
27+
*/
28+
29+
#include "unrealircd.h"
30+
31+
32+
ModuleHeader MOD_HEADER
33+
= {
34+
"third/reduced-moderation",
35+
"1.0",
36+
"Reduced Moderation mode (+x)",
37+
"Valware",
38+
"unrealircd-6",
39+
};
40+
41+
/* Global variables */
42+
Cmode_t EXTCMODE_REDMOD;
43+
44+
/* Forward declarations */
45+
int redmod_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype);
46+
const char *redmod_pre_local_part(Client *client, Channel *channel, const char *text);
47+
48+
/* Macros */
49+
#define IsRedMod(channel) (channel->mode.mode & EXTCMODE_REDMOD)
50+
51+
MOD_INIT()
52+
{
53+
CmodeInfo req;
54+
55+
MARK_AS_GLOBAL_MODULE(modinfo);
56+
57+
memset(&req, 0, sizeof(req));
58+
req.paracount = 0;
59+
req.letter = 'x';
60+
req.is_ok = extcmode_default_requirechop;
61+
CmodeAdd(modinfo->handle, req, &EXTCMODE_REDMOD);
62+
63+
HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 123, redmod_can_send_to_channel);
64+
HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 123, redmod_pre_local_part);
65+
66+
return MOD_SUCCESS;
67+
}
68+
69+
MOD_LOAD()
70+
{
71+
return MOD_SUCCESS;
72+
}
73+
74+
MOD_UNLOAD()
75+
{
76+
return MOD_SUCCESS;
77+
}
78+
79+
/* Overrides for +m also will override +x */
80+
int redmod_can_send_to_channel(Client *client, Channel *channel, Membership *m, const char **text, const char **errmsg, SendType sendtype)
81+
{
82+
MessageTag *mtags = NULL;
83+
if (IsRedMod(channel) && (!m || !check_channel_access_membership(m, "vhoaq")) &&
84+
!op_can_override("channel:override:message:moderated",client,channel,NULL))
85+
{
86+
Hook *h;
87+
for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next)
88+
{
89+
int i = (*(h->func.intfunc))(client, channel, BYPASS_CHANMSG_MODERATED);
90+
if (i == HOOK_ALLOW)
91+
return HOOK_CONTINUE;
92+
if (i != HOOK_CONTINUE)
93+
break;
94+
}
95+
96+
int notice = (sendtype == SEND_TYPE_NOTICE);
97+
98+
new_message(client, NULL, &mtags);
99+
sendto_channel(channel, client, client, "oaq", 0, SEND_ALL, mtags, ":%s %s %s :%s", client->name, (notice ? "NOTICE" : "PRIVMSG"), channel->name, *text);
100+
free_message_tags(mtags);
101+
*text = NULL;
102+
103+
}
104+
105+
return HOOK_CONTINUE;
106+
}
107+
108+
const char *redmod_pre_local_part(Client *client, Channel *channel, const char *text)
109+
{
110+
if (IsRedMod(channel) && !check_channel_access(client, channel, "v") && !check_channel_access(client, channel, "h"))
111+
return NULL;
112+
return text;
113+
}
114+

0 commit comments

Comments
 (0)