2025-04-29 21:38:14 +07:00
|
|
|
import type { DiscordModules } from '@revenge-mod/discord/types'
|
|
|
|
|
|
2025-05-08 18:52:57 +07:00
|
|
|
import type { PluginFlags as PF, PluginStatus as PS } from './src/constants'
|
|
|
|
|
|
|
|
|
|
export type PluginFlags = (typeof PF)[keyof typeof PF]
|
|
|
|
|
export type PluginStatus = (typeof PS)[keyof typeof PS]
|
2025-04-29 21:38:14 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The unscoped plugin API (limited). This API is available as a global for plugins.
|
|
|
|
|
* Available in the `init` phase.
|
|
|
|
|
*/
|
|
|
|
|
export interface UnscopedInitPluginApi {
|
|
|
|
|
discord: typeof import('@revenge-mod/discord')
|
2025-05-08 18:56:41 +07:00
|
|
|
externals: typeof import('@revenge-mod/externals')
|
2025-04-29 21:38:14 +07:00
|
|
|
modules: typeof import('@revenge-mod/modules')
|
|
|
|
|
patcher: typeof import('@revenge-mod/patcher')
|
2025-05-08 18:56:41 +07:00
|
|
|
plugins: typeof import('@revenge-mod/plugins')
|
2025-04-29 21:38:14 +07:00
|
|
|
react: typeof import('@revenge-mod/react')
|
2025-05-06 22:08:35 +07:00
|
|
|
utils: typeof import('@revenge-mod/utils')
|
2025-04-29 21:38:14 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The unscoped plugin API. This API is available as a global for plugins.
|
|
|
|
|
* Available in the `start` and `stop` phase.
|
|
|
|
|
*/
|
|
|
|
|
export interface UnscopedPluginApi extends UnscopedInitPluginApi {
|
|
|
|
|
assets: typeof import('@revenge-mod/assets')
|
|
|
|
|
// ui: typeof import('@revenge-mod/ui')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type PluginCleanup = () => any
|
|
|
|
|
export type PluginCleanupApi = (...fns: PluginCleanup[]) => void
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The plugin API (limited).
|
|
|
|
|
* Available in the `init` phase.
|
|
|
|
|
*/
|
|
|
|
|
export interface InitPluginApi {
|
|
|
|
|
plugin: Plugin
|
|
|
|
|
logger: InstanceType<DiscordModules.Logger>
|
|
|
|
|
unscoped: UnscopedInitPluginApi
|
|
|
|
|
cleanup: PluginCleanupApi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The plugin API.
|
|
|
|
|
* Available in the `start` and `stop` phase.
|
|
|
|
|
*/
|
|
|
|
|
export interface PluginApi extends InitPluginApi {
|
|
|
|
|
// settings: typeof import('@revenge-mod/settings')
|
|
|
|
|
unscoped: UnscopedPluginApi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(plugins): support plugin bundles
|
|
|
|
|
// export interface PluginBundle {
|
|
|
|
|
// /**
|
|
|
|
|
// * The unique identifier for the plugin bundle.
|
|
|
|
|
// */
|
|
|
|
|
// id: string
|
|
|
|
|
// /**
|
|
|
|
|
// * The author of the plugin bundle.
|
|
|
|
|
// */
|
|
|
|
|
// author: string
|
2025-05-01 01:18:36 +07:00
|
|
|
// /**
|
|
|
|
|
// * The URL of the plugin bundle.
|
|
|
|
|
// */
|
|
|
|
|
// url: string
|
2025-04-29 21:38:14 +07:00
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
export interface PluginManifest {
|
|
|
|
|
/**
|
|
|
|
|
* The unique identifier for the plugin.
|
|
|
|
|
*/
|
|
|
|
|
id: string
|
|
|
|
|
/**
|
|
|
|
|
* The name of the plugin.
|
|
|
|
|
*/
|
|
|
|
|
name: string
|
2025-05-01 12:18:28 +07:00
|
|
|
/**
|
|
|
|
|
* The author of the plugin.
|
|
|
|
|
*/
|
|
|
|
|
author: string
|
2025-04-29 21:38:14 +07:00
|
|
|
/**
|
|
|
|
|
* The description of the plugin.
|
|
|
|
|
*/
|
|
|
|
|
description: string
|
|
|
|
|
/**
|
|
|
|
|
* The icon of the plugin.
|
|
|
|
|
*/
|
|
|
|
|
icon?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PluginLifecycles {
|
|
|
|
|
/**
|
|
|
|
|
* Runs immediately as soon as possible with limited APIs.
|
|
|
|
|
*
|
|
|
|
|
* @param api Plugin API (limited).
|
|
|
|
|
* @param context Plugin context.
|
|
|
|
|
*/
|
|
|
|
|
init?: (api: InitPluginApi) => any
|
|
|
|
|
/**
|
|
|
|
|
* Runs when the plugin can be started with all APIs available.
|
|
|
|
|
*
|
|
|
|
|
* @param api Plugin API.
|
|
|
|
|
* @param context Plugin context.
|
|
|
|
|
*/
|
|
|
|
|
start?: (api: PluginApi) => any
|
|
|
|
|
/**
|
|
|
|
|
* Runs when the plugin is stopped.
|
|
|
|
|
*
|
|
|
|
|
* @param api Plugin API.
|
|
|
|
|
* @param context Plugin context.
|
|
|
|
|
*/
|
|
|
|
|
stop?: (api: PluginApi) => any
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Plugin {
|
|
|
|
|
// TODO(plugins): support plugin bundles
|
|
|
|
|
// /**
|
|
|
|
|
// * The plugin bundle this plugin belongs to.
|
|
|
|
|
// */
|
|
|
|
|
// bundle: PluginBundle
|
|
|
|
|
/**
|
|
|
|
|
* The plugin manifest.
|
|
|
|
|
*/
|
|
|
|
|
manifest: PluginManifest
|
|
|
|
|
/**
|
|
|
|
|
* The plugin lifecycles.
|
|
|
|
|
*/
|
|
|
|
|
lifecycles: PluginLifecycles
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The plugin flags.
|
|
|
|
|
*/
|
|
|
|
|
flags: PluginFlags
|
2025-05-01 01:18:36 +07:00
|
|
|
/**
|
|
|
|
|
* The plugin status.
|
|
|
|
|
*/
|
|
|
|
|
status: PluginStatus
|
2025-04-29 21:38:14 +07:00
|
|
|
/**
|
|
|
|
|
* Errors encountered during the plugin lifecycles.
|
|
|
|
|
*/
|
|
|
|
|
errors: unknown[]
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Disable the plugin. This will also stop the plugin if it is running.
|
|
|
|
|
*/
|
|
|
|
|
disable(): Promise<void>
|
|
|
|
|
/**
|
|
|
|
|
* Enable the plugin.
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
enable(): Promise<void>
|
|
|
|
|
}
|