-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
950 additions
and
296 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
diff --git a/node_modules/@discordjs/ws/dist/index.mjs b/node_modules/@discordjs/ws/dist/index.mjs | ||
index be08932..4b8fe39 100644 | ||
--- a/node_modules/@discordjs/ws/dist/index.mjs | ||
+++ b/node_modules/@discordjs/ws/dist/index.mjs | ||
@@ -220,9 +220,6 @@ var WorkerShardingStrategy = class { | ||
} | ||
resolveWorkerPath() { | ||
const path2 = this.options.workerPath; | ||
- if (!path2) { | ||
- return join(__dirname, "defaultWorker.js"); | ||
- } | ||
if (isAbsolute(path2)) { | ||
return path2; | ||
} |
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,7 @@ | ||
import { Component } from '../types.js'; | ||
import { interactionHandler } from './interaction-handler.js'; | ||
import { ready } from './ready.js'; | ||
|
||
export default { | ||
gatewayEvents: [ready, interactionHandler], | ||
} satisfies Component; |
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,95 @@ | ||
import { | ||
ApplicationCommandType, | ||
GatewayDispatchEvents, | ||
InteractionType, | ||
} from '@discordjs/core'; | ||
import { interactions, statefuls } from '../loader.js'; | ||
import { GatewayEvent } from '../types.js'; | ||
|
||
function findStateful(id: string, list: string[]): string | undefined { | ||
return list | ||
.filter((s) => id.startsWith(s)) | ||
.sort((a, b) => b.length - a.length)[0]; | ||
} | ||
|
||
export const interactionHandler = { | ||
name: GatewayDispatchEvents.InteractionCreate, | ||
type: 'on', | ||
async execute(props) { | ||
const { data: interaction } = props; | ||
|
||
switch (interaction.type) { | ||
case InteractionType.ApplicationCommand: | ||
case InteractionType.ApplicationCommandAutocomplete: | ||
const command = interactions.commands.get( | ||
interaction.data.name, | ||
); | ||
|
||
if (!command) | ||
throw new Error( | ||
`Command not defined for ${interaction.data.name}.`, | ||
); | ||
|
||
if ( | ||
interaction.type === InteractionType.ApplicationCommand && | ||
(command.data.type ?? ApplicationCommandType.ChatInput) === | ||
interaction.data.type | ||
) | ||
//@ts-ignore | ||
await command.execute(props); | ||
else if (command.autocomplete) | ||
//@ts-ignore | ||
await command.autocomplete(props); | ||
break; | ||
|
||
case InteractionType.MessageComponent: | ||
const componentId = interaction.data.custom_id; | ||
|
||
let component = interactions.messageComponents.get(componentId); | ||
|
||
if (!component) { | ||
const staticId = findStateful( | ||
componentId, | ||
statefuls.messageComponents, | ||
); | ||
|
||
if (staticId) | ||
component = | ||
interactions.messageComponents.get(staticId); | ||
} | ||
|
||
if (!component) | ||
throw new Error( | ||
`Message component not defined for ${interaction.data.custom_id}.`, | ||
); | ||
|
||
if (component.data.type === interaction.data.component_type) | ||
//@ts-ignore | ||
await component.execute(props); | ||
break; | ||
|
||
case InteractionType.ModalSubmit: | ||
const modalId = interaction.data.custom_id; | ||
|
||
let modal = interactions.modals.get(modalId); | ||
|
||
if (!modal) { | ||
const staticId = findStateful(modalId, statefuls.modals); | ||
|
||
if (staticId) modal = interactions.modals.get(staticId); | ||
} | ||
|
||
if (!modal) | ||
throw new Error( | ||
`Modal not defined for ${interaction.data.custom_id}.`, | ||
); | ||
|
||
//@ts-ignore | ||
await modal.execute(props); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
}, | ||
} satisfies GatewayEvent<GatewayDispatchEvents.InteractionCreate>; |
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,11 @@ | ||
import { GatewayDispatchEvents } from '@discordjs/core'; | ||
import { GatewayEvent } from '../types.js'; | ||
|
||
export const ready = { | ||
name: GatewayDispatchEvents.Ready, | ||
type: 'once', | ||
async execute({ data }) { | ||
const { username, discriminator } = data.user; | ||
console.log(`Ready as ${username}#${discriminator}!`); | ||
}, | ||
} satisfies GatewayEvent<GatewayDispatchEvents.Ready>; |
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
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,15 @@ | ||
import { WebSocketShardEvents } from '@discordjs/ws'; | ||
import { WebSocketEvent } from '../types.js'; | ||
|
||
let ping = -1; | ||
export function getPing() { | ||
return ping; | ||
} | ||
|
||
export const heartbeat = { | ||
name: WebSocketShardEvents.HeartbeatComplete, | ||
type: 'on', | ||
async execute({ latency }) { | ||
ping = latency; | ||
}, | ||
} satisfies WebSocketEvent<WebSocketShardEvents.HeartbeatComplete>; |
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,6 +1,8 @@ | ||
import { Component } from '../types.js'; | ||
import { command } from './command.js'; | ||
import { heartbeat } from './heartbeat.js'; | ||
|
||
export default { | ||
wsEvents: [heartbeat], | ||
commands: [command], | ||
} satisfies Component; |
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
Oops, something went wrong.