@rimori/client 2.1.8 → 2.2.0
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/dist/cli/types/DatabaseTypes.d.ts +12 -4
- package/dist/controller/AccomplishmentController.js +6 -2
- package/dist/controller/SharedContentController.js +28 -25
- package/dist/plugin/CommunicationHandler.d.ts +1 -0
- package/dist/plugin/RimoriClient.js +1 -1
- package/package.json +1 -1
- package/src/cli/types/DatabaseTypes.ts +17 -16
- package/src/controller/AccomplishmentController.ts +7 -3
- package/src/controller/SharedContentController.ts +34 -32
- package/src/plugin/CommunicationHandler.ts +1 -0
- package/src/plugin/RimoriClient.ts +1 -1
|
@@ -42,8 +42,10 @@ export interface DbColumnDefinition {
|
|
|
42
42
|
restrict?: {
|
|
43
43
|
/** Restrictions for the user */
|
|
44
44
|
user: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
45
|
-
/** Restrictions for the moderator */
|
|
46
|
-
|
|
45
|
+
/** Restrictions for the guild moderator */
|
|
46
|
+
guild_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
47
|
+
/** Restrictions for the language moderator */
|
|
48
|
+
lang_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
@@ -69,8 +71,12 @@ export interface DbTableDefinition {
|
|
|
69
71
|
description: string;
|
|
70
72
|
/** Permissions for the table */
|
|
71
73
|
permissions: {
|
|
74
|
+
/** Permissions for the user */
|
|
72
75
|
user: DbPermissionDefinition;
|
|
73
|
-
moderator
|
|
76
|
+
/** Permissions for the guild moderator */
|
|
77
|
+
guild_moderator?: DbPermissionDefinition;
|
|
78
|
+
/** Permissions for the language moderator */
|
|
79
|
+
lang_moderator?: DbPermissionDefinition;
|
|
74
80
|
};
|
|
75
81
|
/** Column definitions for the table */
|
|
76
82
|
columns: {
|
|
@@ -81,11 +87,13 @@ export interface DbTableDefinition {
|
|
|
81
87
|
* Permission definition for a database table.
|
|
82
88
|
* NONE means the action is not allowed.
|
|
83
89
|
* OWN means only do the action on your own records.
|
|
90
|
+
* GUILD means do the action on all records in the guild.
|
|
91
|
+
* LANG means do the action on all records in the language.
|
|
84
92
|
* ALL means do the action on all records.
|
|
85
93
|
*
|
|
86
94
|
* Defines the permissions for a database table.
|
|
87
95
|
*/
|
|
88
|
-
export type DbPermission = 'NONE' | 'OWN' | 'ALL';
|
|
96
|
+
export type DbPermission = 'NONE' | 'OWN' | 'GUILD' | 'LANG' | 'ALL';
|
|
89
97
|
/**
|
|
90
98
|
* Permission definition for a database table.
|
|
91
99
|
* Defines the permissions for a database table.
|
|
@@ -6,7 +6,9 @@ export class AccomplishmentController {
|
|
|
6
6
|
}
|
|
7
7
|
emitAccomplishment(payload) {
|
|
8
8
|
const accomplishmentPayload = Object.assign(Object.assign({}, payload), { type: 'durationMinutes' in payload ? 'macro' : 'micro' });
|
|
9
|
-
this.validateAccomplishment(accomplishmentPayload)
|
|
9
|
+
if (!this.validateAccomplishment(accomplishmentPayload)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
10
12
|
const sanitizedPayload = this.sanitizeAccomplishment(accomplishmentPayload);
|
|
11
13
|
const topic = 'global.accomplishment.trigger' + (accomplishmentPayload.type === 'macro' ? 'Macro' : 'Micro');
|
|
12
14
|
EventBus.emit(this.pluginId, topic, sanitizedPayload);
|
|
@@ -29,7 +31,8 @@ export class AccomplishmentController {
|
|
|
29
31
|
}
|
|
30
32
|
//durationMinutes is required
|
|
31
33
|
if (payload.type === 'macro' && payload.durationMinutes < 4) {
|
|
32
|
-
|
|
34
|
+
console.warn('The duration must be at least 4 minutes');
|
|
35
|
+
return false;
|
|
33
36
|
}
|
|
34
37
|
//errorRatio is required
|
|
35
38
|
if (payload.type === 'macro' && (payload.errorRatio < 0 || payload.errorRatio > 1)) {
|
|
@@ -43,6 +46,7 @@ export class AccomplishmentController {
|
|
|
43
46
|
}
|
|
44
47
|
});
|
|
45
48
|
}
|
|
49
|
+
return true;
|
|
46
50
|
}
|
|
47
51
|
sanitizeAccomplishment(payload) {
|
|
48
52
|
var _a;
|
|
@@ -28,31 +28,34 @@ export class SharedContentController {
|
|
|
28
28
|
//this filter is there if the content should be filtered additionally by a column and value
|
|
29
29
|
filter, options) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
// The db cache of the shared content is temporary disabled until the new shared content implementation is completed
|
|
32
|
+
// if (false) {
|
|
33
|
+
// let query = this.supabase
|
|
34
|
+
// .from('shared_content')
|
|
35
|
+
// .select('*, scc:shared_content_completed(id, state)')
|
|
36
|
+
// .eq('content_type', contentType)
|
|
37
|
+
// .not('scc.state', 'in', '("completed","ongoing","hidden")')
|
|
38
|
+
// .is('deleted_at', null);
|
|
39
|
+
// if (options?.excludeIds?.length ?? 0 > 0) {
|
|
40
|
+
// const excludeIds = options.excludeIds.filter((id) => !id.startsWith('internal-temp-id-'));
|
|
41
|
+
// // Supabase expects raw PostgREST syntax like '("id1","id2")'.
|
|
42
|
+
// const excludeList = `(${excludeIds.map((id) => `"${id}"`).join(',')})`;
|
|
43
|
+
// query = query.not('id', 'in', excludeList);
|
|
44
|
+
// }
|
|
45
|
+
// if (filter) {
|
|
46
|
+
// query.contains('data', filter);
|
|
47
|
+
// }
|
|
48
|
+
// const { data: newAssignments, error } = await query.limit(30);
|
|
49
|
+
// if (error) {
|
|
50
|
+
// console.error('error fetching new assignments:', error);
|
|
51
|
+
// throw new Error('error fetching new assignments');
|
|
52
|
+
// }
|
|
53
|
+
// // console.log('newAssignments:', newAssignments);
|
|
54
|
+
// if (!options?.alwaysGenerateNew && newAssignments.length > 0) {
|
|
55
|
+
// const index = Math.floor(Math.random() * newAssignments.length);
|
|
56
|
+
// return newAssignments[index];
|
|
57
|
+
// }
|
|
58
|
+
// }
|
|
56
59
|
const instructions = yield this.generateNewAssignment(contentType, generatorInstructions, filter);
|
|
57
60
|
console.log('instructions:', instructions);
|
|
58
61
|
//create the shared content object
|
|
@@ -276,7 +276,7 @@ export class RimoriClient {
|
|
|
276
276
|
this.accomplishmentHandler = new AccomplishmentController(info.pluginId);
|
|
277
277
|
this.settingsController = new SettingsController(supabase, info.pluginId, info.guild);
|
|
278
278
|
this.sharedContentController = new SharedContentController(supabase, this);
|
|
279
|
-
this.translator = new Translator(info.
|
|
279
|
+
this.translator = new Translator(info.interfaceLanguage);
|
|
280
280
|
//only init logger in workers and on main plugin pages
|
|
281
281
|
if (this.getQueryParam('applicationMode') !== 'sidebar') {
|
|
282
282
|
Logger.getInstance(this);
|
package/package.json
CHANGED
|
@@ -3,14 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Supported database column data types for table schema definitions.
|
|
5
5
|
*/
|
|
6
|
-
type DbColumnType =
|
|
7
|
-
| 'decimal'
|
|
8
|
-
| 'integer'
|
|
9
|
-
| 'text'
|
|
10
|
-
| 'boolean'
|
|
11
|
-
| 'json'
|
|
12
|
-
| 'timestamp'
|
|
13
|
-
| 'uuid';
|
|
6
|
+
type DbColumnType = 'decimal' | 'integer' | 'text' | 'boolean' | 'json' | 'timestamp' | 'uuid';
|
|
14
7
|
|
|
15
8
|
/**
|
|
16
9
|
* Foreign key relationship configuration with cascade delete support.
|
|
@@ -55,10 +48,12 @@ export interface DbColumnDefinition {
|
|
|
55
48
|
restrict?: {
|
|
56
49
|
/** Restrictions for the user */
|
|
57
50
|
user: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
58
|
-
/** Restrictions for the moderator */
|
|
59
|
-
|
|
51
|
+
/** Restrictions for the guild moderator */
|
|
52
|
+
guild_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
53
|
+
/** Restrictions for the language moderator */
|
|
54
|
+
lang_moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
60
55
|
/** Restrictions for the maintainer */
|
|
61
|
-
// maintainer?: Partial<DbPermissionDefinition
|
|
56
|
+
// maintainer?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
|
|
62
57
|
};
|
|
63
58
|
}
|
|
64
59
|
|
|
@@ -86,9 +81,14 @@ export interface DbTableDefinition {
|
|
|
86
81
|
description: string;
|
|
87
82
|
/** Permissions for the table */
|
|
88
83
|
permissions: {
|
|
84
|
+
/** Permissions for the user */
|
|
89
85
|
user: DbPermissionDefinition;
|
|
90
|
-
moderator
|
|
91
|
-
|
|
86
|
+
/** Permissions for the guild moderator */
|
|
87
|
+
guild_moderator?: DbPermissionDefinition;
|
|
88
|
+
/** Permissions for the language moderator */
|
|
89
|
+
lang_moderator?: DbPermissionDefinition;
|
|
90
|
+
/** Permissions for the maintainer */
|
|
91
|
+
// maintainer?: DbPermissionDefinition;
|
|
92
92
|
};
|
|
93
93
|
/** Column definitions for the table */
|
|
94
94
|
columns: {
|
|
@@ -100,11 +100,13 @@ export interface DbTableDefinition {
|
|
|
100
100
|
* Permission definition for a database table.
|
|
101
101
|
* NONE means the action is not allowed.
|
|
102
102
|
* OWN means only do the action on your own records.
|
|
103
|
+
* GUILD means do the action on all records in the guild.
|
|
104
|
+
* LANG means do the action on all records in the language.
|
|
103
105
|
* ALL means do the action on all records.
|
|
104
106
|
*
|
|
105
107
|
* Defines the permissions for a database table.
|
|
106
108
|
*/
|
|
107
|
-
export type DbPermission = 'NONE' | 'OWN' | 'ALL';
|
|
109
|
+
export type DbPermission = 'NONE' | 'OWN' | 'GUILD' | 'LANG' | 'ALL';
|
|
108
110
|
|
|
109
111
|
/**
|
|
110
112
|
* Permission definition for a database table.
|
|
@@ -120,5 +122,4 @@ export interface DbPermissionDefinition {
|
|
|
120
122
|
/**
|
|
121
123
|
* Full table definition that includes automatically generated fields.
|
|
122
124
|
*/
|
|
123
|
-
export type FullTable<T extends Record<string, DbColumnDefinition>> = T &
|
|
124
|
-
BaseTableStructure;
|
|
125
|
+
export type FullTable<T extends Record<string, DbColumnDefinition>> = T & BaseTableStructure;
|
|
@@ -49,7 +49,9 @@ export class AccomplishmentController {
|
|
|
49
49
|
type: 'durationMinutes' in payload ? 'macro' : 'micro',
|
|
50
50
|
} as AccomplishmentPayload;
|
|
51
51
|
|
|
52
|
-
this.validateAccomplishment(accomplishmentPayload)
|
|
52
|
+
if (!this.validateAccomplishment(accomplishmentPayload)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
53
55
|
|
|
54
56
|
const sanitizedPayload = this.sanitizeAccomplishment(accomplishmentPayload);
|
|
55
57
|
|
|
@@ -58,7 +60,7 @@ export class AccomplishmentController {
|
|
|
58
60
|
EventBus.emit(this.pluginId, topic, sanitizedPayload);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
private validateAccomplishment(payload: AccomplishmentPayload) {
|
|
63
|
+
private validateAccomplishment(payload: AccomplishmentPayload): boolean {
|
|
62
64
|
if (!skillCategories.includes(payload.skillCategory)) {
|
|
63
65
|
throw new Error(`Invalid skill category: ${payload.skillCategory}`);
|
|
64
66
|
}
|
|
@@ -82,7 +84,8 @@ export class AccomplishmentController {
|
|
|
82
84
|
|
|
83
85
|
//durationMinutes is required
|
|
84
86
|
if (payload.type === 'macro' && payload.durationMinutes < 4) {
|
|
85
|
-
|
|
87
|
+
console.warn('The duration must be at least 4 minutes');
|
|
88
|
+
return false;
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
//errorRatio is required
|
|
@@ -98,6 +101,7 @@ export class AccomplishmentController {
|
|
|
98
101
|
}
|
|
99
102
|
});
|
|
100
103
|
}
|
|
104
|
+
return true;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
private sanitizeAccomplishment(payload: AccomplishmentPayload) {
|
|
@@ -36,38 +36,40 @@ export class SharedContentController {
|
|
|
36
36
|
filter?: SharedContentFilter,
|
|
37
37
|
options?: { privateTopic?: boolean; skipDbSave?: boolean; alwaysGenerateNew?: boolean; excludeIds?: string[] },
|
|
38
38
|
): Promise<SharedContent<T>> {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
39
|
+
// The db cache of the shared content is temporary disabled until the new shared content implementation is completed
|
|
40
|
+
// if (false) {
|
|
41
|
+
// let query = this.supabase
|
|
42
|
+
// .from('shared_content')
|
|
43
|
+
// .select('*, scc:shared_content_completed(id, state)')
|
|
44
|
+
// .eq('content_type', contentType)
|
|
45
|
+
// .not('scc.state', 'in', '("completed","ongoing","hidden")')
|
|
46
|
+
// .is('deleted_at', null);
|
|
47
|
+
|
|
48
|
+
// if (options?.excludeIds?.length ?? 0 > 0) {
|
|
49
|
+
// const excludeIds = options.excludeIds.filter((id) => !id.startsWith('internal-temp-id-'));
|
|
50
|
+
// // Supabase expects raw PostgREST syntax like '("id1","id2")'.
|
|
51
|
+
// const excludeList = `(${excludeIds.map((id) => `"${id}"`).join(',')})`;
|
|
52
|
+
// query = query.not('id', 'in', excludeList);
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
// if (filter) {
|
|
56
|
+
// query.contains('data', filter);
|
|
57
|
+
// }
|
|
58
|
+
|
|
59
|
+
// const { data: newAssignments, error } = await query.limit(30);
|
|
60
|
+
|
|
61
|
+
// if (error) {
|
|
62
|
+
// console.error('error fetching new assignments:', error);
|
|
63
|
+
// throw new Error('error fetching new assignments');
|
|
64
|
+
// }
|
|
65
|
+
|
|
66
|
+
// // console.log('newAssignments:', newAssignments);
|
|
67
|
+
|
|
68
|
+
// if (!options?.alwaysGenerateNew && newAssignments.length > 0) {
|
|
69
|
+
// const index = Math.floor(Math.random() * newAssignments.length);
|
|
70
|
+
// return newAssignments[index];
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
71
73
|
const instructions = await this.generateNewAssignment(contentType, generatorInstructions, filter);
|
|
72
74
|
|
|
73
75
|
console.log('instructions:', instructions);
|
|
@@ -43,7 +43,7 @@ export class RimoriClient {
|
|
|
43
43
|
this.accomplishmentHandler = new AccomplishmentController(info.pluginId);
|
|
44
44
|
this.settingsController = new SettingsController(supabase, info.pluginId, info.guild);
|
|
45
45
|
this.sharedContentController = new SharedContentController(supabase, this);
|
|
46
|
-
this.translator = new Translator(info.
|
|
46
|
+
this.translator = new Translator(info.interfaceLanguage);
|
|
47
47
|
|
|
48
48
|
//only init logger in workers and on main plugin pages
|
|
49
49
|
if (this.getQueryParam('applicationMode') !== 'sidebar') {
|