-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
66 lines (62 loc) · 2.9 KB
/
bot.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
const token = require("./auth.json").token;
const Discord = require("discord.js");
const client = new Discord.Client();
function formatTimestamp(timestamp) {
let date = new Date(timestamp);
date = date.getDate().toLocaleString(undefined, {minimumIntegerDigits: 2})
+ "." + date.getMonth().toLocaleString(undefined, {minimumIntegerDigits: 2})
+ "." + date.getFullYear()
+ " at " + date.getHours().toLocaleString(undefined, {minimumIntegerDigits: 2})
+ ":" + date.getMinutes().toLocaleString(undefined, {minimumIntegerDigits: 2});
return date;
}
client.on("message", async (message) => {
if (message.author.bot) return;
if (message.channel.id === "864878446647050257") {
if (!message.content.startsWith("!!")) {
//message is a question
let question = new Discord.MessageEmbed()
.setColor("8c8c8c") // grey - submitted, not answered
.setTitle("Q: " + message.content)
.setDescription("*Not answered yet... Please be patient.*")
.setFooter("Asked on " + formatTimestamp(message.createdTimestamp))
message.channel.send(question);
message.delete();
}
else {
//message is an answer
//!!should check if author is stuco member
if (message.content.startsWith("!!answer")) {
if (message.reference != null) {
let answer = message.content.slice(9);
let name = "Anonymous";
let msg = await message.channel.messages.fetch(message.reference.messageID);
let embed = msg.embeds[0]
.addField(name, "A: " + answer, false)
.setColor("00cc00") // green - answered
.setDescription('')
.setFooter(msg.embeds[0].footer.text + "\nAnswered on " + formatTimestamp(message.createdTimestamp))
msg.edit(embed);
message.delete();
}
}
if (message.content.startsWith("!!lock")) {
if (message.reference != null) {
let msg = await message.channel.messages.fetch(message.reference.messageID);
let embed = msg.embeds[0]
if (embed.fields.length === 0) {
embed.setColor("cc0000"); //red - locked, no answer
} else {
embed.setColor("#e69500"); //orange - locked, answered
}
embed
.setDescription("*This question has been locked.*")
.setFooter(msg.embeds[0].footer.text + "\nLocked on " + formatTimestamp(message.createdTimestamp))
msg.edit(embed);
message.delete();
}
}
}
}
});
client.login(token);