Skip to content

Commit

Permalink
chore: skip trigger logs for auto-generated events
Browse files Browse the repository at this point in the history
This reduces redundant logs for events like "ready" as well as other default events.
  • Loading branch information
Pkmmte committed Apr 29, 2023
1 parent 7375d4f commit 08afac9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-badgers-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roboplay/robo.js': patch
---

chore: skip trigger logs for auto-generated events
10 changes: 7 additions & 3 deletions packages/discord/src/core/robo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { logger } from './logger.js'
import { getManifest, loadManifest } from '../cli/utils/manifest.js'
import { env } from './env.js'
import { pathToFileURL } from 'node:url'
import type { CommandRecord, EventRecord, Handler, PluginData, RoboMessage } from '../types/index.js'
import { executeAutocompleteHandler, executeCommandHandler, executeEventHandler } from './handlers.js'
import type { CommandRecord, EventRecord, Handler, PluginData, RoboMessage } from '../types/index.js'

export const Robo = { restart, start, stop }

Expand Down Expand Up @@ -45,16 +45,19 @@ async function start() {

// Define event handlers
for (const key of events.keys()) {
const onlyAuto = events.get(key).every((event) => event.auto)
client.on(key, async (...args) => {
logger.event(`Event received: ${chalk.bold(key)}`)
if (!onlyAuto) {
logger.event(`Event received: ${chalk.bold(key)}`)
}
logger.trace('Event args:', args)

// Notify event handler
executeEventHandler(plugins, key, ...args)
})
}

// Forward command interactions to our fancy handler
// Forward command interactions to our fancy handlers
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isChatInputCommand()) {
logger.event(`Received slash command interaction: ${chalk.bold('/' + interaction.commandName)}`)
Expand Down Expand Up @@ -126,6 +129,7 @@ async function loadHandlerModules<T extends Handler | Handler[]>(type: 'commands
const importPath = pathToFileURL(path.join(basePath, itemConfig.__path)).toString()

const handler = {
auto: itemConfig.__auto,
handler: await import(importPath),
path: itemConfig.__path,
plugin: itemConfig.__plugin
Expand Down
1 change: 1 addition & 0 deletions packages/discord/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './events.js'
export * from './manifest.js'

export interface Handler {
auto?: boolean
handler: unknown
path: string
plugin?: {
Expand Down

0 comments on commit 08afac9

Please sign in to comment.