3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 22:21:51 +00:00

Fix various issues with the info commands (#151)

Fixed !info not checking for any of the sub-permissions
Fixed message/channel/invite checking non-existent permissions
Fixed ServerCmd being out of line with the rest of the info commands name-wise
This commit is contained in:
Nils 2021-02-13 19:02:43 +01:00 committed by GitHub
parent 4584fa4e87
commit 93618e1bda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 14 deletions

View file

@ -5,7 +5,7 @@ import { GuildCases } from "../../data/GuildCases";
import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { GuildArchives } from "../../data/GuildArchives"; import { GuildArchives } from "../../data/GuildArchives";
import { Supporters } from "../../data/Supporters"; import { Supporters } from "../../data/Supporters";
import { ServerCmd } from "./commands/ServerCmd"; import { ServerInfoCmd } from "./commands/ServerInfoCmd";
import { RolesCmd } from "./commands/RolesCmd"; import { RolesCmd } from "./commands/RolesCmd";
import { LevelCmd } from "./commands/LevelCmd"; import { LevelCmd } from "./commands/LevelCmd";
import { SearchCmd } from "./commands/SearchCmd"; import { SearchCmd } from "./commands/SearchCmd";
@ -116,7 +116,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()("utility",
UserInfoCmd, UserInfoCmd,
LevelCmd, LevelCmd,
RolesCmd, RolesCmd,
ServerCmd, ServerInfoCmd,
NicknameResetCmd, NicknameResetCmd,
NicknameCmd, NicknameCmd,
PingCmd, PingCmd,

View file

@ -7,7 +7,7 @@ export const ChannelInfoCmd = utilityCmd({
trigger: ["channel", "channelinfo"], trigger: ["channel", "channelinfo"],
description: "Show information about a channel", description: "Show information about a channel",
usage: "!channel 534722016549404673", usage: "!channel 534722016549404673",
permission: "can_channel", permission: "can_channelinfo",
signature: { signature: {
channel: ct.channelId({ required: false }), channel: ct.channelId({ required: false }),

View file

@ -27,11 +27,16 @@ export const InfoCmd = utilityCmd({
async run({ message, args, pluginData }) { async run({ message, args, pluginData }) {
const value = args.value || message.author.id; const value = args.value || message.author.id;
const userCfg = pluginData.config.getMatchingConfig({
member: message.member,
channelId: message.channel.id,
message,
});
// 1. Channel // 1. Channel
const channelId = getChannelId(value); const channelId = getChannelId(value);
const channel = channelId && pluginData.guild.channels.get(channelId); const channel = channelId && pluginData.guild.channels.get(channelId);
if (channel) { if (channel && userCfg.can_channelinfo) {
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id); const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
if (embed) { if (embed) {
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
@ -41,7 +46,7 @@ export const InfoCmd = utilityCmd({
// 2. Server // 2. Server
const guild = pluginData.client.guilds.get(value); const guild = pluginData.client.guilds.get(value);
if (guild) { if (guild && userCfg.can_server) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id); const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) { if (embed) {
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
@ -51,7 +56,7 @@ export const InfoCmd = utilityCmd({
// 3. User // 3. User
const user = await resolveUser(pluginData.client, value); const user = await resolveUser(pluginData.client, value);
if (user) { 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), message.author.id);
if (embed) { if (embed) {
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
@ -61,7 +66,7 @@ export const InfoCmd = utilityCmd({
// 4. Message // 4. Message
const messageTarget = await resolveMessageTarget(pluginData, value); const messageTarget = await resolveMessageTarget(pluginData, value);
if (messageTarget) { if (messageTarget && userCfg.can_messageinfo) {
if (canReadChannel(messageTarget.channel, message.member)) { if (canReadChannel(messageTarget.channel, message.member)) {
const embed = await getMessageInfoEmbed( const embed = await getMessageInfoEmbed(
pluginData, pluginData,
@ -80,7 +85,7 @@ export const InfoCmd = utilityCmd({
const inviteCode = await parseInviteCodeInput(value); const inviteCode = await parseInviteCodeInput(value);
if (inviteCode) { if (inviteCode) {
const invite = await resolveInvite(pluginData.client, inviteCode, true); const invite = await resolveInvite(pluginData.client, inviteCode, true);
if (invite) { if (invite && userCfg.can_inviteinfo) {
const embed = await getInviteInfoEmbed(pluginData, inviteCode); const embed = await getInviteInfoEmbed(pluginData, inviteCode);
if (embed) { if (embed) {
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
@ -91,7 +96,7 @@ export const InfoCmd = utilityCmd({
// 6. Server again (fallback for discovery servers) // 6. Server again (fallback for discovery servers)
const serverPreview = getGuildPreview(pluginData.client, value).catch(() => null); const serverPreview = getGuildPreview(pluginData.client, value).catch(() => null);
if (serverPreview) { if (serverPreview && userCfg.can_server) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id); const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) { if (embed) {
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
@ -100,13 +105,17 @@ export const InfoCmd = utilityCmd({
} }
// 7. Arbitrary ID // 7. Arbitrary ID
if (isValidSnowflake(value)) { if (isValidSnowflake(value) && userCfg.can_snowflake) {
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id); const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
return; return;
} }
// 7. No can do // 7. No can do
sendErrorMessage(pluginData, message.channel, "Could not find anything with that value"); sendErrorMessage(
pluginData,
message.channel,
"Could not find anything with that value or you are lacking permission for the snowflake type",
);
}, },
}); });

View file

@ -8,7 +8,7 @@ export const InviteInfoCmd = utilityCmd({
trigger: ["invite", "inviteinfo"], trigger: ["invite", "inviteinfo"],
description: "Show information about an invite", description: "Show information about an invite",
usage: "!invite overwatch", usage: "!invite overwatch",
permission: "can_invite", permission: "can_inviteinfo",
signature: { signature: {
inviteCode: ct.string({ required: false }), inviteCode: ct.string({ required: false }),

View file

@ -8,7 +8,7 @@ export const MessageInfoCmd = utilityCmd({
trigger: ["message", "messageinfo"], trigger: ["message", "messageinfo"],
description: "Show information about a message", description: "Show information about a message",
usage: "!message 534722016549404673-534722219696455701", usage: "!message 534722016549404673-534722219696455701",
permission: "can_message", permission: "can_messageinfo",
signature: { signature: {
message: ct.messageTarget(), message: ct.messageTarget(),

View file

@ -3,7 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed"; import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
export const ServerCmd = utilityCmd({ export const ServerInfoCmd = utilityCmd({
trigger: ["server", "serverinfo"], trigger: ["server", "serverinfo"],
description: "Show server information", description: "Show server information",
usage: "!server", usage: "!server",