gamerbot-module 1.2.3 → 2.1.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.
@@ -1,17 +1,23 @@
1
1
  export declare class ConfigData {
2
2
  id: number;
3
3
  debug: boolean;
4
- username: string;
5
- activity: string;
6
- activityType: string;
7
- removeLinks: boolean;
8
- xp: object;
9
- importantUpdatesChannelId: object;
10
- debugGuildID: string;
11
- json_data: any;
12
- constructor(json_data: any);
4
+ levelSystem: LevelSystem;
5
+ debugGuildId: string;
6
+ extraObjects: Map<string, object>;
7
+ jsonData: any;
8
+ constructor(jsonData: any);
13
9
  /**
14
10
  * Saves config data to database
15
11
  */
16
- save(): Promise<unknown>;
12
+ save(): Promise<any>;
17
13
  }
14
+ interface LevelSystem {
15
+ levelExponent: number;
16
+ levels: Array<Level>;
17
+ }
18
+ export interface Level {
19
+ ids: Array<string>;
20
+ level: number;
21
+ message: string;
22
+ }
23
+ export {};
@@ -1,52 +1,60 @@
1
1
  import { GamerBotAPI } from "./gamerbot.js";
2
2
  export class ConfigData {
3
3
  // eslint-disable-next-line
4
- constructor(json_data) {
5
- this.json_data = JSON.parse(JSON.stringify(json_data));
6
- this.id = json_data.id;
7
- this.debug = json_data.debug;
8
- this.username = json_data.username;
9
- this.activity = json_data.activity;
10
- this.activityType = json_data.activityType;
11
- this.removeLinks = json_data.removeLinks;
12
- this.xp = json_data.xp;
13
- this.importantUpdatesChannelId = json_data.importantUpdatesChannelId;
14
- this.debugGuildID = json_data.debugGuildID;
4
+ constructor(jsonData) {
5
+ this.jsonData = JSON.parse(JSON.stringify(jsonData));
6
+ this.id = jsonData.id;
7
+ this.debugGuildId = jsonData.debugGuildId;
8
+ this.debug = jsonData.debug;
9
+ this.levelSystem = jsonData.levelSystem;
10
+ this.extraObjects = new Map(Object.entries(jsonData.extraObjects));
15
11
  }
16
12
  /**
17
13
  * Saves config data to database
18
14
  */
19
15
  async save() {
20
- return new Promise((resolve) => {
21
- // eslint-disable-next-line
22
- const changed_data = {};
23
- Object.keys(this).forEach((key) => {
24
- if (key == "json_data")
25
- return;
26
- const value = Object.entries(this).find(([k, v]) => {
27
- if (k != key)
28
- return false;
29
- return JSON.stringify(v) != JSON.stringify(this.json_data[key]);
30
- });
31
- if (value)
32
- changed_data[key] = value[1];
33
- });
34
- if (Object.keys(changed_data).length == 0)
35
- return resolve(changed_data);
36
- fetch(GamerBotAPI.API_URL + "/api/config/" + this.id, {
16
+ // eslint-disable-next-line
17
+ const changedData = {};
18
+ for (const key of Object.keys(this)) {
19
+ if (key == "jsonData")
20
+ continue;
21
+ const currentValue = this[key];
22
+ const jsonValue = this.jsonData[key];
23
+ if (key === "extraObjects" && currentValue instanceof Map) {
24
+ const mapAsObject = Object.fromEntries(currentValue);
25
+ if (JSON.stringify(mapAsObject) !== JSON.stringify(jsonValue)) {
26
+ changedData[key] = mapAsObject;
27
+ }
28
+ continue;
29
+ }
30
+ if (typeof currentValue === "object" && currentValue !== null) {
31
+ if (JSON.stringify(currentValue) !== JSON.stringify(jsonValue)) {
32
+ changedData[key] = currentValue;
33
+ }
34
+ }
35
+ else if (currentValue !== jsonValue) {
36
+ changedData[key] = currentValue;
37
+ }
38
+ }
39
+ if (Object.keys(changedData).length > 0) {
40
+ const jsonData = await fetch(GamerBotAPI.API_URL + "/api/config/" + this.id, {
37
41
  method: "POST",
38
- body: JSON.stringify(changed_data),
42
+ body: JSON.stringify(changedData),
39
43
  headers: {
40
44
  "Content-Type": "application/json",
41
45
  authorization: "Bearer " + GamerBotAPI.TOKEN,
42
- },
43
- })
44
- .then((response) => {
45
- resolve(response);
46
- })
47
- .catch((err) => {
48
- console.error(err);
46
+ }
49
47
  });
50
- });
48
+ if (!jsonData.ok) {
49
+ console.error("Failed to save config data:", await jsonData.text());
50
+ return;
51
+ }
52
+ this.jsonData = {
53
+ ...this.jsonData,
54
+ ...changedData,
55
+ };
56
+ const data = await jsonData.json();
57
+ return data;
58
+ }
51
59
  }
52
60
  }
@@ -1,26 +1,39 @@
1
1
  export declare class GuildData {
2
- guildID: string;
3
- privateVoiceChannel: string;
4
- publicVoiceChannel: string;
5
- infoVoiceChannel: string;
6
- notificationChannel: string;
7
- ticketParent: string;
8
- archivedTicketParent: string;
9
- allowedLinksChannels: Array<string>;
10
- trustedLinkRoles: Array<string>;
2
+ guildId: string;
3
+ voiceChannelData: voiceChannelData;
4
+ ticketData: ticketData;
5
+ autoModeration: autoModeration;
6
+ topics: Array<string>;
11
7
  noXpChannels: Array<string>;
12
- whitelistedLinks: Array<object>;
13
- threedChannels: Array<string>;
14
- bansTimes: Array<object>;
15
- topicList: Array<string>;
16
- staffModlogs: string;
17
- sverokMails: Array<string>;
18
- frameConfig: Array<object>;
19
- json_data: any;
20
- extraObjects: Map<string, any>;
21
- constructor(json_data: any);
8
+ frames: Array<frameData>;
9
+ extraObjects: Map<string, object>;
10
+ jsonData: any;
11
+ constructor(jsonData: any);
22
12
  /**
23
13
  * Saves guild data to database
24
14
  */
25
- save(): Promise<unknown>;
15
+ save(): Promise<any>;
16
+ }
17
+ interface voiceChannelData {
18
+ voiceChannelId: string;
19
+ infoChatId: string;
20
+ }
21
+ interface ticketData {
22
+ ticketCategoryId: string;
23
+ archivedTicketCategoryId: string;
24
+ }
25
+ interface autoModeration {
26
+ linkFilter: boolean;
27
+ trustedLinkRoles: Array<string>;
28
+ linkChannels: Array<string>;
29
+ whitelistedLinks: Array<string>;
30
+ bannedUsers: Array<object>;
31
+ modLogChannelId: string;
32
+ }
33
+ interface frameData {
34
+ name: string;
35
+ path: string;
36
+ id: string;
37
+ foregroundPath: string;
26
38
  }
39
+ export {};
@@ -1,61 +1,63 @@
1
1
  import { GamerBotAPI } from "./gamerbot.js";
2
2
  export class GuildData {
3
- //eslint-disable-next-line
4
- constructor(json_data) {
5
- this.json_data = JSON.parse(JSON.stringify(json_data));
6
- this.guildID = json_data.guildID;
7
- this.privateVoiceChannel = json_data.privateVoiceChannel;
8
- this.publicVoiceChannel = json_data.publicVoiceChannel;
9
- this.infoVoiceChannel = json_data.infoVoiceChannel;
10
- this.notificationChannel = json_data.notificationChannel;
11
- this.ticketParent = json_data.ticketParent;
12
- this.archivedTicketParent = json_data.archivedTicketParent;
13
- this.allowedLinksChannels = json_data.allowedLinksChannels;
14
- this.trustedLinkRoles = json_data.trustedLinkRoles;
15
- this.noXpChannels = json_data.noXpChannels;
16
- this.whitelistedLinks = json_data.whitelistedLinks;
17
- this.threedChannels = json_data.threedChannels;
18
- this.bansTimes = json_data.bansTimes;
19
- this.topicList = json_data.topicList;
20
- this.staffModlogs = json_data.staffModlogs;
21
- this.sverokMails = json_data.sverokMails;
22
- this.frameConfig = json_data.frameConfig;
23
- this.extraObjects = new Map(Object.entries(json_data.extraObjects));
3
+ // eslint-disable-next-line
4
+ constructor(jsonData) {
5
+ this.jsonData = JSON.parse(JSON.stringify(jsonData));
6
+ this.guildId = jsonData.guildId;
7
+ this.voiceChannelData = jsonData.voiceChannelData;
8
+ this.ticketData = jsonData.ticketData;
9
+ this.autoModeration = jsonData.autoModeration;
10
+ this.topics = jsonData.topics;
11
+ this.noXpChannels = jsonData.noXpChannels;
12
+ this.frames = jsonData.frames;
13
+ this.extraObjects = new Map(Object.entries(jsonData.extraObjects));
24
14
  }
25
15
  /**
26
16
  * Saves guild data to database
27
17
  */
28
18
  async save() {
29
- return new Promise((resolve) => {
30
- //eslint-disable-next-line
31
- const changed_data = {};
32
- Object.keys(this).forEach((key) => {
33
- if (key == "json_data")
34
- return;
35
- const value = Object.entries(this).find(([k, v]) => {
36
- if (k != key)
37
- return false;
38
- return JSON.stringify(v) != JSON.stringify(this.json_data[key]);
39
- });
40
- if (value)
41
- changed_data[key] = value[1];
42
- });
43
- if (Object.keys(changed_data).length == 0)
44
- return resolve(changed_data);
45
- fetch(GamerBotAPI.API_URL + "/api/guild/" + this.guildID, {
19
+ // eslint-disable-next-line
20
+ const changedData = {};
21
+ for (const key of Object.keys(this)) {
22
+ if (key == "jsonData")
23
+ continue;
24
+ const currentValue = this[key];
25
+ const jsonValue = this.jsonData[key];
26
+ if (key === "extraObjects" && currentValue instanceof Map) {
27
+ const mapAsObject = Object.fromEntries(currentValue);
28
+ if (JSON.stringify(mapAsObject) !== JSON.stringify(jsonValue)) {
29
+ changedData[key] = mapAsObject;
30
+ }
31
+ continue;
32
+ }
33
+ if (typeof currentValue === "object" && currentValue !== null) {
34
+ if (JSON.stringify(currentValue) !== JSON.stringify(jsonValue)) {
35
+ changedData[key] = currentValue;
36
+ }
37
+ }
38
+ else if (currentValue !== jsonValue) {
39
+ changedData[key] = currentValue;
40
+ }
41
+ }
42
+ if (Object.keys(changedData).length > 0) {
43
+ const jsonData = await fetch(GamerBotAPI.API_URL + "/api/guild/" + this.guildId, {
46
44
  method: "POST",
47
- body: JSON.stringify(changed_data),
45
+ body: JSON.stringify(changedData),
48
46
  headers: {
49
47
  "Content-Type": "application/json",
50
48
  authorization: "Bearer " + GamerBotAPI.TOKEN,
51
- },
52
- })
53
- .then((response) => {
54
- resolve(response);
55
- })
56
- .catch((err) => {
57
- console.error(err);
49
+ }
58
50
  });
59
- });
51
+ if (!jsonData.ok) {
52
+ console.error("Failed to save config data:", await jsonData.text());
53
+ return;
54
+ }
55
+ this.jsonData = {
56
+ ...this.jsonData,
57
+ ...changedData,
58
+ };
59
+ const data = await jsonData.json();
60
+ return data;
61
+ }
60
62
  }
61
63
  }
@@ -0,0 +1,6 @@
1
+ export declare class MinecraftData {
2
+ uuid: string;
3
+ name: string;
4
+ discordId: string;
5
+ constructor(jsonData: any);
6
+ }
@@ -0,0 +1,8 @@
1
+ export class MinecraftData {
2
+ // eslint-disable-next-line
3
+ constructor(jsonData) {
4
+ this.uuid = jsonData.uuid;
5
+ this.name = jsonData.name;
6
+ this.discordId = jsonData.discordId;
7
+ }
8
+ }
@@ -0,0 +1,52 @@
1
+ export declare class UserData {
2
+ userId: string;
3
+ levelSystem: LevelSystem;
4
+ frameData: FrameData;
5
+ voiceData: VoiceData;
6
+ modLogs: Array<ModLog>;
7
+ minecraftData: MinecraftData;
8
+ hashedEmail: string;
9
+ reminders: Array<Reminder>;
10
+ extraObjects: Map<string, object>;
11
+ jsonData: any;
12
+ constructor(jsonData: any);
13
+ /**
14
+ * Saves user data to database
15
+ */
16
+ save(): Promise<any>;
17
+ }
18
+ interface LevelSystem {
19
+ level: number;
20
+ xp: number;
21
+ xpTimeoutUntil: number;
22
+ lastMessageTimestamp: number;
23
+ oldMessages: Array<string>;
24
+ }
25
+ interface FrameData {
26
+ frameColorHexCode: string;
27
+ selectedFrame: number;
28
+ frames: Array<string>;
29
+ }
30
+ interface VoiceData {
31
+ voiceChannelId: string;
32
+ voiceChannelThreadId: string;
33
+ }
34
+ interface MinecraftData {
35
+ uuid: string;
36
+ username: string;
37
+ }
38
+ interface ModLog {
39
+ type: string;
40
+ userId: string;
41
+ username: string;
42
+ reason: string;
43
+ timestamp: number;
44
+ length: string | null;
45
+ authorId: string;
46
+ }
47
+ export interface Reminder {
48
+ message: string;
49
+ userId: string;
50
+ timestamp: number;
51
+ }
52
+ export {};
@@ -0,0 +1,64 @@
1
+ import { GamerBotAPI } from "./gamerbot.js";
2
+ export class UserData {
3
+ // eslint-disable-next-line
4
+ constructor(jsonData) {
5
+ this.jsonData = JSON.parse(JSON.stringify(jsonData));
6
+ this.userId = jsonData.userId;
7
+ this.levelSystem = jsonData.levelSystem;
8
+ this.frameData = jsonData.frameData;
9
+ this.voiceData = jsonData.voiceData;
10
+ this.modLogs = jsonData.modLogs;
11
+ this.minecraftData = jsonData.minecraftData;
12
+ this.hashedEmail = jsonData.hashedEmail;
13
+ this.reminders = jsonData.reminders;
14
+ this.extraObjects = new Map(Object.entries(jsonData.extraObjects));
15
+ }
16
+ /**
17
+ * Saves user data to database
18
+ */
19
+ async save() {
20
+ // eslint-disable-next-line
21
+ const changedData = {};
22
+ for (const key of Object.keys(this)) {
23
+ if (key == "jsonData")
24
+ continue;
25
+ const currentValue = this[key];
26
+ const jsonValue = this.jsonData[key];
27
+ if (key === "extraObjects" && currentValue instanceof Map) {
28
+ const mapAsObject = Object.fromEntries(currentValue);
29
+ if (JSON.stringify(mapAsObject) !== JSON.stringify(jsonValue)) {
30
+ changedData[key] = mapAsObject;
31
+ }
32
+ continue;
33
+ }
34
+ if (typeof currentValue === "object" && currentValue !== null) {
35
+ if (JSON.stringify(currentValue) !== JSON.stringify(jsonValue)) {
36
+ changedData[key] = currentValue;
37
+ }
38
+ }
39
+ else if (currentValue !== jsonValue) {
40
+ changedData[key] = currentValue;
41
+ }
42
+ }
43
+ if (Object.keys(changedData).length > 0) {
44
+ const jsonData = await fetch(GamerBotAPI.API_URL + "/api/user/" + this.userId, {
45
+ method: "POST",
46
+ body: JSON.stringify(changedData),
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ authorization: "Bearer " + GamerBotAPI.TOKEN,
50
+ }
51
+ });
52
+ if (!jsonData.ok) {
53
+ console.error("Failed to save config data:", await jsonData.text());
54
+ return;
55
+ }
56
+ this.jsonData = {
57
+ ...this.jsonData,
58
+ ...changedData,
59
+ };
60
+ const data = await jsonData.json();
61
+ return data;
62
+ }
63
+ }
64
+ }
@@ -9,5 +9,4 @@ export declare class GamerBotAPI {
9
9
  models: Models;
10
10
  constructor(TOKEN: string, dev?: boolean);
11
11
  getAPIStatus(): Promise<boolean>;
12
- static arraysEqual<T>(a: Array<T>, b: Array<T>): boolean;
13
12
  }
@@ -46,22 +46,5 @@ export class GamerBotAPI {
46
46
  }
47
47
  return false;
48
48
  }
49
- static arraysEqual(a, b) {
50
- if (a === b)
51
- return true;
52
- if (a == null || b == null)
53
- return false;
54
- if (a.length !== b.length)
55
- return false;
56
- for (let i = 0; i < a.length; ++i) {
57
- if (typeof a[i] === 'object' && typeof b[i] === 'object') {
58
- if (!this.arraysEqual(Object.entries(a[i]), Object.entries(b[i])))
59
- return false;
60
- }
61
- else if (a[i] !== b[i])
62
- return false;
63
- }
64
- return true;
65
- }
66
49
  }
67
50
  GamerBotAPI.API_URL = "https://api.sgc.se";
@@ -1,47 +1,63 @@
1
1
  import { ConfigData } from "./ConfigData.js";
2
2
  import { GuildData } from "./GuildData.js";
3
- import { PorfileData } from "./ProfileData.js";
3
+ import { MinecraftData } from "./MinecraftData.js";
4
+ import { UserData } from "./UserData.js";
4
5
  export declare class Models {
6
+ cachedUsersFrames: Map<string, UserFrameData>;
5
7
  constructor();
6
8
  /**
7
- * get profile data
8
- * @param user_id discord user id
9
+ * Get user data
10
+ * @param userId discord user id
9
11
  * @returns
10
12
  */
11
- get_profile_data(user_id: string): Promise<PorfileData>;
13
+ getUserData(userId: string): Promise<UserData>;
12
14
  /**
13
- * get all profile data
14
- * @param max_users amount of users to fetch
15
+ * Get multiple users data
16
+ * @param maxUsers amount of users to fetch
15
17
  * @returns
16
18
  */
17
- get_all_profile_data(max_users: number, filter?: object): Promise<PorfileData[]>;
19
+ getAllUserData(maxUsers: number, filter?: object): Promise<UserData[]>;
18
20
  /**
19
- * get config data
21
+ * Get config data
20
22
  * @param id config id
21
23
  * @returns
22
24
  */
23
- get_config_data(id: number): Promise<ConfigData>;
25
+ getConfigData(id: number): Promise<ConfigData>;
24
26
  /**
25
- * get guild data
26
- * @param guild_id discord guild id
27
+ * Get guild data
28
+ * @param guildId discord guild id
27
29
  * @returns
28
30
  */
29
- get_guild_data(guild_id: string): Promise<GuildData>;
31
+ getGuildData(guildId: string): Promise<GuildData>;
30
32
  /**
31
33
  * Get users frame
32
- * @param user_id
34
+ * @param userId
33
35
  * @returns
34
36
  */
35
- get_user_frame(user_id: string, username: string, avatar_url: string, force?: boolean): Promise<Buffer>;
36
- get_frame_config(guild_id: string): Promise<any>;
37
+ getUserFrame(userId: string, username: string, avatarUrl: string | null): Promise<Buffer<ArrayBuffer>>;
38
+ getFrameConfig(): Promise<FrameConfigElement[]>;
37
39
  /**
38
40
  * Gets frame image
39
41
  */
40
- get_frame(guild_id: string, frame_id: string): Promise<Buffer>;
42
+ getFrame(frameId: string): Promise<Buffer<ArrayBuffer>>;
41
43
  /**
42
- * Get users frame
43
- * @param user_id
44
- * @returns
44
+ * Get all Minecraft users linked to Discord accounts
45
45
  */
46
- private fetch_data;
46
+ getAllMinecraftUsers(): Promise<MinecraftData[]>;
47
+ private fetchData;
48
+ }
49
+ interface FrameConfigElement {
50
+ name: string;
51
+ id: number;
52
+ path: string;
53
+ frameLink: string;
54
+ }
55
+ interface UserFrameData {
56
+ frameId: number;
57
+ hexColor: string;
58
+ xpPercentage: number;
59
+ xp: number;
60
+ level: number;
61
+ cachedId: string;
47
62
  }
63
+ export {};
@@ -1,106 +1,130 @@
1
1
  import { ConfigData } from "./ConfigData.js";
2
2
  import { GamerBotAPI } from "./gamerbot.js";
3
3
  import { GuildData } from "./GuildData.js";
4
- import { PorfileData } from "./ProfileData.js";
4
+ import { UserData } from "./UserData.js";
5
5
  export class Models {
6
- constructor() { }
6
+ constructor() {
7
+ this.cachedUsersFrames = new Map();
8
+ }
7
9
  /**
8
- * get profile data
9
- * @param user_id discord user id
10
+ * Get user data
11
+ * @param userId discord user id
10
12
  * @returns
11
13
  */
12
- async get_profile_data(user_id) {
13
- const data = await this.fetch_data(GamerBotAPI.API_URL + "/api/user/" + user_id);
14
- const profile_data = new PorfileData(data);
15
- return profile_data;
14
+ async getUserData(userId) {
15
+ const data = await this.fetchData(GamerBotAPI.API_URL + "/api/user/" + userId);
16
+ const userData = new UserData(data);
17
+ return userData;
16
18
  }
17
19
  /**
18
- * get all profile data
19
- * @param max_users amount of users to fetch
20
+ * Get multiple users data
21
+ * @param maxUsers amount of users to fetch
20
22
  * @returns
21
23
  */
22
- async get_all_profile_data(max_users, filter = {}) {
23
- const data = (await this.fetch_data(GamerBotAPI.API_URL + "/api/user/fetch_many", "POST", { maxUsers: max_users, filter: filter }));
24
- const profile_data = [];
25
- // eslint-disable-next-line
26
- data.forEach((element) => {
27
- profile_data.push(new PorfileData(element));
28
- });
29
- return profile_data;
24
+ async getAllUserData(maxUsers, filter = {}) {
25
+ const data = (await this.fetchData(GamerBotAPI.API_URL + "/api/user/fetch_many", "POST", { maxUsers: maxUsers, filter: filter }));
26
+ const userData = [];
27
+ data.forEach((element) => userData.push(new UserData(element)));
28
+ return userData;
30
29
  }
31
30
  /**
32
- * get config data
31
+ * Get config data
33
32
  * @param id config id
34
33
  * @returns
35
34
  */
36
- async get_config_data(id) {
37
- const data = await this.fetch_data(GamerBotAPI.API_URL + "/api/config/" + id);
38
- const config_data = new ConfigData(data);
39
- return config_data;
35
+ async getConfigData(id) {
36
+ const data = await this.fetchData(GamerBotAPI.API_URL + "/api/config/" + id);
37
+ const configData = new ConfigData(data);
38
+ return configData;
40
39
  }
41
40
  /**
42
- * get guild data
43
- * @param guild_id discord guild id
41
+ * Get guild data
42
+ * @param guildId discord guild id
44
43
  * @returns
45
44
  */
46
- async get_guild_data(guild_id) {
47
- const data = await this.fetch_data(GamerBotAPI.API_URL + "/api/guild/" + guild_id);
45
+ async getGuildData(guildId) {
46
+ const data = await this.fetchData(GamerBotAPI.API_URL + "/api/guild/" + guildId);
48
47
  return new GuildData(data);
49
48
  }
50
49
  /**
51
50
  * Get users frame
52
- * @param user_id
51
+ * @param userId
53
52
  * @returns
54
53
  */
55
- async get_user_frame(user_id, username, avatar_url, force = false) {
56
- const profile_data = await this.get_profile_data(user_id);
57
- let xpPercentage = Math.round((profile_data.xp / profile_data.level ** 2) * 100);
54
+ async getUserFrame(userId, username, avatarUrl) {
55
+ const userData = await this.getUserData(userId);
56
+ let xpPercentage;
57
+ if (userData.levelSystem.level == 0) {
58
+ xpPercentage = Math.round((userData.levelSystem.xp / (userData.levelSystem.level + 1) ** 2) * 100);
59
+ }
60
+ else {
61
+ xpPercentage = Math.round((userData.levelSystem.xp / userData.levelSystem.level ** 2) * 100);
62
+ }
58
63
  // Progressbar is constant after lvl 31
59
- if (profile_data.level > 31) {
60
- xpPercentage = Math.round((profile_data.xp / 961) * 100);
64
+ if (userData.levelSystem.level > 31) {
65
+ xpPercentage = Math.round((userData.levelSystem.xp / 961) * 100);
66
+ }
67
+ if (!userData.frameData.frameColorHexCode)
68
+ userData.frameData.frameColorHexCode = "#000000";
69
+ let cachedFrame = null;
70
+ if (this.cachedUsersFrames.has(userId)) {
71
+ cachedFrame = this.cachedUsersFrames.get(userId);
72
+ if (cachedFrame.xp != userData.levelSystem.xp ||
73
+ cachedFrame.level != userData.levelSystem.level ||
74
+ cachedFrame.hexColor != userData.frameData.frameColorHexCode ||
75
+ cachedFrame.frameId != userData.frameData.selectedFrame) {
76
+ cachedFrame = null;
77
+ this.cachedUsersFrames.delete(userId);
78
+ }
79
+ }
80
+ if (cachedFrame == null) {
81
+ cachedFrame = {
82
+ frameId: userData.frameData.selectedFrame,
83
+ hexColor: userData.frameData.frameColorHexCode,
84
+ xpPercentage: xpPercentage,
85
+ xp: userData.levelSystem.xp,
86
+ level: userData.levelSystem.level,
87
+ cachedId: Math.random().toString(36).substring(2, 15),
88
+ };
89
+ this.cachedUsersFrames.set(userId, cachedFrame);
61
90
  }
62
- if (!profile_data.colorHexCode)
63
- profile_data.colorHexCode = "#000000";
64
- const data = (await this.fetch_data(GamerBotAPI.API_URL + "/public_api/frame/generate", "POST", {
65
- userid: user_id,
66
- frame_id: profile_data.profileFrame,
67
- hex_color: profile_data.colorHexCode,
68
- username: username,
69
- level: profile_data.level - 1,
70
- xp_percentage: xpPercentage,
71
- avatar_url: avatar_url,
72
- force: force,
91
+ const data = (await this.fetchData(GamerBotAPI.API_URL + "/public_api/frame/generate", "POST", {
92
+ name: username,
93
+ frameId: cachedFrame.frameId,
94
+ hexColor: cachedFrame.hexColor,
95
+ level: cachedFrame.level,
96
+ xpPercentage: cachedFrame.xpPercentage,
97
+ memberAvatar: avatarUrl,
98
+ cachedId: cachedFrame.cachedId,
73
99
  }, false));
74
100
  return Buffer.from(await data.arrayBuffer());
75
101
  }
76
- async get_frame_config(guild_id) {
77
- const data = await this.fetch_data(GamerBotAPI.API_URL + "/public_api/frame/get/config", "POST", { guildId: guild_id });
78
- return data;
102
+ async getFrameConfig() {
103
+ const data = await this.fetchData(GamerBotAPI.API_URL + "/public_api/frame/config");
104
+ return data.frames;
79
105
  }
80
106
  /**
81
107
  * Gets frame image
82
108
  */
83
- async get_frame(guild_id, frame_id) {
84
- const data = (await this.fetch_data(GamerBotAPI.API_URL +
85
- "/public_api/frame/get/" +
86
- guild_id +
87
- "/" +
88
- frame_id, "GET", null, false));
109
+ async getFrame(frameId) {
110
+ const data = (await this.fetchData(GamerBotAPI.API_URL + "/public_api/frame/" + frameId, "GET", null, false));
89
111
  return Buffer.from(await data.arrayBuffer());
90
112
  }
91
113
  /**
92
- * Get users frame
93
- * @param user_id
94
- * @returns
114
+ * Get all Minecraft users linked to Discord accounts
95
115
  */
96
- fetch_data(url, method = "GET",
116
+ async getAllMinecraftUsers() {
117
+ const data = await this.fetchData(GamerBotAPI.API_URL + "/api/user/minecraft/data/", "GET");
118
+ return data;
119
+ }
120
+ fetchData(url, method = "GET",
97
121
  // eslint-disable-next-line
98
- json_data = null, convert_to_json = true) {
99
- json_data = json_data ? JSON.stringify(json_data) : null;
122
+ jsonData = null, convertToJson = true) {
123
+ jsonData = jsonData ? JSON.stringify(jsonData) : null;
100
124
  return new Promise((resolve, reject) => {
101
125
  fetch(url, {
102
126
  method: method,
103
- body: json_data,
127
+ body: jsonData,
104
128
  headers: {
105
129
  "Content-Type": "application/json",
106
130
  authorization: "Bearer " + GamerBotAPI.TOKEN,
@@ -112,7 +136,7 @@ export class Models {
112
136
  console.error("Error fetching data: ", error);
113
137
  reject(error);
114
138
  }
115
- if (!convert_to_json)
139
+ if (!convertToJson)
116
140
  return response;
117
141
  else
118
142
  return response.json();
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { GamerBotAPI } from "./classes/gamerbot.js";
2
- export { PorfileData } from "./classes/ProfileData.js";
2
+ export { UserData, Reminder } from "./classes/UserData.js";
3
3
  export { GuildData } from "./classes/GuildData.js";
4
4
  export { ConfigData } from "./classes/ConfigData.js";
5
5
  export { Models } from "./classes/models.js";
6
+ export { Level } from "./classes/ConfigData.js";
7
+ export { MinecraftData } from "./classes/MinecraftData.js";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { GamerBotAPI } from "./classes/gamerbot.js";
2
- export { PorfileData } from "./classes/ProfileData.js";
2
+ export { UserData } from "./classes/UserData.js";
3
3
  export { GuildData } from "./classes/GuildData.js";
4
4
  export { ConfigData } from "./classes/ConfigData.js";
5
5
  export { Models } from "./classes/models.js";
6
+ export { MinecraftData } from "./classes/MinecraftData.js";
package/package.json CHANGED
@@ -1,32 +1,51 @@
1
1
  {
2
2
  "name": "gamerbot-module",
3
- "version": "1.2.3",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "files": [
9
- "/dist"
9
+ "dist"
10
10
  ],
11
11
  "scripts": {
12
12
  "test": "echo \"Error: no test specified\" && exit 1",
13
13
  "link": "tsc -p tsconfig.json && npm link",
14
- "tsc": "tsc -p tsconfig.json"
14
+ "prebuild": "rm -rf dist",
15
+ "build": "npm run prebuild && tsc -p tsconfig.json",
16
+ "prepare": "npm run build"
15
17
  },
16
18
  "author": "lukasabbe",
17
19
  "license": "MIT",
18
20
  "devDependencies": {
19
- "@eslint/js": "^9.10.0",
20
- "@types/node": "^20.12.13",
21
- "concurrently": "^8.2.2",
22
- "eslint": "^9.10.0",
23
- "globals": "^15.9.0",
24
- "nodemon": "^3.1.2",
21
+ "@eslint/js": "^9.39.1",
22
+ "@types/node": "^24.10.1",
23
+ "concurrently": "^9.2.1",
24
+ "eslint": "^9.39.1",
25
+ "globals": "^16.5.0",
26
+ "nodemon": "^3.1.11",
25
27
  "ts-node": "^10.9.2",
26
- "typescript": "^5.4.5",
27
- "typescript-eslint": "^8.5.0"
28
+ "typescript": "^5.9.3",
29
+ "typescript-eslint": "^8.48.0"
28
30
  },
29
31
  "dependencies": {
30
- "dotenv": "^16.4.5"
32
+ "dotenv": "^17.2.3"
33
+ }
34
+ ,
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/onlinesgc/Gamerbot-module.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/onlinesgc/Gamerbot-module/issues"
41
+ },
42
+ "homepage": "https://github.com/onlinesgc/Gamerbot-module#readme",
43
+ "engines": {
44
+ "node": ">=16"
45
+ },
46
+ "exports": {
47
+ ".": {
48
+ "import": "./dist/index.js"
49
+ }
31
50
  }
32
51
  }
@@ -1,28 +0,0 @@
1
- export declare class PorfileData {
2
- userID: string;
3
- serverID: string;
4
- xp: number;
5
- lastMessageTimestamp: number;
6
- xpTimeoutUntil: number;
7
- level: number;
8
- reminders: Array<object>;
9
- colorHexCode: string;
10
- privateVoiceID: string;
11
- privateVoiceThreadID: string;
12
- profileFrame: string;
13
- hasLeftTicket: boolean;
14
- xpboost: object;
15
- exclusiveFrames: Array<string>;
16
- modLogs: Array<object>;
17
- minecraftWhiteList: boolean;
18
- minecraftUsername: string;
19
- minecraftUuid: string;
20
- old_messages: Array<string>;
21
- hashed_email: string;
22
- json_data: any;
23
- constructor(json_data: any);
24
- /**
25
- * Saves user data to database
26
- */
27
- save(): Promise<unknown>;
28
- }
@@ -1,63 +0,0 @@
1
- import { GamerBotAPI } from "./gamerbot.js";
2
- export class PorfileData {
3
- // eslint-disable-next-line
4
- constructor(json_data) {
5
- this.json_data = JSON.parse(JSON.stringify(json_data));
6
- this.userID = json_data.userID;
7
- this.serverID = json_data.serverID;
8
- this.xp = json_data.xp;
9
- this.lastMessageTimestamp = json_data.lastMessageTimestamp;
10
- this.xpTimeoutUntil = json_data.xpTimeoutUntil;
11
- this.level = json_data.level;
12
- this.reminders = json_data.reminders;
13
- this.colorHexCode = json_data.colorHexCode;
14
- this.privateVoiceID = json_data.privateVoiceID;
15
- this.privateVoiceThreadID = json_data.privateVoiceThreadID;
16
- this.profileFrame = json_data.profileFrame;
17
- this.hasLeftTicket = json_data.hasLeftTicket;
18
- this.xpboost = json_data.xpboost;
19
- this.exclusiveFrames = json_data.exclusiveFrames;
20
- this.modLogs = json_data.modLogs;
21
- this.minecraftWhiteList = json_data.minecraftWhiteList;
22
- this.minecraftUsername = json_data.minecraftUsername;
23
- this.minecraftUuid = json_data.minecraftUuid;
24
- this.old_messages = json_data.old_messages;
25
- this.hashed_email = json_data.hashed_email;
26
- }
27
- /**
28
- * Saves user data to database
29
- */
30
- async save() {
31
- return new Promise((resolve) => {
32
- // eslint-disable-next-line
33
- const changed_data = {};
34
- Object.keys(this).forEach((key) => {
35
- if (key == "json_data")
36
- return;
37
- const value = Object.entries(this).find(([k, v]) => {
38
- if (k != key)
39
- return false;
40
- return JSON.stringify(v) != JSON.stringify(this.json_data[key]);
41
- });
42
- if (value)
43
- changed_data[key] = value[1];
44
- });
45
- if (Object.keys(changed_data).length == 0)
46
- return resolve(changed_data);
47
- fetch(GamerBotAPI.API_URL + "/api/user/" + this.userID, {
48
- method: "POST",
49
- body: JSON.stringify(changed_data),
50
- headers: {
51
- "Content-Type": "application/json",
52
- authorization: "Bearer " + GamerBotAPI.TOKEN,
53
- },
54
- })
55
- .then((response) => {
56
- resolve(response);
57
- })
58
- .catch((err) => {
59
- console.error(err);
60
- });
61
- });
62
- }
63
- }
@@ -1,17 +0,0 @@
1
- export declare class ConfigData {
2
- id: Number;
3
- debug: Boolean;
4
- username: String;
5
- activity: String;
6
- activityType: String;
7
- removeLinks: Boolean;
8
- xp: Object;
9
- importantUpdatesChannelId: Object;
10
- debugGuildID: String;
11
- json_data: any;
12
- constructor(json_data: any);
13
- /**
14
- * Saves config data to database
15
- */
16
- save(): Promise<unknown>;
17
- }
@@ -1,41 +0,0 @@
1
- import { GamerBotAPI } from "./gamerbot";
2
- export class ConfigData {
3
- constructor(json_data) {
4
- this.json_data = JSON.parse(JSON.stringify(json_data));
5
- this.id = json_data.id;
6
- this.debug = json_data.debug;
7
- this.username = json_data.username;
8
- this.activity = json_data.activity;
9
- this.activityType = json_data.activityType;
10
- this.removeLinks = json_data.removeLinks;
11
- this.xp = json_data.xp;
12
- this.importantUpdatesChannelId = json_data.importantUpdatesChannelId;
13
- this.debugGuildID = json_data.debugGuildID;
14
- }
15
- /**
16
- * Saves config data to database
17
- */
18
- async save() {
19
- return new Promise((resolve, reject) => {
20
- let changed_data = {};
21
- Object.keys(this).forEach((key) => {
22
- if (key == "json_data")
23
- return;
24
- let value = Object.entries(this).find(([k, v]) => k == key &&
25
- ((!Array.isArray(v)) && !Object.is(v, this.json_data[key]) || (Array.isArray(v) && !GamerBotAPI.arraysEqual(v, this.json_data[key]))));
26
- if (value)
27
- changed_data[key] = value[1];
28
- });
29
- if (Object.keys(changed_data).length == 0)
30
- return resolve(changed_data);
31
- fetch(GamerBotAPI.API_URL + "/api/config/" + this.id, {
32
- method: "POST",
33
- body: JSON.stringify(changed_data),
34
- headers: {
35
- 'Content-Type': 'application/json',
36
- 'authorization': 'Bearer ' + GamerBotAPI.TOKEN
37
- }
38
- }).then((response) => { resolve(response); }).catch((err) => { console.error(err); });
39
- });
40
- }
41
- }
@@ -1,24 +0,0 @@
1
- export declare class GuildData {
2
- guildID: string;
3
- privateVoiceChannel: string;
4
- publicVoiceChannel: string;
5
- infoVoiceChannel: string;
6
- notificationChannel: string;
7
- ticketParent: string;
8
- archivedTicketParent: string;
9
- allowedLinksChannels: Array<string>;
10
- trustedLinkRoles: Array<string>;
11
- noXpChannels: Array<string>;
12
- whitelistedLinks: Array<object>;
13
- threedChannels: Array<string>;
14
- bansTimes: Array<object>;
15
- topicList: Array<string>;
16
- staffModlogs: string;
17
- sverokMails: Array<string>;
18
- json_data: any;
19
- constructor(json_data: any);
20
- /**
21
- * Saves guild data to database
22
- */
23
- save(): Promise<unknown>;
24
- }
@@ -1,48 +0,0 @@
1
- import { GamerBotAPI } from "./gamerbot";
2
- export class GuildData {
3
- constructor(json_data) {
4
- this.json_data = JSON.parse(JSON.stringify(json_data));
5
- this.guildID = json_data.guildID;
6
- this.privateVoiceChannel = json_data.privateVoiceChannel;
7
- this.publicVoiceChannel = json_data.publicVoiceChannel;
8
- this.infoVoiceChannel = json_data.infoVoiceChannel;
9
- this.notificationChannel = json_data.notificationChannel;
10
- this.ticketParent = json_data.ticketParent;
11
- this.archivedTicketParent = json_data.archivedTicketParent;
12
- this.allowedLinksChannels = json_data.allowedLinksChannels;
13
- this.trustedLinkRoles = json_data.trustedLinkRoles;
14
- this.noXpChannels = json_data.noXpChannels;
15
- this.whitelistedLinks = json_data.whitelistedLinks;
16
- this.threedChannels = json_data.threedChannels;
17
- this.bansTimes = json_data.bansTimes;
18
- this.topicList = json_data.topicList;
19
- this.staffModlogs = json_data.staffModlogs;
20
- this.sverokMails = json_data.sverokMails;
21
- }
22
- /**
23
- * Saves guild data to database
24
- */
25
- async save() {
26
- return new Promise((resolve, reject) => {
27
- let changed_data = {};
28
- Object.keys(this).forEach((key) => {
29
- if (key == "json_data")
30
- return;
31
- let value = Object.entries(this).find(([k, v]) => k == key &&
32
- ((!Array.isArray(v)) && !Object.is(v, this.json_data[key]) || (Array.isArray(v) && !GamerBotAPI.arraysEqual(v, this.json_data[key]))));
33
- if (value)
34
- changed_data[key] = value[1];
35
- });
36
- if (Object.keys(changed_data).length == 0)
37
- return resolve(changed_data);
38
- fetch(GamerBotAPI.API_URL + "/api/guild/" + this.guildID, {
39
- method: "POST",
40
- body: JSON.stringify(changed_data),
41
- headers: {
42
- 'Content-Type': 'application/json',
43
- 'authorization': 'Bearer ' + GamerBotAPI.TOKEN
44
- }
45
- }).then((response) => { resolve(response); }).catch((err) => { console.error(err); });
46
- });
47
- }
48
- }
@@ -1,21 +0,0 @@
1
- export declare class PorfileData {
2
- userID: String;
3
- serverID: String;
4
- xp: Number;
5
- lastMessageTimestamp: Number;
6
- xpTimeoutUntil: Number;
7
- level: Number;
8
- reminder: Array<String>;
9
- colorHexCode: String;
10
- privateVoiceID: String;
11
- privateVoiceThreadID: String;
12
- profileFrame: String;
13
- hasLeftTicket: Boolean;
14
- xpboost: Object;
15
- exclusiveFrames: Array<String>;
16
- modLogs: Array<Object>;
17
- minecraftWhiteList: Boolean;
18
- minecraftUsername: String;
19
- minecraftUuid: String;
20
- constructor(json_data: any);
21
- }
@@ -1,22 +0,0 @@
1
- export class PorfileData {
2
- constructor(json_data) {
3
- this.userID = json_data.userID;
4
- this.serverID = json_data.serverID;
5
- this.xp = json_data.xp;
6
- this.lastMessageTimestamp = json_data.lastMessageTimestamp;
7
- this.xpTimeoutUntil = json_data.xpTimeoutUntil;
8
- this.level = json_data.level;
9
- this.reminder = json_data.reminder;
10
- this.colorHexCode = json_data.colorHexCode;
11
- this.privateVoiceID = json_data.privateVoiceID;
12
- this.privateVoiceThreadID = json_data.privateVoiceThreadID;
13
- this.profileFrame = json_data.profileFrame;
14
- this.hasLeftTicket = json_data.hasLeftTicket;
15
- this.xpboost = json_data.xpboost;
16
- this.exclusiveFrames = json_data.exclusiveFrames;
17
- this.modLogs = json_data.modLogs;
18
- this.minecraftWhiteList = json_data.minecraftWhiteList;
19
- this.minecraftUsername = json_data.minecraftUsername;
20
- this.minecraftUuid = json_data.minecraftUuid;
21
- }
22
- }