Skip to content

オプションのインターフェース

Module に加えて、Goroku は登録時に以下を確認します。メソッドを宣言すればその機能 が有効になり、宣言しなければ何も起きません。

コンパイル時に固定する

オプションのインターフェースは形で照合されます。シグネチャの打ち間違いは、 メソッドが黙って無視されることを意味します。1行でそれを防げます。

go
var _ goroku.ModuleWithConfigSchema = (*Weather)(nil)

ModuleWithMeta

go
CommandMetas() map[string]CommandMeta

コマンドごとのエイリアスとフィルタ。CommandMeta を 参照。

ModuleWithWatcherMetas

go
WatcherMetas() []CommandMeta

ウォッチャー用のフィルタ。Watchers() と位置で対応します。

ModuleWithConfigSchema

go
ConfigSchema() []ConfigField

既定値と検証を備えた型付き設定。推奨される設定方法です。 ConfigField を参照。

ModuleWithConfigReady

go
ConfigReady(config map[string]any) error

起動時と設定変更のたびに呼ばれます。エラーを返すと変更は拒否されます。

ModuleWithConfig

go
ConfigDefaults() map[string]any

古い、型なしの設定方法です。ConfigSchema を優先してください。

ModuleWithConfigValidators

go
ConfigValidators() map[string]Validator

ConfigDefaults 用のバリデータ。ConfigSchema を使うなら不要です(そちらが自前で 持っています)。

ModuleWithTranslationAliases

go
TranslationAliases() []string

翻訳キーを解決する際に試す追加の名前。翻訳ファイルが Name() から導けない名前を 使っているモジュール向けです。

go
func (m *APIProtection) Name() string { return "APILimiter" }
func (m *APIProtection) TranslationAliases() []string {
	return []string{"api_protection"}
}

ModuleWithAllModules

go
SetAllModules(*Modules)

モジュールレジストリを受け取ります。ヘルプ、設定画面、ローダーなど、他のモジュール を調べたり操作したりするモジュール向けです。

ModuleWithTranslator

go
SetTranslator(*Translator)

翻訳器を受け取ります。Base を埋め込んでいるなら不要です(既に持っています)。

SecuredModule

go
CommandPermissions() map[string]int

コマンドごとの既定の権限マスク。権限 を参照。

RatelimitedModule

go
RatelimitedCommands() map[string]bool

レート制限の対象コマンド。CommandMetaRatelimit: true と同等です。

Released under the GNU AGPL v3 License.