-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ActionsManager): revert to manual requires (#7034)
- Loading branch information
Showing
5 changed files
with
146 additions
and
94 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../.eslintrc.json", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
} |
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,41 @@ | ||
import { readdir, writeFile } from 'node:fs/promises'; | ||
import { Constants } from '../src/index.js'; | ||
|
||
async function writeWebsocketHandlerImports() { | ||
const lines = ["'use strict';\n", 'const handlers = Object.fromEntries([']; | ||
|
||
for (const name of Object.keys(Constants.WSEvents)) { | ||
lines.push(` ['${name}', require('./${name}')],`); | ||
} | ||
|
||
lines.push(']);\n\nmodule.exports = handlers;\n'); | ||
|
||
const outputFile = new URL('../src/client/websocket/handlers/index.js', import.meta.url); | ||
|
||
await writeFile(outputFile, lines.join('\n')); | ||
} | ||
|
||
async function writeClientActionImports() { | ||
const lines = ["'use strict';\n", 'class ActionsManager {', ' constructor(client) {', ' this.client = client;\n']; | ||
|
||
const actionsDirectory = new URL('../src/client/actions', import.meta.url); | ||
for (const file of (await readdir(actionsDirectory)).sort()) { | ||
if (file === 'Action.js' || file === 'ActionsManager.js') continue; | ||
|
||
lines.push(` this.register(require('./${file.slice(0, -3)}'));`); | ||
} | ||
|
||
lines.push(' }\n'); | ||
lines.push(' register(Action) {'); | ||
lines.push(" this[Action.name.replace(/Action$/, '')] = new Action(this.client);"); | ||
lines.push(' }'); | ||
lines.push('}\n'); | ||
lines.push('module.exports = ActionsManager;\n'); | ||
|
||
const outputFile = new URL('../src/client/actions/ActionsManager.js', import.meta.url); | ||
|
||
await writeFile(outputFile, lines.join('\n')); | ||
} | ||
|
||
writeWebsocketHandlerImports(); | ||
writeClientActionImports(); |
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,11 +1,56 @@ | ||
'use strict'; | ||
|
||
const { WSEvents } = require('../../../util/Constants'); | ||
|
||
const handlers = {}; | ||
|
||
for (const name of Object.keys(WSEvents)) { | ||
handlers[name] = require(`./${name}.js`); | ||
} | ||
const handlers = Object.fromEntries([ | ||
['READY', require('./READY')], | ||
['RESUMED', require('./RESUMED')], | ||
['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')], | ||
['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')], | ||
['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')], | ||
['GUILD_CREATE', require('./GUILD_CREATE')], | ||
['GUILD_DELETE', require('./GUILD_DELETE')], | ||
['GUILD_UPDATE', require('./GUILD_UPDATE')], | ||
['INVITE_CREATE', require('./INVITE_CREATE')], | ||
['INVITE_DELETE', require('./INVITE_DELETE')], | ||
['GUILD_MEMBER_ADD', require('./GUILD_MEMBER_ADD')], | ||
['GUILD_MEMBER_REMOVE', require('./GUILD_MEMBER_REMOVE')], | ||
['GUILD_MEMBER_UPDATE', require('./GUILD_MEMBER_UPDATE')], | ||
['GUILD_MEMBERS_CHUNK', require('./GUILD_MEMBERS_CHUNK')], | ||
['GUILD_INTEGRATIONS_UPDATE', require('./GUILD_INTEGRATIONS_UPDATE')], | ||
['GUILD_ROLE_CREATE', require('./GUILD_ROLE_CREATE')], | ||
['GUILD_ROLE_DELETE', require('./GUILD_ROLE_DELETE')], | ||
['GUILD_ROLE_UPDATE', require('./GUILD_ROLE_UPDATE')], | ||
['GUILD_BAN_ADD', require('./GUILD_BAN_ADD')], | ||
['GUILD_BAN_REMOVE', require('./GUILD_BAN_REMOVE')], | ||
['GUILD_EMOJIS_UPDATE', require('./GUILD_EMOJIS_UPDATE')], | ||
['CHANNEL_CREATE', require('./CHANNEL_CREATE')], | ||
['CHANNEL_DELETE', require('./CHANNEL_DELETE')], | ||
['CHANNEL_UPDATE', require('./CHANNEL_UPDATE')], | ||
['CHANNEL_PINS_UPDATE', require('./CHANNEL_PINS_UPDATE')], | ||
['MESSAGE_CREATE', require('./MESSAGE_CREATE')], | ||
['MESSAGE_DELETE', require('./MESSAGE_DELETE')], | ||
['MESSAGE_UPDATE', require('./MESSAGE_UPDATE')], | ||
['MESSAGE_DELETE_BULK', require('./MESSAGE_DELETE_BULK')], | ||
['MESSAGE_REACTION_ADD', require('./MESSAGE_REACTION_ADD')], | ||
['MESSAGE_REACTION_REMOVE', require('./MESSAGE_REACTION_REMOVE')], | ||
['MESSAGE_REACTION_REMOVE_ALL', require('./MESSAGE_REACTION_REMOVE_ALL')], | ||
['MESSAGE_REACTION_REMOVE_EMOJI', require('./MESSAGE_REACTION_REMOVE_EMOJI')], | ||
['THREAD_CREATE', require('./THREAD_CREATE')], | ||
['THREAD_UPDATE', require('./THREAD_UPDATE')], | ||
['THREAD_DELETE', require('./THREAD_DELETE')], | ||
['THREAD_LIST_SYNC', require('./THREAD_LIST_SYNC')], | ||
['THREAD_MEMBER_UPDATE', require('./THREAD_MEMBER_UPDATE')], | ||
['THREAD_MEMBERS_UPDATE', require('./THREAD_MEMBERS_UPDATE')], | ||
['USER_UPDATE', require('./USER_UPDATE')], | ||
['PRESENCE_UPDATE', require('./PRESENCE_UPDATE')], | ||
['TYPING_START', require('./TYPING_START')], | ||
['VOICE_STATE_UPDATE', require('./VOICE_STATE_UPDATE')], | ||
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')], | ||
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')], | ||
['INTERACTION_CREATE', require('./INTERACTION_CREATE')], | ||
['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE')], | ||
['STAGE_INSTANCE_UPDATE', require('./STAGE_INSTANCE_UPDATE')], | ||
['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE')], | ||
['GUILD_STICKERS_UPDATE', require('./GUILD_STICKERS_UPDATE')], | ||
]); | ||
|
||
module.exports = handlers; |
This file was deleted.
Oops, something went wrong.