Skip to content

Commit

Permalink
Fix reload command
Browse files Browse the repository at this point in the history
I think I fixed it by making CrystalClient have a static value in itself to throw around, but I need to test. Events reload, commands I haven't tested yet
  • Loading branch information
natereprogle committed Nov 15, 2023
1 parent f675c58 commit 601a2ae
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 181 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Bot",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/src/index.ts",
"preLaunchTask": "npm: build",
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"cwd": "${workspaceFolder}/out"
}
]
}
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "Build complete"
}
}
}
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "npm run build && cd out && node index.js",
"build": "tsc",
"prebuild": "rimraf ./out",
"postbuild": "echo ✅ Build complete",
"lint": "eslint ./src/**"
},
"keywords": [],
Expand Down
52 changes: 20 additions & 32 deletions src/modules/commands/dm.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
import { SlashCommandBuilder, type ChatInputCommandInteraction } from "discord.js";
import { type Command } from "../../types/Command";
import type CrystalClient from "../../types/CrystalClient";
import { SlashCommandBuilder, type ChatInputCommandInteraction } from "discord.js"
import { type Command } from "../../types/Command"
import type CrystalClient from "../../types/CrystalClient"

module.exports = {
name: 'dm',
name: "dm",
data: new SlashCommandBuilder()
.setName("dm")
.setDescription("Send a direct message to someone using the bot.")
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to message.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('message')
.setDescription("If you want to send a message type it here.")
.setRequired(false))
.addStringOption((option) =>
option
.setName('emojis')
.setDescription('The emoji(s) you want to react with.')
.setRequired(false))
.addAttachmentOption((option) =>
option
.setName('attachment')
.setDescription('The attachment you want to send.')
.setRequired(false))
.addStringOption((option) =>
option
.setName('message_id')
.setDescription('The message id you want to use.')
.setRequired(false)),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient): Promise<void> {

}
.addUserOption(option =>
option.setName("user").setDescription("The user you want to message.").setRequired(true)
)
.addStringOption(option =>
option.setName("message").setDescription("If you want to send a message type it here.").setRequired(false)
)
.addStringOption(option =>
option.setName("emojis").setDescription("The emoji(s) you want to react with.").setRequired(false)
)
.addAttachmentOption(option =>
option.setName("attachment").setDescription("The attachment you want to send.").setRequired(false)
)
.addStringOption(option =>
option.setName("message_id").setDescription("The message id you want to use.").setRequired(false)
),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient): Promise<void> {},
} satisfies Command
7 changes: 3 additions & 4 deletions src/modules/commands/hello.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { SlashCommandBuilder, type ChatInputCommandInteraction } from "discord.js"
import { type Command } from "../../types/Command"
import type CrystalClient from "../../types/CrystalClient"

module.exports = {
name: "hello",
data: new SlashCommandBuilder().setName("hello").setDescription("Say hello!"),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient) {
void await interaction.reply({
execute: async function (interaction: ChatInputCommandInteraction) {
void (await interaction.reply({
content: "Hey there!",
ephemeral: false,
})
}))
},
} satisfies Command
44 changes: 20 additions & 24 deletions src/modules/commands/message.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js";
import { type Command } from "../../types/Command";
import type CrystalClient from "../../types/CrystalClient";
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js"
import { type Command } from "../../types/Command"
import type CrystalClient from "../../types/CrystalClient"

module.exports = {
name: 'message',
name: "message",
data: new SlashCommandBuilder()
.setName("message")
.setDescription("Send a message using the bot.")
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('The channel to send the message to.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('message')
.setDescription('The message you want to send.')
.setRequired(true)),
.addChannelOption(option =>
option.setName("channel").setDescription("The channel to send the message to.").setRequired(true)
)
.addStringOption(option =>
option.setName("message").setDescription("The message you want to send.").setRequired(true)
),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient) {
const textChannel = interaction.options.getChannel('channel') as TextChannel
const botMessage = interaction.options.getString('message')
const textChannel = interaction.options.getChannel("channel") as TextChannel
const botMessage = interaction.options.getString("message")

try {
if (botMessage !== null) {
void await textChannel.send(botMessage)
void await interaction.reply({
void (await textChannel.send(botMessage))
void (await interaction.reply({
content: "Your message was sent.",
ephemeral: true
})
ephemeral: true,
}))
} else {
void await interaction.reply({
void (await interaction.reply({
content: "Your message could not get sent.",
ephemeral: true
})
ephemeral: true,
}))
}
} catch (error) {
console.error(error)
}
}
},
} satisfies Command
59 changes: 29 additions & 30 deletions src/modules/commands/pin.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js";
import { type Command } from "../../types/Command";
import type CrystalClient from "../../types/CrystalClient";
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js"
import { type Command } from "../../types/Command"
import type CrystalClient from "../../types/CrystalClient"

