3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-14 21:31:50 +00:00

Add !channel/!channelinfo

This commit is contained in:
Dragory 2020-08-05 22:54:14 +03:00
parent a1a5952e44
commit 14af94e7a3
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
10 changed files with 144 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

View file

@ -0,0 +1 @@
<svg class="icon-1_QxNX" aria-hidden="false" width="16" height="16" viewBox="0 0 24 24"><path d="M3.9 8.26H2V15.2941H3.9V8.26Z" fill="currentColor"></path><path d="M19.1 4V5.12659L4.85 8.26447V18.1176C4.85 18.5496 5.1464 18.9252 5.5701 19.0315L9.3701 19.9727C9.4461 19.9906 9.524 20 9.6 20C9.89545 20 10.1776 19.8635 10.36 19.6235L12.7065 16.5242L19.1 17.9304V19.0588H21V4H19.1ZM9.2181 17.9944L6.75 17.3826V15.2113L10.6706 16.0753L9.2181 17.9944Z" fill="currentColor"></path></svg>

After

Width:  |  Height:  |  Size: 481 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

@ -0,0 +1 @@
<svg width="24" height="24" viewBox="0 0 24 24" class="icon-1_QxNX"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M5.88657 21C5.57547 21 5.3399 20.7189 5.39427 20.4126L6.00001 17H2.59511C2.28449 17 2.04905 16.7198 2.10259 16.4138L2.27759 15.4138C2.31946 15.1746 2.52722 15 2.77011 15H6.35001L7.41001 9H4.00511C3.69449 9 3.45905 8.71977 3.51259 8.41381L3.68759 7.41381C3.72946 7.17456 3.93722 7 4.18011 7H7.76001L8.39677 3.41262C8.43914 3.17391 8.64664 3 8.88907 3H9.87344C10.1845 3 10.4201 3.28107 10.3657 3.58738L9.76001 7H15.76L16.3968 3.41262C16.4391 3.17391 16.6466 3 16.8891 3H17.8734C18.1845 3 18.4201 3.28107 18.3657 3.58738L17.76 7H21.1649C21.4755 7 21.711 7.28023 21.6574 7.58619L21.4824 8.58619C21.4406 8.82544 21.2328 9 20.9899 9H17.41L16.35 15H19.7549C20.0655 15 20.301 15.2802 20.2474 15.5862L20.0724 16.5862C20.0306 16.8254 19.8228 17 19.5799 17H16L15.3632 20.5874C15.3209 20.8261 15.1134 21 14.8709 21H13.8866C13.5755 21 13.3399 20.7189 13.3943 20.4126L14 17H8.00001L7.36325 20.5874C7.32088 20.8261 7.11337 21 6.87094 21H5.88657ZM9.41045 9L8.35045 15H14.3504L15.4104 9H9.41045Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -0,0 +1 @@
<svg class="icon-1_QxNX" aria-hidden="false" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M11.383 3.07904C11.009 2.92504 10.579 3.01004 10.293 3.29604L6 8.00204H3C2.45 8.00204 2 8.45304 2 9.00204V15.002C2 15.552 2.45 16.002 3 16.002H6L10.293 20.71C10.579 20.996 11.009 21.082 11.383 20.927C11.757 20.772 12 20.407 12 20.002V4.00204C12 3.59904 11.757 3.23204 11.383 3.07904ZM14 5.00195V7.00195C16.757 7.00195 19 9.24595 19 12.002C19 14.759 16.757 17.002 14 17.002V19.002C17.86 19.002 21 15.863 21 12.002C21 8.14295 17.86 5.00195 14 5.00195ZM14 9.00195C15.654 9.00195 17 10.349 17 12.002C17 13.657 15.654 15.002 14 15.002V13.002C14.551 13.002 15 12.553 15 12.002C15 11.451 14.551 11.002 14 11.002V9.00195Z"></path></svg>

After

Width:  |  Height:  |  Size: 785 B

View file

