@spatulox/simplediscordbot 1.0.16 → 1.0.18
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/bot/BotMessage.d.ts +6 -6
- package/dist/bot/BotMessage.d.ts.map +1 -1
- package/dist/bot/BotMessage.js +4 -4
- package/dist/manager/direct/BasicUserManager.d.ts +28 -0
- package/dist/manager/direct/BasicUserManager.d.ts.map +1 -0
- package/dist/manager/direct/BasicUserManager.js +81 -0
- package/dist/manager/direct/UserManager.d.ts +3 -24
- package/dist/manager/direct/UserManager.d.ts.map +1 -1
- package/dist/manager/direct/UserManager.js +2 -71
- package/dist/manager/guild/GuildManager.d.ts +1 -0
- package/dist/manager/guild/GuildManager.d.ts.map +1 -1
- package/dist/manager/guild/GuildManager.js +3 -0
- package/dist/manager/guild/GuildUserManager.d.ts +4 -3
- package/dist/manager/guild/GuildUserManager.d.ts.map +1 -1
- package/dist/manager/guild/GuildUserManager.js +18 -2
- package/package.json +1 -1
package/dist/bot/BotMessage.d.ts
CHANGED
|
@@ -4,17 +4,17 @@ export declare class BotMessage {
|
|
|
4
4
|
/**
|
|
5
5
|
* Send message to any text-based channel
|
|
6
6
|
*/
|
|
7
|
-
static send(channel: TextChannel | DMChannel | ThreadChannel | string, content?: string | null, component?: SendableComponent): Promise<Message |
|
|
8
|
-
static send(channel: TextChannel | DMChannel | ThreadChannel | string, content: SendableComponent): Promise<Message |
|
|
9
|
-
static send(channel: TextChannel | DMChannel | ThreadChannel | string, content: MessageCreateOptions): Promise<Message |
|
|
10
|
-
static sendDM(user: User | GuildMember | string, content?: string, component?: SendableComponent): Promise<Message |
|
|
7
|
+
static send(channel: TextChannel | DMChannel | ThreadChannel | string, content?: string | null, component?: SendableComponent): Promise<Message | null>;
|
|
8
|
+
static send(channel: TextChannel | DMChannel | ThreadChannel | string, content: SendableComponent): Promise<Message | null>;
|
|
9
|
+
static send(channel: TextChannel | DMChannel | ThreadChannel | string, content: MessageCreateOptions): Promise<Message | null>;
|
|
10
|
+
static sendDM(user: User | GuildMember | string, content?: string, component?: SendableComponent): Promise<Message | null>;
|
|
11
11
|
/**
|
|
12
12
|
* Quick success message
|
|
13
13
|
*/
|
|
14
|
-
static success(channel: TextChannel | DMChannel | ThreadChannel | User | GuildMember, message: string): Promise<Message |
|
|
14
|
+
static success(channel: TextChannel | DMChannel | ThreadChannel | User | GuildMember, message: string): Promise<Message | null>;
|
|
15
15
|
/**
|
|
16
16
|
* Quick error message
|
|
17
17
|
*/
|
|
18
|
-
static error(channel: TextChannel | DMChannel | ThreadChannel | User | GuildMember, message: string): Promise<Message |
|
|
18
|
+
static error(channel: TextChannel | DMChannel | ThreadChannel | User | GuildMember, message: string): Promise<Message | null>;
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=BotMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BotMessage.d.ts","sourceRoot":"","sources":["../../src/bot/BotMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,IAAI,EACJ,WAAW,EAAE,oBAAoB,EACpC,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAC,iBAAiB,EAA2B,MAAM,6CAA6C,CAAC;AAGxG,qBAAa,UAAU;IACnB;;OAEG;WACU,IAAI,CAAC,OAAO,EAAC,WAAW,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,SAAS,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"BotMessage.d.ts","sourceRoot":"","sources":["../../src/bot/BotMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,IAAI,EACJ,WAAW,EAAE,oBAAoB,EACpC,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAC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
14
|
+
return null;
|
|
15
15
|
}
|
|
16
16
|
if (typeof channel === "string") {
|
|
17
17
|
const fetchedChannel = Bot_1.Bot.client.channels.cache.get(channel);
|
|
18
18
|
if (!fetchedChannel?.isTextBased()) {
|
|
19
19
|
Log_1.Log.warn(`Invalid channel ID: ${channel}`);
|
|
20
|
-
return
|
|
20
|
+
return null;
|
|
21
21
|
}
|
|
22
22
|
channel = fetchedChannel;
|
|
23
23
|
}
|
|
@@ -54,7 +54,7 @@ class BotMessage {
|
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
56
56
|
Log_1.Log.error(`Failed to send message : ${e}`);
|
|
57
|
-
return
|
|
57
|
+
return null;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
static async sendDM(user, content, component) {
|
|
@@ -83,7 +83,7 @@ class BotMessage {
|
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
85
|
Log_1.Log.error(`Failed to send message to ${user}: ${error}`);
|
|
86
|
-
return
|
|
86
|
+
return null;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GuildMember, Message, MessageCreateOptions, User } from "discord.js";
|
|
2
|
+
import { SendableComponent } from "../builder/SendableComponentBuilder";
|
|
3
|
+
export declare abstract class BasicUserManager {
|
|
4
|
+
/**
|
|
5
|
+
* Find member in specific guild
|
|
6
|
+
*/
|
|
7
|
+
static findInGuild(guildId: string, memberId: string): Promise<GuildMember | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Check if user is still in guild
|
|
10
|
+
*/
|
|
11
|
+
static isInGuild(guildId: string, userId: string): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Overload for send
|
|
14
|
+
*/
|
|
15
|
+
static send(user_id: string, content: string): Promise<Message>;
|
|
16
|
+
static send(user: User, content: string): Promise<Message>;
|
|
17
|
+
static send(user: GuildMember, content: string): Promise<Message>;
|
|
18
|
+
static send(user_id: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
19
|
+
static send(user: User, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
20
|
+
static send(user: GuildMember, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
21
|
+
static send(user_id: string, content: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
22
|
+
static send(user: User, content: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
23
|
+
static send(user: GuildMember, content: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
24
|
+
static send(user_id_or_user: string, options: MessageCreateOptions): Promise<Message>;
|
|
25
|
+
static send(user_id_or_user: User, options: MessageCreateOptions): Promise<Message>;
|
|
26
|
+
static send(user_id_or_user: GuildMember, options: MessageCreateOptions): Promise<Message>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=BasicUserManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BasicUserManager.d.ts","sourceRoot":"","sources":["../../../src/manager/direct/BasicUserManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAC,MAAM,YAAY,CAAC;AAG5E,OAAO,EAAC,iBAAiB,EAA2B,MAAM,qCAAqC,CAAC;AAEhG,8BAAsB,gBAAgB;IAElC;;OAEG;WACU,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAaxF;;OAEG;WACU,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYzE;;OAEG;WAEU,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;WACxD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAA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
|
|
3
|
+
exports.BasicUserManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const Bot_1 = require("../../bot/Bot");
|
|
6
|
+
const Log_1 = require("../../utils/Log");
|
|
7
|
+
const SendableComponentBuilder_1 = require("../builder/SendableComponentBuilder");
|
|
8
|
+
class BasicUserManager {
|
|
9
|
+
/**
|
|
10
|
+
* Find member in specific guild
|
|
11
|
+
*/
|
|
12
|
+
static async findInGuild(guildId, memberId) {
|
|
13
|
+
try {
|
|
14
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
15
|
+
if (!guild)
|
|
16
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
17
|
+
const member = await guild.members.fetch({ user: memberId, force: true });
|
|
18
|
+
return member ?? null;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
Log_1.Log.error(`UserManager: Member ${memberId} not found in ${guildId}`);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if user is still in guild
|
|
27
|
+
*/
|
|
28
|
+
static async isInGuild(guildId, userId) {
|
|
29
|
+
try {
|
|
30
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
31
|
+
if (!guild)
|
|
32
|
+
return false;
|
|
33
|
+
await guild.members.fetch({ user: userId, force: true });
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return error.code !== 10007; // Unknown Member
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Impl
|
|
42
|
+
*/
|
|
43
|
+
static async send(user_id_or_user, content_or_component_or_options, component) {
|
|
44
|
+
try {
|
|
45
|
+
let user;
|
|
46
|
+
if (typeof user_id_or_user === 'string') {
|
|
47
|
+
user = await Bot_1.Bot.client.users.fetch(user_id_or_user);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
user = user_id_or_user;
|
|
51
|
+
}
|
|
52
|
+
const dmChannel = await user.createDM();
|
|
53
|
+
let payload;
|
|
54
|
+
if (component && typeof content_or_component_or_options == "string") { // component + content
|
|
55
|
+
payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options, component);
|
|
56
|
+
}
|
|
57
|
+
else if (typeof content_or_component_or_options === 'string') { // content only
|
|
58
|
+
payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
59
|
+
}
|
|
60
|
+
else if (SendableComponentBuilder_1.SendableComponentBuilder.isSendableComponent(content_or_component_or_options)) { // component only
|
|
61
|
+
payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
62
|
+
}
|
|
63
|
+
else { // MessageCreationOptionOnly
|
|
64
|
+
payload = content_or_component_or_options;
|
|
65
|
+
}
|
|
66
|
+
const message = await dmChannel.send(payload);
|
|
67
|
+
if (user instanceof discord_js_1.GuildMember) {
|
|
68
|
+
Log_1.Log.info(`Sent DM to ${user.id} (${user.user.username}): "${(payload.content || 'Embed/Component').substring(0, 50)}..."`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
Log_1.Log.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || 'Embed/Component').substring(0, 50)}..."`);
|
|
72
|
+
}
|
|
73
|
+
return message;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
Log_1.Log.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
|
|
77
|
+
throw new Error(`Cannot send DM to ${user_id_or_user}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.BasicUserManager = BasicUserManager;
|
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare class UserManager {
|
|
4
|
-
/**
|
|
5
|
-
* Find a member
|
|
6
|
-
*/
|
|
1
|
+
import { BasicUserManager } from "./BasicUserManager";
|
|
2
|
+
import { User } from "discord.js";
|
|
3
|
+
export declare class UserManager extends BasicUserManager {
|
|
7
4
|
static find(userId: string): Promise<User | null>;
|
|
8
|
-
/**
|
|
9
|
-
* Find member in specific guild
|
|
10
|
-
*/
|
|
11
|
-
static findInGuild(guildId: string, memberId: string): Promise<GuildMember | null>;
|
|
12
|
-
/**
|
|
13
|
-
* Check if user is still in guild
|
|
14
|
-
*/
|
|
15
|
-
static isInGuild(guildId: string, userId: string): Promise<boolean>;
|
|
16
|
-
/**
|
|
17
|
-
* Overload for send
|
|
18
|
-
*/
|
|
19
|
-
static send(user_id: string, content: string): Promise<Message>;
|
|
20
|
-
static send(user: User, content: string): Promise<Message>;
|
|
21
|
-
static send(user_id: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
22
|
-
static send(user: User, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
23
|
-
static send(user_id: string, content: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
24
|
-
static send(user: User, content: string, component: SendableComponent | SendableComponent[]): Promise<Message>;
|
|
25
|
-
static send(user_id_or_user: string | User, options: MessageCreateOptions): Promise<Message>;
|
|
26
5
|
}
|
|
27
6
|
//# sourceMappingURL=UserManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserManager.d.ts","sourceRoot":"","sources":["../../../src/manager/direct/UserManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"UserManager.d.ts","sourceRoot":"","sources":["../../../src/manager/direct/UserManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAGhC,qBAAa,WAAY,SAAQ,gBAAgB;WAChC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;CAQ1D"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserManager = void 0;
|
|
4
|
+
const BasicUserManager_1 = require("./BasicUserManager");
|
|
4
5
|
const Bot_1 = require("../../bot/Bot");
|
|
5
6
|
const Log_1 = require("../../utils/Log");
|
|
6
|
-
|
|
7
|
-
class UserManager {
|
|
8
|
-
/**
|
|
9
|
-
* Find a member
|
|
10
|
-
*/
|
|
7
|
+
class UserManager extends BasicUserManager_1.BasicUserManager {
|
|
11
8
|
static async find(userId) {
|
|
12
9
|
try {
|
|
13
10
|
return await Bot_1.Bot.client.users.fetch(userId);
|
|
@@ -17,71 +14,5 @@ class UserManager {
|
|
|
17
14
|
return null;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Find member in specific guild
|
|
22
|
-
*/
|
|
23
|
-
static async findInGuild(guildId, memberId) {
|
|
24
|
-
try {
|
|
25
|
-
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
26
|
-
if (!guild)
|
|
27
|
-
throw new Error(`Guild ${guildId} not found`);
|
|
28
|
-
const member = await guild.members.fetch({ user: memberId, force: true });
|
|
29
|
-
return member ?? null;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
Log_1.Log.error(`UserManager: Member ${memberId} not found in ${guildId}`);
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Check if user is still in guild
|
|
38
|
-
*/
|
|
39
|
-
static async isInGuild(guildId, userId) {
|
|
40
|
-
try {
|
|
41
|
-
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
42
|
-
if (!guild)
|
|
43
|
-
return false;
|
|
44
|
-
await guild.members.fetch({ user: userId, force: true });
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
return error.code !== 10007; // Unknown Member
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Impl
|
|
53
|
-
*/
|
|
54
|
-
static async send(user_id_or_user, content_or_component_or_options, component) {
|
|
55
|
-
try {
|
|
56
|
-
let user;
|
|
57
|
-
if (typeof user_id_or_user === 'string') {
|
|
58
|
-
user = await Bot_1.Bot.client.users.fetch(user_id_or_user);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
user = user_id_or_user;
|
|
62
|
-
}
|
|
63
|
-
const dmChannel = await user.createDM();
|
|
64
|
-
let payload;
|
|
65
|
-
if (component && typeof content_or_component_or_options == "string") { // component + content
|
|
66
|
-
payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options, component);
|
|
67
|
-
}
|
|
68
|
-
else if (typeof content_or_component_or_options === 'string') { // content only
|
|
69
|
-
payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
70
|
-
}
|
|
71
|
-
else if (SendableComponentBuilder_1.SendableComponentBuilder.isSendableComponent(content_or_component_or_options)) { // component only
|
|
72
|
-
payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
73
|
-
}
|
|
74
|
-
else { // MessageCreationOptionOnly
|
|
75
|
-
payload = content_or_component_or_options;
|
|
76
|
-
}
|
|
77
|
-
const message = await dmChannel.send(payload);
|
|
78
|
-
Log_1.Log.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || 'Embed/Component').substring(0, 50)}..."`);
|
|
79
|
-
return message;
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
Log_1.Log.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
|
|
83
|
-
throw new Error(`Cannot send DM to ${user_id_or_user}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
17
|
}
|
|
87
18
|
exports.UserManager = UserManager;
|
|
@@ -9,6 +9,7 @@ export declare class GuildManager {
|
|
|
9
9
|
static readonly channel: typeof GuildChannelList;
|
|
10
10
|
static readonly invite: typeof InviteManager;
|
|
11
11
|
static list(): Guild[];
|
|
12
|
+
static find(guild_id: string): Promise<Guild>;
|
|
12
13
|
/**
|
|
13
14
|
* Search channel by ID (TextChannel, DMChannel, ThreadChannel)
|
|
14
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuildManager.d.ts","sourceRoot":"","sources":["../../../src/manager/guild/GuildManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,EACL,QAAQ,EACoB,OAAO,EACtC,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,qBAAa,YAAY;IAErB,gBAAuB,IAAI,qBAAe;IAC1C,gBAAuB,IAAI,0BAAmB;IAC9C,gBAAuB,OAAO,0BAAqB;IACnD,gBAAuB,MAAM,uBAAiB;IAE9C,MAAM,CAAC,IAAI,IAAI,KAAK,EAAE;
|
|
1
|
+
{"version":3,"file":"GuildManager.d.ts","sourceRoot":"","sources":["../../../src/manager/guild/GuildManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,EACL,QAAQ,EACoB,OAAO,EACtC,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,qBAAa,YAAY;IAErB,gBAAuB,IAAI,qBAAe;IAC1C,gBAAuB,IAAI,0BAAmB;IAC9C,gBAAuB,OAAO,0BAAqB;IACnD,gBAAuB,MAAM,uBAAiB;IAE9C,MAAM,CAAC,IAAI,IAAI,KAAK,EAAE;WAIT,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAInD;;OAEG;WACU,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IASvF;;OAEG;WACU,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IASzF;;OAEG;WACU,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQjF;;OAEG;WACU,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,YAAY,GAAE,MAAU,EAAE,WAAW,GAAE,MAA4C,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;WAwBvK,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;WAe7D,UAAU,CACnB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC;CAkDtB"}
|
|
@@ -14,6 +14,9 @@ class GuildManager {
|
|
|
14
14
|
static list() {
|
|
15
15
|
return Array.from(Bot_1.Bot.client.guilds.cache.values());
|
|
16
16
|
}
|
|
17
|
+
static async find(guild_id) {
|
|
18
|
+
return await Bot_1.Bot.client.guilds.fetch(guild_id);
|
|
19
|
+
}
|
|
17
20
|
/**
|
|
18
21
|
* Search channel by ID (TextChannel, DMChannel, ThreadChannel)
|
|
19
22
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BanOptions, GuildMember } from "discord.js";
|
|
3
|
-
export declare class GuildUserManager extends
|
|
1
|
+
import { BasicUserManager } from "../direct/BasicUserManager";
|
|
2
|
+
import { BanOptions, Guild, GuildMember } from "discord.js";
|
|
3
|
+
export declare class GuildUserManager extends BasicUserManager {
|
|
4
|
+
static find(userId: string, guild: Guild | string): Promise<GuildMember | null>;
|
|
4
5
|
static rename(member: GuildMember, nickname: string, maxAttempts?: number): Promise<boolean>;
|
|
5
6
|
/**
|
|
6
7
|
* Check if user is banned from guild
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuildUserManager.d.ts","sourceRoot":"","sources":["../../../src/manager/guild/GuildUserManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"GuildUserManager.d.ts","sourceRoot":"","sources":["../../../src/manager/guild/GuildUserManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAC,UAAU,EAAE,KAAK,EAAE,WAAW,EAAC,MAAM,YAAY,CAAC;AAO1D,qBAAa,gBAAiB,SAAQ,gBAAgB;WAErC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;WAaxE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAE,MAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBrG;;OAEG;WACU,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBxE;;OAEG;WACU,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBjF;;OAEG;WACU,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,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OAAO,CAAC,IAAI,CAAC;CActF"}
|
|
@@ -3,11 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GuildUserManager = void 0;
|
|
4
4
|
const Bot_1 = require("../../bot/Bot");
|
|
5
5
|
const Log_1 = require("../../utils/Log");
|
|
6
|
-
const
|
|
6
|
+
const BasicUserManager_1 = require("../direct/BasicUserManager");
|
|
7
|
+
const discord_js_1 = require("discord.js");
|
|
7
8
|
const promises_1 = require("timers/promises");
|
|
8
9
|
const EmbedManager_1 = require("../messages/EmbedManager");
|
|
10
|
+
const GuildManager_1 = require("./GuildManager");
|
|
9
11
|
const MAX_NICKNAME_LENGTH = 32;
|
|
10
|
-
class GuildUserManager extends
|
|
12
|
+
class GuildUserManager extends BasicUserManager_1.BasicUserManager {
|
|
13
|
+
static async find(userId, guild) {
|
|
14
|
+
try {
|
|
15
|
+
if (guild instanceof discord_js_1.Guild) {
|
|
16
|
+
return await guild.members.fetch(userId);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return await (await GuildManager_1.GuildManager.find(guild)).members.fetch(userId);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
Log_1.Log.error(`UserManager: Member ${userId} not found`);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
11
27
|
static async rename(member, nickname, maxAttempts = 3) {
|
|
12
28
|
if (nickname.length > MAX_NICKNAME_LENGTH) {
|
|
13
29
|
nickname = nickname.slice(0, MAX_NICKNAME_LENGTH);
|