This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.ts
60 lines (50 loc) · 1.92 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
57
58
59
60
import {
AkairoClient, Command,
CommandExecFunction, CommandOptions,
ConditionalCommandExecFunction,
RegexCommandExecFunction
} from "discord-akairo";
import { GuildMember, Message, TextChannel } from "discord.js";
import pino from "pino";
import { chain } from "ramda";
import R = require("ramda");
import { withDatadog } from "./analytics/datadog";
const _send = TextChannel.prototype.send;
TextChannel.prototype.send = function(...args: any[]) {
withDatadog((client) => client.increment("bot.messages.sent"));
return _send.call(this, ...args);
};
export const boxContents = (...texts: string[]) => {
const getLines = (text: string) => text.split("\n").map((line) => line.length);
const splitTexts = chain(getLines);
const maxLength = Math.max(...splitTexts(texts));
const [head, ...tail] = texts;
const spacer = "-".repeat(maxLength);
return tail.reduce((all, text) => [...all, text, spacer], [spacer, head, spacer]).join("\n");
};
export const countMembers = (client: AkairoClient) =>
client.guilds.reduce((all, guild) => guild.memberCount + all, 0);
export const logger = pino({
prettyPrint: process.env.NODE_ENV !== "production",
level: "debug"
});
interface CreateCommand extends CommandOptions {
/**
* The exec function can be called in 3 different ways, however,
* Typescript doesn't seem to be able to support explicit `this`
* coming from external types, union types or overloads. In order to
* specify the `this` type the signature MUST be directly assigned
* in the interface
* @param message
* @param args
* @param edited
*/
exec: (this: Command, message: Message, args: any, edited: boolean) => any;
id: string;
}
export const isOwner = (id: string) => (process.env.HIFUMI_OWNERS || "140862798832861184")
.split(",")
.some(R.equals(id));
export const isMod = (member: GuildMember) =>
member.hasPermission("BAN_MEMBERS") || isOwner(member.id);
export const STAR = "⭐";