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
|
import { InteractionResponseType } from "discord-interactions";
import { Message } from "./message-scheduler.js";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import { get } from "https";
function send(state, data) {
return state.res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: data,
});
}
export function schedule_message(state, msg, channel, crontab) {
const message = new Message(msg, channel, crontab);
const schedule_valid = state.schedule.schedule(message);
const cancel = new ButtonBuilder()
.setCustomId(`stop-${message.id}`)
.setLabel("Cancel")
.setStyle(ButtonStyle.Secondary);
return send(state, {
content: schedule_valid
? `registered message: "${msg}" with cron: "${crontab}"`
: "invalid cron",
components: [new ActionRowBuilder().addComponents(cancel)],
});
}
export function pet(state) {
return send(state, { content: "[purring noises]" });
}
export function help(state) {
return send(state, {
content: `Hi, I'm sily-bot!
Here are the available commands and their descriptions:
- \`/blep\` blep.
- \`/catfact\` Get a fact about cats.
- \`/fomx\` Get an image of a fox.
- \`/help\` Show this message.
- \`/pet\` You can pet sily-bot.
- \`/schedule-message <message> <cron>\` Schedule a message to be send later. Works like Linux cron jobs in the format second minute hour day month weekday. Put the number (or name of month or weekday) in each spot. If you want it to run every second, minute, etc. instead of once when it reaches the provided number, use a \`*\` instead of a number. For instance, to run a job every minute on January 4th, you might use \`0 * * 4 January *\`.`,
});
}
export function blep(state) {
return send(state, { content: "≽^•𐃷•^≼" });
}
export function catfact(state) {
get("https://meowfacts.herokuapp.com/", (res) => {
res.on("data", (d) => {
const obj = JSON.parse(d);
const fact = obj.data[0];
return send(state, { content: fact });
});
}).on("error", (e) => {
console.error(e);
return send(state, { content: "failed to request fact" });
});
}
export function fomx(state) {
get("https://randomfox.ca/floof/", (res) => {
res.on("data", (d) => {
const obj = JSON.parse(d);
const fomx = obj.image;
return send(state, { content: fomx });
});
}).on("error", (e) => {
console.error(e);
return send(state, { content: "failed to get fomx" });
});
}
export function factcheck(state, truth) {
if (truth) return send(state, { content: "true" });
else return send(state, { content: "false" });
}
|