-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.ts
92 lines (79 loc) · 2.1 KB
/
generate.ts
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
import { Sabr, SabrTable } from "https://deno.land/x/[email protected]/mod.ts";
import {
cache,
startBot,
ws,
} from "https://deno.land/x/[email protected]/mod.ts";
import { TOKEN } from "./configs.ts";
import {
hideDate,
hideEUDText,
hideHash,
hideSnowflake,
loopObject,
} from "./utils.ts";
const sabr = new Sabr();
// Creates a db object that can be imported in other files.
export const db = {
// This will allow us to access table methods easily as we will see below.
sabr,
// Sets up a table. If this table did not exist, it will create one.
events: new SabrTable(sabr, "events"),
};
// This is important as it prepares all the tables.
await sabr.init();
let counter = 1;
const payloads = new Map<number, any>();
startBot({
token: TOKEN,
intents: [
"DirectMessageReactions",
"DirectMessages",
"GuildBans",
"GuildEmojis",
"GuildInvites",
"GuildMembers",
"GuildMessageReactions",
"GuildMessages",
"GuildVoiceStates",
"Guilds",
],
eventHandlers: {
raw: async function (data) {},
},
});
ws.log = function (type, data: any) {
if (type !== "RAW") return;
const payload = data as any;
const numberreg = /^\d+$/;
const cleanPayload = loopObject(payload, (value, key) => {
if (typeof value !== "string") return value;
// IF ITS A NUMBER MASK NUMBER
if (numberreg.test(value)) return hideSnowflake(value);
if (["icon", "banner", "splash", "avatar"].includes(key)) {
return hideHash(value);
}
// IF ITS DATE REGEX
if (Date.parse(value)) return hideDate();
return hideEUDText(value);
});
console.log("Creating Event #", counter, payload.payload.t);
if (cache.isReady) {
payloads.set(counter, {
...cleanPayload,
payload: { ...cleanPayload.payload, t: payload.payload.t },
});
if (payloads.size === 1000) {
db.events.create(counter.toString(), [...payloads.values()]);
payloads.clear();
}
} else {
db.events.create(counter.toString(), [
{
...cleanPayload,
payload: { ...cleanPayload.payload, t: payload.payload.t },
},
]);
}
counter++;
};