]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_stripcolor.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2016 0x277F <0x277F@gmail.com>
6  *   Copyright (C) 2013, 2017 Sadie Powell <sadie@witchery.services>
7  *   Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
8  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
11  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *   Copyright (C) 2004, 2006, 2010 Craig Edwards <brain@inspircd.org>
14  *
15  * This file is part of InspIRCd.  InspIRCd is free software: you can
16  * redistribute it and/or modify it under the terms of the GNU General Public
17  * License as published by the Free Software Foundation, version 2.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  */
27
28
29 #include "inspircd.h"
30 #include "modules/exemption.h"
31
32 class ModuleStripColor : public Module
33 {
34         CheckExemption::EventProvider exemptionprov;
35         SimpleChannelModeHandler csc;
36         SimpleUserModeHandler usc;
37
38  public:
39         ModuleStripColor()
40                 : exemptionprov(this)
41                 , csc(this, "stripcolor", 'S')
42                 , usc(this, "u_stripcolor", 'S')
43         {
44         }
45
46         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
47         {
48                 tokens["EXTBAN"].push_back('S');
49         }
50
51         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
52         {
53                 if (!IS_LOCAL(user))
54                         return MOD_RES_PASSTHRU;
55
56                 bool active = false;
57                 switch (target.type)
58                 {
59                         case MessageTarget::TYPE_USER:
60                         {
61                                 User* t = target.Get<User>();
62                                 active = t->IsModeSet(usc);
63                                 break;
64                         }
65                         case MessageTarget::TYPE_CHANNEL:
66                         {
67                                 Channel* t = target.Get<Channel>();
68                                 ModResult res = CheckExemption::Call(exemptionprov, user, t, "stripcolor");
69
70                                 if (res == MOD_RES_ALLOW)
71                                         return MOD_RES_PASSTHRU;
72
73                                 active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet(csc));
74                                 break;
75                         }
76                         case MessageTarget::TYPE_SERVER:
77                                 break;
78                 }
79
80                 if (active)
81                 {
82                         InspIRCd::StripColor(details.text);
83                 }
84
85                 return MOD_RES_PASSTHRU;
86         }
87
88         void OnUserPart(Membership* memb, std::string& partmessage, CUList& except_list) CXX11_OVERRIDE
89         {
90                 User* user = memb->user;
91                 Channel* channel = memb->chan;
92
93                 if (!IS_LOCAL(user))
94                         return;
95
96                 if (channel->GetExtBanStatus(user, 'S').check(!user->IsModeSet(csc)))
97                 {
98                         ModResult res = CheckExemption::Call(exemptionprov, user, channel, "stripcolor");
99
100                         if (res != MOD_RES_ALLOW)
101                                 InspIRCd::StripColor(partmessage);
102                 }
103         }
104
105         Version GetVersion() CXX11_OVERRIDE
106         {
107                 return Version("Adds channel mode S (stripcolor) which allows channels to strip IRC formatting codes from messages.", VF_VENDOR);
108         }
109
110 };
111
112 MODULE_INIT(ModuleStripColor)