module.exports = {
name: 'pin',
name: "pin",
data: new SlashCommandBuilder()
.setName("pin")
.setDescription("pin a message using the bot.")
.addChannelOption((option) =>
.addChannelOption(option =>
option.setName("channel").setDescription("The channel you want to pin a message in.").setRequired(true)
)
.addStringOption(option =>
option
.setName('channel')
.setDescription('The channel you want to pin a message in.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('message_id')
.setDescription('The message you want to pin to using a message id.')
.setRequired(true)),
.setName("message_id")
.setDescription("The message you want to pin to using a message id.")
.setRequired(true)
),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient) {
const textChannel = interaction.options.getChannel('channel') as TextChannel
const messageId = interaction.options.getString('message_id')
const textChannel = interaction.options.getChannel("channel") as TextChannel
const messageId = interaction.options.getString("message_id")

try {
if (messageId !== null) {
const targetMessage = await textChannel.messages.fetch(messageId)

void await targetMessage.pin()
void await interaction.reply({
void (await targetMessage.pin())
void (await interaction.reply({
content: "Successfully pinned the message.",
ephemeral: true
})
ephemeral: true,
}))
} else {
void await interaction.reply({
void (await interaction.reply({
content: "Unsuccessfully pinned the message.",
ephemeral: true
})
ephemeral: true,
}))
}
} catch (error: any) {
switch (true) {
case error.message.includes('Unknown Message'):
void await interaction.reply({
case error.message.includes("Unknown Message"):
void (await interaction.reply({
content: "Unsuccessfully pinned the message: Invalid message id.",
ephemeral: true
})
ephemeral: true,
}))
break
default:
void await interaction.reply({
void (await interaction.reply({
content: "Unsuccessfully pinned the message.",
ephemeral: true
})
ephemeral: true,
}))

console.error(error)
}
}
}
},
} satisfies Command
81 changes: 39 additions & 42 deletions src/modules/commands/react.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js";
import { type Command } from "../../types/Command";
import type CrystalClient from "../../types/CrystalClient";
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js"
import { type Command } from "../../types/Command"
import type CrystalClient from "../../types/CrystalClient"

module.exports = {
name: 'react',
name: "react",
data: new SlashCommandBuilder()
.setName("react")
.setDescription("React to a message using the bot.")
.addChannelOption((option) =>
.addChannelOption(option =>
option.setName("channel").setDescription("The channel you want to react to.").setRequired(true)
)
.addStringOption(option =>
option
.setName('channel')
.setDescription('The channel you want to react to.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('message_id')
.setDescription('The message you want to react to using a message id.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('emojis')
.setDescription('The emoji(s) you want to react with.')
.setRequired(true)),
.setName("message_id")
.setDescription("The message you want to react to using a message id.")
.setRequired(true)
)
.addStringOption(option =>
option.setName("emojis").setDescription("The emoji(s) you want to react with.").setRequired(true)
),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient) {
const textChannel = interaction.options.getChannel('channel') as TextChannel
const messageId = interaction.options.getString('message_id')
const emojis = interaction.options.getString('emojis')
const textChannel = interaction.options.getChannel("channel") as TextChannel
const messageId = interaction.options.getString("message_id")
const emojis = interaction.options.getString("emojis")

try {
if ((emojis !== null) && (messageId !== null)) {
if (emojis !== null && messageId !== null) {
const targetMessage = await textChannel.messages.fetch(messageId)
const emojiArray = emojis.split(' ')
const emojiArray = emojis.split(" ")

for (const emoji of emojiArray) {
void await targetMessage.react(emoji.trim())
void (await targetMessage.react(emoji.trim()))
}

void await interaction.reply({
void (await interaction.reply({
content: "The reaction was successful.",
ephemeral: true
})
ephemeral: true,
}))
} else {
void await interaction.reply({
void (await interaction.reply({
content: "The reaction failed.",
ephemeral: true
})
ephemeral: true,
}))
}
} catch (error: any) {
switch (true) {
case error.message.includes('Unknown Message'):
void await interaction.reply({
case error.message.includes("Unknown Message"):
void (await interaction.reply({
content: "The reaction failed: Invalid message id.",
ephemeral: true
})
ephemeral: true,
}))
break
case error.message.includes('Unknown Emoji'):
void await interaction.reply({
case error.message.includes("Unknown Emoji"):
void (await interaction.reply({
content: "The reaction failed: Invalid emoji(s).",
ephemeral: true
})
ephemeral: true,
}))
break
default:
void await interaction.reply({
void (await interaction.reply({
content: "The reaction failed.",
ephemeral: true
})
ephemeral: true,
}))

console.error(error)
}
}
}
},
} satisfies Command
Loading

0 comments on commit 601a2ae

Please sign in to comment.