Compare commits

...

5 Commits

Author SHA1 Message Date
mightypanders
a60f35459c use event handling code
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-03-05 01:24:22 +01:00
mightypanders
03d9b43c44 add event handling code 2022-03-05 01:24:05 +01:00
mightypanders
6ce9d8db46 lock 2022-03-05 01:23:50 +01:00
mightypanders
bbbefc8a6c update tsconfig 2022-03-05 01:23:38 +01:00
mightypanders
54fc2f4ab6 update all packages 2022-03-05 01:23:18 +01:00
10 changed files with 840 additions and 766 deletions

View File

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

View File

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

View File

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

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

View File

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

View 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}`)
}

View 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
View File

@ -0,0 +1,4 @@
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. */
/* 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. */
// "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. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "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'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

1514
yarn.lock

File diff suppressed because it is too large Load Diff