-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
117 lines (104 loc) · 3.46 KB
/
Copy pathmod.ts
File metadata and controls
117 lines (104 loc) · 3.46 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
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
import { bold, CommandHandler, fmt, Module, updateMessage } from "$xor";
import { Api } from "$grm";
const I_PTO = "purge__purge_to";
const I_PFROM = "purge__purge_from";
const cleaner: Module = {
name: "cleaner",
handlers: [
new CommandHandler("purge", async ({ event, client, args }) => {
let purgeTo = Number(sessionStorage.getItem(I_PTO));
const purgeFrom = Number(sessionStorage.getItem(I_PFROM));
if (!purgeTo) {
const reply = await event.message.getReplyMessage();
if (!reply) {
await updateMessage(
event,
"Reply a message to purge to or mark with pto (and pfrom).",
);
return;
}
purgeTo = reply.id;
}
sessionStorage.removeItem(I_PTO);
sessionStorage.removeItem(I_PFROM);
let messages = new Array<Api.Message>();
const self = args[0]?.startsWith("s");
const all = args[1] == "ALL" && self;
for await (
const message of client.iterMessages(event.chatId, {
minId: all ? undefined : purgeTo - 1,
maxId: all ? undefined : purgeFrom == 0 ? undefined : purgeFrom + 1,
fromUser: args[0]?.startsWith("s") ? "me" : undefined,
})
) {
messages.push(message);
if (messages.length == 100) {
await client.deleteMessages(event.chat, messages, { revoke: true });
messages = [];
}
}
if (messages.length > 0) {
await client.deleteMessages(event.chatId, messages, { revoke: true });
}
}),
new CommandHandler("pfrom", async ({ event }) => {
const reply = await event.message.getReplyMessage();
if (!reply) {
await updateMessage(
event,
"Reply a message to mark.",
);
return;
}
const purgeTo = Number(sessionStorage.getItem(I_PTO));
if (purgeTo > reply.id) {
await updateMessage(
event,
"Cannot purge from a message older than the purge to message.",
);
return;
}
sessionStorage.setItem(I_PFROM, String(reply.id));
await updateMessage(event, "Marked.");
}),
new CommandHandler("pto", async ({ event }) => {
const reply = await event.message.getReplyMessage();
if (!reply) {
await updateMessage(
event,
"Reply a message to mark.",
);
return;
}
const purgeFrom = Number(sessionStorage.getItem(I_PFROM));
if (reply.id > purgeFrom) {
await updateMessage(
event,
"Cannot purge to a message newer than the purge from message.",
);
return;
}
sessionStorage.setItem(I_PTO, String(reply.id));
await updateMessage(event, "Marked.");
}),
new CommandHandler("del", async ({ event }) => {
await event.message.delete();
const reply = await event.message.getReplyMessage();
if (reply) {
await reply.delete();
}
}, { aliases: ["d"] }),
],
help: fmt`${bold("Introduction")}
The cleaner module lets you delete large numbers of messages easily.
${bold("Commands")}
> purge (s (ALL))
Purges messages from the latest until the replied one, or as you mark with pto and/or pfrom. When the "s" flag is used, only messages sent by you will be deleted. You can also do "s ALL" to delete all of the messages sent by you.
> pfrom
Marks a message to purge from.
> pto
Marks a message to purge to.
> del, d
Deletes the replied message.`,
};
export default cleaner;