@open-discord-bots/framework 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/api/main.js +1 -1
- package/dist/api/modules/responder.js +50 -26
- package/package.json +1 -1
- package/.gitattributes +0 -2
- package/src/api/index.ts +0 -31
- package/src/api/main.ts +0 -203
- package/src/api/modules/action.ts +0 -89
- package/src/api/modules/base.ts +0 -845
- package/src/api/modules/builder.ts +0 -1755
- package/src/api/modules/checker.ts +0 -1826
- package/src/api/modules/client.ts +0 -2345
- package/src/api/modules/code.ts +0 -84
- package/src/api/modules/component.ts +0 -2000
- package/src/api/modules/config.ts +0 -264
- package/src/api/modules/console.ts +0 -697
- package/src/api/modules/cooldown.ts +0 -369
- package/src/api/modules/database.ts +0 -321
- package/src/api/modules/event.ts +0 -123
- package/src/api/modules/flag.ts +0 -99
- package/src/api/modules/fuse.ts +0 -365
- package/src/api/modules/helpmenu.ts +0 -273
- package/src/api/modules/language.ts +0 -230
- package/src/api/modules/permission.ts +0 -363
- package/src/api/modules/plugin.ts +0 -294
- package/src/api/modules/post.ts +0 -137
- package/src/api/modules/progressbar.ts +0 -370
- package/src/api/modules/responder.ts +0 -1625
- package/src/api/modules/session.ts +0 -181
- package/src/api/modules/startscreen.ts +0 -345
- package/src/api/modules/state.ts +0 -298
- package/src/api/modules/statistic.ts +0 -380
- package/src/api/modules/verifybar.ts +0 -68
- package/src/api/modules/worker.ts +0 -119
- package/src/cli/editConfig.ts +0 -930
- package/src/cli/index.ts +0 -152
- package/src/index.ts +0 -8
- package/src/startup/compilation.ts +0 -204
- package/src/startup/dump.ts +0 -46
- package/src/startup/errorHandling.ts +0 -42
- package/src/startup/pluginLauncher.ts +0 -265
- package/src/utilities/index.ts +0 -229
- package/tools/cleanup.js +0 -2
- package/tsconfig.json +0 -15
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import * as api from "../api/index.js"
|
|
2
|
-
import * as utilities from "../utilities/index.js"
|
|
3
|
-
import fs from "fs"
|
|
4
|
-
|
|
5
|
-
export const loadAllPlugins = async (opendiscord:api.ODMain) => {
|
|
6
|
-
//start launching plugins
|
|
7
|
-
opendiscord.log("Loading plugins...","system")
|
|
8
|
-
let initPluginError: boolean = false
|
|
9
|
-
|
|
10
|
-
if (!fs.existsSync("./plugins")){
|
|
11
|
-
opendiscord.log("Couldn't find ./plugins directory, canceling all plugin execution!","error")
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
const plugins = fs.readdirSync("./plugins")
|
|
15
|
-
const pluginVersionRegex = /^(OT|OM)v(\d+)\.(\d+|x)\.(\d+|x)$/
|
|
16
|
-
|
|
17
|
-
//check & validate
|
|
18
|
-
for (const p of plugins){
|
|
19
|
-
//prechecks
|
|
20
|
-
if (p === ".DS_Store") continue //ignore MacOS DS_Store file
|
|
21
|
-
if (!fs.statSync("./plugins/"+p).isDirectory()){
|
|
22
|
-
opendiscord.log("Plugin is not a directory, canceling plugin execution...","plugin",[
|
|
23
|
-
{key:"plugin",value:"./plugins/"+p}
|
|
24
|
-
])
|
|
25
|
-
continue
|
|
26
|
-
}
|
|
27
|
-
if (!fs.existsSync("./plugins/"+p+"/plugin.json")){
|
|
28
|
-
initPluginError = true
|
|
29
|
-
opendiscord.log("Plugin doesn't have a plugin.json, canceling plugin execution...","plugin",[
|
|
30
|
-
{key:"plugin",value:"./plugins/"+p}
|
|
31
|
-
])
|
|
32
|
-
continue
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//plugin loading
|
|
36
|
-
try {
|
|
37
|
-
const rawplugindata: api.ODPluginData = JSON.parse(fs.readFileSync("./plugins/"+p+"/plugin.json").toString())
|
|
38
|
-
|
|
39
|
-
if (typeof rawplugindata != "object") throw new api.ODPluginError("Failed to load plugin.json")
|
|
40
|
-
if (typeof rawplugindata.id != "string") throw new api.ODPluginError("Failed to load plugin.json/id")
|
|
41
|
-
if (typeof rawplugindata.name != "string") throw new api.ODPluginError("Failed to load plugin.json/name")
|
|
42
|
-
if (typeof rawplugindata.version != "string") throw new api.ODPluginError("Failed to load plugin.json/version")
|
|
43
|
-
if (typeof rawplugindata.startFile != "string") throw new api.ODPluginError("Failed to load plugin.json/startFile")
|
|
44
|
-
|
|
45
|
-
//only check "supportedVersions" if it exists (should be array)
|
|
46
|
-
if (rawplugindata.supportedVersions){
|
|
47
|
-
if (!Array.isArray(rawplugindata.supportedVersions)) throw new api.ODPluginError("Failed to load plugin.json/supportedVersions (must be array)")
|
|
48
|
-
for (const version of rawplugindata.supportedVersions){
|
|
49
|
-
if (typeof version !== "string"){
|
|
50
|
-
throw new api.ODPluginError("Failed to load plugin.json/supportedVersions (all items must be strings)")
|
|
51
|
-
}
|
|
52
|
-
//only OT (Open Ticket) & OM (Open Moderation) are supported at the moment
|
|
53
|
-
if (!pluginVersionRegex.test(version)){
|
|
54
|
-
throw new api.ODPluginError(`Failed to load plugin.json/supportedVersions (invalid format: "${version}", expected format like "OTv4.0.x" or "OMv1.0.0")`)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (typeof rawplugindata.enabled != "boolean") throw new api.ODPluginError("Failed to load plugin.json/enabled")
|
|
60
|
-
if (typeof rawplugindata.priority != "number") throw new api.ODPluginError("Failed to load plugin.json/priority")
|
|
61
|
-
if (!Array.isArray(rawplugindata.events)) throw new api.ODPluginError("Failed to load plugin.json/events")
|
|
62
|
-
|
|
63
|
-
if (!Array.isArray(rawplugindata.npmDependencies)) throw new api.ODPluginError("Failed to load plugin.json/npmDependencies")
|
|
64
|
-
if (!Array.isArray(rawplugindata.requiredPlugins)) throw new api.ODPluginError("Failed to load plugin.json/requiredPlugins")
|
|
65
|
-
if (!Array.isArray(rawplugindata.incompatiblePlugins)) throw new api.ODPluginError("Failed to load plugin.json/incompatiblePlugins")
|
|
66
|
-
|
|
67
|
-
if (typeof rawplugindata.details != "object") throw new api.ODPluginError("Failed to load plugin.json/details")
|
|
68
|
-
if (typeof rawplugindata.details.author != "string") throw new api.ODPluginError("Failed to load plugin.json/details/author")
|
|
69
|
-
|
|
70
|
-
//only check "contributors" if it exists (should be array)
|
|
71
|
-
if (rawplugindata.details.contributors && !Array.isArray(rawplugindata.details.contributors)) throw new api.ODPluginError("Failed to load plugin.json/details/contributors (must be array)")
|
|
72
|
-
|
|
73
|
-
if (typeof rawplugindata.details.shortDescription != "string") throw new api.ODPluginError("Failed to load plugin.json/details/shortDescription")
|
|
74
|
-
if (typeof rawplugindata.details.longDescription != "string") throw new api.ODPluginError("Failed to load plugin.json/details/longDescription")
|
|
75
|
-
if (typeof rawplugindata.details.imageUrl != "string") throw new api.ODPluginError("Failed to load plugin.json/details/imageUrl")
|
|
76
|
-
if (typeof rawplugindata.details.projectUrl != "string") throw new api.ODPluginError("Failed to load plugin.json/details/projectUrl")
|
|
77
|
-
if (!Array.isArray(rawplugindata.details.tags)) throw new api.ODPluginError("Failed to load plugin.json/details/tags")
|
|
78
|
-
|
|
79
|
-
if (rawplugindata.id != p) throw new api.ODPluginError("Failed to load plugin, directory name is required to match the id")
|
|
80
|
-
|
|
81
|
-
if (opendiscord.plugins.exists(rawplugindata.id)) throw new api.ODPluginError("Failed to load plugin, this id already exists in another plugin")
|
|
82
|
-
|
|
83
|
-
//plugin.json is valid => load plugin
|
|
84
|
-
const plugin = new api.ODPlugin(p,rawplugindata)
|
|
85
|
-
opendiscord.plugins.add(plugin)
|
|
86
|
-
|
|
87
|
-
}catch(e:any){
|
|
88
|
-
//when any of the above errors happen, crash the bot when soft mode isn't enabled
|
|
89
|
-
initPluginError = true
|
|
90
|
-
opendiscord.log(e.message+", canceling plugin execution...","plugin",[
|
|
91
|
-
{key:"path",value:"./plugins/"+p}
|
|
92
|
-
])
|
|
93
|
-
opendiscord.log("You can see more about this error in the ./debug.txt file!","info")
|
|
94
|
-
opendiscord.debugfile.writeText(e.stack)
|
|
95
|
-
|
|
96
|
-
//try to get some crashed plugin data
|
|
97
|
-
try{
|
|
98
|
-
const rawplugindata: api.ODPluginData = JSON.parse(fs.readFileSync("./plugins/"+p+"/plugin.json").toString())
|
|
99
|
-
opendiscord.plugins.unknownCrashedPlugins.push({
|
|
100
|
-
name:rawplugindata.name ?? "./plugins/"+p,
|
|
101
|
-
description:(rawplugindata.details && rawplugindata.details.shortDescription) ? rawplugindata.details.shortDescription : "This plugin crashed :(",
|
|
102
|
-
})
|
|
103
|
-
}catch{}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
//sorted plugins (sorted on priority. All plugins are loaded & enabled)
|
|
108
|
-
const sortedPlugins = opendiscord.plugins.getAll().sort((a,b) => {
|
|
109
|
-
return (b.priority - a.priority)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
//check for incompatible & missing plugins/dependencies
|
|
113
|
-
const incompatibilities: {from:string,to:string}[] = []
|
|
114
|
-
const missingDependencies: {id:string,missing:string}[] = []
|
|
115
|
-
const missingPlugins: {id:string,missing:string}[] = []
|
|
116
|
-
const versionIncompatibilities: {id:string}[] = []
|
|
117
|
-
|
|
118
|
-
//go through all plugins for errors
|
|
119
|
-
sortedPlugins.filter((plugin) => plugin.enabled).forEach((plugin) => {
|
|
120
|
-
const from = plugin.id.value
|
|
121
|
-
plugin.dependenciesInstalled().forEach((missing) => missingDependencies.push({id:from,missing}))
|
|
122
|
-
plugin.pluginsIncompatible(opendiscord.plugins).forEach((incompatible) => incompatibilities.push({from,to:incompatible}))
|
|
123
|
-
plugin.pluginsInstalled(opendiscord.plugins).forEach((missing) => missingPlugins.push({id:from,missing}))
|
|
124
|
-
|
|
125
|
-
//check if plugins are compatible with version of bot
|
|
126
|
-
if (plugin.data.supportedVersions && plugin.data.supportedVersions.length > 0){
|
|
127
|
-
const currentVersion = opendiscord.versions.get("opendiscord:version")
|
|
128
|
-
if (!currentVersion) throw new api.ODSystemError("Unable to get project version: opendiscord.versions.get('opendiscord:version')!")
|
|
129
|
-
let isCompatible = false
|
|
130
|
-
|
|
131
|
-
for (const versionStr of plugin.data.supportedVersions){
|
|
132
|
-
const match = versionStr.match(pluginVersionRegex)
|
|
133
|
-
if (!match) continue
|
|
134
|
-
|
|
135
|
-
const projectPrefix = match[1]
|
|
136
|
-
const primary = parseInt(match[2])
|
|
137
|
-
const secondary = (match[3] === "x") ? null : parseInt(match[3])
|
|
138
|
-
const tertiary = (match[4] === "x") ? null : parseInt(match[4])
|
|
139
|
-
|
|
140
|
-
if (projectPrefix !== "OT") continue
|
|
141
|
-
else if (primary !== currentVersion.primary) continue
|
|
142
|
-
else if (typeof secondary === "number" && secondary !== currentVersion.secondary) continue
|
|
143
|
-
else if (typeof tertiary === "number" && tertiary !== currentVersion.tertiary) continue
|
|
144
|
-
else{
|
|
145
|
-
isCompatible = true
|
|
146
|
-
break
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!isCompatible) versionIncompatibilities.push({id:from})
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
//handle all incompatibilities
|
|
155
|
-
const alreadyLoggedCompatPlugins: string[] = []
|
|
156
|
-
incompatibilities.forEach((match) => {
|
|
157
|
-
if (alreadyLoggedCompatPlugins.includes(match.from) || alreadyLoggedCompatPlugins.includes(match.to)) return
|
|
158
|
-
else alreadyLoggedCompatPlugins.push(match.from,match.to)
|
|
159
|
-
|
|
160
|
-
const fromPlugin = opendiscord.plugins.get(match.from)
|
|
161
|
-
if (fromPlugin && !fromPlugin.crashed){
|
|
162
|
-
fromPlugin.crashed = true
|
|
163
|
-
fromPlugin.crashReason = "incompatible.plugin"
|
|
164
|
-
}
|
|
165
|
-
const toPlugin = opendiscord.plugins.get(match.to)
|
|
166
|
-
if (toPlugin && !toPlugin.crashed){
|
|
167
|
-
toPlugin.crashed = true
|
|
168
|
-
toPlugin.crashReason = "incompatible.plugin"
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
opendiscord.log(`Incompatible plugins => "${match.from}" & "${match.to}", canceling plugin execution...`,"plugin",[
|
|
172
|
-
{key:"path1",value:"./plugins/"+match.from},
|
|
173
|
-
{key:"path2",value:"./plugins/"+match.to}
|
|
174
|
-
])
|
|
175
|
-
initPluginError = true
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
//handle all missing dependencies
|
|
179
|
-
missingDependencies.forEach((match) => {
|
|
180
|
-
const plugin = opendiscord.plugins.get(match.id)
|
|
181
|
-
if (plugin && !plugin.crashed){
|
|
182
|
-
plugin.crashed = true
|
|
183
|
-
plugin.crashReason = "missing.dependency"
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
opendiscord.log(`Missing npm dependency "${match.missing}", canceling plugin execution...`,"plugin",[
|
|
187
|
-
{key:"path",value:"./plugins/"+match.id}
|
|
188
|
-
])
|
|
189
|
-
initPluginError = true
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
//handle all missing plugins
|
|
193
|
-
missingPlugins.forEach((match) => {
|
|
194
|
-
const plugin = opendiscord.plugins.get(match.id)
|
|
195
|
-
if (plugin && !plugin.crashed){
|
|
196
|
-
plugin.crashed = true
|
|
197
|
-
plugin.crashReason = "missing.plugin"
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
opendiscord.log(`Missing required plugin "${match.missing}", canceling plugin execution...`,"plugin",[
|
|
201
|
-
{key:"path",value:"./plugins/"+match.id}
|
|
202
|
-
])
|
|
203
|
-
initPluginError = true
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
//handle all bot version incompatibilities
|
|
207
|
-
versionIncompatibilities.forEach((match) => {
|
|
208
|
-
const plugin = opendiscord.plugins.get(match.id)
|
|
209
|
-
if (plugin && !plugin.crashed){
|
|
210
|
-
plugin.crashed = true
|
|
211
|
-
plugin.crashReason = "incompatible.version"
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const versions = plugin?.data.supportedVersions?.join(", ") ?? "<unknown-version>"
|
|
215
|
-
const currentVersion = opendiscord.versions.get("opendiscord:version")?.toString() ?? "<OD:UNKNOWN_VERION>"
|
|
216
|
-
opendiscord.log(`Plugin version incompatibility: plugin requires "${versions}" but current bot version is "${currentVersion}", canceling plugin execution...`,"plugin",[
|
|
217
|
-
{key:"path",value:"./plugins/"+match.id}
|
|
218
|
-
])
|
|
219
|
-
initPluginError = true
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
//exit on error (when soft mode disabled)
|
|
223
|
-
if (!opendiscord.sharedFuses.getFuse("softPluginLoading") && initPluginError){
|
|
224
|
-
console.log("")
|
|
225
|
-
opendiscord.log("Please fix all plugin errors above & try again!","error")
|
|
226
|
-
process.exit(1)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
//preload all events required for every plugin
|
|
230
|
-
for (const plugin of sortedPlugins){
|
|
231
|
-
if (plugin.enabled) plugin.data.events.forEach((event) => opendiscord.events.add(new api.ODEvent(event)))
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
//execute all working plugins
|
|
235
|
-
for (const plugin of sortedPlugins){
|
|
236
|
-
const status = await plugin.execute(opendiscord.debug,false)
|
|
237
|
-
|
|
238
|
-
//exit on error (when soft mode disabled)
|
|
239
|
-
if (!status && !opendiscord.sharedFuses.getFuse("softPluginLoading")){
|
|
240
|
-
console.log("")
|
|
241
|
-
opendiscord.log("Please fix all plugin errors above & try again!","error")
|
|
242
|
-
process.exit(1)
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
for (const plugin of sortedPlugins){
|
|
247
|
-
const authors = [plugin.details.author,...(plugin.details.contributors ?? [])].join(", ")
|
|
248
|
-
|
|
249
|
-
if (plugin.enabled){
|
|
250
|
-
opendiscord.debug.debug("Plugin \""+plugin.id.value+"\" loaded",[
|
|
251
|
-
{key:"status",value:(plugin.crashed ? "crashed" : "success")},
|
|
252
|
-
{key:"crashReason",value:(plugin.crashed ? (plugin.crashReason ?? "/") : "/")},
|
|
253
|
-
{key:"authors",value:authors},
|
|
254
|
-
{key:"version",value:plugin.version.toString()},
|
|
255
|
-
{key:"priority",value:plugin.priority.toString()}
|
|
256
|
-
])
|
|
257
|
-
}else{
|
|
258
|
-
opendiscord.debug.debug("Plugin \""+plugin.id.value+"\" disabled",[
|
|
259
|
-
{key:"authors",value:authors},
|
|
260
|
-
{key:"version",value:plugin.version.toString()},
|
|
261
|
-
{key:"priority",value:plugin.priority.toString()}
|
|
262
|
-
])
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
package/src/utilities/index.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs"
|
|
2
|
-
import ansis from "ansis"
|
|
3
|
-
import * as api from "../api/index.js"
|
|
4
|
-
import * as discord from "discord.js"
|
|
5
|
-
|
|
6
|
-
/**## sharedFuses `utility variable`
|
|
7
|
-
* All shared fuses from Open Discord. Please use `opendiscord.sharedFuses` instead!
|
|
8
|
-
*/
|
|
9
|
-
export const sharedFuses: api.ODSharedFuseManager = new api.ODSharedFuseManager()
|
|
10
|
-
|
|
11
|
-
/**## checkNodeVersion `utility function`
|
|
12
|
-
* Check if the node.js version is v20 or higher.
|
|
13
|
-
*/
|
|
14
|
-
export function checkNodeVersion(project:api.ODProjectType){
|
|
15
|
-
const nodev = process.versions.node.split(".")
|
|
16
|
-
if (Number(nodev[0]) < 20){
|
|
17
|
-
const title = (project == "openticket") ? "OPEN TICKET" : "OPEN MODERATION"
|
|
18
|
-
console.log("\n\n==============================\n["+title+" ERROR]: Invalid node.js version. Open Ticket requires node.js v20 or above!\n==============================\n\n")
|
|
19
|
-
process.exit(1)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**## moduleInstalled `utility function`
|
|
24
|
-
* Use this function to check if an npm package is installed or not!
|
|
25
|
-
* @example utilities.moduleInstalled("discord.js") //check if discord.js is installed
|
|
26
|
-
*/
|
|
27
|
-
export function moduleInstalled(id:string,throwError?:boolean): boolean {
|
|
28
|
-
try{
|
|
29
|
-
import.meta.resolve(id)
|
|
30
|
-
return true
|
|
31
|
-
}catch{
|
|
32
|
-
if (throwError) throw new Error("npm module \""+id+"\" is not installed! Install it via 'npm install "+id+"'")
|
|
33
|
-
return false
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**## initialStartupLogs `utility function`
|
|
38
|
-
* Use this function to check if an npm package is installed or not!
|
|
39
|
-
* @example utilities.moduleInstalled("discord.js") //check if discord.js is installed
|
|
40
|
-
*/
|
|
41
|
-
export function initialStartupLogs(opendiscord:api.ODMain,project:api.ODProjectType){
|
|
42
|
-
const title = (project == "openticket") ? "OPEN TICKET" : "OPEN MODERATION"
|
|
43
|
-
console.log("\n--------------------------- "+title+" STARTUP ---------------------------")
|
|
44
|
-
opendiscord.log("Logging system activated!","system")
|
|
45
|
-
opendiscord.debug.debug("Using Node.js "+process.version+"!")
|
|
46
|
-
|
|
47
|
-
try{
|
|
48
|
-
const packageJson = JSON.parse(fs.readFileSync("./package.json").toString())
|
|
49
|
-
opendiscord.debug.debug("Using discord.js "+packageJson.dependencies["discord.js"]+"!")
|
|
50
|
-
opendiscord.debug.debug("Using @discordjs/rest "+packageJson.dependencies["@discordjs/rest"]+"!")
|
|
51
|
-
opendiscord.debug.debug("Using ansis "+packageJson.dependencies["ansis"]+"!")
|
|
52
|
-
opendiscord.debug.debug("Using formatted-json-stringify "+packageJson.dependencies["formatted-json-stringify"]+"!")
|
|
53
|
-
opendiscord.debug.debug("Using terminal-kit "+packageJson.dependencies["terminal-kit"]+"!")
|
|
54
|
-
opendiscord.debug.debug("Using typescript "+packageJson.dependencies["typescript"]+"!")
|
|
55
|
-
opendiscord.debug.debug("Using @open-discord-bots/framework "+packageJson.dependencies["@open-discord-bots/framework"]+"!")
|
|
56
|
-
}catch{
|
|
57
|
-
opendiscord.debug.debug("Failed to fetch module versions!")
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**## timer `utility function`
|
|
62
|
-
* Use this to wait for a certain amount of milliseconds. This only works when using `await`
|
|
63
|
-
* @example await utilities.timer(1000) //wait 1sec
|
|
64
|
-
*/
|
|
65
|
-
export async function timer(ms:number): Promise<void> {
|
|
66
|
-
return new Promise((resolve) => {
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
resolve()
|
|
69
|
-
},ms)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**## emojiTitle `utility function`
|
|
74
|
-
* Use this function to create a title with an emoji before/after the text. The style & divider are set in `opendiscord.sharedFuses`
|
|
75
|
-
* @example utilities.emojiTitle("📎","Links") //create a title with an emoji based on the bot emoji style
|
|
76
|
-
*/
|
|
77
|
-
export function emojiTitle(emoji:string, text:string){
|
|
78
|
-
const style = sharedFuses.getFuse("emojiTitleStyle")
|
|
79
|
-
const divider = sharedFuses.getFuse("emojiTitleDivider")
|
|
80
|
-
|
|
81
|
-
if (style == "disabled") return text
|
|
82
|
-
else if (style == "before") return emoji+divider+text
|
|
83
|
-
else if (style == "after") return text+divider+emoji
|
|
84
|
-
else if (style == "double") return emoji+divider+text+divider+emoji
|
|
85
|
-
else return text
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**## runAsync `utility function`
|
|
89
|
-
* Use this function to run a snippet of code asyncronous without creating a separate function for it!
|
|
90
|
-
*/
|
|
91
|
-
export async function runAsync(func:() => Promise<void>): Promise<void> {
|
|
92
|
-
func()
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**## timedAwait `utility function`
|
|
96
|
-
* Use this function to await a promise but reject after the certain timeout has been reached.
|
|
97
|
-
*/
|
|
98
|
-
export function timedAwait<ReturnValue>(promise:ReturnValue,timeout:number,onError:(err:Error) => void): ReturnValue {
|
|
99
|
-
let allowResolve = true
|
|
100
|
-
return new Promise(async (resolve,reject) => {
|
|
101
|
-
//set timeout & stop if it is before the promise resolved
|
|
102
|
-
setTimeout(() => {
|
|
103
|
-
allowResolve = false
|
|
104
|
-
reject("utilities.timedAwait() => Promise Timeout")
|
|
105
|
-
},timeout)
|
|
106
|
-
|
|
107
|
-
//get promise result & return if not already rejected
|
|
108
|
-
try{
|
|
109
|
-
const res = await promise
|
|
110
|
-
if (allowResolve) resolve(res)
|
|
111
|
-
}catch(err:any){
|
|
112
|
-
onError(err)
|
|
113
|
-
}
|
|
114
|
-
return promise
|
|
115
|
-
}) as ReturnValue
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**## dateString `utility function`
|
|
119
|
-
* Use this function to create a short date string in the following format: `DD/MM/YYYY HH:MM:SS`
|
|
120
|
-
*/
|
|
121
|
-
export function dateString(date:Date): string {
|
|
122
|
-
return `${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**## asyncReplace `utility function`
|
|
126
|
-
* Same as `string.replace(search, value)` but with async compatibility
|
|
127
|
-
*/
|
|
128
|
-
export async function asyncReplace(text:string, regex:RegExp, func:(value:string,...args:any[]) => Promise<string>): Promise<string> {
|
|
129
|
-
const promises: Promise<string>[] = []
|
|
130
|
-
text.replace(regex,(match,...args) => {
|
|
131
|
-
promises.push(func(match,...args))
|
|
132
|
-
return match
|
|
133
|
-
})
|
|
134
|
-
const data = await Promise.all(promises)
|
|
135
|
-
const result = text.replace(regex,(match) => {
|
|
136
|
-
const replaceResult = data.shift()
|
|
137
|
-
return replaceResult ?? match
|
|
138
|
-
})
|
|
139
|
-
return result
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**## getLongestLength `utility function`
|
|
143
|
-
* Get the length of the longest string in the array.
|
|
144
|
-
*/
|
|
145
|
-
export function getLongestLength(texts:string[]): number {
|
|
146
|
-
return Math.max(...texts.map((t) => ansis.strip(t).length))
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**## ordinalNumber `utility function`
|
|
150
|
-
* Get a human readable ordinal number (e.g. 1st, 2nd, 3rd, 4th, ...) from a Javascript number.
|
|
151
|
-
*/
|
|
152
|
-
export function ordinalNumber(num:number){
|
|
153
|
-
const i = Math.abs(Math.round(num))
|
|
154
|
-
const cent = i % 100
|
|
155
|
-
if (cent >= 10 && cent <= 20) return i+'th'
|
|
156
|
-
const dec = i % 10
|
|
157
|
-
if (dec === 1) return i+'st'
|
|
158
|
-
if (dec === 2) return i+'nd'
|
|
159
|
-
if (dec === 3) return i+'rd'
|
|
160
|
-
return i+'th'
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**## trimEmojis `utility function`
|
|
164
|
-
* Trim/remove all emoji's from a Javascript string.
|
|
165
|
-
*/
|
|
166
|
-
export function trimEmojis(text:string){
|
|
167
|
-
return text.replace(/(\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?(?:\u200D\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?)*)/gu,"")
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**## getMessageFromBuildResult `utility function`
|
|
171
|
-
* Get the final `messageCreateOptions` from a returned build result from builders/components.
|
|
172
|
-
*/
|
|
173
|
-
export function getMessageFromBuildResult(build:api.ODMessageBuildResult|api.ODMessageComponentBuildResult,type:"interaction"|"message"){
|
|
174
|
-
const msgFlags: number[] = []
|
|
175
|
-
let msgData: discord.MessageCreateOptions
|
|
176
|
-
if ('message' in build){
|
|
177
|
-
//USING BUILDERS (deprecated)
|
|
178
|
-
msgData = build.message
|
|
179
|
-
if (build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral)
|
|
180
|
-
}else{
|
|
181
|
-
//USING COMPONENTS
|
|
182
|
-
msgData = build.msg
|
|
183
|
-
if (type == "interaction" && build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral) //disabled with regular messages
|
|
184
|
-
if (build.componentsV2) msgFlags.push(discord.MessageFlags.IsComponentsV2)
|
|
185
|
-
if (build.supressEmbeds) msgFlags.push(discord.MessageFlags.SuppressEmbeds)
|
|
186
|
-
if (build.supressNotifications) msgFlags.push(discord.MessageFlags.SuppressNotifications)
|
|
187
|
-
}
|
|
188
|
-
return Object.assign(msgData,{flags:msgFlags})
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**## easterEggs `utility object`
|
|
192
|
-
* Object containing data for Open Ticket easter eggs.
|
|
193
|
-
*/
|
|
194
|
-
export const easterEggs: api.ODEasterEggs = {
|
|
195
|
-
/* THANK YOU TO ALL OUR CONTRIBUTORS!!! */
|
|
196
|
-
creator:"779742674932072469", //DJj123dj
|
|
197
|
-
translators:[
|
|
198
|
-
"779742674932072469", //DJj123dj
|
|
199
|
-
"574172558006681601", //Sanke
|
|
200
|
-
"540639725300613136", //Guillee.3
|
|
201
|
-
"547231585368539136", //Mods HD
|
|
202
|
-
"664934139954331649", //SpyEye
|
|
203
|
-
"498055992962187264", //Redactado
|
|
204
|
-
"912052735950618705", //T0miiis
|
|
205
|
-
"366673202610569227", //johusens
|
|
206
|
-
"360780292853858306", //David.3
|
|
207
|
-
"950611418389024809", //Sarcastic
|
|
208
|
-
"461603955517161473", //Maurizo
|
|
209
|
-
"465111430274875402", //The_Gamer
|
|
210
|
-
"586376952470831104", //Erxg
|
|
211
|
-
"226695254433202176", //Mkevas
|
|
212
|
-
"437695615095275520", //NoOneNook
|
|
213
|
-
"530047191222583307", //Anderskiy
|
|
214
|
-
"719072181631320145", //ToStam
|
|
215
|
-
"1172870906377408512", //Stragar
|
|
216
|
-
"1084794575945744445", //Sasanwm
|
|
217
|
-
"449613814049275905", //Benzorich
|
|
218
|
-
"905373133085741146", //Ronalds
|
|
219
|
-
"918504977369018408", //Palestinian
|
|
220
|
-
"807970841035145216", //Kornel0706
|
|
221
|
-
"1198883915826475080", //Nova
|
|
222
|
-
"669988226819162133", //Danoglez
|
|
223
|
-
"1313597620996018271", //Fraden1
|
|
224
|
-
"547809968145956884", //TsgIndrius
|
|
225
|
-
"264120132660363267", //Quiradon
|
|
226
|
-
"1272034143777329215", //NotMega
|
|
227
|
-
"LOREMIPSUM", //TODO, ADD MORE IDS IN FUTURE!
|
|
228
|
-
]
|
|
229
|
-
}
|
package/tools/cleanup.js
DELETED
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2025",
|
|
4
|
-
"strictNullChecks": true,
|
|
5
|
-
"strictPropertyInitialization": true,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"module": "NodeNext",
|
|
8
|
-
"moduleResolution": "NodeNext",
|
|
9
|
-
"rootDir": "./src",
|
|
10
|
-
"outDir": "./dist"
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"src/**/*"
|
|
14
|
-
]
|
|
15
|
-
}
|