Files
open-ticket/plugins/example-plugin/index.ts
T
DJj123dj 05b4080ac5 Plugins can now use import path shortcuts
Plugins are now able to use import path shortcuts to import all API classes, utilities and the openticket globals. You can now import everything from "#opendiscord" instead of "../../src/index"
2024-12-25 18:20:58 +01:00

43 lines
2.0 KiB
TypeScript

import {api, openticket, utilities} from "#opendiscord"
import * as discord from "discord.js"
/////////////////////////////////////////////
//// This plugin is not enabled yet! ////
//// Enable it in the plugin.json file! ////
/////////////////////////////////////////////
if (utilities.project != "openticket") throw new api.ODPluginError("This plugin only works in Open Ticket!")
//Add Typescript autocomplete support for plugin data. (!!!OPTIONAL!!!)
declare module "#opendiscord-types" {
export interface ODConfigManagerIds_Default {
"example-plugin:config":api.ODJsonConfig
}
}
//Let's register the example config. This way it's available for all plugins & systems.
openticket.events.get("onConfigLoad").listen((configManager) => {
configManager.add(new api.ODJsonConfig("example-plugin:config","config.json","./plugins/example-plugin/"))
/*===== What did we do? =====
- "example-plugin:config" Is the ID of this config. You can use this id troughout the bot to access this config file. Even in other plugins.
- "config.json" Is the FILE of this config. It is just the filename.
- "./plugins/example-plugin/" Is the DIRECTORY of this config. By default it's "./config/", but we want to change it to point at the plugin directory.
*/
//Let's also log it to the console to let us know it worked!
const ourConfig = configManager.get("example-plugin:config")
openticket.log("The example config loaded successfully!","plugin",[
{key:"var-1",value:ourConfig.data.testVariable1},
{key:"var-2",value:ourConfig.data.testVariable2.toString()},
{key:"var-3",value:ourConfig.data.testVariable3.toString()}
])
})
openticket.events.get("onTicketCreate").listen((creator) => {
//This is logged before the ticket is created (after the button is pressed)
openticket.log("Ticket is getting created...","plugin")
})
openticket.events.get("afterTicketCreated").listen((ticket,creator,channel) => {
//This is logged after the ticket is created
openticket.log("Ticket ready!","plugin")
})