-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_profileLink.cpp
87 lines (76 loc) · 2.58 KB
/
m_profileLink.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
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2021 Sadie Powell <[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: Jean Chevronnet <[email protected]>
/// $ModDepends: core 4
/// $ModDesc: Adds a profile link to the WHOIS response for registered users, ignoring services, bots.
/// $ModConfig: <profilelink baseurl="https://example.com/profil/">
#include "inspircd.h"
#include "modules/whois.h"
#include "modules/account.h"
enum
{
// Define a custom WHOIS numeric reply for the profile link.
RPL_WHOISPROFILE = 320,
};
class ModuleProfileLink final
: public Module
, public Whois::EventListener
{
private:
Account::API accountapi;
std::string profileBaseUrl;
UserModeReference botmode;
public:
ModuleProfileLink()
: Module(VF_OPTCOMMON, "Adds a profile link to the WHOIS response for registered users, ignoring services, bots.")
, Whois::EventListener(this)
, accountapi(this)
, botmode(this, "bot")
{
}
void ReadConfig(ConfigStatus& status) override
{
auto& tag = ServerInstance->Config->ConfValue("profilelink");
profileBaseUrl = tag->getString("baseurl");
}
void OnWhois(Whois::Context& whois) override
{
User* target = whois.GetTarget();
// Skip services, bots.
if (target->server->IsService() || target->IsModeSet(botmode))
return;
// Ensure the account module is loaded before attempting to get the account name.
if (!accountapi)
return;
// Check if the user has an account name (is registered).
const std::string* account = accountapi->GetAccountName(target);
if (account)
{
// Construct the profile URL using the user's account name.
const std::string profileUrl = profileBaseUrl + *account;
// Send the profile URL in the WHOIS response.
whois.SendLine(RPL_WHOISPROFILE, "*", "Profil: " + profileUrl);
}
else
{
// Indicate that the account is not registered.
whois.SendLine(RPL_WHOISPROFILE, "*", "Profile: The user is not logged in or the account is not registered.");
}
}
};
MODULE_INIT(ModuleProfileLink)