-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from IgorKowalczyk/v4
Typescript rewrite
- Loading branch information
Showing
16 changed files
with
545 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ActivityType, Client, TextChannel } from "discord.js"; | ||
import { logger } from "../../utils/logger.js"; | ||
import { defaultConfig } from "../../config.js"; | ||
|
||
export async function ready(client: Client): Promise<void> { | ||
try { | ||
logger("ready", `Logged in as ${client.user?.tag}! (ID: ${client.user?.id})`); | ||
if (!defaultConfig.channel) return logger("error", "Channel not found! Please check your CHANNEL_ID .env variable."); | ||
const channel = client.channels.cache.get(defaultConfig.channel) as TextChannel; | ||
logger("ready", `Watching for commands in ${channel.guild.name}#${channel.name}`); | ||
client.user?.setActivity("👀 Watching all ports!", { type: ActivityType.Custom }); | ||
} catch (error) { | ||
logger("error", `Error setting activity: ${error}`); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { Client, EmbedBuilder, Message, TextChannel } from "discord.js"; | ||
import { defaultConfig } from "../../config.js"; | ||
import { execCommand } from "../../utils/execCommand.ts"; | ||
import { logger } from "../../utils/logger.js"; | ||
|
||
export async function messageCreate(client: Client, message: Message): Promise<void | Message<boolean>> { | ||
try { | ||
if (message.author.bot) return; | ||
if (!(message.channel instanceof TextChannel)) return; | ||
if (message.channel.id !== defaultConfig.channel && !defaultConfig.owners.includes(message.author.id)) return; | ||
if (!message.content) return; | ||
|
||
const [command, ...args] = message.content.split(" "); | ||
|
||
if (command === "cd") { | ||
const newCWD = args.join(" "); | ||
if (!newCWD) return; | ||
|
||
const resolvedPath = path.resolve(defaultConfig.cwd, newCWD); | ||
if (!fs.existsSync(resolvedPath)) { | ||
const error = new EmbedBuilder() // prettier | ||
.setDescription(`${defaultConfig.emojis.error} **Directory does not exist**`) | ||
.setColor(defaultConfig.embedColor); | ||
return message.reply({ embeds: [error] }); | ||
} | ||
|
||
try { | ||
process.chdir(resolvedPath); | ||
defaultConfig.debugger.changeDir && logger("event", `Changed directory from ${defaultConfig.cwd} to ${resolvedPath}`); | ||
|
||
const changedDirectory = new EmbedBuilder() // prettier | ||
.setDescription(`${defaultConfig.emojis.change} **Changed directory from \`${defaultConfig.cwd}\` to \`${resolvedPath}\`**`) | ||
.setColor(defaultConfig.embedColor); | ||
|
||
defaultConfig.cwd = resolvedPath; | ||
return message.reply({ embeds: [changedDirectory] }); | ||
} catch (error) { | ||
defaultConfig.debugger.changeDir && logger("error", `Error changing directory: ${error}`); | ||
const errorEmbed = new EmbedBuilder() // prettier | ||
.setDescription(`${defaultConfig.emojis.error} **Error changing directory**`) | ||
.setColor(defaultConfig.embedColor); | ||
|
||
return message.reply({ embeds: [errorEmbed] }); | ||
} | ||
} | ||
|
||
const wait = new EmbedBuilder() // prettier | ||
.setDescription(`${defaultConfig.emojis.loading} **Waiting for server response...**`) | ||
.setColor(defaultConfig.embedColor); | ||
|
||
await message.reply({ embeds: [wait] }); | ||
|
||
await execCommand(client, message.content); | ||
} catch (error) { | ||
logger("error", `Error executing command: ${error}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.