@ -28,6 +28,7 @@ import { AvatarCmd } from "./commands/AvatarCmd";
import { CleanCmd } from "./commands/CleanCmd";
import { Message } from "eris";
import { InviteInfoCmd } from "./commands/InviteInfoCmd";
import { ChannelInfoCmd } from "./commands/ChannelInfoCmd";
const defaultOptions: PluginOptions<UtilityPluginType> = {
config: {
@ -38,6 +39,7 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
can_info: false,
can_server: false,
can_invite: false,
can_channel: false,
can_reload_guild: false,
can_nickname: false,
can_ping: false,
@ -62,6 +64,7 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
can_info: true,
can_server: true,
can_invite: true,
can_channel: true,
can_nickname: true,
can_vcmove: true,
can_help: true,
@ -112,6 +115,7 @@ export const UtilityPlugin = zeppelinPlugin<UtilityPluginType>()("utility", {
AvatarCmd,
CleanCmd,
InviteInfoCmd,
ChannelInfoCmd,
],
onLoad(pluginData) {

View file

@ -0,0 +1,25 @@
import { utilityCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
export const ChannelInfoCmd = utilityCmd({
trigger: ["channel", "channelinfo"],
description: "Show information about a channel",
usage: "!channel 534722016549404673",
permission: "can_channel",
signature: {
channel: ct.channelId({ required: false }),
},
async run({ message, args, pluginData }) {
const embed = await getChannelInfoEmbed(pluginData, args.channel);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "Unknown channel");
return;
}
message.channel.createMessage({ embed });
},
});

View file

@ -0,0 +1,111 @@
import { PluginData } from "knub";
import { UtilityPluginType } from "../types";
import { Constants, EmbedOptions } from "eris";
import moment from "moment-timezone";
import humanizeDuration from "humanize-duration";
import { formatNumber, preEmbedPadding, trimLines } from "../../../utils";
const TEXT_CHANNEL_ICON =
"https://cdn.discordapp.com/attachments/740650744830623756/740656843545772062/text-channel.png";
const VOICE_CHANNEL_ICON =
"https://cdn.discordapp.com/attachments/740650744830623756/740656845982662716/voice-channel.png";
const ANNOUNCEMENT_CHANNEL_ICON =
"https://cdn.discordapp.com/attachments/740650744830623756/740656841687564348/announcement-channel.png";
export async function getChannelInfoEmbed(
pluginData: PluginData<UtilityPluginType>,
channelId: string,
): Promise<EmbedOptions | null> {
const channel = pluginData.guild.channels.get(channelId);
if (!channel) {
return null;
}
const embed: EmbedOptions = {
fields: [],
};
let icon;
if (channel.type === Constants.ChannelTypes.GUILD_VOICE) {
icon = VOICE_CHANNEL_ICON;
} else if (channel.type === Constants.ChannelTypes.GUILD_NEWS) {
icon = ANNOUNCEMENT_CHANNEL_ICON;
} else {
icon = TEXT_CHANNEL_ICON;
}
const channelType =
{
[Constants.ChannelTypes.GUILD_TEXT]: "Text channel",
[Constants.ChannelTypes.GUILD_VOICE]: "Voice channel",
[Constants.ChannelTypes.GUILD_CATEGORY]: "Category",
[Constants.ChannelTypes.GUILD_NEWS]: "Announcement channel",
[Constants.ChannelTypes.GUILD_STORE]: "Store channel",
}[channel.type] || "Channel";
embed.author = {
name: `${channelType}: ${channel.name}`,
icon_url: icon,
};
let channelName;
if (channel.type === Constants.ChannelTypes.GUILD_VOICE || channel.type === Constants.ChannelTypes.GUILD_CATEGORY) {
channelName = channel.name;
} else {
channelName = `#${channel.name}`;
}
const createdAt = moment(channel.createdAt, "x");
const channelAge = humanizeDuration(Date.now() - channel.createdAt, {
largest: 2,
round: true,
});
const showMention =
channel.type !== Constants.ChannelTypes.GUILD_VOICE && channel.type !== Constants.ChannelTypes.GUILD_CATEGORY;
embed.fields.push({
name: preEmbedPadding + "Channel information",
value: trimLines(`
Name: **${channelName}**
ID: \`${channel.id}\`
Created: **${channelAge} ago** (\`${createdAt.format("MMM D, YYYY [at] H:mm [UTC]")}\`)
Type: **${channelType}**
${showMention ? `Mention: <#${channel.id}>` : ""}
`),
});
if (channel.type === Constants.ChannelTypes.GUILD_VOICE) {
const voiceMembers = Array.from(channel.voiceMembers.values());
const muted = voiceMembers.filter(vm => vm.voiceState.mute || vm.voiceState.selfMute);
const deafened = voiceMembers.filter(vm => vm.voiceState.deaf || vm.voiceState.selfDeaf);
embed.fields.push({
name: preEmbedPadding + "Voice information",
value: trimLines(`
Users on voice channel: **${formatNumber(voiceMembers.length)}**
Muted: **${formatNumber(muted.length)}**
Deafened: **${formatNumber(deafened.length)}**
`),
});
}
if (channel.type === Constants.ChannelTypes.GUILD_CATEGORY) {
const textChannels = pluginData.guild.channels.filter(
ch => ch.parentID === channel.id && ch.type !== Constants.ChannelTypes.GUILD_VOICE,
);
const voiceChannels = pluginData.guild.channels.filter(
ch => ch.parentID === channel.id && ch.type === Constants.ChannelTypes.GUILD_VOICE,
);
embed.fields.push({
name: preEmbedPadding + "Category information",
value: trimLines(`
Text channels: **${textChannels.length}**
Voice channels: **${voiceChannels.length}**
`),
});
}
return embed;
}

View file

@ -14,6 +14,7 @@ export const ConfigSchema = t.type({
can_info: t.boolean,
can_server: t.boolean,
can_invite: t.boolean,
can_channel: t.boolean,
can_reload_guild: t.boolean,
can_nickname: t.boolean,
can_ping: t.boolean,