Skip to content

Commit

Permalink
Merge pull request #6 from tannnxr/dev
Browse files Browse the repository at this point in the history
Pushing new commits to prod
  • Loading branch information
tannnxr authored May 28, 2024
2 parents 7f08e03 + 854e879 commit f36c941
Show file tree
Hide file tree
Showing 10 changed files with 5,190 additions and 1,693 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
.env
build
dist
db
db
/tests/.env
6 changes: 6 additions & 0 deletions jest.config.js
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']
};
6,781 changes: 5,098 additions & 1,683 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
"cld": "^2.9.1",
"discord.js": "^14.15.2",
"dotenv": "^16.4.5",
"pouchdb": "^8.0.1"
"pouchdb": "^8.0.1",
"redis": "^4.6.14"
},
"devDependencies": {
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^9.0.0",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"globals": "^15.0.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.3",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion src/events/client/onReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
name: Events.ClientReady,
execute: (client: Shork) => {
const logger = new Logger(__filename, LogType.DEBUG)
logger.log("Client is ready.");
logger.log("Client is ready.", LogType.SUCCESS);
const logChannel = getChannel(client, "1243357415852867604");
const clientReadyAt = client.readyAt;
const embed = new EmbedBuilder()
Expand Down
9 changes: 7 additions & 2 deletions src/events/interactions/interactionCreate.ts
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";

Check failure on line 4 in src/events/interactions/interactionCreate.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../db/cache' or its corresponding type declarations.

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()
}

}
}
}
12 changes: 10 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Shork } from "./Shork";
import { GatewayIntentBits } from "discord.js";
import dotenv from "dotenv";
import { Logger, LogType } from "./utils/logging";

dotenv.config()
dotenv.config();

const logger = new Logger(__filename, LogType.DEBUG);

const SHORK = new Shork({
intents: [
Expand All @@ -12,7 +15,12 @@ const SHORK = new Shork({
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});

process.on('exit', (errCode) => {
logger.log(`Process Exiting (${errCode})`, LogType.ERROR);
})

export const rootDir = __dirname;

SHORK.login(process.env.TOKEN)
SHORK.login(process.env.TOKEN);
26 changes: 26 additions & 0 deletions src/tests/clientLogin.test.ts
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();
});
});
19 changes: 16 additions & 3 deletions src/utils/commands.ts
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";

Check failure on line 5 in src/utils/commands.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../db/cache' or its corresponding type declarations.

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))
}
19 changes: 19 additions & 0 deletions src/utils/files.ts
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 };

0 comments on commit f36c941

Please sign in to comment.