Skip to content

Commit d93d4ee

Browse files
committed
Merge branch 'dev' of https://github.com/Khaaz/AxonCore into dev
2 parents f74e947 + 4768d90 commit d93d4ee

File tree

25 files changed

+137
-106
lines changed

25 files changed

+137
-106
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"mongoose": "^5.7.7",
2828
"signale": "^1.4.0",
2929
"superagent": "^5.2.1",
30-
"typescript": "^3.7.5",
30+
"typescript": "^3.9.7",
3131
"winston": "^3.2.1",
3232
"yarn": "^1.22.0"
3333
},

src/Core/Models/GuildConfig.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,17 @@ class GuildConfig {
219219
if (guildConfig.guildID !== this.guildID) {
220220
return Promise.resolve(null);
221221
}
222+
const update = {};
222223
for (const key in guildConfig) {
223224
this[key] = guildConfig[key];
225+
if (!key.startsWith('_') ) {
226+
update[key] = guildConfig[key];
227+
}
224228
}
225229
this.updatedAt = new Date();
230+
update.updatedAt = new Date();
226231

227-
const newConf = await this._axon.DBProvider.saveGuild(this.guildID, this);
232+
const newConf = await this._axon.DBProvider.saveGuild(this.guildID, update);
228233
return newConf ? this : null;
229234
}
230235

