forked from wwosimulation/Narrator-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslash.js
125 lines (114 loc) · 5.75 KB
/
slash.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
120
121
122
123
124
125
const Discord = require("discord.js")
const db = require("quick.db")
const ms = require("ms")
const { ids } = require("./config")
const sim = ["465795320526274561"]
const game = ["472261911526768642"]
const both = [sim[0], game[0]]
const defaultOptions = {
private: false,
}
const allCommands = [
{
command: "ping",
description: "See the bot's ping",
server: both,
},
{
command: "stafflist",
description: "Regenerate the staff list",
server: sim,
},
{
command: "timer",
description: "Set a timer for a certain amount of time",
server: both,
options: [{ type: 3, name: "Time", description: "length of timer", required: true }],
},
{
command: "skip",
description: "Skip the discussion phase (only after day 5)",
server: game,
},
]
module.exports = (client) => {
const baseReply = (msg, interaction, options = {}) => {
for (let o in defaultOptions) {
if (!options[o]) options[o] = defaultOptions[o]
}
let sendData = { content: msg }
if (options.private) sendData.flags = 1 << 6
if (options.embeds) sendData.embeds = options.embeds
let data = { type: 4, data: sendData }
client.api.interactions(interaction.id, interaction.token).callback.post({ data })
}
client.on("ready", () => {
if (client.user.tag.toLowerCase().includes("beta")) return console.log("Beta bot detected... not loading slash commands")
console.log("Loading slash commands...")
allCommands.forEach((cmd) => {
cmd.server.forEach((x) => {
let data = {
name: cmd.command,
description: cmd.description,
}
if (cmd.options) data.options = cmd.options
client.guilds.cache.get(x)?.commands.create(data)
})
})
// client.ws.on("INTERACTION_CREATE", async (interaction) => {
// const command = interaction.data.name.toLowerCase()
// const args = interaction.data.options
// console.log(`Slash: ${command}`, args)
// client.channels.cache.get("832884582315458570").send(`Slash Command ran: **${command}**\nArguments: **${"None"}**\nAuthor: ${interaction.member.user.username}#${interaction.member.user.discriminator} (${interaction.member.user.id})`)
// if (command === "ping") return baseReply(`Pong! ${client.ws.ping} ms`, interaction)
// if (command === "stafflist") {
// let msg = `Only a staff member can regenerate the staff list!`
// if (!interaction.member.roles.includes(ids.staff) && !interaction.member.roles.includes(ids.afkstaff)) baseReply(`Only a staff member can regenerate the staff list!`, interaction)
// client.emit("stafflist")
// baseReply(`Done!`, interaction)
// }
// if (command == "timer") {
// let timer = ms(args[0].value)
// if (!timer) return message.channel.send("Invalid time format!")
// baseReply(`Setting the time for ${ms(timer)}`, interaction)
// setTimeout(function () {
// client.channels.cache.get(interaction.channel_id).send(`Time is up! <@${interaction.member.user.id}>`)
// }, timer)//.catch(e => message.channel.send(`Error: ${e.message}`))
// }
// if (command == "skip") {
// console.log(interaction)
// let channel = client.channels.cache.get(interaction.channel_id)
// let guild = client.guilds.cache.get(interaction.guild_id)
// if (!interaction.member.roles.includes(guild.roles.cache.find((r) => r.name === "Alive").id)) return baseReply(`You are not Alive! You cannot use this`, interaction, { private: true })
// let isDay = await db.fetch(`isDay_${guild.id}`)
// let day = await db.fetch(`dayCount_${guild.id}`)
// let vote = db.get(`commandEnabled_${guild.id}`)
// let skipus = db.get(`skipus_${interaction.member.user.id}`)
// if (day < 5) return baseReply("You can only skip after Day 5!", interaction, { private: true })
// if (isDay != "yes" || vote == "yes") {
// return baseReply("You can only skip the discussion phase during the day!", interaction, { private: true })
// }
// let alive = guild.roles.cache.find((r) => r.name === "Alive")
// if (alive.members.size > 8) {
// return baseReply("You can only skip the discussion phase if there are 8 or less players alive!", interaction, { private: true })
// } else {
// if (skipus == true) return baseReply("You already voted to skip the discussion phase!", interaction, { private: true })
// let dayChat = guild.channels.cache.find((c) => c.name === "day-chat")
// let commands = guild.channels.cache.find((c) => c.name === "commands")
// dayChat.send(`Someone voted to skip the discussion phase!`)
// commands.send(`${interaction.member.nick} decided to skip the discussion phase!`)
// db.add(`skippedpl`, 1)
// db.set(`skipus_${interaction.member.user.id}`, true)
// if (db.get(`skippedpl`) == alive.members.size - 1) {
// let message = new Discord.Message()
// message.slashGenerate = true
// message.guild = guild
// dayChat.send(`Enough players voted to skip the discussion phase!`)
// commands.send("Starting voting phase due to skips")
// client.commands.get("vt").run(message, ["nm", process.env.SHADOW], client)
// }
// }
// }
// })
})
}