Compare commits

..

No commits in common. "a60f35459c125aa98cd3a0afca582a7ecf068b95" and "cd447b703a29126bbab72077965133ccaa16964a" have entirely different histories.

10 changed files with 767 additions and 841 deletions

View File

@ -17,16 +17,15 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@discordjs/rest": "^0.3.0", "@discordjs/rest": "^0.1.0-canary.0",
"axios": "^0.26.0", "axios": "^0.24.0",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"discord-api-types": "^0.27.3", "discord-api-types": "^0.24.0",
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"dotenv": "^16.0.0", "dotenv": "^10.0.0",
"eslint": "^8.2.0", "eslint": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"ical-generator": "^3.2.1",
"jest": "^27.3.1", "jest": "^27.3.1",
"typescript": "^4.4.4", "typescript": "^4.4.4",
"winston": "^3.3.3" "winston": "^3.3.3"

View File

@ -1,22 +1,22 @@
import { REST } from '@discordjs/rest' import { REST } from '@discordjs/rest'
import { Routes } from 'discord-api-types/v9' import { Routes } from 'discord-api-types/v9'
import { config } from './configuration' import { config } from './configuration'
import { Client, CommandInteraction, Intents, } from 'discord.js' import { Client, Collection, CommandInteraction, GuildMember, GuildScheduledEvent, GuildScheduledEventManager, Intents, Snowflake } from 'discord.js'
import RegistrationHandler from './RegistrationHandler'
import { discordCommand } from './interfaces' import { discordCommand } from './interfaces'
import eventHandler from './eventHandler' import eventHandler from './eventHandler'
import fs from 'fs'
export default class DiscordAdapter { export default class DiscordAdapter {
private rest: REST private rest: REST
private client: Client private client: Client
private eventFilePath = `${__dirname}/events` private registration: RegistrationHandler
public constructor() { public constructor() {
this.rest = new REST({ version: '9' }).setToken(config.token) this.rest = new REST({ version: '9' }).setToken(config.token)
this.client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_SCHEDULED_EVENTS] }) this.client = new Client({ intents: [Intents.FLAGS.GUILDS] })
this.registerEventCallback().then(() => { this.registration = RegistrationHandler.Instance
this.setupCallbacks(this.client)
this.client.login(config.token) this.client.login(config.token)
})
this.registerCommands(this.commandList) this.registerCommands(this.commandList)
} }
public async registerCommands(pCommands: discordCommand[]) { public async registerCommands(pCommands: discordCommand[]) {
@ -28,31 +28,16 @@ export default class DiscordAdapter {
console.log(`Error refreshing slash commands: ${error}`) console.log(`Error refreshing slash commands: ${error}`)
} }
} }
private async importFile(filepath: string): Promise<any> { private setupCallbacks(c: Client) {
console.debug(`Importing ${filepath}`) c.on('ready', () => {
const imported = await import(filepath) console.log(`Logged in as ${c.user?.tag}`)
console.debug(`Imported ${JSON.stringify(imported)}`) })
return imported c.on('interactionCreate', async interaction => {
} if (!interaction.isCommand()) return
public async registerEventCallback() { const interactionCommand = this.commandList.find(x => x.name == interaction.commandName)
try { if (interactionCommand)
const eventFiles = fs.readdirSync(this.eventFilePath).filter(file => file.endsWith('.ts') || file.endsWith('.js')); interactionCommand.performCommand(interaction, this.registration)
for (const file of eventFiles) { })
const filePath = `${this.eventFilePath}/${file}`
const event = await this.importFile(filePath)
if (event.once) {
console.log(`Registering once ${file}`)
this.client.once(event.name, (...args: any[]) => event.execute(...args))
}
else {
console.log(`Registering on ${file}`)
this.client.on(event.name, (...args: any[]) => event.execute(...args))
}
}
console.log(this.client.eventNames())
} catch (error) {
console.error(error)
}
} }
public async showNext(interaction: CommandInteraction): Promise<void> { public async showNext(interaction: CommandInteraction): Promise<void> {
const guild = interaction.guild const guild = interaction.guild

View File

@ -1,5 +0,0 @@
export const name = 'channelCreate'
export function execute(channel: any) {
console.log(`${JSON.stringify(channel)} has been Created.`)
}

View File

@ -1,9 +0,0 @@
import { GuildScheduledEvent } from 'discord.js'
export const name = 'guildScheduledEventCreate'
export function execute(guildScheduledEvent: GuildScheduledEvent) {
try{
console.log(`${JSON.stringify(guildScheduledEvent)} has been created.`)
}catch(error) {
console.error(error)
}
}

View File

@ -1,4 +0,0 @@
export const name = 'guildScheduledEventDelete'
export function execute(guildScheduledEvent: any) {
console.log(`${JSON.stringify(guildScheduledEvent)} has been Deleted.`)
}

View File

@ -1,4 +0,0 @@
export const name = 'guildScheduledEventUpdate'
export function execute(oldguildScheduledEvent: any,newguildScheduledEvent: any) {
console.log(`${JSON.stringify(oldguildScheduledEvent)} has been Updated to be ${newguildScheduledEvent}`)
}

View File

@ -1,4 +0,0 @@
export const name = 'messageCreate'
export function execute(message: any) {
console.log(`${JSON.stringify(message)} has been created`)
}

View File

@ -1,4 +0,0 @@
export const name = 'ready'
export function execute(client: any) {
console.log(`${JSON.stringify(client)} has been created.`)
}

View File

@ -39,13 +39,13 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */ /* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */ // "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */ // "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

1516
yarn.lock

File diff suppressed because it is too large Load Diff