src/Utility/AxonUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ class AxonUtils {
172172
* @memberof AxonUtils
173173
*/
174174
isBotStaff(uID) {
175-
for (const rank in this.axon.staff) {
176-
if (rank.find(u => u === uID) ) {
175+
for (const rank of Object.values(this.axon.staff) ) {
176+
if (rank.includes(uID) ) {
177177
return true;
178178
}
179179
}
@@ -257,7 +257,7 @@ class AxonUtils {
257257
* @memberof AxonUtils
258258
*/
259259
sendDM(user, content, options = {} ) {
260-
this.library.user.getDM(user)
260+
return this.library.user.getDM(user)
261261
.then(chan => this.sendMessage(chan, content, options) )
262262
.catch(err => {
263263
this.logger.verbose(`DM disabled/Bot blocked [${user.username}#${user.discriminator} - ${user.id}]!`);

types/AxonClient.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { EventEmitter } from 'events';
22
import {
3-
AxonConfs, AxonParams, Info, AxonInfo, ALogger, AxonUtils, LibClient, LibraryInterface, Utils, ADBProvider, ModuleRegistry, CommandRegistry, ListenerRegistry,
4-
EventManager, GuildConfigCache, AxonConfig, ModuleLoader, CommandDispatcher, MessageManager, AxonStaffIDs, AxonOptions, Collection, AHandler, Listener, Resolver,
5-
Webhooks, AxonTemplate, Module, Command, LOG_LEVELS, Ctx, LibMessage, GuildConfig, DEBUG_FLAGS, Executor, ExtentionInitReturn,
3+
AxonConfs, AxonParams, Info, AxonInfo, ALogger, AxonUtils, LibClient, LibraryInterface, Utils, ADBProvider, ModuleRegistry, CommandRegistry, ListenerRegistry, EventManager,
4+
GuildConfigCache, AxonConfig, ModuleLoader, CommandDispatcher, MessageManagerType, AxonStaffIDs, AxonOptions, Collection, AHandler, Listener, Resolver, Webhooks,
5+
AxonTemplate, Module, Command, LOG_LEVELS, Ctx, LibMessage, GuildConfig, DEBUG_FLAGS, Executor, ExtentionInitReturn, AxonLanguageResponse, DefaultLanguageResponse, LibDMChannel,
66
} from './';
77

8-
export declare class AxonClient extends EventEmitter {
8+
export declare class AxonClient<L extends AxonLanguageResponse = DefaultLanguageResponse> extends EventEmitter {
99
/** Configs (webhooks, template, custom) */
1010
private _configs: AxonConfs;
1111
/** Bot settings */
@@ -49,7 +49,7 @@ export declare class AxonClient extends EventEmitter {
4949
public dispatcher: CommandDispatcher;
5050
public executor: Executor;
5151
/** Message manager object accessible with `<AxonClient>.l` */
52-
private _messageManager: MessageManager;
52+
private _messageManager: MessageManagerType<L>;
5353

5454
/** Bot Staff (owners, admins, +...) */
5555
public staff: AxonStaffIDs;
@@ -119,7 +119,7 @@ export declare class AxonClient extends EventEmitter {
119119
* @readonly
120120
* @memberof AxonClient
121121
*/
122-
readonly l: MessageManager;
122+
readonly l: MessageManagerType<L>;
123123

124124
/**
125125
* Get a module from AxonClient with the given label.
@@ -221,7 +221,7 @@ export declare class AxonClient extends EventEmitter {
221221
*
222222
* @memberof AxonClient
223223
*/
224-
public sendFullHelp(msg: LibMessage, guildConfig?: GuildConfig): Promise<void>;
224+
public sendFullHelp(msg: LibMessage<LibDMChannel>, guildConfig?: GuildConfig): Promise<void>;
225225
/**
226226
* Register a guild prefix.
227227
* Shortcut to guildConfig.registerPrefix()

types/Core/Base.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
AxonClient, LibClient, ALogger, Resolver, AxonUtils, Utils, MessageManager, Module, Command,
3-
LOG_LEVELS, Ctx, LibUser, AxonMSGCont, AxonMSGOpt, LibMessage, LibTextableChannel, CommandResponse,
2+
AxonClient, LibClient, ALogger, Resolver, AxonUtils, Utils, MessageManager, Module, Command, LOG_LEVELS,
3+
Ctx, LibUser, AxonMSGCont, AxonMSGOpt, LibMessage, LibTextableChannel, CommandResponse, LibDMChannel,
44
} from '../';
55

66
/**
@@ -112,7 +112,7 @@ export declare class Base {
112112
* @returns Message Object
113113
* @memberof Base
114114
*/
115-
public sendDM(user: LibUser, content: AxonMSGCont, options?: AxonMSGOpt): Promise<LibMessage|void>;
115+
public sendDM(user: LibUser, content: AxonMSGCont, options?: AxonMSGOpt): Promise<LibMessage<LibDMChannel>|void>;
116116
/**
117117
* Send a message.
118118
* Check for bot permissions + message/embed length
@@ -127,7 +127,7 @@ export declare class Base {
127127
* @returns Message Object
128128
* @memberof Base
129129
*/
130-
public sendMessage(channel: LibTextableChannel, content: AxonMSGCont, options?: AxonMSGOpt): Promise<LibMessage>;
130+
public sendMessage<T extends LibTextableChannel>(channel: T, content: AxonMSGCont, options?: AxonMSGOpt): Promise<LibMessage<T>>;
131131
/**
132132
* Edit a message
133133
* Check for bot permissions + message embed/length
@@ -137,7 +137,7 @@ export declare class Base {
137137
* @returns Message Object
138138
* @memberof Base
139139
*/
140-
public editMessage(message: LibMessage, content: AxonMSGCont): Promise<LibMessage>;
140+
public editMessage<T extends LibTextableChannel>(message: LibMessage<T>, content: AxonMSGCont): Promise<LibMessage<T>>;
141141
/**
142142
* Send a success message. If the content is a string, suffix the success emote to the content.
143143
* Check for sendMessage perms.

types/Core/Command/CommandEnvironment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
COMMAND_EXECUTION_TYPES, CommandEnvironmentProps, CommandEnvironmentParams, LibMessage, GuildConfig, Command,
2+
COMMAND_EXECUTION_TYPES, CommandEnvironmentProps, CommandEnvironmentParams, LibMessage, GuildConfig, Command, LibTextableChannel,
33
} from '../../';
44

55
/**
@@ -9,11 +9,11 @@ import {
99
*
1010
* @class CommandEnvironment
1111
*/
12-
export declare class CommandEnvironment implements CommandEnvironmentProps {
12+
export declare class CommandEnvironment<T extends LibTextableChannel = LibTextableChannel> implements CommandEnvironmentProps {
1313
/** The raw message content */
1414
public raw: string;
1515
public command: string;
16-
public msg: LibMessage;
16+
public msg: LibMessage<T>;
1717
public args: string[];
1818
public prefix: string;
1919
public guildConfig: GuildConfig;

types/Langs/MessageManager.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
AxonClient, Languages, TranslationManager, MessageParser, AxonLanguageResponse,
2+
AxonClient, Languages, TranslationManager, MessageParser, AxonLanguageResponse, DefaultLanguageResponse,
33
} from '..';
44

55
/**
@@ -10,11 +10,11 @@ import {
1010
*
1111
* @class MessageManager
1212
*/
13-
export declare class MessageManager {
13+
export declare class MessageManager<L extends AxonLanguageResponse = DefaultLanguageResponse> {
1414
private _axon: AxonClient;
1515
/** All messages (all langs) */
16-
private _messages: Languages;
17-
public translation: TranslationManager;
16+
private _messages: Languages<L>;
17+
public translation: TranslationManager<L>;
1818
public parser: MessageParser;
1919

2020
/**
@@ -23,15 +23,15 @@ export declare class MessageManager {
2323
*
2424
* @memberof MessageManager
2525
*/
26-
constructor(axonClient: AxonClient, messages: Languages, baseLang: string)
26+
constructor(axonClient: AxonClient, messages: Languages<L>, baseLang: string)
2727

2828
/**
2929
* Returns all messages (all langs)
3030
*
3131
* @readonly
3232
* @memberof MessageManager
3333
*/
34-
readonly messages: Languages;
34+
readonly messages: Languages<L>;
3535
/**
3636
* All message from the given lang (or default lang)
3737
*
@@ -45,12 +45,18 @@ export declare class MessageManager {
4545
* @returns The message
4646
* @memberof MessageManager
4747
*/
48-
public getMessage(message: string, lang?: string): string;
48+
public getMessage(message: keyof L, lang?: string): string;
4949
/**
5050
* Get the message in the correct lang, parsed to replace {{key}} with the correct argument
5151
*
5252
* @returns The actual message
5353
* @memberof MessageManager
5454
*/
55-
public get(message: string, args: AxonLanguageResponse, lang: string): string;
55+
public get(message: keyof L, args: AxonLanguageResponse, lang: string): string;
5656
}
57+
58+
type DynamicMethods<L extends AxonLanguageResponse = DefaultLanguageResponse> = {
59+
[P in keyof L]: (args: AxonLanguageResponse, lang: string) => string;
60+
}
61+
62+
export declare type MessageManagerType<L extends AxonLanguageResponse = DefaultLanguageResponse> = MessageManager<L> & DynamicMethods<L>;

types/Langs/MessageParser.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ import { AxonLanguageResponse } from '..';
88
* @class MessageParser
99
*/
1010
export declare class MessageParser {
11-
public match: RegExp;
12-
constructor();
13-
/**
14-
* Generator function that will match all occurrence of the regex and yield a Match structure
15-
*
16-
* @generator
17-
* @yields Match
18-
* @memberof MessageParser
19-
*/
20-
public matchAll(message: string): Generator<RegExpExecArray, void, unknown>;
21-
/**
22-
* Parse the message by replacing the dynamic content.
23-
*
24-
* @param args - Custom object with all arguments that needs to be inserted in the string
25-
* @returns - The Parsed message
26-
* @memberof MessageParser
27-
*/
28-
public parse(message: string, args: AxonLanguageResponse): string;
29-
/**
30-
* Same as above but arguments are unnamed and passed as parameters instead of inside one object.
31-
*
32-
* @returns The Parsed message
33-
* @memberof MessageParser
34-
*/
35-
public parse2(message: string, args: string[] ): string;
11+
public match: RegExp;
12+
constructor();
13+
/**
14+
* Generator function that will match all occurrence of the regex and yield a Match structure
15+
*
16+
* @generator
17+
* @yields Match
18+
* @memberof MessageParser
19+
*/
20+
public matchAll(message: string): Generator<RegExpExecArray, void, unknown>;
21+
/**
22+
* Parse the message by replacing the dynamic content.
23+
*
24+
* @param args - Custom object with all arguments that needs to be inserted in the string
25+
* @returns - The Parsed message
26+
* @memberof MessageParser
27+
*/
28+
public parse(message: string, args: AxonLanguageResponse): string;
29+
/**
30+
* Same as above but arguments are unnamed and passed as parameters instead of inside one object.
31+
*
32+
* @returns The Parsed message
33+
* @memberof MessageParser
34+
*/
35+
public parse2(message: string, args: string[] ): string;
3636
}

types/Langs/TranslationManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MessageManager, Languages, AxonLanguageResponse } from '..';
1+
import { MessageManager, Languages, AxonLanguageResponse, DefaultLanguageResponse } from '..';
22

33
/**
44
* Class dedicated to manage translations.
@@ -8,33 +8,33 @@ import { MessageManager, Languages, AxonLanguageResponse } from '..';
88
*
99
* @class TranslationManager
1010
*/
11-
export declare class TranslationManager {
12-
private _manager: MessageManager;
11+
export declare class TranslationManager<L extends AxonLanguageResponse = DefaultLanguageResponse> {
12+
private _manager: MessageManager<L>;
1313
/** The default lang */
1414
public lang: string;
1515
/**
1616
* Creates an instance of TranslationManager.
1717
* @memberof TranslationManager
1818
*/
19-
constructor(manager: MessageManager, lang: string);
19+
constructor(manager: MessageManager<L>, lang: string);
2020

2121
/**
2222
* Returns all messages (all langs)
2323
*
2424
* @readonly
2525
* @memberof TranslationManager
2626
*/
27-
readonly messages: Languages;
27+
readonly messages: Languages<L>;
2828
/**
2929
* Return all messages for the specified lang or the default lang if no specified lang.
3030
*
3131
* @memberof TranslationManager
3232
*/
33-
public getMessages(lang: string): AxonLanguageResponse;
33+
public getMessages(lang: string): L;
3434
/**
3535
* Return a specified message for the specified lang or the default lang if no specified lang
3636
*
3737
* @memberof TranslationManager
3838
*/
39-
public getMessage(message: string, lang: string): string;
39+
public getMessage(message: keyof L, lang?: string): string;
4040
}

types/Libraries/definitions/Channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
LibraryInterface, LibChannel, LibGuild, LibUser, AxonMSGCont, LibMessage,
2+
LibraryInterface, LibChannel, LibGuild, LibUser, AxonMSGCont, LibMessage, LibTextableChannel,
33
} from '../../';
44

55
export declare class Channel {
@@ -43,5 +43,5 @@ export declare class Channel {
4343
* Send a message in the channel
4444
* @memberof Channel
4545
*/
46-
public sendMessage(channel: LibChannel, content: AxonMSGCont): Promise<LibMessage | LibMessage[]>; // Not Implemented // LibMessage[] is for Discord.JS
46+
public sendMessage<T extends LibTextableChannel = LibTextableChannel>(channel: T, content: AxonMSGCont): Promise<LibMessage<T> | LibMessage<T>[]>; // Not Implemented // LibMessage[] is for Discord.JS
4747
}

0 commit comments

Comments
 (0)