-
Notifications
You must be signed in to change notification settings - Fork 0
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 #6 from tannnxr/dev
Pushing new commits to prod
- Loading branch information
Showing
10 changed files
with
5,190 additions
and
1,693 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
.env | ||
build | ||
dist | ||
db | ||
db | ||
/tests/.env |
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,6 @@ | ||
module.exports = { | ||
transform: {'^.+\\.ts?$': 'ts-jest'}, | ||
testEnvironment: 'node', | ||
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] | ||
}; |
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { BaseInteraction, Events, InteractionType, TextChannel } from "discord.js"; | ||
import { Shork } from "../../Shork"; | ||
import { getChannel } from "../../utils/channel"; | ||
import { shorkCache } from "../../db/cache"; | ||
|
||
import { getCommandFiles } from "../../utils/commands"; | ||
|
||
export default { | ||
name: Events.InteractionCreate, | ||
execute: (interaction: BaseInteraction) => { | ||
execute: async (interaction: BaseInteraction) => { | ||
if (interaction.type == InteractionType.ApplicationCommand) { | ||
getCommandFiles() | ||
const redisCmdFiles = await shorkCache.get('commandFiles') | ||
if (!redisCmdFiles) { | ||
getCommandFiles() | ||
} | ||
|
||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// bot.test.js | ||
import { Client, GatewayIntentBits } from 'discord.js'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config() | ||
|
||
describe('Bot Login', () => { | ||
test('should log in successfully', async () => { | ||
// Create a mock client with real login method | ||
const mockClient = new Client({ | ||
intents: [ | ||
GatewayIntentBits.Guilds, | ||
GatewayIntentBits.GuildMembers, | ||
GatewayIntentBits.GuildModeration, | ||
GatewayIntentBits.GuildMessages, | ||
GatewayIntentBits.MessageContent, | ||
], | ||
}); | ||
|
||
// Call the actual login method with the provided token | ||
const loginResult = await mockClient.login(process.env.TOKEN); | ||
|
||
// Assert that the login was successful | ||
expect(loginResult).toBeTruthy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import path from "path"; | ||
import fs from 'fs'; | ||
import { rootDir } from "../main"; | ||
import { LogType, Logger } from "./logging"; | ||
import { shorkCache } from "../db/cache"; | ||
|
||
import { getFilesRecursively } from "./files"; | ||
|
||
const logger = new Logger(__filename, LogType.DEBUG) | ||
|
||
export async function getCommandFiles() { | ||
const cmdDir = path.join(rootDir, 'commands') | ||
if (!fs.existsSync(cmdDir)) { | ||
logger.log(`Directory '${cmdDir}' does not exist. Failing.`, LogType.ERROR) | ||
process.exit() | ||
} | ||
|
||
const commandFiles = await getFilesRecursively(cmdDir) | ||
|
||
const filteredCommands = commandFiles.filter(file => (file.endsWith('.js') || file.endsWith('.ts')) && !file.endsWith('.d.ts')); | ||
|
||
export function getCommandFiles() { | ||
const workingDir = __filename; | ||
logger.log(`${workingDir}`, LogType.DEBUG) | ||
shorkCache.set('commandFiles', JSON.stringify(filteredCommands)) | ||
} |
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,19 @@ | ||
import { readdir, stat } from "fs/promises"; | ||
import path from "path"; | ||
async function getFilesRecursively(directory: string): Promise<string[]> { | ||
const files = await readdir(directory); | ||
const filePaths = await Promise.all( | ||
files.map(async (file) => { | ||
const filePath = path.join(directory, file); | ||
const fileStat = await stat(filePath); | ||
if (fileStat.isDirectory()) { | ||
return getFilesRecursively(filePath); | ||
} else { | ||
return filePath; | ||
} | ||
}) | ||
); | ||
return filePaths.flat(); | ||
} | ||
|
||
export { getFilesRecursively }; |