aboutsummaryrefslogtreecommitdiff
path: root/src/modules/m_helpmode.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2023-02-27 11:26:12 +0000
committerGravatar Sadie Powell2023-02-27 20:29:56 +0000
commitf4f39c57f0622ab8224a7d772b3f00ba06bb730e (patch)
tree5bc38cf5c18764c70ce68d3b45ed5e329aee072b /src/modules/m_helpmode.cpp
parentLoad both help and helpmode if a user has helpop in their config. (diff)
Allow non-opers with +h to show in `/STATS P`.
Diffstat (limited to 'src/modules/m_helpmode.cpp')
-rw-r--r--src/modules/m_helpmode.cpp68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/modules/m_helpmode.cpp b/src/modules/m_helpmode.cpp
index 79da6c577..065848681 100644
--- a/src/modules/m_helpmode.cpp
+++ b/src/modules/m_helpmode.cpp
@@ -18,21 +18,85 @@
#include "inspircd.h"
+#include "duration.h"
+#include "modules/stats.h"
#include "modules/whois.h"
+class HelpOp final
+ : public SimpleUserMode
+{
+public:
+ std::vector<User*> helpopers;
+
+ HelpOp(Module* mod)
+ : SimpleUserMode(mod, "helpop", 'h', true)
+ {
+ }
+
+ bool OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override
+ {
+ if (!SimpleUserMode::OnModeChange(source, dest, channel, change))
+ return false;
+
+ if (change.adding)
+ helpopers.push_back(dest);
+ else
+ stdalgo::erase(helpopers, dest);
+
+ return true;
+ }
+};
+
class ModuleHelpMode final
: public Module
+ , public Stats::EventListener
, public Whois::EventListener
{
private:
- SimpleUserMode helpop;
+ HelpOp helpop;
public:
ModuleHelpMode()
: Module(VF_VENDOR, "Adds user mode h (helpop) which marks a server operator as being available for help.")
+ , Stats::EventListener(this)
, Whois::EventListener(this)
- , helpop(this, "helpop", 'h', true)
+ , helpop(this)
+ {
+ }
+
+ ModResult OnStats(Stats::Context& stats) override
{
+ if (stats.GetSymbol() != 'P')
+ return MOD_RES_PASSTHRU;
+
+ for (auto* oper : helpop.helpopers)
+ {
+ if (oper->IsOper() || oper->server->IsService())
+ continue; // Ignore opers and services.
+
+ std::string extra;
+ if (oper->IsAway())
+ {
+ const std::string awayperiod = Duration::ToString(ServerInstance->Time() - oper->awaytime);
+ const std::string awaytime = InspIRCd::TimeString(oper->awaytime);
+
+ extra = INSP_FORMAT(": away for {} [since {}] ({})", awayperiod, awaytime, oper->awaymsg);
+ }
+
+ auto* loper = IS_LOCAL(oper);
+ if (loper)
+ {
+ const std::string idleperiod = Duration::ToString(ServerInstance->Time() - loper->idle_lastmsg);
+ const std::string idletime = InspIRCd::TimeString(loper->idle_lastmsg);
+
+ extra += INSP_FORMAT("{} idle for {} [since {}]", extra.empty() ? ':' : ',', idleperiod, idletime);
+ }
+
+ stats.AddGenericRow(INSP_FORMAT("\x02{}\x02 ({}){}", oper->nick, oper->GetRealUserHost(), extra));
+ }
+
+ // Allow the core to add normal opers.
+ return MOD_RES_PASSTHRU;
}
void OnWhois(Whois::Context& whois) override