-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofflinemsg.cpp
More file actions
77 lines (66 loc) · 1.92 KB
/
offlinemsg.cpp
File metadata and controls
77 lines (66 loc) · 1.92 KB
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
/*
* offlinemsg - Automatic Offline Message Delivery for Anope 2.0
*
* When a user identifies with NickServ, this module checks for
* memos and delivers them as PRIVMSGs that appear to come from the
* original sender via MSGAS. Memos are deleted after delivery.
*
* Designed to work with the m_offlinemsg UnrealIRCd module which
* intercepts PRIVMSGs to offline users and creates memos automatically.
*
* Requires the MSGAS command (from m_cnotice) to be available on the
* IRCd with CMD_USER flag for ULine clients.
*
* Copyright 2026 The Fuel Rats Mischief
* Author: Alex Sørlie
*/
#include "module.h"
class OfflineMsg : public Module
{
static Anope::string FormatTime(time_t t)
{
char buf[64];
struct tm *tm = gmtime(&t);
snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d.000Z",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
return buf;
}
public:
OfflineMsg(const Anope::string &modname, const Anope::string &creator)
: Module(modname, creator, THIRD)
{
}
void OnUserLogin(User *u) anope_override
{
const NickCore *nc = u->Account();
if (!nc)
return;
MemoInfo *mi = const_cast<MemoInfo *>(&nc->memos);
if (!mi || mi->memos->empty())
return;
BotInfo *nickserv = BotInfo::Find("NickServ", true);
if (!nickserv)
return;
unsigned delivered = 0;
/* Iterate backwards since we're deleting */
for (int i = mi->memos->size() - 1; i >= 0; --i)
{
Memo *m = mi->GetMemo(i);
/* Send via MSGAS with ISO 8601 timestamp */
Anope::string timestamp = FormatTime(m->time);
UplinkSocket::Message(nickserv) << "MSGAS " << m->sender
<< " " << u->nick << " " << timestamp << " :" << m->text;
FOREACH_MOD(OnMemoDel, (nc->display, mi, m));
mi->Del(i);
++delivered;
}
if (delivered > 0)
{
u->SendMessage(nickserv,
"%d offline message%s delivered.",
delivered, delivered == 1 ? "" : "s");
}
}
};
MODULE_INIT(OfflineMsg)