3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 13:55:03 +00:00

Added Discord attachment link reaction, fixed emoji configuration and moved util functions

This commit is contained in:
Lily Bergonzat 2024-02-16 11:51:58 +01:00
parent a4c4b17a14
commit 592d037148
173 changed files with 1540 additions and 1170 deletions

View file

@ -5,8 +5,9 @@ import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { Supporters } from "../../data/Supporters";
import { makeIoTsConfigParser, sendSuccessMessage } from "../../pluginUtils";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners";
import { CommonPlugin } from "../Common/CommonPlugin";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { ModActionsPlugin } from "../ModActions/ModActionsPlugin";
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
@ -169,8 +170,8 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
},
userInfo(pluginData) {
return (userId: Snowflake, requestMemberId?: Snowflake) => {
return getUserInfoEmbed(pluginData, userId, false, requestMemberId);
return (userId: Snowflake) => {
return getUserInfoEmbed(pluginData, userId, false);
};
},
@ -214,7 +215,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
const { guild } = pluginData;
if (activeReloads.has(guild.id)) {
sendSuccessMessage(pluginData, activeReloads.get(guild.id)!, "Reloaded!");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(activeReloads.get(guild.id)!, "Reloaded!");
activeReloads.delete(guild.id);
}
},

View file

@ -1,7 +1,7 @@
import { APIEmbed, ImageFormat } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { UnknownUser, renderUserUsername } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { utilityCmd } from "../types";
export const AvatarCmd = utilityCmd({
@ -24,7 +24,7 @@ export const AvatarCmd = utilityCmd({
};
msg.channel.send({ embeds: [embed] });
} else {
sendErrorMessage(pluginData, msg.channel, "Invalid user ID");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid user ID");
}
},
});

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
import { utilityCmd } from "../types";
@ -16,7 +16,7 @@ export const ChannelInfoCmd = utilityCmd({
async run({ message, args, pluginData }) {
const embed = await getChannelInfoEmbed(pluginData, args.channel);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "Unknown channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown channel");
return;
}

View file

@ -5,9 +5,10 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { SavedMessage } from "../../../data/entities/SavedMessage";
import { humanizeDurationShort } from "../../../humanizeDurationShort";
import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { getBaseUrl } from "../../../pluginUtils";
import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin";
import { DAYS, SECONDS, chunkArray, getInviteCodesInString, noop } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { UtilityPluginType, utilityCmd } from "../types";
@ -82,19 +83,22 @@ export interface CleanArgs {
export async function cleanCmd(pluginData: GuildPluginData<UtilityPluginType>, args: CleanArgs | any, msg) {
if (args.count > MAX_CLEAN_COUNT || args.count <= 0) {
sendErrorMessage(
pluginData,
msg.channel,
`Clean count must be between 1 and ${MAX_CLEAN_COUNT}`,
undefined,
args["response-interaction"],
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
msg,
`Clean count must be between 1 and ${MAX_CLEAN_COUNT}`,
undefined,
args["response-interaction"],
);
return;
}
const targetChannel = args.channel ? pluginData.guild.channels.cache.get(args.channel as Snowflake) : msg.channel;
if (!targetChannel?.isTextBased()) {
sendErrorMessage(pluginData, msg.channel, `Invalid channel specified`, undefined, args["response-interaction"]);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `Invalid channel specified`, undefined, args["response-interaction"]);
return;
}
@ -106,13 +110,14 @@ export async function cleanCmd(pluginData: GuildPluginData<UtilityPluginType>, a
categoryId: targetChannel.parentId,
});
if (configForTargetChannel.can_clean !== true) {
sendErrorMessage(
pluginData,
msg.channel,
`Missing permissions to use clean on that channel`,
undefined,
args["response-interaction"],
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
msg,
`Missing permissions to use clean on that channel`,
undefined,
args["response-interaction"],
);
return;
}
}
@ -218,22 +223,14 @@ export async function cleanCmd(pluginData: GuildPluginData<UtilityPluginType>, a
}
}
responseMsg = await sendSuccessMessage(
pluginData,
msg.channel,
responseText,
undefined,
args["response-interaction"],
);
responseMsg = await pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(msg, responseText, undefined, args["response-interaction"]);
} else {
const responseText = `Found no messages to clean${note ? ` (${note})` : ""}!`;
responseMsg = await sendErrorMessage(
pluginData,
msg.channel,
responseText,
undefined,
args["response-interaction"],
);
responseMsg = await pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, responseText, undefined, args["response-interaction"]);
}
cleaningMessage?.delete();

