2019-04-20 19:23:11 +03:00
|
|
|
import { decorators as d, getCommandSignature, IPluginOptions, ICommandDefinition } from "knub";
|
2019-04-23 05:58:50 +03:00
|
|
|
import {
|
|
|
|
CategoryChannel,
|
|
|
|
Channel,
|
|
|
|
EmbedOptions,
|
|
|
|
GuildChannel,
|
|
|
|
Member,
|
|
|
|
Message,
|
|
|
|
MessageContent,
|
|
|
|
Role,
|
|
|
|
TextChannel,
|
|
|
|
User,
|
|
|
|
VoiceChannel,
|
|
|
|
} from "eris";
|
2019-02-15 03:55:18 +02:00
|
|
|
import {
|
2019-02-17 16:45:29 +02:00
|
|
|
channelMentionRegex,
|
2019-02-15 03:55:18 +02:00
|
|
|
chunkArray,
|
2019-04-13 03:54:36 +03:00
|
|
|
createChunkedMessage,
|
2019-02-15 03:55:18 +02:00
|
|
|
embedPadding,
|
|
|
|
errorMessage,
|
2019-02-17 16:45:29 +02:00
|
|
|
isSnowflake,
|
2019-02-17 22:49:14 +02:00
|
|
|
multiSorter,
|
2019-02-15 03:55:18 +02:00
|
|
|
noop,
|
2019-04-23 05:58:50 +03:00
|
|
|
resolveMember,
|
2019-02-17 16:45:29 +02:00
|
|
|
simpleClosestStringMatch,
|
2019-04-23 05:58:50 +03:00
|
|
|
sleep,
|
2019-02-17 22:49:14 +02:00
|
|
|
sorter,
|
2019-02-15 03:55:18 +02:00
|
|
|
stripObjectToScalars,
|
|
|
|
successMessage,
|
|
|
|
trimLines,
|
2019-04-20 19:03:30 +03:00
|
|
|
UnknownUser,
|
2019-02-15 03:55:18 +02:00
|
|
|
} from "../utils";
|
2018-07-31 02:42:45 +03:00
|
|
|
import { GuildLogs } from "../data/GuildLogs";
|
|
|
|
import { LogType } from "../data/LogType";
|
2018-07-31 04:02:45 +03:00
|
|
|
import moment from "moment-timezone";
|
|
|
|
import humanizeDuration from "humanize-duration";
|
|
|
|
import { GuildCases } from "../data/GuildCases";
|
2018-10-26 06:41:20 +03:00
|
|
|
import { CaseTypes } from "../data/CaseTypes";
|
2018-11-24 18:39:17 +02:00
|
|
|
import { SavedMessage } from "../data/entities/SavedMessage";
|
|
|
|
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
|
|
|
import { GuildArchives } from "../data/GuildArchives";
|
2018-12-15 17:28:36 +02:00
|
|
|
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
2019-04-23 05:58:50 +03:00
|
|
|
import { getCurrentUptime } from "../uptime";
|
|
|
|
|
|
|
|
import LCL from "last-commit-log";
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2019-01-13 23:30:48 +02:00
|
|
|
const { performance } = require("perf_hooks");
|
|
|
|
|
2018-07-31 02:42:45 +03:00
|
|
|
const MAX_SEARCH_RESULTS = 15;
|
|
|
|
const MAX_CLEAN_COUNT = 50;
|
2018-11-24 19:33:29 +02:00
|
|
|
const CLEAN_COMMAND_DELETE_DELAY = 5000;
|
2019-04-30 05:42:01 +03:00
|
|
|
const MEMBER_REFRESH_FREQUENCY = 10 * 60 * 1000; // How often to do a full member refresh when using !search or !roles --counts
|
2018-07-01 03:35:51 +03:00
|
|
|
|
2018-08-03 19:26:54 +03:00
|
|
|
const activeReloads: Map<string, TextChannel> = new Map();
|
|
|
|
|
2019-04-13 01:44:18 +03:00
|
|
|
interface IUtilityPluginConfig {
|
|
|
|
can_roles: boolean;
|
|
|
|
can_level: boolean;
|
|
|
|
can_search: boolean;
|
|
|
|
can_clean: boolean;
|
|
|
|
can_info: boolean;
|
|
|
|
can_server: boolean;
|
|
|
|
can_reload_guild: boolean;
|
|
|
|
can_nickname: boolean;
|
|
|
|
can_ping: boolean;
|
|
|
|
can_source: boolean;
|
|
|
|
can_vcmove: boolean;
|
2019-04-13 03:54:36 +03:00
|
|
|
can_help: boolean;
|
2019-04-23 05:58:50 +03:00
|
|
|
can_about: boolean;
|
2019-03-04 21:44:04 +02:00
|
|
|
}
|
|
|
|
|
2019-04-13 01:44:18 +03:00
|
|
|
export class UtilityPlugin extends ZeppelinPlugin<IUtilityPluginConfig> {
|
2019-01-13 17:56:14 +02:00
|
|
|
public static pluginName = "utility";
|
2019-01-03 06:15:28 +02:00
|
|
|
|
2018-07-31 02:42:45 +03:00
|
|
|
protected logs: GuildLogs;
|
2018-07-31 04:02:45 +03:00
|
|
|
protected cases: GuildCases;
|
2018-11-24 18:39:17 +02:00
|
|
|
protected savedMessages: GuildSavedMessages;
|
|
|
|
protected archives: GuildArchives;
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2019-04-30 05:42:01 +03:00
|
|
|
protected lastFullMemberRefresh = 0;
|
|
|
|
|
2019-04-13 01:44:18 +03:00
|
|
|
getDefaultOptions(): IPluginOptions<IUtilityPluginConfig> {
|
2018-07-01 03:35:51 +03:00
|
|
|
return {
|
2019-04-13 01:44:18 +03:00
|
|
|
config: {
|
|
|
|
can_roles: false,
|
|
|
|
can_level: false,
|
|
|
|
can_search: false,
|
|
|
|
can_clean: false,
|
|
|
|
can_info: false,
|
|
|
|
can_server: false,
|
|
|
|
can_reload_guild: false,
|
|
|
|
can_nickname: false,
|
|
|
|
can_ping: false,
|
|
|
|
can_source: false,
|
|
|
|
can_vcmove: false,
|
2019-04-13 03:54:36 +03:00
|
|
|
can_help: false,
|
2019-04-23 05:58:50 +03:00
|
|
|
can_about: false,
|
2018-07-01 03:35:51 +03:00
|
|
|
},
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
level: ">=50",
|
2019-04-13 01:44:18 +03:00
|
|
|
config: {
|
|
|
|
can_roles: true,
|
|
|
|
can_level: true,
|
|
|
|
can_search: true,
|
|
|
|
can_clean: true,
|
|
|
|
can_info: true,
|
|
|
|
can_server: true,
|
|
|
|
can_nickname: true,
|
|
|
|
can_vcmove: true,
|
2019-04-13 03:54:36 +03:00
|
|
|
can_help: true,
|
2019-02-15 03:55:18 +02:00
|
|
|
},
|
2019-01-13 23:30:48 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
level: ">=100",
|
2019-04-13 01:44:18 +03:00
|
|
|
config: {
|
|
|
|
can_reload_guild: true,
|
|
|
|
can_ping: true,
|
|
|
|
can_source: true,
|
2019-04-23 05:58:50 +03:00
|
|
|
can_about: true,
|
2019-02-15 03:55:18 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2018-07-01 03:35:51 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-31 02:42:45 +03:00
|
|
|
onLoad() {
|
|
|
|
this.logs = new GuildLogs(this.guildId);
|
2018-10-26 06:41:20 +03:00
|
|
|
this.cases = GuildCases.getInstance(this.guildId);
|
2018-11-24 18:39:17 +02:00
|
|
|
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
|
|
|
this.archives = GuildArchives.getInstance(this.guildId);
|
2018-08-03 19:26:54 +03:00
|
|
|
|
|
|
|
if (activeReloads && activeReloads.has(this.guildId)) {
|
|
|
|
activeReloads.get(this.guildId).createMessage(successMessage("Reloaded!"));
|
|
|
|
activeReloads.delete(this.guildId);
|
|
|
|
}
|
2018-07-31 02:42:45 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 05:42:01 +03:00
|
|
|
protected async refreshMembersIfNeeded() {
|
|
|
|
if (Date.now() < this.lastFullMemberRefresh + MEMBER_REFRESH_FREQUENCY) return;
|
|
|
|
await this.guild.fetchAllMembers();
|
|
|
|
this.lastFullMemberRefresh = Date.now();
|
|
|
|
}
|
|
|
|
|
2019-02-17 15:42:52 +02:00
|
|
|
@d.command("roles", "[search:string$]", {
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "counts",
|
|
|
|
type: "bool",
|
|
|
|
},
|
2019-04-23 05:59:29 +03:00
|
|
|
{
|
|
|
|
name: "sort",
|
|
|
|
type: "string",
|
|
|
|
},
|
2019-02-17 15:42:52 +02:00
|
|
|
],
|
|
|
|
})
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_roles")
|
2019-04-23 05:59:29 +03:00
|
|
|
async rolesCmd(msg: Message, args: { search?: string; counts?: boolean; sort?: string }) {
|
2019-02-17 15:42:52 +02:00
|
|
|
let roles: Array<{ _memberCount?: number } & Role> = Array.from((msg.channel as TextChannel).guild.roles.values());
|
2019-04-23 05:59:29 +03:00
|
|
|
let sort = args.sort;
|
|
|
|
|
2019-02-15 03:55:18 +02:00
|
|
|
if (args.search) {
|
|
|
|
const searchStr = args.search.toLowerCase();
|
2019-02-17 15:42:52 +02:00
|
|
|
roles = roles.filter(r => r.name.toLowerCase().includes(searchStr) || r.id === searchStr);
|
2019-02-15 03:55:18 +02:00
|
|
|
}
|
|
|
|
|
2019-02-17 15:42:52 +02:00
|
|
|
if (args.counts) {
|
2019-04-30 05:42:01 +03:00
|
|
|
this.refreshMembersIfNeeded();
|
|
|
|
|
2019-02-17 15:42:52 +02:00
|
|
|
// If the user requested role member counts as well, calculate them and sort the roles by their member count
|
|
|
|
const roleCounts: Map<string, number> = Array.from(this.guild.members.values()).reduce((map, member) => {
|
|
|
|
for (const roleId of member.roles) {
|
|
|
|
if (!map.has(roleId)) map.set(roleId, 0);
|
|
|
|
map.set(roleId, map.get(roleId) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}, new Map());
|
|
|
|
|
|
|
|
// The "everyone" role always has all members in it
|
|
|
|
roleCounts.set(this.guildId, this.guild.memberCount);
|
|
|
|
|
|
|
|
for (const role of roles) {
|
|
|
|
role._memberCount = roleCounts.has(role.id) ? roleCounts.get(role.id) : 0;
|
|
|
|
}
|
|
|
|
|
2019-04-23 05:59:29 +03:00
|
|
|
if (!sort) sort = "-memberCount";
|
2019-02-17 15:42:52 +02:00
|
|
|
roles.sort((a, b) => {
|
|
|
|
if (a._memberCount > b._memberCount) return -1;
|
|
|
|
if (a._memberCount < b._memberCount) return 1;
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Otherwise sort by name
|
|
|
|
roles.sort((a, b) => {
|
|
|
|
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1;
|
|
|
|
if (a.name.toLowerCase() < b.name.toLowerCase()) return -1;
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
2019-02-15 05:20:38 +02:00
|
|
|
|
2019-04-23 05:59:29 +03:00
|
|
|
if (!sort) sort = "name";
|
|
|
|
|
|
|
|
let sortDir: "ASC" | "DESC" = "ASC";
|
|
|
|
if (sort && sort[0] === "-") {
|
|
|
|
sort = sort.slice(1);
|
|
|
|
sortDir = "DESC";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sort === "position" || sort === "order") {
|
|
|
|
roles.sort(sorter("position", sortDir));
|
|
|
|
} else if (sort === "memberCount" && args.counts) {
|
|
|
|
roles.sort(sorter("_memberCount", sortDir));
|
|
|
|
} else if (sort === "name") {
|
|
|
|
roles.sort(sorter(r => r.name.toLowerCase(), sortDir));
|
|
|
|
} else {
|
|
|
|
this.sendErrorMessage(msg.channel, "Unknown sorting method");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:51:04 +02:00
|
|
|
const longestId = roles.reduce((longest, role) => Math.max(longest, role.id.length), 0);
|
|
|
|
|
2019-02-15 03:55:18 +02:00
|
|
|
const chunks = chunkArray(roles, 20);
|
|
|
|
for (const [i, chunk] of chunks.entries()) {
|
2019-02-17 15:42:52 +02:00
|
|
|
const roleLines = chunk.map(role => {
|
2019-02-17 22:51:04 +02:00
|
|
|
const paddedId = role.id.padEnd(longestId, " ");
|
|
|
|
let line = `${paddedId} ${role.name}`;
|
2019-02-17 15:42:52 +02:00
|
|
|
if (role._memberCount != null) {
|
|
|
|
line += role._memberCount === 1 ? ` (${role._memberCount} member)` : ` (${role._memberCount} members)`;
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
});
|
|
|
|
|
2019-02-15 03:55:18 +02:00
|
|
|
if (i === 0) {
|
|
|
|
msg.channel.createMessage(
|
|
|
|
trimLines(`
|
|
|
|
${args.search ? "Total roles found" : "Total roles"}: ${roles.length}
|
2019-02-17 15:42:52 +02:00
|
|
|
\`\`\`py\n${roleLines.join("\n")}\`\`\`
|
2019-02-15 03:55:18 +02:00
|
|
|
`),
|
|
|
|
);
|
|
|
|
} else {
|
2019-02-17 15:42:52 +02:00
|
|
|
msg.channel.createMessage("```py\n" + roleLines.join("\n") + "```");
|
2019-02-15 03:55:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-01 03:35:51 +03:00
|
|
|
}
|
2018-07-14 20:56:08 +03:00
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
@d.command("level", "[member:resolvedMember]")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_level")
|
2019-04-20 19:03:30 +03:00
|
|
|
async levelCmd(msg: Message, args: { member?: Member }) {
|
|
|
|
const member = args.member || msg.member;
|
2018-07-14 20:56:08 +03:00
|
|
|
const level = this.getMemberLevel(member);
|
2018-10-26 06:41:20 +03:00
|
|
|
msg.channel.createMessage(`The permission level of ${member.username}#${member.discriminator} is **${level}**`);
|
2018-07-14 20:56:08 +03:00
|
|
|
}
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
@d.command("search", "[query:string$]", {
|
2019-04-13 02:23:22 +03:00
|
|
|
aliases: ["s"],
|
2019-02-17 22:49:14 +02:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "page",
|
|
|
|
type: "number",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "role",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "voice",
|
|
|
|
type: "bool",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sort",
|
|
|
|
type: "string",
|
|
|
|
},
|
2019-04-13 03:24:02 +03:00
|
|
|
{
|
|
|
|
name: "case-sensitive",
|
|
|
|
type: "boolean",
|
|
|
|
shortcut: "cs",
|
|
|
|
},
|
2019-02-17 22:49:14 +02:00
|
|
|
],
|
|
|
|
})
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_search")
|
2019-02-17 22:49:14 +02:00
|
|
|
async searchCmd(
|
|
|
|
msg: Message,
|
2019-04-13 03:24:02 +03:00
|
|
|
args: { query?: string; role?: string; page?: number; voice?: boolean; sort?: string; "case-sensitive"?: boolean },
|
2019-02-17 22:49:14 +02:00
|
|
|
) {
|
2019-04-30 05:42:01 +03:00
|
|
|
this.refreshMembersIfNeeded();
|
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
let matchingMembers = Array.from(this.guild.members.values());
|
2018-08-02 04:00:42 +03:00
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
if (args.role) {
|
|
|
|
const roleIds = args.role.split(",");
|
|
|
|
matchingMembers = matchingMembers.filter(member => {
|
|
|
|
for (const role of roleIds) {
|
|
|
|
if (!member.roles.includes(role)) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.voice) {
|
|
|
|
matchingMembers = matchingMembers.filter(m => m.voiceState.channelID != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.query) {
|
2019-04-13 03:24:02 +03:00
|
|
|
const query = args["case-sensitive"] ? args.query : args.query.toLowerCase();
|
2019-02-17 22:49:14 +02:00
|
|
|
|
|
|
|
matchingMembers = matchingMembers.filter(member => {
|
2019-04-13 03:24:02 +03:00
|
|
|
const nick = args["case-sensitive"] ? member.nick : member.nick && member.nick.toLowerCase();
|
|
|
|
|
|
|
|
const fullUsername = args["case-sensitive"]
|
|
|
|
? `${member.user.username}#${member.user.discriminator}`
|
|
|
|
: `${member.user.username}#${member.user.discriminator}`.toLowerCase();
|
|
|
|
|
|
|
|
if (nick && nick.indexOf(query) !== -1) return true;
|
|
|
|
if (fullUsername.indexOf(query) !== -1) return true;
|
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2018-07-31 02:42:45 +03:00
|
|
|
|
|
|
|
if (matchingMembers.length > 0) {
|
|
|
|
let header;
|
|
|
|
const resultText = matchingMembers.length === 1 ? "result" : "results";
|
|
|
|
|
2018-08-02 04:00:42 +03:00
|
|
|
const paginated = matchingMembers.length > MAX_SEARCH_RESULTS;
|
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
const inputPage = args.page || 1;
|
2018-08-02 04:00:42 +03:00
|
|
|
const lastPage = Math.ceil(matchingMembers.length / MAX_SEARCH_RESULTS);
|
|
|
|
const page = Math.min(lastPage, Math.max(1, inputPage));
|
|
|
|
|
|
|
|
const from = (page - 1) * MAX_SEARCH_RESULTS;
|
|
|
|
const to = Math.min(from + MAX_SEARCH_RESULTS, matchingMembers.length);
|
|
|
|
|
|
|
|
if (paginated) {
|
|
|
|
header = `Found ${matchingMembers.length} ${resultText} (showing ${from + 1}-${to})`;
|
2018-07-31 02:42:45 +03:00
|
|
|
} else {
|
|
|
|
header = `Found ${matchingMembers.length} ${resultText}`;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
const [, sortDir, sortBy] = args.sort ? args.sort.match(/^(-?)(.*)$/) : [null, "ASC", "name"];
|
|
|
|
const realSortDir = sortDir === "-" ? "DESC" : "ASC";
|
|
|
|
|
|
|
|
if (sortBy === "id") {
|
2019-02-17 23:15:24 +02:00
|
|
|
matchingMembers.sort(sorter(m => BigInt(m.id), realSortDir));
|
2019-02-17 22:49:14 +02:00
|
|
|
} else {
|
2019-02-17 23:15:24 +02:00
|
|
|
matchingMembers.sort(
|
2019-02-17 22:49:14 +02:00
|
|
|
multiSorter([[m => m.username.toLowerCase(), realSortDir], [m => m.discriminator, realSortDir]]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-17 23:15:24 +02:00
|
|
|
const pageMembers = matchingMembers.slice(from, to);
|
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
const longestId = pageMembers.reduce((longest, member) => Math.max(longest, member.id.length), 0);
|
|
|
|
const lines = pageMembers.map(member => {
|
|
|
|
const paddedId = member.id.padEnd(longestId, " ");
|
2019-04-13 03:24:02 +03:00
|
|
|
let line = `${paddedId} ${member.user.username}#${member.user.discriminator}`;
|
|
|
|
if (member.nick) line += ` (${member.nick})`;
|
|
|
|
return line;
|
2018-07-31 02:42:45 +03:00
|
|
|
});
|
2018-08-02 04:00:42 +03:00
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
const footer = paginated ? "Use --page=n to browse results" : "";
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2019-02-17 22:49:14 +02:00
|
|
|
msg.channel.createMessage(`${header}\n\`\`\`js\n${lines.join("\n")}\`\`\`${footer}`);
|
2018-07-31 02:42:45 +03:00
|
|
|
} else {
|
|
|
|
msg.channel.createMessage(errorMessage("No results found"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:39:17 +02:00
|
|
|
async cleanMessages(channel: Channel, savedMessages: SavedMessage[], mod: User) {
|
|
|
|
this.logs.ignoreLog(LogType.MESSAGE_DELETE, savedMessages[0].id);
|
|
|
|
this.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, savedMessages[0].id);
|
|
|
|
|
2018-12-22 13:06:40 +02:00
|
|
|
// Delete & archive in ID order
|
|
|
|
savedMessages = Array.from(savedMessages).sort((a, b) => (a.id > b.id ? 1 : -1));
|
2018-11-24 19:33:29 +02:00
|
|
|
const idsToDelete = savedMessages.map(m => m.id);
|
2018-12-22 13:06:40 +02:00
|
|
|
|
|
|
|
// Make sure the deletions aren't double logged
|
|
|
|
idsToDelete.forEach(id => this.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
|
|
|
|
this.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, idsToDelete[0]);
|
|
|
|
|
|
|
|
// Actually delete the messages
|
2018-11-24 19:33:29 +02:00
|
|
|
await this.bot.deleteMessages(channel.id, idsToDelete);
|
|
|
|
await this.savedMessages.markBulkAsDeleted(idsToDelete);
|
2018-11-24 18:39:17 +02:00
|
|
|
|
2018-12-22 13:06:40 +02:00
|
|
|
// Create an archive
|
|
|
|
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild);
|
2019-01-15 04:03:28 +02:00
|
|
|
const archiveUrl = this.archives.getUrl(this.knub.getGlobalConfig().url, archiveId);
|
2018-11-24 18:39:17 +02:00
|
|
|
|
2018-07-31 02:42:45 +03:00
|
|
|
this.logs.log(LogType.CLEAN, {
|
|
|
|
mod: stripObjectToScalars(mod),
|
|
|
|
channel: stripObjectToScalars(channel),
|
2018-11-24 18:39:17 +02:00
|
|
|
count: savedMessages.length,
|
2019-02-15 03:55:18 +02:00
|
|
|
archiveUrl,
|
2018-07-31 02:42:45 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-13 02:23:45 +03:00
|
|
|
@d.command("clean", "<count:number>", {
|
|
|
|
aliases: ["clean all"],
|
|
|
|
})
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_clean")
|
2018-07-31 02:42:45 +03:00
|
|
|
async cleanAllCmd(msg: Message, args: { count: number }) {
|
|
|
|
if (args.count > MAX_CLEAN_COUNT || args.count <= 0) {
|
2018-10-26 06:41:20 +03:00
|
|
|
msg.channel.createMessage(errorMessage(`Clean count must be between 1 and ${MAX_CLEAN_COUNT}`));
|
2018-07-31 02:42:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:39:17 +02:00
|
|
|
const messagesToClean = await this.savedMessages.getLatestByChannelBeforeId(msg.channel.id, msg.id, args.count);
|
2018-07-31 04:02:45 +03:00
|
|
|
if (messagesToClean.length > 0) {
|
2018-11-24 18:39:17 +02:00
|
|
|
await this.cleanMessages(msg.channel, messagesToClean, msg.author);
|
2018-07-31 04:02:45 +03:00
|
|
|
}
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2018-11-24 19:33:29 +02:00
|
|
|
const responseMsg = await msg.channel.createMessage(
|
2019-02-15 03:55:18 +02:00
|
|
|
successMessage(`Cleaned ${messagesToClean.length} ${messagesToClean.length === 1 ? "message" : "messages"}`),
|
2018-07-31 02:42:45 +03:00
|
|
|
);
|
2018-11-24 19:33:29 +02:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-15 17:21:51 +02:00
|
|
|
msg.delete().catch(noop);
|
|
|
|
responseMsg.delete().catch(noop);
|
2018-11-24 19:33:29 +02:00
|
|
|
}, CLEAN_COMMAND_DELETE_DELAY);
|
2018-07-31 02:42:45 +03:00
|
|
|
}
|
|
|
|
|
2018-11-24 19:42:51 +02:00
|
|
|
@d.command("clean user", "<userId:userid> <count:number>")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_clean")
|
2018-07-31 02:42:45 +03:00
|
|
|
async cleanUserCmd(msg: Message, args: { userId: string; count: number }) {
|
|
|
|
if (args.count > MAX_CLEAN_COUNT || args.count <= 0) {
|
2018-10-26 06:41:20 +03:00
|
|
|
msg.channel.createMessage(errorMessage(`Clean count must be between 1 and ${MAX_CLEAN_COUNT}`));
|
2018-07-31 02:42:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:39:17 +02:00
|
|
|
const messagesToClean = await this.savedMessages.getLatestByChannelAndUser(msg.channel.id, args.userId, args.count);
|
2018-07-31 04:02:45 +03:00
|
|
|
if (messagesToClean.length > 0) {
|
2018-11-24 18:39:17 +02:00
|
|
|
await this.cleanMessages(msg.channel, messagesToClean, msg.author);
|
2018-07-31 04:02:45 +03:00
|
|
|
}
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2018-11-24 19:33:29 +02:00
|
|
|
const responseMsg = await msg.channel.createMessage(
|
2019-02-15 03:55:18 +02:00
|
|
|
successMessage(`Cleaned ${messagesToClean.length} ${messagesToClean.length === 1 ? "message" : "messages"}`),
|
2018-07-31 02:42:45 +03:00
|
|
|
);
|
2018-11-24 19:33:29 +02:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-15 17:21:51 +02:00
|
|
|
msg.delete().catch(noop);
|
|
|
|
responseMsg.delete().catch(noop);
|
2018-11-24 19:33:29 +02:00
|
|
|
}, CLEAN_COMMAND_DELETE_DELAY);
|
2018-07-31 02:42:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@d.command("clean bot", "<count:number>")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_clean")
|
2018-07-31 02:42:45 +03:00
|
|
|
async cleanBotCmd(msg: Message, args: { count: number }) {
|
|
|
|
if (args.count > MAX_CLEAN_COUNT || args.count <= 0) {
|
2018-10-26 06:41:20 +03:00
|
|
|
msg.channel.createMessage(errorMessage(`Clean count must be between 1 and ${MAX_CLEAN_COUNT}`));
|
2018-07-31 02:42:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:39:17 +02:00
|
|
|
const messagesToClean = await this.savedMessages.getLatestBotMessagesByChannel(msg.channel.id, args.count);
|
2018-07-31 04:02:45 +03:00
|
|
|
if (messagesToClean.length > 0) {
|
2018-11-24 18:39:17 +02:00
|
|
|
await this.cleanMessages(msg.channel, messagesToClean, msg.author);
|
2018-07-31 04:02:45 +03:00
|
|
|
}
|
2018-07-31 02:42:45 +03:00
|
|
|
|
2018-11-24 19:33:29 +02:00
|
|
|
const responseMsg = await msg.channel.createMessage(
|
2019-02-15 03:55:18 +02:00
|
|
|
successMessage(`Cleaned ${messagesToClean.length} ${messagesToClean.length === 1 ? "message" : "messages"}`),
|
2018-07-31 02:42:45 +03:00
|
|
|
);
|
2018-11-24 19:33:29 +02:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-12-15 17:21:51 +02:00
|
|
|
msg.delete().catch(noop);
|
|
|
|
responseMsg.delete().catch(noop);
|
2018-11-24 19:33:29 +02:00
|
|
|
}, CLEAN_COMMAND_DELETE_DELAY);
|
2018-07-31 02:42:45 +03:00
|
|
|
}
|
2018-07-31 04:02:45 +03:00
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
@d.command("info", "[user:resolvedUserLoose]")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_info")
|
2019-04-20 19:03:30 +03:00
|
|
|
async infoCmd(msg: Message, args: { user?: User | UnknownUser }) {
|
|
|
|
const user = args.user || msg.author;
|
2019-05-02 18:14:36 +03:00
|
|
|
|
|
|
|
let member;
|
|
|
|
if (!(user instanceof UnknownUser)) {
|
|
|
|
member = await this.getMember(user.id);
|
|
|
|
}
|
2019-04-20 19:03:30 +03:00
|
|
|
|
2018-07-31 04:02:45 +03:00
|
|
|
const embed: EmbedOptions = {
|
2019-02-15 03:55:18 +02:00
|
|
|
fields: [],
|
2018-07-31 04:02:45 +03:00
|
|
|
};
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
if (user && !(user instanceof UnknownUser)) {
|
2018-07-31 04:02:45 +03:00
|
|
|
const createdAt = moment(user.createdAt);
|
|
|
|
const accountAge = humanizeDuration(moment().valueOf() - user.createdAt, {
|
|
|
|
largest: 2,
|
2019-02-15 03:55:18 +02:00
|
|
|
round: true,
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
embed.title = `${user.username}#${user.discriminator}`;
|
|
|
|
embed.thumbnail = { url: user.avatarURL };
|
|
|
|
|
|
|
|
embed.fields.push({
|
|
|
|
name: "User information",
|
|
|
|
value:
|
|
|
|
trimLines(`
|
2019-03-20 00:34:41 +02:00
|
|
|
ID: **${user.id}**
|
2018-07-31 04:02:45 +03:00
|
|
|
Profile: <@!${user.id}>
|
2019-03-20 00:34:41 +02:00
|
|
|
Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
2019-02-15 03:55:18 +02:00
|
|
|
`) + embedPadding,
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
embed.title = `Unknown user`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (member) {
|
|
|
|
const joinedAt = moment(member.joinedAt);
|
|
|
|
const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, {
|
|
|
|
largest: 2,
|
2019-02-15 03:55:18 +02:00
|
|
|
round: true,
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
2019-03-09 18:16:42 +02:00
|
|
|
const roles = member.roles.map(id => this.guild.roles.get(id)).filter(r => !!r);
|
2018-07-31 04:02:45 +03:00
|
|
|
|
|
|
|
embed.fields.push({
|
|
|
|
name: "Member information",
|
|
|
|
value:
|
|
|
|
trimLines(`
|
2019-03-20 00:34:41 +02:00
|
|
|
Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**
|
2018-07-31 04:02:45 +03:00
|
|
|
${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""}
|
2019-02-15 03:55:18 +02:00
|
|
|
`) + embedPadding,
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
2019-03-20 00:34:41 +02:00
|
|
|
|
|
|
|
const voiceChannel = member.voiceState.channelID ? this.guild.channels.get(member.voiceState.channelID) : null;
|
|
|
|
if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) {
|
|
|
|
embed.fields.push({
|
|
|
|
name: "Voice information",
|
|
|
|
value:
|
|
|
|
trimLines(`
|
|
|
|
${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""}
|
|
|
|
${member.voiceState.mute ? "Server voice muted: **Yes**" : ""}
|
|
|
|
${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""}
|
|
|
|
`) + embedPadding,
|
|
|
|
});
|
|
|
|
}
|
2019-05-02 18:53:32 +03:00
|
|
|
} else {
|
|
|
|
embed.fields.push({
|
|
|
|
name: "!! USER IS NOT ON THE SERVER !!",
|
|
|
|
value: embedPadding,
|
|
|
|
});
|
2018-07-31 04:02:45 +03:00
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
const cases = (await this.cases.getByUserId(user.id)).filter(c => !c.is_hidden);
|
2019-01-15 04:16:34 +02:00
|
|
|
|
2018-07-31 04:02:45 +03:00
|
|
|
if (cases.length > 0) {
|
|
|
|
cases.sort((a, b) => {
|
2018-11-24 19:14:12 +02:00
|
|
|
return a.created_at < b.created_at ? 1 : -1;
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
|
2019-01-15 04:16:34 +02:00
|
|
|
const caseSummary = cases.slice(0, 3).map(c => {
|
|
|
|
return `${CaseTypes[c.type]} (#${c.case_number})`;
|
|
|
|
});
|
2018-07-31 04:02:45 +03:00
|
|
|
|
2018-11-24 19:14:12 +02:00
|
|
|
const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary";
|
|
|
|
|
2018-07-31 04:02:45 +03:00
|
|
|
embed.fields.push({
|
|
|
|
name: "Cases",
|
|
|
|
value: trimLines(`
|
2019-03-20 00:34:41 +02:00
|
|
|
Total cases: **${cases.length}**
|
2018-11-24 19:14:12 +02:00
|
|
|
${summaryText}: ${caseSummary.join(", ")}
|
2019-02-15 03:55:18 +02:00
|
|
|
`),
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.channel.createMessage({ embed });
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
@d.command(/(?:nickname|nick) reset/, "<member:resolvedMember>")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_nickname")
|
2019-04-20 19:03:30 +03:00
|
|
|
async nicknameResetCmd(msg: Message, args: { member: Member }) {
|
|
|
|
if (msg.member.id !== args.member.id && !this.canActOn(msg.member, args.member)) {
|
2018-12-22 16:11:53 +02:00
|
|
|
msg.channel.createMessage(errorMessage("Cannot reset nickname: insufficient permissions"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-04-20 19:03:30 +03:00
|
|
|
await args.member.edit({
|
2019-02-15 03:55:18 +02:00
|
|
|
nick: "",
|
2018-12-22 16:11:53 +02:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
msg.channel.createMessage(errorMessage("Failed to reset nickname"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
msg.channel.createMessage(successMessage(`The nickname of <@!${args.member.id}> has been reset`));
|
2018-12-22 16:11:53 +02:00
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
@d.command(/nickname|nick/, "<member:resolvedMember> <nickname:string$>")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_nickname")
|
2019-04-20 19:03:30 +03:00
|
|
|
async nicknameCmd(msg: Message, args: { member: Member; nickname: string }) {
|
|
|
|
if (msg.member.id !== args.member.id && !this.canActOn(msg.member, args.member)) {
|
2018-12-15 17:28:36 +02:00
|
|
|
msg.channel.createMessage(errorMessage("Cannot change nickname: insufficient permissions"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:02:53 +02:00
|
|
|
const nicknameLength = [...args.nickname].length;
|
|
|
|
if (nicknameLength < 2 || nicknameLength > 32) {
|
|
|
|
msg.channel.createMessage(errorMessage("Nickname must be between 2 and 32 characters long"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
const oldNickname = args.member.nick || "<none>";
|
|
|
|
|
2018-12-15 17:28:36 +02:00
|
|
|
try {
|
2019-04-20 19:03:30 +03:00
|
|
|
await args.member.edit({
|
2019-02-15 03:55:18 +02:00
|
|
|
nick: args.nickname,
|
2018-12-15 17:28:36 +02:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
msg.channel.createMessage(errorMessage("Failed to change nickname"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
msg.channel.createMessage(
|
|
|
|
successMessage(`Changed nickname of <@!${args.member.id}> from **${oldNickname}** to **${args.nickname}**`),
|
|
|
|
);
|
2018-12-15 17:28:36 +02:00
|
|
|
}
|
|
|
|
|
2018-07-31 04:02:45 +03:00
|
|
|
@d.command("server")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_server")
|
2018-07-31 04:02:45 +03:00
|
|
|
async serverCmd(msg: Message) {
|
|
|
|
await this.guild.fetchAllMembers();
|
|
|
|
|
|
|
|
const embed: EmbedOptions = {
|
2019-02-15 03:55:18 +02:00
|
|
|
fields: [],
|
2019-02-17 23:05:20 +02:00
|
|
|
color: parseInt("6b80cf", 16),
|
2018-07-31 04:02:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
embed.thumbnail = { url: this.guild.iconURL };
|
|
|
|
|
|
|
|
const createdAt = moment(this.guild.createdAt);
|
|
|
|
const serverAge = humanizeDuration(moment().valueOf() - this.guild.createdAt, {
|
|
|
|
largest: 2,
|
2019-02-15 03:55:18 +02:00
|
|
|
round: true,
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
|
2019-02-17 23:05:20 +02:00
|
|
|
const owner = this.bot.users.get(this.guild.ownerID);
|
|
|
|
const ownerName = owner ? `${owner.username}#${owner.discriminator}` : "Unknown#0000";
|
|
|
|
|
2018-07-31 04:02:45 +03:00
|
|
|
embed.fields.push({
|
2019-02-17 23:05:20 +02:00
|
|
|
name: `Server information - ${this.guild.name}`,
|
2018-07-31 04:02:45 +03:00
|
|
|
value:
|
|
|
|
trimLines(`
|
2019-02-17 23:05:20 +02:00
|
|
|
Created: **${serverAge} ago** (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})
|
|
|
|
Owner: **${ownerName}** (${this.guild.ownerID})
|
|
|
|
Voice region: **${this.guild.region}**
|
2018-07-31 04:02:45 +03:00
|
|
|
${this.guild.features.length > 0 ? "Features: " + this.guild.features.join(", ") : ""}
|
2019-02-15 03:55:18 +02:00
|
|
|
`) + embedPadding,
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const onlineMembers = this.guild.members.filter(m => m.status === "online");
|
|
|
|
const dndMembers = this.guild.members.filter(m => m.status === "dnd");
|
|
|
|
const idleMembers = this.guild.members.filter(m => m.status === "idle");
|
|
|
|
const offlineMembers = this.guild.members.filter(m => m.status === "offline");
|
2019-02-17 23:05:20 +02:00
|
|
|
const notOfflineMembers = this.guild.members.filter(m => m.status !== "offline");
|
2018-07-31 04:02:45 +03:00
|
|
|
|
|
|
|
embed.fields.push({
|
|
|
|
name: "Members",
|
2019-02-17 23:05:20 +02:00
|
|
|
inline: true,
|
2018-07-31 04:02:45 +03:00
|
|
|
value: trimLines(`
|
2019-02-17 23:05:20 +02:00
|
|
|
Total: **${this.guild.memberCount}**
|
2018-07-31 04:02:45 +03:00
|
|
|
Online: **${onlineMembers.length}**
|
|
|
|
Idle: **${idleMembers.length}**
|
|
|
|
DND: **${dndMembers.length}**
|
|
|
|
Offline: **${offlineMembers.length}**
|
2019-02-17 23:05:20 +02:00
|
|
|
Not offline: **${notOfflineMembers.length}**
|
2019-02-15 03:55:18 +02:00
|
|
|
`),
|
2018-07-31 04:02:45 +03:00
|
|
|
});
|
|
|
|
|
2019-02-18 02:07:54 +02:00
|
|
|
const categories = this.guild.channels.filter(channel => channel instanceof CategoryChannel);
|
|
|
|
const textChannels = this.guild.channels.filter(channel => channel instanceof TextChannel);
|
|
|
|
const voiceChannels = this.guild.channels.filter(channel => channel instanceof VoiceChannel);
|
|
|
|
|
|
|
|
embed.fields.push({
|
|
|
|
name: "Other stats",
|
|
|
|
inline: true,
|
|
|
|
value:
|
|
|
|
trimLines(`
|
|
|
|
Roles: **${this.guild.roles.size}**
|
|
|
|
Categories: **${categories.length}**
|
|
|
|
Text channels: **${textChannels.length}**
|
|
|
|
Voice channels: **${voiceChannels.length}**
|
|
|
|
Emojis: **${this.guild.emojis.length}**
|
|
|
|
`) + embedPadding,
|
|
|
|
});
|
|
|
|
|
2018-07-31 04:02:45 +03:00
|
|
|
msg.channel.createMessage({ embed });
|
|
|
|
}
|
2018-08-03 19:26:54 +03:00
|
|
|
|
2019-01-13 23:30:48 +02:00
|
|
|
@d.command("ping")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_ping")
|
2019-01-13 23:30:48 +02:00
|
|
|
async pingCmd(msg: Message) {
|
|
|
|
const times = [];
|
|
|
|
const messages: Message[] = [];
|
2019-01-13 23:34:54 +02:00
|
|
|
let msgToMsgDelay = null;
|
2019-01-13 23:30:48 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
const start = performance.now();
|
|
|
|
const message = await msg.channel.createMessage(`Calculating ping... ${i + 1}`);
|
|
|
|
times.push(performance.now() - start);
|
|
|
|
messages.push(message);
|
2019-01-13 23:34:54 +02:00
|
|
|
|
|
|
|
if (msgToMsgDelay === null) {
|
|
|
|
msgToMsgDelay = message.timestamp - msg.timestamp;
|
|
|
|
}
|
2019-01-13 23:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const highest = Math.round(Math.max(...times));
|
|
|
|
const lowest = Math.round(Math.min(...times));
|
|
|
|
const mean = Math.round(times.reduce((t, v) => t + v, 0) / times.length);
|
|
|
|
|
2019-04-23 05:59:46 +03:00
|
|
|
const shard = this.bot.shards.get(this.bot.guildShardMap[this.guildId]);
|
|
|
|
|
2019-01-13 23:30:48 +02:00
|
|
|
msg.channel.createMessage(
|
|
|
|
trimLines(`
|
|
|
|
**Ping:**
|
|
|
|
Lowest: **${lowest}ms**
|
|
|
|
Highest: **${highest}ms**
|
|
|
|
Mean: **${mean}ms**
|
2019-01-13 23:34:54 +02:00
|
|
|
Time between ping command and first reply: **${msgToMsgDelay}ms**
|
2019-04-23 05:59:46 +03:00
|
|
|
Shard latency: **${shard.latency}ms**
|
2019-02-15 03:55:18 +02:00
|
|
|
`),
|
2019-01-13 23:30:48 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// Clean up test messages
|
|
|
|
this.bot.deleteMessages(messages[0].channel.id, messages.map(m => m.id)).catch(noop);
|
|
|
|
}
|
|
|
|
|
2019-01-15 04:03:28 +02:00
|
|
|
@d.command("source", "<messageId:string>")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_source")
|
2019-01-15 04:03:28 +02:00
|
|
|
async sourceCmd(msg: Message, args: { messageId: string }) {
|
|
|
|
const savedMessage = await this.savedMessages.find(args.messageId);
|
|
|
|
if (!savedMessage) {
|
|
|
|
msg.channel.createMessage(errorMessage("Unknown message"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-30 05:35:38 +03:00
|
|
|
const source =
|
|
|
|
(savedMessage.data.content || "<no text content>") + "\n\nSource:\n\n" + JSON.stringify(savedMessage.data);
|
2019-01-15 04:03:28 +02:00
|
|
|
|
2019-04-30 05:35:38 +03:00
|
|
|
const archiveId = await this.archives.create(source, moment().add(1, "hour"));
|
2019-01-15 04:03:28 +02:00
|
|
|
const url = this.archives.getUrl(this.knub.getGlobalConfig().url, archiveId);
|
|
|
|
msg.channel.createMessage(`Message source: ${url}`);
|
|
|
|
}
|
|
|
|
|
2019-04-20 19:03:30 +03:00
|
|
|
@d.command("vcmove", "<member:resolvedMember> <channel:string$>")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_vcmove")
|
2019-02-17 16:45:29 +02:00
|
|
|
async vcmoveCmd(msg: Message, args: { member: Member; channel: string }) {
|
|
|
|
let channel: VoiceChannel;
|
|
|
|
|
|
|
|
if (isSnowflake(args.channel)) {
|
|
|
|
// Snowflake -> resolve channel directly
|
|
|
|
const potentialChannel = this.guild.channels.get(args.channel);
|
|
|
|
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
|
|
|
|
msg.channel.createMessage(errorMessage("Unknown or non-voice channel"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = potentialChannel;
|
|
|
|
} else if (channelMentionRegex.test(args.channel)) {
|
|
|
|
// Channel mention -> parse channel id and resolve channel from that
|
|
|
|
const channelId = args.channel.match(channelMentionRegex)[1];
|
|
|
|
const potentialChannel = this.guild.channels.get(channelId);
|
|
|
|
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
|
|
|
|
msg.channel.createMessage(errorMessage("Unknown or non-voice channel"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = potentialChannel;
|
|
|
|
} else {
|
|
|
|
// Search string -> find closest matching voice channel name
|
|
|
|
const voiceChannels = this.guild.channels.filter(theChannel => {
|
|
|
|
return theChannel instanceof VoiceChannel;
|
|
|
|
}) as VoiceChannel[];
|
|
|
|
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, ch => ch.name);
|
|
|
|
if (!closestMatch) {
|
|
|
|
msg.channel.createMessage(errorMessage("No matching voice channels"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = closestMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!args.member.voiceState || !args.member.voiceState.channelID) {
|
|
|
|
msg.channel.createMessage(errorMessage("Member is not in a voice channel"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-16 11:45:30 +02:00
|
|
|
if (args.member.voiceState.channelID === channel.id) {
|
|
|
|
msg.channel.createMessage(errorMessage("Member is already on that channel!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const oldVoiceChannel = this.guild.channels.get(args.member.voiceState.channelID);
|
|
|
|
|
2019-02-17 16:45:29 +02:00
|
|
|
try {
|
|
|
|
await args.member.edit({
|
|
|
|
channelID: channel.id,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
msg.channel.createMessage(errorMessage("Failed to move member"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-16 11:45:30 +02:00
|
|
|
this.logs.log(LogType.VOICE_CHANNEL_FORCE_MOVE, {
|
|
|
|
mod: stripObjectToScalars(msg.author),
|
2019-05-03 08:08:21 +03:00
|
|
|
member: stripObjectToScalars(args.member, ["user", "roles"]),
|
2019-03-16 11:45:30 +02:00
|
|
|
oldChannel: stripObjectToScalars(oldVoiceChannel),
|
|
|
|
newChannel: stripObjectToScalars(channel),
|
|
|
|
});
|
|
|
|
|
2019-02-17 16:45:29 +02:00
|
|
|
msg.channel.createMessage(
|
|
|
|
successMessage(`**${args.member.user.username}#${args.member.user.discriminator}** moved to **${channel.name}**`),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-13 03:54:36 +03:00
|
|
|
@d.command("help", "<command:string$>")
|
|
|
|
@d.permission("can_help")
|
|
|
|
helpCmd(msg: Message, args: { command: string }) {
|
|
|
|
const searchStr = args.command.toLowerCase();
|
|
|
|
|
|
|
|
const matchingCommands: ICommandDefinition[] = [];
|
|
|
|
|
|
|
|
const guildData = this.knub.getGuildData(this.guildId);
|
|
|
|
for (const plugin of guildData.loadedPlugins.values()) {
|
|
|
|
if (!(plugin instanceof ZeppelinPlugin)) continue;
|
|
|
|
|
|
|
|
const commands = plugin.getRegisteredCommands();
|
|
|
|
for (const command of commands) {
|
|
|
|
const trigger = command.trigger.source.toLowerCase();
|
|
|
|
if (trigger.startsWith(searchStr)) {
|
|
|
|
matchingCommands.push(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const totalResults = matchingCommands.length;
|
|
|
|
const limitedResults = matchingCommands.slice(0, 15);
|
|
|
|
const signatures = limitedResults.map(command => {
|
|
|
|
return (
|
|
|
|
"`" +
|
|
|
|
getCommandSignature(
|
|
|
|
guildData.config.prefix,
|
|
|
|
command.trigger.source,
|
|
|
|
command.parameters,
|
|
|
|
command.config.options,
|
|
|
|
) +
|
|
|
|
"`"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (totalResults === 0) {
|
|
|
|
msg.channel.createMessage("No matching commands found!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let message =
|
|
|
|
totalResults !== limitedResults.length
|
|
|
|
? `Results (${totalResults} total, showing first ${limitedResults.length}):`
|
|
|
|
: `Results:`;
|
|
|
|
|
|
|
|
message += `\n\n${signatures.join("\n")}`;
|
|
|
|
createChunkedMessage(msg.channel, message);
|
|
|
|
}
|
|
|
|
|
2019-04-23 05:58:50 +03:00
|
|
|
@d.command("about")
|
|
|
|
@d.permission("can_about")
|
|
|
|
async aboutCmd(msg: Message) {
|
|
|
|
const uptime = getCurrentUptime();
|
|
|
|
const prettyUptime = humanizeDuration(uptime, { largest: 2, round: true });
|
|
|
|
|
|
|
|
const lcl = new LCL();
|
|
|
|
const lastCommit = await lcl.getLastCommit();
|
|
|
|
|
|
|
|
const shard = this.bot.shards.get(this.bot.guildShardMap[this.guildId]);
|
|
|
|
|
|
|
|
const basicInfoRows = [
|
|
|
|
["Uptime", prettyUptime],
|
|
|
|
["Last update", moment(lastCommit.committer.date, "X").format("LL [at] H:mm [(UTC)]")],
|
|
|
|
["Version", lastCommit.shortHash],
|
|
|
|
["API latency", `${shard.latency}ms`],
|
|
|
|
];
|
|
|
|
|
2019-04-23 06:05:39 +03:00
|
|
|
const loadedPlugins = Array.from(this.knub.getGuildData(this.guildId).loadedPlugins.keys());
|
|
|
|
loadedPlugins.sort();
|
2019-04-23 05:58:50 +03:00
|
|
|
|
|
|
|
const aboutContent: MessageContent = {
|
|
|
|
embed: {
|
|
|
|
title: `About ${this.bot.user.username}`,
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: "Basic info",
|
|
|
|
value:
|
|
|
|
basicInfoRows
|
|
|
|
.map(([label, value]) => {
|
|
|
|
return `${label}: **${value}**`;
|
|
|
|
})
|
|
|
|
.join("\n") + embedPadding,
|
|
|
|
},
|
|
|
|
{
|
2019-04-23 06:05:39 +03:00
|
|
|
name: `Loaded plugins on this server (${loadedPlugins.length})`,
|
2019-04-23 05:58:50 +03:00
|
|
|
value: loadedPlugins.join(", "),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// For the embed color, find the highest colored role the bot has - this is their color on the server as well
|
|
|
|
const botMember = await resolveMember(this.bot, this.guild, this.bot.user.id);
|
|
|
|
let botRoles = botMember.roles.map(r => (msg.channel as GuildChannel).guild.roles.get(r));
|
|
|
|
botRoles = botRoles.filter(r => !!r); // Drop any unknown roles
|
|
|
|
botRoles = botRoles.filter(r => r.color); // Filter to those with a color
|
|
|
|
botRoles.sort(sorter("position", "DESC")); // Sort by position (highest first)
|
|
|
|
if (botRoles.length) {
|
|
|
|
aboutContent.embed.color = botRoles[0].color;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the bot avatar as the embed image
|
|
|
|
if (this.bot.user.avatarURL) {
|
|
|
|
aboutContent.embed.thumbnail = { url: this.bot.user.avatarURL };
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.channel.createMessage(aboutContent);
|
|
|
|
}
|
|
|
|
|
2018-08-03 19:26:54 +03:00
|
|
|
@d.command("reload_guild")
|
2019-04-13 01:44:18 +03:00
|
|
|
@d.permission("can_reload_guild")
|
2018-08-03 19:26:54 +03:00
|
|
|
reloadGuildCmd(msg: Message) {
|
|
|
|
if (activeReloads.has(this.guildId)) return;
|
|
|
|
activeReloads.set(this.guildId, msg.channel as TextChannel);
|
|
|
|
|
|
|
|
msg.channel.createMessage("Reloading...");
|
|
|
|
this.knub.reloadGuild(this.guildId);
|
|
|
|
}
|
2018-07-01 03:35:51 +03:00
|
|
|
}
|