mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Add !about command
This commit is contained in:
parent
3b340a92c1
commit
a5f34d6e9a
5 changed files with 112 additions and 3 deletions
|
@ -90,6 +90,7 @@ import { RemindersPlugin } from "./plugins/Reminders";
|
|||
import { errorMessage, successMessage } from "./utils";
|
||||
import { ZeppelinPlugin } from "./plugins/ZeppelinPlugin";
|
||||
import { customArgumentTypes } from "./customArgumentTypes";
|
||||
import { startUptimeCounter } from "./uptime";
|
||||
|
||||
// Run latest database migrations
|
||||
logger.info("Running database migrations");
|
||||
|
@ -204,6 +205,10 @@ connect().then(async conn => {
|
|||
},
|
||||
});
|
||||
|
||||
client.once("ready", () => {
|
||||
startUptimeCounter();
|
||||
});
|
||||
|
||||
logger.info("Starting the bot");
|
||||
bot.run();
|
||||
});
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
import { decorators as d, getCommandSignature, IPluginOptions, ICommandDefinition } from "knub";
|
||||
import { CategoryChannel, Channel, EmbedOptions, Member, Message, Role, TextChannel, User, VoiceChannel } from "eris";
|
||||
import {
|
||||
CategoryChannel,
|
||||
Channel,
|
||||
EmbedOptions,
|
||||
GuildChannel,
|
||||
Member,
|
||||
Message,
|
||||
MessageContent,
|
||||
Role,
|
||||
TextChannel,
|
||||
User,
|
||||
VoiceChannel,
|
||||
} from "eris";
|
||||
import {
|
||||
channelMentionRegex,
|
||||
chunkArray,
|
||||
|
@ -9,7 +21,9 @@ import {
|
|||
isSnowflake,
|
||||
multiSorter,
|
||||
noop,
|
||||
resolveMember,
|
||||
simpleClosestStringMatch,
|
||||
sleep,
|
||||
sorter,
|
||||
stripObjectToScalars,
|
||||
successMessage,
|
||||
|
@ -26,6 +40,9 @@ import { SavedMessage } from "../data/entities/SavedMessage";
|
|||
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||
import { GuildArchives } from "../data/GuildArchives";
|
||||
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
||||
import { getCurrentUptime } from "../uptime";
|
||||
|
||||
import LCL from "last-commit-log";
|
||||
|
||||
const { performance } = require("perf_hooks");
|
||||
|
||||
|
@ -48,6 +65,7 @@ interface IUtilityPluginConfig {
|
|||
can_source: boolean;
|
||||
can_vcmove: boolean;
|
||||
can_help: boolean;
|
||||
can_about: boolean;
|
||||
}
|
||||
|
||||
export class UtilityPlugin extends ZeppelinPlugin<IUtilityPluginConfig> {
|
||||
|
@ -73,6 +91,7 @@ export class UtilityPlugin extends ZeppelinPlugin<IUtilityPluginConfig> {
|
|||
can_source: false,
|
||||
can_vcmove: false,
|
||||
can_help: false,
|
||||
can_about: false,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
|
@ -95,6 +114,7 @@ export class UtilityPlugin extends ZeppelinPlugin<IUtilityPluginConfig> {
|
|||
can_reload_guild: true,
|
||||
can_ping: true,
|
||||
can_source: true,
|
||||
can_about: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -792,6 +812,65 @@ export class UtilityPlugin extends ZeppelinPlugin<IUtilityPluginConfig> {
|
|||
createChunkedMessage(msg.channel, message);
|
||||
}
|
||||
|
||||
@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`],
|
||||
];
|
||||
|
||||
const loadedPlugins = Object.keys(this.guildConfig.plugins);
|
||||
|
||||
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,
|
||||
},
|
||||
{
|
||||
name: "Loaded plugins on this server",
|
||||
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);
|
||||
}
|
||||
|
||||
@d.command("reload_guild")
|
||||
@d.permission("can_reload_guild")
|
||||
reloadGuildCmd(msg: Message) {
|
||||
|
|
9
src/uptime.ts
Normal file
9
src/uptime.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
let start = 0;
|
||||
|
||||
export function startUptimeCounter() {
|
||||
start = Date.now();
|
||||
}
|
||||
|
||||
export function getCurrentUptime() {
|
||||
return Date.now() - start;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue