@open-discord-bots/framework 0.2.4 → 0.2.6
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 +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/main.d.ts +3 -3
- package/dist/api/main.js +2 -2
- package/dist/api/modules/action.d.ts +4 -4
- package/dist/api/modules/base.d.ts +12 -6
- package/dist/api/modules/builder.d.ts +25 -25
- package/dist/api/modules/checker.d.ts +7 -7
- package/dist/api/modules/client.d.ts +13 -13
- package/dist/api/modules/code.d.ts +5 -5
- package/dist/api/modules/code.js +1 -1
- package/dist/api/modules/config.d.ts +4 -4
- package/dist/api/modules/console.d.ts +4 -4
- package/dist/api/modules/console.js +2 -2
- package/dist/api/modules/cooldown.d.ts +4 -4
- package/dist/api/modules/database.d.ts +13 -13
- package/dist/api/modules/event.d.ts +4 -4
- package/dist/api/modules/flag.d.ts +4 -4
- package/dist/api/modules/fuse.d.ts +6 -6
- package/dist/api/modules/fuse.js +3 -3
- package/dist/api/modules/helpmenu.d.ts +7 -7
- package/dist/api/modules/language.d.ts +6 -6
- package/dist/api/modules/permission.d.ts +4 -4
- package/dist/api/modules/plugin.d.ts +7 -7
- package/dist/api/modules/post.d.ts +4 -4
- package/dist/api/modules/progressbar.d.ts +7 -7
- package/dist/api/modules/responder.d.ts +19 -19
- package/dist/api/modules/session.d.ts +4 -4
- package/dist/api/modules/startscreen.d.ts +4 -4
- package/dist/api/modules/statistic.d.ts +176 -0
- package/dist/api/modules/{stat.js → statistic.js} +52 -52
- package/dist/api/modules/verifybar.d.ts +4 -4
- package/package.json +1 -1
- package/src/api/index.ts +1 -1
- package/src/api/main.ts +14 -14
- package/src/api/modules/action.ts +4 -4
- package/src/api/modules/base.ts +15 -10
- package/src/api/modules/builder.ts +25 -25
- package/src/api/modules/checker.ts +7 -7
- package/src/api/modules/client.ts +13 -13
- package/src/api/modules/code.ts +5 -5
- package/src/api/modules/config.ts +4 -4
- package/src/api/modules/console.ts +6 -6
- package/src/api/modules/cooldown.ts +4 -4
- package/src/api/modules/database.ts +13 -13
- package/src/api/modules/event.ts +4 -4
- package/src/api/modules/flag.ts +4 -4
- package/src/api/modules/fuse.ts +9 -9
- package/src/api/modules/helpmenu.ts +7 -7
- package/src/api/modules/language.ts +6 -6
- package/src/api/modules/permission.ts +4 -4
- package/src/api/modules/plugin.ts +7 -7
- package/src/api/modules/post.ts +4 -4
- package/src/api/modules/progressbar.ts +7 -7
- package/src/api/modules/responder.ts +19 -19
- package/src/api/modules/session.ts +4 -4
- package/src/api/modules/startscreen.ts +4 -4
- package/src/api/modules/{stat.ts → statistic.ts} +117 -117
- package/src/api/modules/verifybar.ts +4 -4
- package/dist/api/modules/stat.d.ts +0 -176
|
@@ -1,66 +1,66 @@
|
|
|
1
1
|
///////////////////////////////////////
|
|
2
|
-
//
|
|
2
|
+
//STATISTIC MODULE
|
|
3
3
|
///////////////////////////////////////
|
|
4
|
-
import { ODId, ODManager, ODManagerData, ODSystemError, ODValidId } from "./base"
|
|
4
|
+
import { ODId, ODManager, ODManagerData, ODNoGeneric, ODSystemError, ODValidId } from "./base"
|
|
5
5
|
import { ODDebugger } from "./console"
|
|
6
6
|
import { ODDatabase, ODDatabaseIdConstraint, ODJsonDatabaseStructure } from "./database"
|
|
7
7
|
import * as discord from "discord.js"
|
|
8
8
|
|
|
9
|
-
/**##
|
|
10
|
-
* These are the only allowed types for a
|
|
9
|
+
/**## ODValidStatisticValue `type`
|
|
10
|
+
* These are the only allowed types for a statistic value to improve compatibility with different database systems.
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
12
|
+
export type ODValidStatisticValue = string|number|boolean
|
|
13
13
|
|
|
14
|
-
/**##
|
|
15
|
-
* This callback can be used to execute something when the
|
|
14
|
+
/**## ODStatisticManagerInitCallback `type`
|
|
15
|
+
* This callback can be used to execute something when the statistics have been initiated.
|
|
16
16
|
*
|
|
17
|
-
* By default this is used to clear
|
|
17
|
+
* By default this is used to clear statistics from users that left the server or tickets which don't exist anymore.
|
|
18
18
|
*/
|
|
19
|
-
export type
|
|
19
|
+
export type ODStatisticManagerInitCallback = (database:ODJsonDatabaseStructure, deletables:ODJsonDatabaseStructure) => void|Promise<void>
|
|
20
20
|
|
|
21
|
-
/**##
|
|
22
|
-
* This type contains all valid methods for changing the value of a
|
|
21
|
+
/**## ODStatisticScopeSetMode `type`
|
|
22
|
+
* This type contains all valid methods for changing the value of a statistic.
|
|
23
23
|
*/
|
|
24
|
-
export type
|
|
24
|
+
export type ODStatisticScopeSetMode = "set"|"increase"|"decrease"
|
|
25
25
|
|
|
26
|
-
/**##
|
|
27
|
-
* The constraint/layout for id mappings/interfaces of the `
|
|
26
|
+
/**## ODStatisticManagerIdConstraint `type`
|
|
27
|
+
* The constraint/layout for id mappings/interfaces of the `ODStatisticManager` class.
|
|
28
28
|
*/
|
|
29
|
-
export type
|
|
29
|
+
export type ODStatisticManagerIdConstraint = Record<string,ODStatisticScope>
|
|
30
30
|
|
|
31
|
-
/**##
|
|
32
|
-
* This is an Open Discord
|
|
31
|
+
/**## ODStatisticManager `class`
|
|
32
|
+
* This is an Open Discord statistics manager.
|
|
33
33
|
*
|
|
34
|
-
* This class is responsible for managing all
|
|
35
|
-
*
|
|
34
|
+
* This class is responsible for managing all statistics of the bot.
|
|
35
|
+
* Statistic are categorized in "scopes" which can be accessed in this manager.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* Statistic can be accessed in the individual scopes.
|
|
38
38
|
*/
|
|
39
|
-
export class
|
|
39
|
+
export class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint = ODStatisticManagerIdConstraint> extends ODManager<ODStatisticScope> {
|
|
40
40
|
/**Alias to Open Discord debugger. */
|
|
41
41
|
#debug: ODDebugger
|
|
42
|
-
/**Alias to Open Discord
|
|
42
|
+
/**Alias to Open Discord statistics database. */
|
|
43
43
|
database: ODDatabase<ODDatabaseIdConstraint>|null = null
|
|
44
44
|
/**All the listeners for the init event. */
|
|
45
|
-
#initListeners:
|
|
45
|
+
#initListeners: ODStatisticManagerInitCallback[] = []
|
|
46
46
|
|
|
47
47
|
constructor(debug:ODDebugger){
|
|
48
|
-
super(debug,"
|
|
48
|
+
super(debug,"statistic scope")
|
|
49
49
|
this.#debug = debug
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/**Select the database to use to read/write all
|
|
52
|
+
/**Select the database to use to read/write all statistics from/to. */
|
|
53
53
|
useDatabase(database:ODDatabase<ODDatabaseIdConstraint>){
|
|
54
54
|
this.database = database
|
|
55
55
|
}
|
|
56
|
-
add(data:
|
|
56
|
+
add(data:ODStatisticScope, overwrite?:boolean): boolean {
|
|
57
57
|
data.useDebug(this.#debug,"stat")
|
|
58
58
|
if (this.database) data.useDatabase(this.database)
|
|
59
59
|
return super.add(data,overwrite)
|
|
60
60
|
}
|
|
61
|
-
/**Init all
|
|
61
|
+
/**Init all statistics and run `onInit()` listeners. */
|
|
62
62
|
async init(){
|
|
63
|
-
if (!this.database) throw new ODSystemError("Unable to initialize
|
|
63
|
+
if (!this.database) throw new ODSystemError("Unable to initialize statistics scopes due to missing database!")
|
|
64
64
|
|
|
65
65
|
//get all valid categories
|
|
66
66
|
const validCategories: string[] = []
|
|
@@ -68,7 +68,7 @@ export class ODStatsManager<IdList extends ODStatsManagerIdConstraint = ODStatsM
|
|
|
68
68
|
validCategories.push(...scope.init())
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
//filter out the deletable
|
|
71
|
+
//filter out the deletable statistics
|
|
72
72
|
const deletableStats: ODJsonDatabaseStructure = []
|
|
73
73
|
const data = await this.database.getAll()
|
|
74
74
|
data.forEach((data) => {
|
|
@@ -80,13 +80,13 @@ export class ODStatsManager<IdList extends ODStatsManagerIdConstraint = ODStatsM
|
|
|
80
80
|
await cb(data,deletableStats)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
//delete all deletable
|
|
83
|
+
//delete all deletable statistics
|
|
84
84
|
for (const data of deletableStats){
|
|
85
85
|
if (!this.database) return
|
|
86
86
|
await this.database.delete(data.category,data.key)
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
/**Reset all
|
|
89
|
+
/**Reset all statistics. (clears the entire database) */
|
|
90
90
|
async reset(){
|
|
91
91
|
if (!this.database) return
|
|
92
92
|
const data = await this.database.getAll()
|
|
@@ -95,51 +95,51 @@ export class ODStatsManager<IdList extends ODStatsManagerIdConstraint = ODStatsM
|
|
|
95
95
|
await this.database.delete(d.category,d.key)
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
/**Run a function when the
|
|
99
|
-
onInit(callback:
|
|
98
|
+
/**Run a function when the statistics are initialized. This can be used to clear statistics from users that left the server or tickets which don't exist anymore. */
|
|
99
|
+
onInit(callback:ODStatisticManagerInitCallback){
|
|
100
100
|
this.#initListeners.push(callback)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
get<
|
|
104
|
-
get(id:ODValidId):
|
|
103
|
+
get<ScopeId extends keyof ODNoGeneric<IdList>>(id:ScopeId): IdList[ScopeId]
|
|
104
|
+
get(id:ODValidId): ODStatisticScope|null
|
|
105
105
|
|
|
106
|
-
get(id:ODValidId):
|
|
106
|
+
get(id:ODValidId): ODStatisticScope|null {
|
|
107
107
|
return super.get(id)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
remove<
|
|
111
|
-
remove(id:ODValidId):
|
|
110
|
+
remove<ScopeId extends keyof ODNoGeneric<IdList>>(id:ScopeId): IdList[ScopeId]
|
|
111
|
+
remove(id:ODValidId): ODStatisticScope|null
|
|
112
112
|
|
|
113
|
-
remove(id:ODValidId):
|
|
113
|
+
remove(id:ODValidId): ODStatisticScope|null {
|
|
114
114
|
return super.remove(id)
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
exists(id:keyof IdList): boolean
|
|
117
|
+
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
118
118
|
exists(id:ODValidId): boolean
|
|
119
119
|
|
|
120
120
|
exists(id:ODValidId): boolean {
|
|
121
121
|
return super.exists(id)
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
/**##
|
|
125
|
-
* The constraint/layout for id mappings/interfaces of the `
|
|
124
|
+
/**## ODStatisticScopeIdConstraint `type`
|
|
125
|
+
* The constraint/layout for id mappings/interfaces of the `ODStatisticScope` class.
|
|
126
126
|
*/
|
|
127
|
-
export type
|
|
127
|
+
export type ODStatisticScopeIdConstraint = Record<string,ODStatistic>
|
|
128
128
|
|
|
129
|
-
/**##
|
|
130
|
-
* This is an Open Discord
|
|
129
|
+
/**## ODStatisticScope `class`
|
|
130
|
+
* This is an Open Discord statistic scope.
|
|
131
131
|
*
|
|
132
|
-
* A scope can contain multiple
|
|
133
|
-
* Here, you can read & write the values of all
|
|
132
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
133
|
+
* Here, you can read & write the values of all statistics.
|
|
134
134
|
*
|
|
135
135
|
* The built-in Open Discord scopes are: `global`, `user`, `ticket`
|
|
136
136
|
*/
|
|
137
|
-
export class
|
|
137
|
+
export class ODStatisticScope<IdList extends ODStatisticScopeIdConstraint = ODStatisticScopeIdConstraint> extends ODManager<ODStatistic> {
|
|
138
138
|
/**The id of this statistics scope. */
|
|
139
139
|
id: ODId
|
|
140
|
-
/**Is this
|
|
140
|
+
/**Is this scope already initialized? */
|
|
141
141
|
ready: boolean = false
|
|
142
|
-
/**Alias to Open Discord
|
|
142
|
+
/**Alias to Open Discord statistics database. */
|
|
143
143
|
database: ODDatabase<ODDatabaseIdConstraint>|null = null
|
|
144
144
|
/**The name of this scope (used in embed title) */
|
|
145
145
|
name:string
|
|
@@ -150,20 +150,20 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
150
150
|
this.name = name
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
/**Select the database to use to read/write all
|
|
153
|
+
/**Select the database to use to read/write all statistics from/to. (Automatically assigned when used in `ODStatisticManager`) */
|
|
154
154
|
useDatabase(database:ODDatabase<ODDatabaseIdConstraint>){
|
|
155
155
|
this.database = database
|
|
156
156
|
}
|
|
157
|
-
/**Get the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the
|
|
158
|
-
getStat<
|
|
159
|
-
getStat(id:ODValidId, scopeId:string): Promise<
|
|
160
|
-
async getStat(id:ODValidId, scopeId:string): Promise<
|
|
157
|
+
/**Get the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
158
|
+
getStat<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId, scopeId:string): Promise<ODValidStatisticValue|null>
|
|
159
|
+
getStat(id:ODValidId, scopeId:string): Promise<ODValidStatisticValue|null>
|
|
160
|
+
async getStat(id:ODValidId, scopeId:string): Promise<ODValidStatisticValue|null> {
|
|
161
161
|
if (!this.database) return null
|
|
162
162
|
const newId = new ODId(id)
|
|
163
163
|
const data = await this.database.get(this.id.value+"_"+newId.value,scopeId)
|
|
164
164
|
|
|
165
165
|
if (typeof data == "undefined"){
|
|
166
|
-
//set
|
|
166
|
+
//set statistics to default value & return
|
|
167
167
|
return this.resetStat(id,scopeId)
|
|
168
168
|
}else if (typeof data == "string" || typeof data == "boolean" || typeof data == "number"){
|
|
169
169
|
//return value received from database
|
|
@@ -172,14 +172,14 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
172
172
|
//return null on error
|
|
173
173
|
return null
|
|
174
174
|
}
|
|
175
|
-
/**Get the value of a statistic for all `scopeId`'s. The `scopeId` is the unique id of the user, channel, role, etc that the
|
|
176
|
-
getAllStats<
|
|
177
|
-
getAllStats(id:ODValidId): Promise<{id:string,value:
|
|
178
|
-
async getAllStats(id:ODValidId): Promise<{id:string,value:
|
|
175
|
+
/**Get the value of a statistic for all `scopeId`'s. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
176
|
+
getAllStats<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId): Promise<{id:string,value:ODValidStatisticValue}[]>
|
|
177
|
+
getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatisticValue}[]>
|
|
178
|
+
async getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatisticValue}[]> {
|
|
179
179
|
if (!this.database) return []
|
|
180
180
|
const newId = new ODId(id)
|
|
181
181
|
const data = await this.database.getCategory(this.id.value+"_"+newId.value) ?? []
|
|
182
|
-
const output: {id:string,value:
|
|
182
|
+
const output: {id:string,value:ODValidStatisticValue}[] = []
|
|
183
183
|
|
|
184
184
|
for (const stat of data){
|
|
185
185
|
if (typeof stat.value == "string" || typeof stat.value == "boolean" || typeof stat.value == "number"){
|
|
@@ -191,10 +191,10 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
191
191
|
//return null on error
|
|
192
192
|
return output
|
|
193
193
|
}
|
|
194
|
-
/**Set, increase or decrease the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the
|
|
195
|
-
setStat<
|
|
196
|
-
setStat(id:ODValidId, scopeId:string, value:
|
|
197
|
-
async setStat(id:ODValidId, scopeId:string, value:
|
|
194
|
+
/**Set, increase or decrease the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
195
|
+
setStat<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId, scopeId:string, value:ODValidStatisticValue, mode:ODStatisticScopeSetMode): Promise<boolean>
|
|
196
|
+
setStat(id:ODValidId, scopeId:string, value:ODValidStatisticValue, mode:ODStatisticScopeSetMode): Promise<boolean>
|
|
197
|
+
async setStat(id:ODValidId, scopeId:string, value:ODValidStatisticValue, mode:ODStatisticScopeSetMode): Promise<boolean> {
|
|
198
198
|
if (!this.database) return false
|
|
199
199
|
const stat = this.get(id)
|
|
200
200
|
if (!stat) return false
|
|
@@ -211,23 +211,23 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
211
211
|
}
|
|
212
212
|
return true
|
|
213
213
|
}
|
|
214
|
-
/**Reset the value of a statistic to the initial value. The `scopeId` is the unique id of the user, channel, role, etc that the
|
|
215
|
-
resetStat<
|
|
216
|
-
resetStat(id:ODValidId, scopeId:string): Promise<
|
|
217
|
-
async resetStat(id:ODValidId, scopeId:string): Promise<
|
|
214
|
+
/**Reset the value of a statistic to the initial value. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
215
|
+
resetStat<StatisticId extends keyof ODNoGeneric<IdList>>(id:ODValidId, scopeId:string): Promise<ODValidStatisticValue|null>
|
|
216
|
+
resetStat(id:ODValidId, scopeId:string): Promise<ODValidStatisticValue|null>
|
|
217
|
+
async resetStat(id:ODValidId, scopeId:string): Promise<ODValidStatisticValue|null> {
|
|
218
218
|
if (!this.database) return null
|
|
219
219
|
const stat = this.get(id)
|
|
220
220
|
if (!stat) return null
|
|
221
221
|
if (stat.value != null) await this.database.set(this.id.value+"_"+stat.id.value,scopeId,stat.value)
|
|
222
222
|
return stat.value
|
|
223
223
|
}
|
|
224
|
-
/**Initialize this
|
|
224
|
+
/**Initialize this statistic scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
|
|
225
225
|
init(): string[] {
|
|
226
|
-
//get all valid
|
|
226
|
+
//get all valid statistics categories
|
|
227
227
|
this.ready = true
|
|
228
228
|
return this.getAll().map((stat) => this.id.value+"_"+stat.id.value)
|
|
229
229
|
}
|
|
230
|
-
/**Render all
|
|
230
|
+
/**Render all statistics in this scope for usage in a discord message/embed. */
|
|
231
231
|
async render(scopeId:string, guild:discord.Guild, channel:discord.TextBasedChannel, user:discord.User): Promise<string> {
|
|
232
232
|
//sort from high priority to low
|
|
233
233
|
const derefArray = [...this.getAll()]
|
|
@@ -238,7 +238,7 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
238
238
|
|
|
239
239
|
for (const stat of derefArray){
|
|
240
240
|
try {
|
|
241
|
-
if (stat instanceof
|
|
241
|
+
if (stat instanceof ODDynamicStatistic){
|
|
242
242
|
//dynamic render (without value)
|
|
243
243
|
result.push(await stat.render("",scopeId,guild,channel,user))
|
|
244
244
|
}else{
|
|
@@ -255,21 +255,21 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
255
255
|
return result.filter((stat) => stat !== "").join("\n")
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
get<
|
|
259
|
-
get(id:ODValidId):
|
|
258
|
+
get<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId): IdList[StatisticId]
|
|
259
|
+
get(id:ODValidId): ODStatistic|null
|
|
260
260
|
|
|
261
|
-
get(id:ODValidId):
|
|
261
|
+
get(id:ODValidId): ODStatistic|null {
|
|
262
262
|
return super.get(id)
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
remove<
|
|
266
|
-
remove(id:ODValidId):
|
|
265
|
+
remove<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId): IdList[StatisticId]
|
|
266
|
+
remove(id:ODValidId): ODStatistic|null
|
|
267
267
|
|
|
268
|
-
remove(id:ODValidId):
|
|
268
|
+
remove(id:ODValidId): ODStatistic|null {
|
|
269
269
|
return super.remove(id)
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
exists(id:keyof IdList): boolean
|
|
272
|
+
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
273
273
|
exists(id:ODValidId): boolean
|
|
274
274
|
|
|
275
275
|
exists(id:ODValidId): boolean {
|
|
@@ -277,36 +277,36 @@ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdC
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
/**##
|
|
281
|
-
* This is an Open Discord
|
|
280
|
+
/**## ODStatisticGlobalScope `class`
|
|
281
|
+
* This is an Open Discord statistic global scope.
|
|
282
282
|
*
|
|
283
|
-
* A scope can contain multiple
|
|
284
|
-
* Here, you can read & write the values of all
|
|
283
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
284
|
+
* Here, you can read & write the values of all statistics.
|
|
285
285
|
*
|
|
286
|
-
* This scope is made specifically for the global
|
|
286
|
+
* This scope is made specifically for the global statistics of Open Discord.
|
|
287
287
|
*/
|
|
288
|
-
export class
|
|
289
|
-
getStat<
|
|
290
|
-
getStat(id:ODValidId): Promise<
|
|
291
|
-
getStat(id:ODValidId): Promise<
|
|
288
|
+
export class ODStatisticGlobalScope<IdList extends ODStatisticScopeIdConstraint = ODStatisticScopeIdConstraint> extends ODStatisticScope<IdList> {
|
|
289
|
+
getStat<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId): Promise<ODValidStatisticValue|null>
|
|
290
|
+
getStat(id:ODValidId): Promise<ODValidStatisticValue|null>
|
|
291
|
+
getStat(id:ODValidId): Promise<ODValidStatisticValue|null> {
|
|
292
292
|
return super.getStat(id,"GLOBAL")
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
getAllStats<
|
|
296
|
-
getAllStats(id:ODValidId): Promise<{id:string,value:
|
|
297
|
-
getAllStats(id:ODValidId): Promise<{id:string,value:
|
|
295
|
+
getAllStats<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId): Promise<{id:string,value:ODValidStatisticValue}[]>
|
|
296
|
+
getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatisticValue}[]>
|
|
297
|
+
getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatisticValue}[]> {
|
|
298
298
|
return super.getAllStats(id)
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
setStat<
|
|
302
|
-
setStat(id:ODValidId, value:
|
|
303
|
-
setStat(id:ODValidId, value:
|
|
301
|
+
setStat<StatisticId extends keyof ODNoGeneric<IdList>>(id:StatisticId, value:ODValidStatisticValue, mode:ODStatisticScopeSetMode): Promise<boolean>
|
|
302
|
+
setStat(id:ODValidId, value:ODValidStatisticValue, mode:ODStatisticScopeSetMode): Promise<boolean>
|
|
303
|
+
setStat(id:ODValidId, value:ODValidStatisticValue, mode:ODStatisticScopeSetMode): Promise<boolean> {
|
|
304
304
|
return super.setStat(id,"GLOBAL",value,mode)
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
resetStat<
|
|
308
|
-
resetStat(id:ODValidId): Promise<
|
|
309
|
-
resetStat(id:ODValidId): Promise<
|
|
307
|
+
resetStat<StatisticId extends keyof ODNoGeneric<IdList>>(id:ODValidId): Promise<ODValidStatisticValue|null>
|
|
308
|
+
resetStat(id:ODValidId): Promise<ODValidStatisticValue|null>
|
|
309
|
+
resetStat(id:ODValidId): Promise<ODValidStatisticValue|null> {
|
|
310
310
|
return super.resetStat(id,"GLOBAL")
|
|
311
311
|
}
|
|
312
312
|
|
|
@@ -315,28 +315,28 @@ export class ODStatGlobalScope<IdList extends ODStatScopeIdConstraint = ODStatSc
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
/**##
|
|
318
|
+
/**## ODStatisticRenderer `type`
|
|
319
319
|
* This callback will render a single statistic for a discord embed/message.
|
|
320
320
|
*/
|
|
321
|
-
export type
|
|
321
|
+
export type ODStatisticRenderer = (value:ODValidStatisticValue, scopeId:string, guild:discord.Guild, channel:discord.TextBasedChannel, user:discord.User) => string|Promise<string>
|
|
322
322
|
|
|
323
|
-
/**##
|
|
323
|
+
/**## ODStatistic `class`
|
|
324
324
|
* This is an Open Discord statistic.
|
|
325
325
|
*
|
|
326
326
|
* This single statistic doesn't do anything except defining the rules of this statistic.
|
|
327
|
-
* Use it in a
|
|
327
|
+
* Use it in a statistics scope to register a new statistic. A statistic can also include a priority to choose the render priority.
|
|
328
328
|
*
|
|
329
|
-
* It's recommended to use the `
|
|
329
|
+
* It's recommended to use the `ODBaseStatistic` & `ODDynamicStatistic` classes instead of this one!
|
|
330
330
|
*/
|
|
331
|
-
export class
|
|
331
|
+
export class ODStatistic extends ODManagerData {
|
|
332
332
|
/**The priority of this statistic. */
|
|
333
333
|
priority: number
|
|
334
334
|
/**The render function of this statistic. */
|
|
335
|
-
render:
|
|
335
|
+
render: ODStatisticRenderer
|
|
336
336
|
/**The value of this statistic. */
|
|
337
|
-
value:
|
|
337
|
+
value: ODValidStatisticValue|null
|
|
338
338
|
|
|
339
|
-
constructor(id:ODValidId, priority:number, render:
|
|
339
|
+
constructor(id:ODValidId, priority:number, render:ODStatisticRenderer, value?:ODValidStatisticValue){
|
|
340
340
|
super(id)
|
|
341
341
|
this.priority = priority
|
|
342
342
|
this.render = render
|
|
@@ -344,17 +344,17 @@ export class ODStat extends ODManagerData {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
/**##
|
|
347
|
+
/**## ODBaseStatistic `class`
|
|
348
348
|
* This is an Open Discord basic statistic.
|
|
349
349
|
*
|
|
350
350
|
* This single statistic will store a number, boolean or string in the database.
|
|
351
|
-
* Use it to create a simple statistic for any
|
|
351
|
+
* Use it to create a simple statistic for any statistics scope.
|
|
352
352
|
*/
|
|
353
|
-
export class
|
|
354
|
-
/**The name of this
|
|
353
|
+
export class ODBaseStatistic extends ODStatistic {
|
|
354
|
+
/**The name of this statistic. Rendered in discord embeds/messages. */
|
|
355
355
|
name: string
|
|
356
356
|
|
|
357
|
-
constructor(id:ODValidId, priority:number, name:string, value:
|
|
357
|
+
constructor(id:ODValidId, priority:number, name:string, value:ODValidStatisticValue){
|
|
358
358
|
super(id,priority,(value) => {
|
|
359
359
|
return ""+name+": `"+value.toString()+"`"
|
|
360
360
|
},value)
|
|
@@ -362,12 +362,12 @@ export class ODBasicStat extends ODStat {
|
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
/**##
|
|
365
|
+
/**## ODDynamicStatisticRenderer `type`
|
|
366
366
|
* This callback will render a single dynamic statistic for a discord embed/message.
|
|
367
367
|
*/
|
|
368
|
-
export type
|
|
368
|
+
export type ODDynamicStatisticRenderer = (scopeId:string, guild:discord.Guild, channel:discord.TextBasedChannel, user:discord.User) => string|Promise<string>
|
|
369
369
|
|
|
370
|
-
/**##
|
|
370
|
+
/**## ODDynamicStatistic `class`
|
|
371
371
|
* This is an Open Discord dynamic statistic.
|
|
372
372
|
*
|
|
373
373
|
* A dynamic statistic does not store anything in the database! Instead, it will execute a function to return a custom result.
|
|
@@ -375,8 +375,8 @@ export type ODDynamicStatRenderer = (scopeId:string, guild:discord.Guild, channe
|
|
|
375
375
|
*
|
|
376
376
|
* This is used in Open Discord for the live ticket status, participants & system status.
|
|
377
377
|
*/
|
|
378
|
-
export class
|
|
379
|
-
constructor(id:ODValidId, priority:number, render:
|
|
378
|
+
export class ODDynamicStatistic extends ODStatistic {
|
|
379
|
+
constructor(id:ODValidId, priority:number, render:ODDynamicStatisticRenderer){
|
|
380
380
|
super(id,priority,(value,scopeId,guild,channel,user) => {
|
|
381
381
|
return render(scopeId,guild,channel,user)
|
|
382
382
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
///////////////////////////////////////
|
|
2
2
|
//VERIFYBAR MODULE
|
|
3
3
|
///////////////////////////////////////
|
|
4
|
-
import { ODId, ODManager, ODManagerData, ODValidId } from "./base"
|
|
4
|
+
import { ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base"
|
|
5
5
|
import { ODMessage } from "./builder"
|
|
6
6
|
import { ODDebugger } from "./console"
|
|
7
7
|
import { ODButtonResponderInstance } from "./responder"
|
|
@@ -64,21 +64,21 @@ export class ODVerifyBarManager<IdList extends ODVerifyBarManagerIdConstraint =
|
|
|
64
64
|
super(debug,"verifybar")
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
get<VerifyBarId extends keyof IdList
|
|
67
|
+
get<VerifyBarId extends keyof ODNoGeneric<IdList>>(id:VerifyBarId): ODVerifyBar<IdList[VerifyBarId]["successWorkerIds"],IdList[VerifyBarId]["failureWorkerIds"]>
|
|
68
68
|
get(id:ODValidId): ODVerifyBar|null
|
|
69
69
|
|
|
70
70
|
get(id:ODValidId): ODVerifyBar|null {
|
|
71
71
|
return super.get(id)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
remove<VerifyBarId extends keyof IdList
|
|
74
|
+
remove<VerifyBarId extends keyof ODNoGeneric<IdList>>(id:VerifyBarId): ODVerifyBar<IdList[VerifyBarId]["successWorkerIds"],IdList[VerifyBarId]["failureWorkerIds"]>
|
|
75
75
|
remove(id:ODValidId): ODVerifyBar|null
|
|
76
76
|
|
|
77
77
|
remove(id:ODValidId): ODVerifyBar|null {
|
|
78
78
|
return super.remove(id)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
exists(id:keyof IdList): boolean
|
|
81
|
+
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
82
82
|
exists(id:ODValidId): boolean
|
|
83
83
|
|
|
84
84
|
exists(id:ODValidId): boolean {
|