@open-discord-bots/framework 0.2.4 → 0.2.5

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.
@@ -1,176 +0,0 @@
1
- import { ODId, ODManager, ODManagerData, ODValidId } from "./base";
2
- import { ODDebugger } from "./console";
3
- import { ODDatabase, ODDatabaseIdConstraint, ODJsonDatabaseStructure } from "./database";
4
- import * as discord from "discord.js";
5
- /**## ODValidStatValue `type`
6
- * These are the only allowed types for a stat value to improve compatibility with different database systems.
7
- */
8
- export type ODValidStatValue = string | number | boolean;
9
- /**## ODStatsManagerInitCallback `type`
10
- * This callback can be used to execute something when the stats have been initiated.
11
- *
12
- * By default this is used to clear stats from users that left the server or tickets which don't exist anymore.
13
- */
14
- export type ODStatsManagerInitCallback = (database: ODJsonDatabaseStructure, deletables: ODJsonDatabaseStructure) => void | Promise<void>;
15
- /**## ODStatScopeSetMode `type`
16
- * This type contains all valid methods for changing the value of a stat.
17
- */
18
- export type ODStatScopeSetMode = "set" | "increase" | "decrease";
19
- /**## ODStatsManagerIdConstraint `type`
20
- * The constraint/layout for id mappings/interfaces of the `ODStatsManager` class.
21
- */
22
- export type ODStatsManagerIdConstraint = Record<string, ODStatScope>;
23
- /**## ODStatsManager `class`
24
- * This is an Open Discord stats manager.
25
- *
26
- * This class is responsible for managing all stats of the bot.
27
- * Stats are categorized in "scopes" which can be accessed in this manager.
28
- *
29
- * Stats can be accessed in the individual scopes.
30
- */
31
- export declare class ODStatsManager<IdList extends ODStatsManagerIdConstraint = ODStatsManagerIdConstraint> extends ODManager<ODStatScope> {
32
- #private;
33
- /**Alias to Open Discord stats database. */
34
- database: ODDatabase<ODDatabaseIdConstraint> | null;
35
- constructor(debug: ODDebugger);
36
- /**Select the database to use to read/write all stats from/to. */
37
- useDatabase(database: ODDatabase<ODDatabaseIdConstraint>): void;
38
- add(data: ODStatScope, overwrite?: boolean): boolean;
39
- /**Init all stats and run `onInit()` listeners. */
40
- init(): Promise<void>;
41
- /**Reset all stats. (clears the entire database) */
42
- reset(): Promise<void>;
43
- /**Run a function when the stats are initialized. This can be used to clear stats from users that left the server or tickets which don't exist anymore. */
44
- onInit(callback: ODStatsManagerInitCallback): void;
45
- get<StatsId extends keyof IdList>(id: StatsId): IdList[StatsId];
46
- get(id: ODValidId): ODStatScope | null;
47
- remove<StatsId extends keyof IdList>(id: StatsId): IdList[StatsId];
48
- remove(id: ODValidId): ODStatScope | null;
49
- exists(id: keyof IdList): boolean;
50
- exists(id: ODValidId): boolean;
51
- }
52
- /**## ODStatScopeIdConstraint `type`
53
- * The constraint/layout for id mappings/interfaces of the `ODStatScope` class.
54
- */
55
- export type ODStatScopeIdConstraint = Record<string, ODStat>;
56
- /**## ODStatScope `class`
57
- * This is an Open Discord stat scope.
58
- *
59
- * A scope can contain multiple stats. Every scope is seperated from other scopes.
60
- * Here, you can read & write the values of all stats.
61
- *
62
- * The built-in Open Discord scopes are: `global`, `user`, `ticket`
63
- */
64
- export declare class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdConstraint> extends ODManager<ODStat> {
65
- /**The id of this statistics scope. */
66
- id: ODId;
67
- /**Is this stat scope already initialized? */
68
- ready: boolean;
69
- /**Alias to Open Discord stats database. */
70
- database: ODDatabase<ODDatabaseIdConstraint> | null;
71
- /**The name of this scope (used in embed title) */
72
- name: string;
73
- constructor(id: ODValidId, name: string);
74
- /**Select the database to use to read/write all stats from/to. (Automatically assigned when used in `ODStatsManager`) */
75
- useDatabase(database: ODDatabase<ODDatabaseIdConstraint>): void;
76
- /**Get the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
77
- getStat<StatsId extends keyof IdList>(id: StatsId, scopeId: string): Promise<ODValidStatValue | null>;
78
- getStat(id: ODValidId, scopeId: string): Promise<ODValidStatValue | null>;
79
- /**Get the value of a statistic for all `scopeId`'s. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
80
- getAllStats<StatsId extends keyof IdList>(id: StatsId): Promise<{
81
- id: string;
82
- value: ODValidStatValue;
83
- }[]>;
84
- getAllStats(id: ODValidId): Promise<{
85
- id: string;
86
- value: ODValidStatValue;
87
- }[]>;
88
- /**Set, increase or decrease the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
89
- setStat<StatsId extends keyof IdList>(id: StatsId, scopeId: string, value: ODValidStatValue, mode: ODStatScopeSetMode): Promise<boolean>;
90
- setStat(id: ODValidId, scopeId: string, value: ODValidStatValue, mode: ODStatScopeSetMode): Promise<boolean>;
91
- /**Reset the value of a statistic to the initial value. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
92
- resetStat<StatsId extends keyof IdList>(id: ODValidId, scopeId: string): Promise<ODValidStatValue | null>;
93
- resetStat(id: ODValidId, scopeId: string): Promise<ODValidStatValue | null>;
94
- /**Initialize this stat scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
95
- init(): string[];
96
- /**Render all stats in this scope for usage in a discord message/embed. */
97
- render(scopeId: string, guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User): Promise<string>;
98
- get<StatsId extends keyof IdList>(id: StatsId): IdList[StatsId];
99
- get(id: ODValidId): ODStat | null;
100
- remove<StatsId extends keyof IdList>(id: StatsId): IdList[StatsId];
101
- remove(id: ODValidId): ODStat | null;
102
- exists(id: keyof IdList): boolean;
103
- exists(id: ODValidId): boolean;
104
- }
105
- /**## ODStatGlobalScope `class`
106
- * This is an Open Discord stat global scope.
107
- *
108
- * A scope can contain multiple stats. Every scope is seperated from other scopes.
109
- * Here, you can read & write the values of all stats.
110
- *
111
- * This scope is made specifically for the global stats of Open Discord.
112
- */
113
- export declare class ODStatGlobalScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdConstraint> extends ODStatScope<IdList> {
114
- getStat<StatsId extends keyof IdList>(id: StatsId): Promise<ODValidStatValue | null>;
115
- getStat(id: ODValidId): Promise<ODValidStatValue | null>;
116
- getAllStats<StatsId extends keyof IdList>(id: StatsId): Promise<{
117
- id: string;
118
- value: ODValidStatValue;
119
- }[]>;
120
- getAllStats(id: ODValidId): Promise<{
121
- id: string;
122
- value: ODValidStatValue;
123
- }[]>;
124
- setStat<StatsId extends keyof IdList>(id: StatsId, value: ODValidStatValue, mode: ODStatScopeSetMode): Promise<boolean>;
125
- setStat(id: ODValidId, value: ODValidStatValue, mode: ODStatScopeSetMode): Promise<boolean>;
126
- resetStat<StatsId extends keyof IdList>(id: ODValidId): Promise<ODValidStatValue | null>;
127
- resetStat(id: ODValidId): Promise<ODValidStatValue | null>;
128
- render(scopeId: "GLOBAL", guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User): Promise<string>;
129
- }
130
- /**## ODStatRenderer `type`
131
- * This callback will render a single statistic for a discord embed/message.
132
- */
133
- export type ODStatRenderer = (value: ODValidStatValue, scopeId: string, guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User) => string | Promise<string>;
134
- /**## ODStat `class`
135
- * This is an Open Discord statistic.
136
- *
137
- * This single statistic doesn't do anything except defining the rules of this statistic.
138
- * Use it in a stats scope to register a new statistic. A statistic can also include a priority to choose the render priority.
139
- *
140
- * It's recommended to use the `ODBasicStat` & `ODDynamicStat` classes instead of this one!
141
- */
142
- export declare class ODStat extends ODManagerData {
143
- /**The priority of this statistic. */
144
- priority: number;
145
- /**The render function of this statistic. */
146
- render: ODStatRenderer;
147
- /**The value of this statistic. */
148
- value: ODValidStatValue | null;
149
- constructor(id: ODValidId, priority: number, render: ODStatRenderer, value?: ODValidStatValue);
150
- }
151
- /**## ODBasicStat `class`
152
- * This is an Open Discord basic statistic.
153
- *
154
- * This single statistic will store a number, boolean or string in the database.
155
- * Use it to create a simple statistic for any stats scope.
156
- */
157
- export declare class ODBasicStat extends ODStat {
158
- /**The name of this stat. Rendered in discord embeds/messages. */
159
- name: string;
160
- constructor(id: ODValidId, priority: number, name: string, value: ODValidStatValue);
161
- }
162
- /**## ODDynamicStatRenderer `type`
163
- * This callback will render a single dynamic statistic for a discord embed/message.
164
- */
165
- export type ODDynamicStatRenderer = (scopeId: string, guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User) => string | Promise<string>;
166
- /**## ODDynamicStat `class`
167
- * This is an Open Discord dynamic statistic.
168
- *
169
- * A dynamic statistic does not store anything in the database! Instead, it will execute a function to return a custom result.
170
- * This can be used to show statistics which are not stored in the database.
171
- *
172
- * This is used in Open Discord for the live ticket status, participants & system status.
173
- */
174
- export declare class ODDynamicStat extends ODStat {
175
- constructor(id: ODValidId, priority: number, render: ODDynamicStatRenderer);
176
- }