commit c12697c3ed764158eabdac16e4ac2c98f1b6bb88
parent 6b2c28c58510c0d6e37bf8d268e58bee214400cd
Author: Demonstrandum <moi@knutsen.co>
Date: Mon, 9 Mar 2020 03:16:41 +0000
Fix extensions file.
Diffstat:
2 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/lib/extensions.ts b/lib/extensions.ts
@@ -1,10 +1,21 @@
-// Array Extensions:
-interface Array<T> {
- unique() : Array<T>
- mut_unique(): Array<T>
- mut_map(f : (T) => any) : Array<any>
+// Global Extensions:
+declare global {
+ interface Array<T> {
+ unique(): Array<T>
+ mut_unique(): Array<T>
+ mut_map(f: (T) => any): Array<any>
+ }
+ interface String {
+ squeeze(): string
+ capitalize(): string
+ }
+ interface Number {
+ round_to(dp: number): number
+ }
+
}
+// Array Extensions:
Array.prototype.unique = function () {
return this.filter((e, i) => this.indexOf(e) === i)
}
@@ -24,11 +35,6 @@ Array.prototype.mut_map = function (f) {
}
// String Extensions:
-interface String {
- squeeze() : string
- capitalize() : string
-}
-
String.prototype.squeeze = function () {
return this.split(/[ ]+/).join(' ');
};
@@ -38,11 +44,21 @@ String.prototype.capitalize = function () {
}
// Number Extensions:
-interface Number {
- round_to(dp : number) : number
-}
-
Number.prototype.round_to = function (dp : number) {
const exp = 10 ** dp;
return Math.round(this.valueOf() * exp) / exp;
};
+
+// Discord Extensions:
+
+declare module 'discord.js' {
+ interface Message {
+ answer(...args: any): void
+ }
+}
+import { Message } from 'discord.js';
+
+Message.prototype.answer = function (...args) {
+ return this.channel.send(`${this.author}, ${args[0]}`,
+ ...(args.slice(1)));
+};
diff --git a/lib/main.ts b/lib/main.ts
@@ -49,17 +49,6 @@ for (const msg of help_sections)
new_messages.push(acc);
const HELP_MESSAGES = new_messages;
-declare module 'discord.js' {
- interface Message {
- answer(...args : any) : void
- }
-}
-
-Message.prototype.answer = function (...args) {
- return this.channel.send(`${this.author}, ${args[0]}`,
- ...(args.slice(1)));
-};
-
@Discord
export class SimpOMatic {
private static _client : Client;