BREAKING: changed openticket to opendiscord in API

This commit is contained in:
DJj123dj
2025-02-01 10:22:27 +01:00
parent ce242741cd
commit 29f8e1452c
103 changed files with 2160 additions and 2175 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
import * as fs from "fs"
@@ -22,7 +22,7 @@ const disableDumpCommand = false
export const loadDumpCommand = () => {
if (disableDumpCommand) return
openticket.client.textCommands.add(new api.ODTextCommand("openticket:dump",{
opendiscord.client.textCommands.add(new api.ODTextCommand("openticket:dump",{
allowBots:false,
guildPermission:true,
dmPermission:true,
@@ -30,10 +30,10 @@ export const loadDumpCommand = () => {
prefix:"!OPENTICKET:"
}))
openticket.client.textCommands.onInteraction("!OPENTICKET:","dump",async (msg) => {
if (msg.author.id == "779742674932072469" || openticket.permissions.hasPermissions("developer",await openticket.permissions.getPermissions(msg.author,msg.channel,null))){
opendiscord.client.textCommands.onInteraction("!OPENTICKET:","dump",async (msg) => {
if (msg.author.id == "779742674932072469" || opendiscord.permissions.hasPermissions("developer",await opendiscord.permissions.getPermissions(msg.author,msg.channel,null))){
//user is bot owner OR creator of Open Ticket :)
openticket.log("Dumped otdebug.txt!","system",[
opendiscord.log("Dumped otdebug.txt!","system",[
{key:"user",value:msg.author.username},
{key:"id",value:msg.author.id}
])
+11 -11
View File
@@ -38,19 +38,19 @@ import * as api from "../api/api" //import for local use
export * as api from "../api/api" //export to other parts of bot
export const openticket = new api.ODMain()
export const opendiscord = new api.ODMain()
console.log("\n--------------------------- OPEN TICKET STARTUP ---------------------------")
openticket.log("Logging system activated!","system")
openticket.debug.debug("Using Node.js "+process.version+"!")
opendiscord.log("Logging system activated!","system")
opendiscord.debug.debug("Using Node.js "+process.version+"!")
try{
const packageJson = JSON.parse(fs.readFileSync("./package.json").toString())
openticket.debug.debug("Using discord.js "+packageJson.dependencies["discord.js"]+"!")
openticket.debug.debug("Using ansis "+packageJson.dependencies["ansis"]+"!")
openticket.debug.debug("Using formatted-json-stringify "+packageJson.dependencies["formatted-json-stringify"]+"!")
openticket.debug.debug("Using typescript "+packageJson.dependencies["typescript"]+"!")
opendiscord.debug.debug("Using discord.js "+packageJson.dependencies["discord.js"]+"!")
opendiscord.debug.debug("Using ansis "+packageJson.dependencies["ansis"]+"!")
opendiscord.debug.debug("Using formatted-json-stringify "+packageJson.dependencies["formatted-json-stringify"]+"!")
opendiscord.debug.debug("Using typescript "+packageJson.dependencies["typescript"]+"!")
}catch{
openticket.debug.debug("Failed to fetch module versions!")
opendiscord.debug.debug("Failed to fetch module versions!")
}
const timer = (ms:number): Promise<void> => {
@@ -83,7 +83,7 @@ export interface ODUtilities {
*/
timer(ms:number): Promise<void>
/**## emojiTitle `utility function`
* Use this function to create a title with an emoji before/after the text. The style & divider are set in `openticket.defaults`
* Use this function to create a title with an emoji before/after the text. The style & divider are set in `opendiscord.defaults`
* @example utilities.emojiTitle("📎","Links") //create a title with an emoji based on the bot emoji style
*/
emojiTitle(emoji:string, text:string): string
@@ -149,8 +149,8 @@ export const utilities: ODUtilities = {
},
timer,
emojiTitle(emoji:string, text:string){
const style = openticket.defaults.getDefault("emojiTitleStyle")
const divider = openticket.defaults.getDefault("emojiTitleDivider")
const style = opendiscord.defaults.getDefault("emojiTitleStyle")
const divider = opendiscord.defaults.getDefault("emojiTitleDivider")
if (style == "disabled") return text
else if (style == "before") return emoji+divider+text
+27 -27
View File
@@ -1,60 +1,60 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadVersionMigrationSystem = async () => {
//ENTER MIGRATION CONTEXT
await preloadMigrationContext()
const lastVersion = await isMigrationRequired()
openticket.versions.add(lastVersion ? lastVersion : api.ODVersion.fromString("openticket:last-version",openticket.versions.get("openticket:version").toString()))
if (lastVersion && !openticket.flags.get("openticket:no-migration").value){
opendiscord.versions.add(lastVersion ? lastVersion : api.ODVersion.fromString("openticket:last-version",opendiscord.versions.get("openticket:version").toString()))
if (lastVersion && !opendiscord.flags.get("openticket:no-migration").value){
//MIGRATION IS REQUIRED
openticket.log("Detected old data!","info")
openticket.log("Starting closed API context...","debug")
opendiscord.log("Detected old data!","info")
opendiscord.log("Starting closed API context...","debug")
await utilities.timer(600)
openticket.log("Migrating data to new version...","debug")
opendiscord.log("Migrating data to new version...","debug")
await loadAllVersionMigrations(lastVersion)
openticket.log("Stopping closed API context...","debug")
opendiscord.log("Stopping closed API context...","debug")
await utilities.timer(400)
openticket.log("All data is now up to date!","info")
opendiscord.log("All data is now up to date!","info")
await utilities.timer(200)
console.log("---------------------------------------------------------------------")
}
saveAllVersionsToDatabase()
//DEFAULT FLAGS
if (openticket.flags.exists("openticket:no-plugins") && openticket.flags.get("openticket:no-plugins").value) openticket.defaults.setDefault("pluginLoading",false)
if (openticket.flags.exists("openticket:soft-plugins") && openticket.flags.get("openticket:soft-plugins").value) openticket.defaults.setDefault("softPluginLoading",true)
if (openticket.flags.exists("openticket:crash") && openticket.flags.get("openticket:crash").value) openticket.defaults.setDefault("crashOnError",true)
if (openticket.flags.exists("openticket:force-slash-update") && openticket.flags.get("openticket:force-slash-update").value) openticket.defaults.setDefault("forceSlashCommandRegistration",true)
if (opendiscord.flags.exists("openticket:no-plugins") && opendiscord.flags.get("openticket:no-plugins").value) opendiscord.defaults.setDefault("pluginLoading",false)
if (opendiscord.flags.exists("openticket:soft-plugins") && opendiscord.flags.get("openticket:soft-plugins").value) opendiscord.defaults.setDefault("softPluginLoading",true)
if (opendiscord.flags.exists("openticket:crash") && opendiscord.flags.get("openticket:crash").value) opendiscord.defaults.setDefault("crashOnError",true)
if (opendiscord.flags.exists("openticket:force-slash-update") && opendiscord.flags.get("openticket:force-slash-update").value) opendiscord.defaults.setDefault("forceSlashCommandRegistration",true)
//LEAVE MIGRATION CONTEXT
await unloadMigrationContext()
}
const preloadMigrationContext = async () => {
openticket.debug.debug("-- MIGRATION CONTEXT START --")
opendiscord.debug.debug("-- MIGRATION CONTEXT START --")
await (await import("../../data/framework/flagLoader.js")).loadAllFlags()
await openticket.flags.init()
await opendiscord.flags.init()
await (await import("../../data/framework/configLoader.js")).loadAllConfigs()
await openticket.configs.init()
await opendiscord.configs.init()
await (await import("../../data/framework/databaseLoader.js")).loadAllDatabases()
await openticket.databases.init()
openticket.debug.visible = true
await opendiscord.databases.init()
opendiscord.debug.visible = true
}
const unloadMigrationContext = async () => {
openticket.debug.visible = false
await openticket.databases.loopAll((database,id) => {openticket.databases.remove(id)})
await openticket.configs.loopAll((config,id) => {openticket.configs.remove(id)})
await openticket.flags.loopAll((flag,id) => {openticket.flags.remove(id)})
openticket.debug.debug("-- MIGRATION CONTEXT END --")
opendiscord.debug.visible = false
await opendiscord.databases.loopAll((database,id) => {opendiscord.databases.remove(id)})
await opendiscord.configs.loopAll((config,id) => {opendiscord.configs.remove(id)})
await opendiscord.flags.loopAll((flag,id) => {opendiscord.flags.remove(id)})
opendiscord.debug.debug("-- MIGRATION CONTEXT END --")
}
const isMigrationRequired = async (): Promise<false|api.ODVersion> => {
const rawVersion = await openticket.databases.get("openticket:global").get("openticket:last-version","openticket:version")
const rawVersion = await opendiscord.databases.get("openticket:global").get("openticket:last-version","openticket:version")
if (!rawVersion) return false
const version = api.ODVersion.fromString("openticket:last-version",rawVersion)
if (openticket.versions.get("openticket:version").compare(version) == "higher"){
if (opendiscord.versions.get("openticket:version").compare(version) == "higher"){
return version
}else return false
}
@@ -70,7 +70,7 @@ const loadAllVersionMigrations = async (lastVersion:api.ODVersion) => {
for (const migration of migrations){
if (migration.version.compare(lastVersion) == "higher"){
const success = await migration.migrate()
if (success) openticket.log("Migrated data to "+migration.version.toString()+"!","debug",[
if (success) opendiscord.log("Migrated data to "+migration.version.toString()+"!","debug",[
{key:"success",value:success ? "true" : "false"}
])
}
@@ -78,9 +78,9 @@ const loadAllVersionMigrations = async (lastVersion:api.ODVersion) => {
}
const saveAllVersionsToDatabase = async () => {
const globalDatabase = openticket.databases.get("openticket:global")
const globalDatabase = opendiscord.databases.get("openticket:global")
await openticket.versions.loopAll(async (version,id) => {
await opendiscord.versions.loopAll(async (version,id) => {
await globalDatabase.set("openticket:last-version",id.value,version.toString())
})
}
+1 -1
View File
@@ -1,4 +1,4 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const migrations = [
//MIGRATE TO v4.0.0
+29 -29
View File
@@ -1,14 +1,14 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import fs from "fs"
import { ODPluginError } from "../api/api"
export const loadAllPlugins = async () => {
//start launching plugins
openticket.log("Loading plugins...","system")
opendiscord.log("Loading plugins...","system")
let initPluginError: boolean = false
if (!fs.existsSync("./plugins")){
openticket.log("Couldn't find ./plugins directory, canceling all plugin execution!","error")
opendiscord.log("Couldn't find ./plugins directory, canceling all plugin execution!","error")
return
}
const plugins = fs.readdirSync("./plugins")
@@ -16,12 +16,12 @@ export const loadAllPlugins = async () => {
//check & validate
plugins.forEach(async (p) => {
//prechecks
if (!fs.statSync("./plugins/"+p).isDirectory()) return openticket.log("Plugin is not a directory, canceling plugin execution...","plugin",[
if (!fs.statSync("./plugins/"+p).isDirectory()) return opendiscord.log("Plugin is not a directory, canceling plugin execution...","plugin",[
{key:"plugin",value:"./plugins/"+p}
])
if (!fs.existsSync("./plugins/"+p+"/plugin.json")){
initPluginError = true
openticket.log("Plugin doesn't have a plugin.json, canceling plugin execution...","plugin",[
opendiscord.log("Plugin doesn't have a plugin.json, canceling plugin execution...","plugin",[
{key:"plugin",value:"./plugins/"+p}
])
return
@@ -55,25 +55,25 @@ export const loadAllPlugins = async () => {
if (rawplugindata.id != p) throw new ODPluginError("Failed to load plugin, directory name is required to match the id")
if (openticket.plugins.exists(rawplugindata.id)) throw new ODPluginError("Failed to load plugin, this id already exists in another plugin")
if (opendiscord.plugins.exists(rawplugindata.id)) throw new ODPluginError("Failed to load plugin, this id already exists in another plugin")
//plugin.json is valid => load plugin
const plugin = new api.ODPlugin(p,rawplugindata)
openticket.plugins.add(plugin)
opendiscord.plugins.add(plugin)
}catch(e){
//when any of the above errors happen, crash the bot when soft mode isn't enabled
initPluginError = true
openticket.log(e.message+", canceling plugin execution...","plugin",[
opendiscord.log(e.message+", canceling plugin execution...","plugin",[
{key:"path",value:"./plugins/"+p}
])
openticket.log("You can see more about this error in the ./otdebug.txt file!","info")
openticket.debugfile.writeText(e.stack)
opendiscord.log("You can see more about this error in the ./otdebug.txt file!","info")
opendiscord.debugfile.writeText(e.stack)
//try to get some crashed plugin data
try{
const rawplugindata: api.ODPluginData = JSON.parse(fs.readFileSync("./plugins/"+p+"/plugin.json").toString())
openticket.plugins.unknownCrashedPlugins.push({
opendiscord.plugins.unknownCrashedPlugins.push({
name:rawplugindata.name ?? "./plugins/"+p,
description:(rawplugindata.details && rawplugindata.details.shortDescription) ? rawplugindata.details.shortDescription : "This plugin crashed :(",
})
@@ -82,7 +82,7 @@ export const loadAllPlugins = async () => {
})
//sorted plugins (based on priority)
const sortedPlugins = openticket.plugins.getAll().sort((a,b) => {
const sortedPlugins = opendiscord.plugins.getAll().sort((a,b) => {
return (b.priority - a.priority)
})
@@ -95,8 +95,8 @@ export const loadAllPlugins = async () => {
sortedPlugins.filter((plugin) => plugin.enabled).forEach((plugin) => {
const from = plugin.id.value
plugin.dependenciesInstalled().forEach((missing) => missingDependencies.push({id:from,missing}))
plugin.pluginsIncompatible(openticket.plugins).forEach((incompatible) => incompatibilities.push({from,to:incompatible}))
plugin.pluginsInstalled(openticket.plugins).forEach((missing) => missingPlugins.push({id:from,missing}))
plugin.pluginsIncompatible(opendiscord.plugins).forEach((incompatible) => incompatibilities.push({from,to:incompatible}))
plugin.pluginsInstalled(opendiscord.plugins).forEach((missing) => missingPlugins.push({id:from,missing}))
})
//handle all incompatibilities
@@ -105,18 +105,18 @@ export const loadAllPlugins = async () => {
if (alreadyLoggedCompatPlugins.includes(match.from) || alreadyLoggedCompatPlugins.includes(match.to)) return
else alreadyLoggedCompatPlugins.push(match.from,match.to)
const fromPlugin = openticket.plugins.get(match.from)
const fromPlugin = opendiscord.plugins.get(match.from)
if (fromPlugin && !fromPlugin.crashed){
fromPlugin.crashed = true
fromPlugin.crashReason = "incompatible.plugin"
}
const toPlugin = openticket.plugins.get(match.to)
const toPlugin = opendiscord.plugins.get(match.to)
if (toPlugin && !toPlugin.crashed){
toPlugin.crashed = true
toPlugin.crashReason = "incompatible.plugin"
}
openticket.log(`Incompatible plugins => "${match.from}" & "${match.to}", canceling plugin execution...`,"plugin",[
opendiscord.log(`Incompatible plugins => "${match.from}" & "${match.to}", canceling plugin execution...`,"plugin",[
{key:"path1",value:"./plugins/"+match.from},
{key:"path2",value:"./plugins/"+match.to}
])
@@ -125,13 +125,13 @@ export const loadAllPlugins = async () => {
//handle all missing dependencies
missingDependencies.forEach((match) => {
const plugin = openticket.plugins.get(match.id)
const plugin = opendiscord.plugins.get(match.id)
if (plugin && !plugin.crashed){
plugin.crashed = true
plugin.crashReason = "missing.dependency"
}
openticket.log(`Missing npm dependency "${match.missing}", canceling plugin execution...`,"plugin",[
opendiscord.log(`Missing npm dependency "${match.missing}", canceling plugin execution...`,"plugin",[
{key:"path",value:"./plugins/"+match.id}
])
initPluginError = true
@@ -139,45 +139,45 @@ export const loadAllPlugins = async () => {
//handle all missing plugins
missingPlugins.forEach((match) => {
const plugin = openticket.plugins.get(match.id)
const plugin = opendiscord.plugins.get(match.id)
if (plugin && !plugin.crashed){
plugin.crashed = true
plugin.crashReason = "missing.plugin"
}
openticket.log(`Missing required plugin "${match.missing}", canceling plugin execution...`,"plugin",[
opendiscord.log(`Missing required plugin "${match.missing}", canceling plugin execution...`,"plugin",[
{key:"path",value:"./plugins/"+match.id}
])
initPluginError = true
})
//exit on error (when soft mode disabled)
if (!openticket.defaults.getDefault("softPluginLoading") && initPluginError){
if (!opendiscord.defaults.getDefault("softPluginLoading") && initPluginError){
console.log("")
openticket.log("Please fix all plugin errors above & try again!","error")
opendiscord.log("Please fix all plugin errors above & try again!","error")
process.exit(1)
}
//preload all events required for every plugin
for (const plugin of sortedPlugins){
if (plugin.enabled) plugin.data.events.forEach((event) => openticket.events.add(new api.ODEvent(event)))
if (plugin.enabled) plugin.data.events.forEach((event) => opendiscord.events.add(new api.ODEvent(event)))
}
//execute all working plugins
for (const plugin of sortedPlugins){
const status = await plugin.execute(openticket.debug,false)
const status = await plugin.execute(opendiscord.debug,false)
//exit on error (when soft mode disabled)
if (!status && !openticket.defaults.getDefault("softPluginLoading")){
if (!status && !opendiscord.defaults.getDefault("softPluginLoading")){
console.log("")
openticket.log("Please fix all plugin errors above & try again!","error")
opendiscord.log("Please fix all plugin errors above & try again!","error")
process.exit(1)
}
}
for (const plugin of sortedPlugins){
if (plugin.enabled){
openticket.debug.debug("Plugin \""+plugin.id.value+"\" loaded",[
opendiscord.debug.debug("Plugin \""+plugin.id.value+"\" loaded",[
{key:"status",value:(plugin.crashed ? "crashed" : "success")},
{key:"crashReason",value:(plugin.crashed ? (plugin.crashReason ?? "/") : "/")},
{key:"author",value:plugin.details.author},
@@ -185,7 +185,7 @@ export const loadAllPlugins = async () => {
{key:"priority",value:plugin.priority.toString()}
])
}else{
openticket.debug.debug("Plugin \""+plugin.id.value+"\" disabled",[
opendiscord.debug.debug("Plugin \""+plugin.id.value+"\" disabled",[
{key:"author",value:plugin.details.author},
{key:"version",value:plugin.version.toString()},
{key:"priority",value:plugin.priority.toString()}