-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
119 lines (98 loc) · 3.09 KB
/
main.js
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
118
119
import {
createBot, startBot, editBotStatus, sendMessage, GatewayIntents, ActivityTypes
} from "https://deno.land/x/[email protected]/mod.ts";
import { enableCachePlugin, enableCacheSweepers }
from "https://deno.land/x/[email protected]/mod.ts";
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import {
parse, text, fetchLog, log, executeTasks, dispatch, reloadActions
} from "./parser.js";
import { Channels, Welcome, Time, Icon, TwitchIcon } from "./config.js";
import { Database } from "./database.js";
import { quote_of_the_day } from "./components/quote.js";
export const PID = Math.floor(Math.random() * 10000);
log("status", "PID " + PID);
// ==== Attachments ========================
import "./attachments/pgn.js";
// ==== Tasks ==============================
//import "./tasks/quote.js";
import "./tasks/schedule.js";
import "./tasks/youtube.js";
import "./tasks/twitch.js";
import "./tasks/reddit.js";
import "./tasks/sweep.js";
import "./tasks/welcome.js";
// ==== Commands ===========================
import "./commands/actions.js";
import "./commands/clear.js";
import "./commands/diagram.js";
import "./commands/links.js";
import "./commands/poll.js";
import "./commands/rating.js";
import "./commands/system.js";
// =========================================
export function setQuoteAction() {
console.log("Setting quote action.");
const quote = quote_of_the_day();
editBotStatus(bot, {
activities: [{
name: 'thechessnerdlive',
type: ActivityTypes.Watching,
createdAt: Date.now(),
/*assets: {
largeImage: Icon,
largeText: 'The Chess Nerd',
smallImage: TwitchIcon,
smallText: 'Watching the stream.'
},
buttons: [{
label: '💜 Watch Together',
url: 'https://www.twitch.tv/thechessnerdlive',
}],*/
url: 'https://www.twitch.tv/thechessnerdlive',
}],
since: Date.now(), afk: false, status: 'online'
});
}
const baseBot = createBot({
botId: Deno.env.get("ID"),
token: Deno.env.get("TOKEN"),
intents: (
GatewayIntents.Guilds |
GatewayIntents.GuildMembers |
GatewayIntents.GuildMessages |
GatewayIntents.GuildIntegrations |
GatewayIntents.MessageContent
),
events: {
messageCreate(_bot, message) { parse(message); },
guildMemberAdd(bot, member, _) {
const message = Welcome[Math.floor(Math.random() * Welcome.length)];
sendMessage(
bot, Channels.general,
text(`**Welcome** <@${member.id}>, ${message}`)
).then(({ id }) => Database.push("welcome", {
id: id.toString(), time: Date.now()
}));
},
interactionCreate(_bot, interaction) { dispatch(interaction); }
}
});
export const bot = enableCachePlugin(baseBot);
enableCacheSweepers(bot);
log("status", "en-passant ready");
setQuoteAction();
// =========================================
// web server for constant uptime:
serve(_request => {
return new Response(fetchLog(), {
headers: { "Content-Type": "text/plain" },
status: 200
});
});
log("status", "web server ready");
// tasks interval:
setInterval(executeTasks, Time.minute);
// =========================================
reloadActions();
await startBot(bot);