Compare commits
5 Commits
cd447b703a
...
a60f35459c
Author | SHA1 | Date | |
---|---|---|---|
|
a60f35459c | ||
|
03d9b43c44 | ||
|
6ce9d8db46 | ||
|
bbbefc8a6c | ||
|
54fc2f4ab6 |
@ -17,15 +17,16 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/rest": "^0.1.0-canary.0",
|
"@discordjs/rest": "^0.3.0",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.26.0",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"discord-api-types": "^0.24.0",
|
"discord-api-types": "^0.27.3",
|
||||||
"discord.js": "^13.6.0",
|
"discord.js": "^13.6.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^16.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"
|
||||||
|
@ -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, Collection, CommandInteraction, GuildMember, GuildScheduledEvent, GuildScheduledEventManager, Intents, Snowflake } from 'discord.js'
|
import { Client, CommandInteraction, Intents, } 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 registration: RegistrationHandler
|
private eventFilePath = `${__dirname}/events`
|
||||||
|
|
||||||
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] })
|
this.client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_SCHEDULED_EVENTS] })
|
||||||
this.registration = RegistrationHandler.Instance
|
this.registerEventCallback().then(() => {
|
||||||
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,16 +28,31 @@ export default class DiscordAdapter {
|
|||||||
console.log(`Error refreshing slash commands: ${error}`)
|
console.log(`Error refreshing slash commands: ${error}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private setupCallbacks(c: Client) {
|
private async importFile(filepath: string): Promise<any> {
|
||||||
c.on('ready', () => {
|
console.debug(`Importing ${filepath}`)
|
||||||
console.log(`Logged in as ${c.user?.tag}`)
|
const imported = await import(filepath)
|
||||||
})
|
console.debug(`Imported ${JSON.stringify(imported)}`)
|
||||||
c.on('interactionCreate', async interaction => {
|
return imported
|
||||||
if (!interaction.isCommand()) return
|
}
|
||||||
const interactionCommand = this.commandList.find(x => x.name == interaction.commandName)
|
public async registerEventCallback() {
|
||||||
if (interactionCommand)
|
try {
|
||||||
interactionCommand.performCommand(interaction, this.registration)
|
const eventFiles = fs.readdirSync(this.eventFilePath).filter(file => file.endsWith('.ts') || file.endsWith('.js'));
|
||||||
})
|
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
|
||||||
|
5
server/events/channelCreate.ts
Normal file
5
server/events/channelCreate.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
export const name = 'channelCreate'
|
||||||
|
export function execute(channel: any) {
|
||||||
|
console.log(`${JSON.stringify(channel)} has been Created.`)
|
||||||
|
}
|
9
server/events/guildScheduledEventCreate.ts
Normal file
9
server/events/guildScheduledEventCreate.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
4
server/events/guildScheduledEventDelete.ts
Normal file
4
server/events/guildScheduledEventDelete.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const name = 'guildScheduledEventDelete'
|
||||||
|
export function execute(guildScheduledEvent: any) {
|
||||||
|
console.log(`${JSON.stringify(guildScheduledEvent)} has been Deleted.`)
|
||||||
|
}
|
4
server/events/guildScheduledEventUpdate.ts
Normal file
4
server/events/guildScheduledEventUpdate.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const name = 'guildScheduledEventUpdate'
|
||||||
|
export function execute(oldguildScheduledEvent: any,newguildScheduledEvent: any) {
|
||||||
|
console.log(`${JSON.stringify(oldguildScheduledEvent)} has been Updated to be ${newguildScheduledEvent}`)
|
||||||
|
}
|
4
server/events/messageCreate.ts
Normal file
4
server/events/messageCreate.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const name = 'messageCreate'
|
||||||
|
export function execute(message: any) {
|
||||||
|
console.log(`${JSON.stringify(message)} has been created`)
|
||||||
|
}
|
4
server/events/ready.ts
Normal file
4
server/events/ready.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const name = 'ready'
|
||||||
|
export function execute(client: any) {
|
||||||
|
console.log(`${JSON.stringify(client)} has been created.`)
|
||||||
|
}
|
@ -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. */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user