Updated example plugin
This commit is contained in:
@@ -1,14 +1,17 @@
|
|||||||
import {api, opendiscord, utilities} from "#opendiscord"
|
import {api, opendiscord, utilities} from "#opendiscord"
|
||||||
import * as discord from "discord.js"
|
import * as discord from "discord.js"
|
||||||
|
if (opendiscord.project != "openticket") throw new api.ODPluginError("This plugin only works in Open Ticket.")
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/** ============= Warning! =============
|
||||||
//// This plugin is not enabled yet! ////
|
*
|
||||||
//// Enable it in the plugin.json file! ////
|
* This plugin is not yet enabled and will not run by default.
|
||||||
/////////////////////////////////////////////
|
* Please enable this plugin in the "plugin.json" file!
|
||||||
|
*
|
||||||
|
* =====================================
|
||||||
|
*/
|
||||||
|
|
||||||
if (opendiscord.project != "openticket") throw new api.ODPluginError("This plugin only works in Open Ticket!")
|
|
||||||
|
|
||||||
//Add Typescript autocomplete support for plugin data. (!!!OPTIONAL!!!)
|
//Add optional Typescript type-safety. This improves the developer experience.
|
||||||
declare module "#opendiscord-types" {
|
declare module "#opendiscord-types" {
|
||||||
export interface ODPluginManagerIdMappings {
|
export interface ODPluginManagerIdMappings {
|
||||||
"example-plugin":api.ODPlugin
|
"example-plugin":api.ODPlugin
|
||||||
@@ -18,29 +21,48 @@ declare module "#opendiscord-types" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Let's register the example config. This way it's available for all plugins & systems.
|
//REGISTER CONFIG
|
||||||
opendiscord.events.get("onConfigLoad").listen((configManager) => {
|
opendiscord.events.get("onConfigLoad").listen((configs) => {
|
||||||
configManager.add(new api.ODJsonConfig("example-plugin:config","config.json","./plugins/example-plugin/"))
|
//Let's register our example config. The plugin, all systems and even other plugins can access it.
|
||||||
/*===== What did we do? =====
|
configs.add(new api.ODJsonConfig("example-plugin:config","config.json","./plugins/example-plugin/"))
|
||||||
- "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.
|
/* ===== What did we do? =====
|
||||||
- "config.json" Is the FILE of this config. It is just the filename.
|
* "example-plugin:config" --> Is the ID of this config. It will be used throughout the code to access this config file.
|
||||||
- "./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.
|
* "config.json" --> Is the FILENAME of this config with extension.
|
||||||
|
* "./plugins/example-plugin/" --> Is the DIRECTORY of this config. It is set to "./config/" by default, but we want to change it to our plugin directory.
|
||||||
*/
|
*/
|
||||||
|
})
|
||||||
|
|
||||||
//Let's also log it to the console to let us know it worked!
|
//CONFIG READY FOR USAGE
|
||||||
const ourConfig = configManager.get("example-plugin:config")
|
opendiscord.events.get("afterConfigsInitiated").listen((configs) => {
|
||||||
|
//After the "afterConfigsInitiated" event is fired, configs can be read without problems.
|
||||||
|
//Almost all events happen after this one, so you don't need to worry about it.
|
||||||
|
|
||||||
|
const ourConfig = configs.get("example-plugin:config")
|
||||||
opendiscord.log("The example config loaded successfully!","plugin",[
|
opendiscord.log("The example config loaded successfully!","plugin",[
|
||||||
{key:"var-1",value:ourConfig.data.testVariable1.toString()},
|
{key:"test-property-1",value:ourConfig.data.testVariable1.toString()},
|
||||||
{key:"var-2",value:ourConfig.data.testVariable2.toString()},
|
{key:"test-property-2",value:ourConfig.data.testVariable2.toString()},
|
||||||
{key:"var-3",value:ourConfig.data.testVariable3.toString()}
|
{key:"test-property-3",value:ourConfig.data.testVariable3.toString()}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//LISTEN FOR TICKET EVENTS
|
||||||
opendiscord.events.get("onTicketCreate").listen((creator) => {
|
opendiscord.events.get("onTicketCreate").listen((creator) => {
|
||||||
//This is logged before the ticket is created (after the button is pressed)
|
//Do something before a ticket is created (just after the button press)
|
||||||
opendiscord.log("Ticket is getting created...","plugin")
|
opendiscord.log("Ticket is getting created...","plugin")
|
||||||
})
|
})
|
||||||
opendiscord.events.get("afterTicketCreated").listen((ticket,creator,channel) => {
|
opendiscord.events.get("afterTicketCreated").listen((ticket,creator,channel) => {
|
||||||
//This is logged after the ticket is created
|
//Do something after a ticket is created and ready for usage
|
||||||
opendiscord.log("Ticket ready!","plugin")
|
opendiscord.log("Ticket ready!","plugin")
|
||||||
|
})
|
||||||
|
opendiscord.events.get("onTicketClose").listen((ticket,closer,channel,reason) => {
|
||||||
|
//Do something when a ticket will be closed
|
||||||
|
opendiscord.log("Ticket is getting closed...","plugin")
|
||||||
|
})
|
||||||
|
|
||||||
|
//MODIFY BUILT-IN OPEN TICKET MESSAGES
|
||||||
|
opendiscord.events.get("afterEmbedBuildersLoaded").listen((embeds) => {
|
||||||
|
//Let's modify the close message to include a URL in the embed.
|
||||||
|
embeds.get("opendiscord:close-message").workers.add(new api.ODWorker("example-plugin:testing",0,(instance,params,origin,cancel) => {
|
||||||
|
instance.setUrl("https://example.com")
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user