View file

@ -1,8 +1,8 @@
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { messageLink } from "../../../utils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { utilityCmd } from "../types";
export const ContextCmd = utilityCmd({
@ -23,7 +23,7 @@ export const ContextCmd = utilityCmd({
async run({ message: msg, args, pluginData }) {
if (args.channel && !(args.channel instanceof TextChannel)) {
sendErrorMessage(pluginData, msg.channel, "Channel must be a text channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Channel must be a text channel");
return;
}
@ -31,7 +31,7 @@ export const ContextCmd = utilityCmd({
const messageId = args.messageId ?? args.message.messageId;
if (!canReadChannel(channel, msg.member)) {
sendErrorMessage(pluginData, msg.channel, "Message context not found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Message context not found");
return;
}
@ -42,7 +42,7 @@ export const ContextCmd = utilityCmd({
})
)[0];
if (!previousMessage) {
sendErrorMessage(pluginData, msg.channel, "Message context not found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Message context not found");
return;
}

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getCustomEmojiId } from "../functions/getCustomEmojiId";
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
import { utilityCmd } from "../types";
@ -17,13 +17,13 @@ export const EmojiInfoCmd = utilityCmd({
async run({ message, args, pluginData }) {
const emojiId = getCustomEmojiId(args.emoji);
if (!emojiId) {
sendErrorMessage(pluginData, message.channel, "Emoji not found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Emoji not found");
return;
}
const embed = await getEmojiInfoEmbed(pluginData, emojiId);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "Emoji not found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Emoji not found");
return;
}

View file

@ -1,10 +1,10 @@
import { Snowflake } from "discord.js";
import { getChannelId, getRoleId } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
import { getCustomEmojiId } from "../functions/getCustomEmojiId";
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
@ -42,7 +42,7 @@ export const InfoCmd = utilityCmd({
const channelId = getChannelId(value);
const channel = channelId && pluginData.guild.channels.cache.get(channelId as Snowflake);
if (channel) {
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
const embed = await getChannelInfoEmbed(pluginData, channelId!);
if (embed) {
message.channel.send({ embeds: [embed] });
return;
@ -54,7 +54,7 @@ export const InfoCmd = utilityCmd({
if (userCfg.can_server) {
const guild = await pluginData.client.guilds.fetch(value as Snowflake).catch(noop);
if (guild) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
const embed = await getServerInfoEmbed(pluginData, value);
if (embed) {
message.channel.send({ embeds: [embed] });
return;
@ -66,7 +66,7 @@ export const InfoCmd = utilityCmd({
if (userCfg.can_userinfo) {
const user = await resolveUser(pluginData.client, value);
if (user && userCfg.can_userinfo) {
const embed = await getUserInfoEmbed(pluginData, user.id, Boolean(args.compact), message.author.id);
const embed = await getUserInfoEmbed(pluginData, user.id, Boolean(args.compact));
if (embed) {
message.channel.send({ embeds: [embed] });
return;
@ -79,12 +79,7 @@ export const InfoCmd = utilityCmd({
const messageTarget = await resolveMessageTarget(pluginData, value);
if (messageTarget) {
if (canReadChannel(messageTarget.channel, message.member)) {
const embed = await getMessageInfoEmbed(
pluginData,
messageTarget.channel.id,
messageTarget.messageId,
message.author.id,
);
const embed = await getMessageInfoEmbed(pluginData, messageTarget.channel.id, messageTarget.messageId);
if (embed) {
message.channel.send({ embeds: [embed] });
return;
@ -112,7 +107,7 @@ export const InfoCmd = utilityCmd({
if (userCfg.can_server) {
const serverPreview = await getGuildPreview(pluginData.client, value).catch(() => null);
if (serverPreview) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
const embed = await getServerInfoEmbed(pluginData, value);
if (embed) {
message.channel.send({ embeds: [embed] });
return;
@ -125,7 +120,7 @@ export const InfoCmd = utilityCmd({
const roleId = getRoleId(value);
const role = roleId && pluginData.guild.roles.cache.get(roleId as Snowflake);
if (role) {
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
const embed = await getRoleInfoEmbed(pluginData, role);
message.channel.send({ embeds: [embed] });
return;
}
@ -145,16 +140,17 @@ export const InfoCmd = utilityCmd({
// 9. Arbitrary ID
if (isValidSnowflake(value) && userCfg.can_snowflake) {
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
const embed = await getSnowflakeInfoEmbed(value, true);
message.channel.send({ embeds: [embed] });
return;
}
// 10. No can do
sendErrorMessage(
pluginData,
message.channel,
"Could not find anything with that value or you are lacking permission for the snowflake type",
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
message,
"Could not find anything with that value or you are lacking permission for the snowflake type",
);
},
});

View file

@ -1,6 +1,6 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { parseInviteCodeInput } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getInviteInfoEmbed } from "../functions/getInviteInfoEmbed";
import { utilityCmd } from "../types";
@ -18,7 +18,7 @@ export const InviteInfoCmd = utilityCmd({
const inviteCode = parseInviteCodeInput(args.inviteCode);
const embed = await getInviteInfoEmbed(pluginData, inviteCode);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "Unknown invite");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown invite");
return;
}

View file

@ -3,8 +3,8 @@ import { AttachmentBuilder } from "discord.js";
import fs from "fs";
import twemoji from "twemoji";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { downloadFile, isEmoji, SECONDS } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { utilityCmd } from "../types";
const fsp = fs.promises;
@ -51,7 +51,7 @@ export const JumboCmd = utilityCmd({
let file: AttachmentBuilder | undefined;
if (!isEmoji(args.emoji)) {
sendErrorMessage(pluginData, msg.channel, "Invalid emoji");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid emoji");
return;
}
@ -87,7 +87,7 @@ export const JumboCmd = utilityCmd({
}
}
if (!image) {
sendErrorMessage(pluginData, msg.channel, "Error occurred while jumboing default emoji");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Error occurred while jumboing default emoji");
return;
}

View file

@ -1,6 +1,6 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed";
import { utilityCmd } from "../types";
@ -16,18 +16,13 @@ export const MessageInfoCmd = utilityCmd({
async run({ message, args, pluginData }) {
if (!canReadChannel(args.message.channel, message.member)) {
sendErrorMessage(pluginData, message.channel, "Unknown message");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown message");
return;
}
const embed = await getMessageInfoEmbed(
pluginData,
args.message.channel.id,
args.message.messageId,
message.author.id,
);
const embed = await getMessageInfoEmbed(pluginData, args.message.channel.id, args.message.messageId);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "Unknown message");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown message");
return;
}

View file

@ -1,7 +1,8 @@
import { escapeBold } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendSuccessMessage } from "../../../pluginUtils";
import { canActOn } from "../../../pluginUtils";
import { errorMessage } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { utilityCmd } from "../types";
export const NicknameCmd = utilityCmd({
@ -45,10 +46,11 @@ export const NicknameCmd = utilityCmd({
return;
}
sendSuccessMessage(
pluginData,
msg.channel,
`Changed nickname of <@!${args.member.id}> from **${oldNickname}** to **${args.nickname}**`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`Changed nickname of <@!${args.member.id}> from **${oldNickname}** to **${args.nickname}**`,
);
},
});

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendSuccessMessage } from "../../../pluginUtils";
import { canActOn } from "../../../pluginUtils";
import { errorMessage } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { utilityCmd } from "../types";
export const NicknameResetCmd = utilityCmd({
@ -31,6 +32,6 @@ export const NicknameResetCmd = utilityCmd({
return;
}
sendSuccessMessage(pluginData, msg.channel, `The nickname of <@!${args.member.id}> has been reset`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `The nickname of <@!${args.member.id}> has been reset`);
},
});

View file

@ -13,7 +13,7 @@ export const RoleInfoCmd = utilityCmd({
},
async run({ message, args, pluginData }) {
const embed = await getRoleInfoEmbed(pluginData, args.role, message.author.id);
const embed = await getRoleInfoEmbed(pluginData, args.role);
message.channel.send({ embeds: [embed] });
},
});

View file

@ -1,7 +1,7 @@
import { Role } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { chunkArray, sorter, trimLines } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { refreshMembersIfNeeded } from "../refreshMembers";
import { utilityCmd } from "../types";
@ -62,7 +62,7 @@ export const RolesCmd = utilityCmd({
} else if (sort === "name") {
roles.sort(sorter((r) => r.name.toLowerCase(), sortDir));
} else {
sendErrorMessage(pluginData, msg.channel, "Unknown sorting method");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown sorting method");
return;
}

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
import { utilityCmd } from "../types";
@ -15,9 +15,9 @@ export const ServerInfoCmd = utilityCmd({
async run({ message, pluginData, args }) {
const serverId = args.serverId || pluginData.guild.id;
const serverInfoEmbed = await getServerInfoEmbed(pluginData, serverId, message.author.id);
const serverInfoEmbed = await getServerInfoEmbed(pluginData, serverId);
if (!serverInfoEmbed) {
sendErrorMessage(pluginData, message.channel, "Could not find information for that server");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Could not find information for that server");
return;
}

View file

@ -12,8 +12,8 @@ export const SnowflakeInfoCmd = utilityCmd({
id: ct.anyId(),
},
async run({ message, args, pluginData }) {
const embed = await getSnowflakeInfoEmbed(pluginData, args.id, false, message.author.id);
async run({ message, args }) {
const embed = await getSnowflakeInfoEmbed(args.id, false);
message.channel.send({ embeds: [embed] });
},
});

View file

@ -1,7 +1,8 @@
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { getBaseUrl, sendErrorMessage } from "../../../pluginUtils";
import { getBaseUrl } from "../../../pluginUtils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { utilityCmd } from "../types";
export const SourceCmd = utilityCmd({
@ -16,13 +17,13 @@ export const SourceCmd = utilityCmd({
async run({ message: cmdMessage, args, pluginData }) {
if (!canReadChannel(args.message.channel, cmdMessage.member)) {
sendErrorMessage(pluginData, cmdMessage.channel, "Unknown message");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(cmdMessage, "Unknown message");
return;
}
const message = await args.message.channel.messages.fetch(args.message.messageId);
if (!message) {
sendErrorMessage(pluginData, cmdMessage.channel, "Unknown message");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(cmdMessage, "Unknown message");
return;
}

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
import { utilityCmd } from "../types";
@ -17,9 +17,9 @@ export const UserInfoCmd = utilityCmd({
async run({ message, args, pluginData }) {
const userId = args.user?.id || message.author.id;
const embed = await getUserInfoEmbed(pluginData, userId, args.compact, message.author.id);
const embed = await getUserInfoEmbed(pluginData, userId, args.compact);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "User not found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "User not found");
return;
}

View file

@ -1,7 +1,8 @@
import { VoiceChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { canActOn } from "../../../pluginUtils";
import { renderUserUsername } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { utilityCmd } from "../types";
@ -17,12 +18,12 @@ export const VcdisconnectCmd = utilityCmd({
async run({ message: msg, args, pluginData }) {
if (!canActOn(pluginData, msg.member, args.member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot move: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot move: insufficient permissions");
return;
}
if (!args.member.voice?.channelId) {
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Member is not in a voice channel");
return;
}
const channel = pluginData.guild.channels.cache.get(args.member.voice.channelId) as VoiceChannel;
@ -30,7 +31,7 @@ export const VcdisconnectCmd = utilityCmd({
try {
await args.member.voice.disconnect();
} catch {
sendErrorMessage(pluginData, msg.channel, "Failed to disconnect member");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Failed to disconnect member");
return;
}
@ -40,10 +41,8 @@ export const VcdisconnectCmd = utilityCmd({
oldChannel: channel,
});
sendSuccessMessage(
pluginData,
msg.channel,
`**${renderUserUsername(args.member.user)}** disconnected from **${channel.name}**`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(msg, `**${renderUserUsername(args.member.user)}** disconnected from **${channel.name}**`);
},
});

View file

@ -1,7 +1,8 @@
import { ChannelType, Snowflake, VoiceChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { canActOn } from "../../../pluginUtils";
import { channelMentionRegex, isSnowflake, renderUserUsername, simpleClosestStringMatch } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { utilityCmd } from "../types";
@ -23,7 +24,7 @@ export const VcmoveCmd = utilityCmd({
// Snowflake -> resolve channel directly
const potentialChannel = pluginData.guild.channels.cache.get(args.channel as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown or non-voice channel");
return;
}
@ -33,7 +34,7 @@ export const VcmoveCmd = utilityCmd({
const channelId = args.channel.match(channelMentionRegex)![1];
const potentialChannel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown or non-voice channel");
return;
}
@ -45,7 +46,7 @@ export const VcmoveCmd = utilityCmd({
);
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name);
if (!closestMatch) {
sendErrorMessage(pluginData, msg.channel, "No matching voice channels");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "No matching voice channels");
return;
}
@ -53,12 +54,12 @@ export const VcmoveCmd = utilityCmd({
}
if (!args.member.voice?.channelId) {
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Member is not in a voice channel");
return;
}
if (args.member.voice.channelId === channel.id) {
sendErrorMessage(pluginData, msg.channel, "Member is already on that channel!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Member is already on that channel!");
return;
}
@ -69,7 +70,7 @@ export const VcmoveCmd = utilityCmd({
channel: channel.id,
});
} catch {
sendErrorMessage(pluginData, msg.channel, "Failed to move member");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Failed to move member");
return;
}
@ -80,11 +81,9 @@ export const VcmoveCmd = utilityCmd({
newChannel: channel,
});
sendSuccessMessage(
pluginData,
msg.channel,
`**${renderUserUsername(args.member.user)}** moved to **${channel.name}**`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(msg, `**${renderUserUsername(args.member.user)}** moved to **${channel.name}**`);
},
});
@ -106,7 +105,7 @@ export const VcmoveAllCmd = utilityCmd({
// Snowflake -> resolve channel directly
const potentialChannel = pluginData.guild.channels.cache.get(args.channel as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown or non-voice channel");
return;
}
@ -116,7 +115,7 @@ export const VcmoveAllCmd = utilityCmd({
const channelId = args.channel.match(channelMentionRegex)![1];
const potentialChannel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof VoiceChannel)) {
sendErrorMessage(pluginData, msg.channel, "Unknown or non-voice channel");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown or non-voice channel");
return;
}
@ -128,7 +127,7 @@ export const VcmoveAllCmd = utilityCmd({
);
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name);
if (!closestMatch) {
sendErrorMessage(pluginData, msg.channel, "No matching voice channels");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "No matching voice channels");
return;
}
@ -136,12 +135,12 @@ export const VcmoveAllCmd = utilityCmd({
}
if (args.oldChannel.members.size === 0) {
sendErrorMessage(pluginData, msg.channel, "Voice channel is empty");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Voice channel is empty");
return;
}
if (args.oldChannel.id === channel.id) {
sendErrorMessage(pluginData, msg.channel, "Cant move from and to the same channel!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cant move from and to the same channel!");
return;
}
@ -154,11 +153,12 @@ export const VcmoveAllCmd = utilityCmd({
// Check for permissions but allow self-moves
if (currMember.id !== msg.member.id && !canActOn(pluginData, msg.member, currMember)) {
sendErrorMessage(
pluginData,
msg.channel,
`Failed to move ${renderUserUsername(currMember.user)} (${currMember.id}): You cannot act on this member`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
msg,
`Failed to move ${renderUserUsername(currMember.user)} (${currMember.id}): You cannot act on this member`,
);
errAmt++;
continue;
}
@ -169,14 +169,12 @@ export const VcmoveAllCmd = utilityCmd({
});
} catch {
if (msg.member.id === currMember.id) {
sendErrorMessage(pluginData, msg.channel, "Unknown error when trying to move members");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown error when trying to move members");
return;
}
sendErrorMessage(
pluginData,
msg.channel,
`Failed to move ${renderUserUsername(currMember.user)} (${currMember.id})`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `Failed to move ${renderUserUsername(currMember.user)} (${currMember.id})`);
errAmt++;
continue;
}
@ -190,13 +188,14 @@ export const VcmoveAllCmd = utilityCmd({
}
if (moveAmt !== errAmt) {
sendSuccessMessage(
pluginData,
msg.channel,
`${moveAmt - errAmt} members from **${args.oldChannel.name}** moved to **${channel.name}**`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`${moveAmt - errAmt} members from **${args.oldChannel.name}** moved to **${channel.name}**`,
);
} else {
sendErrorMessage(pluginData, msg.channel, `Failed to move any members.`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Failed to move any members.`);
}
},
});

View file

@ -22,7 +22,6 @@ const FORUM_CHANNEL_ICON =
export async function getChannelInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
channelId: string,
requestMemberId?: string,
): Promise<APIEmbed | null> {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!channel) {

View file

@ -9,7 +9,6 @@ import {
trimEmptyLines,
trimLines,
} from "../../../utils";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { UtilityPluginType } from "../types";
const MESSAGE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/740685652152025088/message.png";
@ -18,7 +17,6 @@ export async function getMessageInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
channelId: string,
messageId: string,
requestMemberId?: string,
): Promise<APIEmbed | null> {
const message = await (pluginData.guild.channels.resolve(channelId as Snowflake) as TextChannel).messages
.fetch(messageId as Snowflake)
@ -27,8 +25,6 @@ export async function getMessageInfoEmbed(
return null;
}
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
const embed: EmbedWith<"fields" | "author"> = {
fields: [],
author: {

View file

@ -6,11 +6,7 @@ import { UtilityPluginType } from "../types";
const MENTION_ICON = "https://cdn.discordapp.com/attachments/705009450855039042/839284872152481792/mention.png";
export async function getRoleInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
role: Role,
requestMemberId?: string,
): Promise<APIEmbed> {
export async function getRoleInfoEmbed(pluginData: GuildPluginData<UtilityPluginType>, role: Role): Promise<APIEmbed> {
const embed: EmbedWith<"fields" | "author" | "color"> = {
fields: [],
author: {

View file

@ -25,7 +25,6 @@ const prettifyFeature = (feature: string): string =>
export async function getServerInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
serverId: string,
requestMemberId?: string,
): Promise<APIEmbed | null> {
const thisServer = serverId === pluginData.guild.id ? pluginData.guild : null;
const [restGuild, guildPreview] = await Promise.all([

View file

@ -1,17 +1,10 @@
import { APIEmbed } from "discord.js";
import { GuildPluginData } from "knub";
import { EmbedWith, preEmbedPadding } from "../../../utils";
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
import { UtilityPluginType } from "../types";
const SNOWFLAKE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/742020790471491668/snowflake.png";
export async function getSnowflakeInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
snowflake: string,
showUnknownWarning = false,
requestMemberId?: string,
): Promise<APIEmbed> {
export async function getSnowflakeInfoEmbed(snowflake: string, showUnknownWarning = false): Promise<APIEmbed> {
const embed: EmbedWith<"fields" | "author"> = {
fields: [],
author: {

View file

@ -13,7 +13,6 @@ import {
trimLines,
UnknownUser,
} from "../../../utils";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { UtilityPluginType } from "../types";
const MAX_ROLES_TO_DISPLAY = 15;
@ -27,7 +26,6 @@ export async function getUserInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
userId: string,
compact = false,
requestMemberId?: string,
): Promise<APIEmbed | null> {
const user = await resolveUser(pluginData.client, userId);
if (!user || user instanceof UnknownUser) {
@ -40,8 +38,6 @@ export async function getUserInfoEmbed(
fields: [],
};
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
embed.author = {
name: `${user.bot ? "Bot" : "User"}: ${renderUsername(user.username, user.discriminator)}`,
};

View file

@ -13,11 +13,12 @@ import escapeStringRegexp from "escape-string-regexp";
import { ArgsFromSignatureOrArray, GuildPluginData } from "knub";
import moment from "moment-timezone";
import { RegExpRunner, allowTimeout } from "../../RegExpRunner";
import { getBaseUrl, sendErrorMessage } from "../../pluginUtils";
import { getBaseUrl } from "../../pluginUtils";
import { MINUTES, multiSorter, renderUserUsername, sorter, trimLines } from "../../utils";
import { asyncFilter } from "../../utils/async";
import { hasDiscordPermissions } from "../../utils/hasDiscordPermissions";
import { InvalidRegexError, inputPatternToRegExp } from "../../validatorUtils";
import { CommonPlugin } from "../Common/CommonPlugin";
import { banSearchSignature } from "./commands/BanSearchCmd";
import { searchCmdSignature } from "./commands/SearchCmd";
import { getUserInfoEmbed } from "./functions/getUserInfoEmbed";
@ -115,12 +116,12 @@ export async function displaySearch(
}
} catch (e) {
if (e instanceof SearchError) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
if (e instanceof InvalidRegexError) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
@ -128,7 +129,7 @@ export async function displaySearch(
}
if (searchResult.totalResults === 0) {
sendErrorMessage(pluginData, msg.channel, "No results found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "No results found");
return;
}
@ -259,12 +260,12 @@ export async function archiveSearch(
}
} catch (e) {
if (e instanceof SearchError) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
if (e instanceof InvalidRegexError) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
@ -272,7 +273,7 @@ export async function archiveSearch(
}
if (results.totalResults === 0) {
sendErrorMessage(pluginData, msg.channel, "No results found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "No results found");
return;
}