-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_allsend.cpp
121 lines (107 loc) · 3.69 KB
/
m_allsend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2015-2016 reverse Chevronnet [email protected]
*
* This file is part of InspIRCd. InspIRCd is free software; you can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/// $ModAuthor: reverse [email protected]
/// $ModConfig: <module name="allsend">
/// $ModDepends: core 4
/// $ModDesc: Adds the /ALLSEND command for opers to send messages to specific groups of users.
#include "inspircd.h"
class CommandAllSend : public Command
{
public:
CommandAllSend(Module* Creator)
: Command(Creator, "ALLSEND", 4)
{
syntax.push_back("<target> <notice|private> <local|global> <message>");
// Restrict command to operators using IsOper check in the Handle method
}
CmdResult Handle(User* user, const Params& parameters) override
{
std::string target = parameters[0];
std::string mode = parameters[1];
std::string scope = parameters[2];
std::string message = parameters[3];
bool isNotice = (mode == "notice");
bool isLocal = (scope == "local");
auto sendMessage = [&](User* recipient) {
if (isNotice)
{
recipient->WriteNotice(message);
}
else
{
CommandBase::Params privmsgParams;
privmsgParams.push_back(recipient->nick);
privmsgParams.push_back(message);
ServerInstance->Parser.CallHandler("PRIVMSG", privmsgParams, user);
}
};
auto sendToUsers = [&](const std::function<bool(User*)>& predicate) {
const UserManager::LocalList& users = ServerInstance->Users.GetLocalUsers();
for (auto* recipient : users)
{
if (predicate(recipient))
{
sendMessage(recipient);
}
}
};
if (target == "opers")
{
sendToUsers([&](User* recipient) {
return recipient->IsOper() && (!isLocal || IS_LOCAL(recipient));
});
user->WriteNotice("Message sent to all opers.");
}
else if (target == "users")
{
sendToUsers([&](User* recipient) {
return !recipient->IsOper() && (!isLocal || IS_LOCAL(recipient));
});
user->WriteNotice("Message sent to all users.");
}
else if (target == "all")
{
sendToUsers([&](User* recipient) {
return !isLocal || IS_LOCAL(recipient);
});
user->WriteNotice("Message sent to everyone.");
}
else
{
user->WriteNotice("Error: Invalid target. Use 'opers', 'users', or 'all'.");
return CmdResult::FAILURE;
}
return CmdResult::SUCCESS;
}
};
class ModuleAllSend : public Module
{
private:
CommandAllSend cmd;
public:
ModuleAllSend()
: Module(VF_VENDOR, "Adds the /ALLSEND command for opers to send messages to specific groups."),
cmd(this)
{
}
void init() override
{
// Removed AddService call as services are automatically added since v3
}
};
MODULE_INIT(ModuleAllSend)