白雪はるか
白雪はるか
SIASapphire - Imagine a framework
Created by 白雪はるか on 5/25/2024 in #sapphire-support
Any common guideline for making plugins?
So what I'm trying to do is to create a module of commands which made available through plugin system. I used the following template to start up but it's currently not able to run properly. Problem : I mostly followed other plugins as example where you create a class extending Plugin and define the hook functions. Later on registering the hooks to the SapphireClient instance. My code roughly looks like this
// register.ts
import { Plugin, SapphireClient, postLogin } from '@sapphire/framework';

export class WagakkiPlugin extends Plugin {
public static [postLogin](this: SapphireClient): void {
console.log('====wagakki=== initializing');
// code omitted
}
}
SapphireClient.plugins.registerPostLoginHook(WagakkiPlugin[postLogin], 'Wagakki-PostLogin');
console.log('Sapphire has loaded wagakki');
// register.ts
import { Plugin, SapphireClient, postLogin } from '@sapphire/framework';

export class WagakkiPlugin extends Plugin {
public static [postLogin](this: SapphireClient): void {
console.log('====wagakki=== initializing');
// code omitted
}
}
SapphireClient.plugins.registerPostLoginHook(WagakkiPlugin[postLogin], 'Wagakki-PostLogin');
console.log('Sapphire has loaded wagakki');
Some part of the code are omitted since not only it doesn't work, I am not even getting any logs from the postLogin hook. The only log I received is "Sapphire has loaded wagakki" and that's it. Tried other hooks as well (preInitialization, postInitialization) and still same. Any ideas where did I do wrong? Additional context: I'm developing this plugin as separate module, which later used by my main codebase through yarn link since it's still in local.
7 replies
SIASapphire - Imagine a framework
Created by 白雪はるか on 6/2/2023 in #sapphire-support
Custom Hook before a Piece being called/run
Is there something like beforeRun hook where we can register custom function to be called. I'd imagine something like a middleware before the piece messageRun or chatInputRun being called. What I'm trying to do is to add a logger that is able to read the piece name and it's message/content. Currently doing it by adding the code right on the beginning of the run function, in which is not efficient and easy to forget.
3 replies