work smarter not harder

This commit is contained in:
Cynthia Foxwell 2023-09-14 21:09:20 -06:00
parent 14bb433a75
commit b61ba47fe4
6 changed files with 42 additions and 95 deletions

View file

@ -9,6 +9,7 @@ const apikeys = require("../apikeys.json");
const Command = require("./lib/command.js"); const Command = require("./lib/command.js");
const events = require("./lib/events.js"); const events = require("./lib/events.js");
const timer = require("./lib/timer.js"); const timer = require("./lib/timer.js");
const {pomello} = require("./lib/utils.js");
const bot = new Dysnomia.Client(config.token, { const bot = new Dysnomia.Client(config.token, {
defaultImageFormat: "png", defaultImageFormat: "png",
@ -82,14 +83,7 @@ bot.on("messageUpdate", (msg, oldMsg) => {
bot.once("ready", async () => { bot.once("ready", async () => {
logger.info("hf:main", "Connected to Discord."); logger.info("hf:main", "Connected to Discord.");
logger.info( logger.info("hf:main", `Logged in as: ${pomello(bot.user)} (${bot.user.id})`);
"hf:main",
`Logged in as: ${
bot.user.discriminator != "0"
? `${bot.user.username}#${bot.user.discriminator}`
: bot.user.username
} (${bot.user.id})`
);
const channel = await bot.getDMChannel(config.owner_id); const channel = await bot.getDMChannel(config.owner_id);
if (channel) { if (channel) {

View file

@ -10,6 +10,12 @@ function pastelize(id) {
return parseInt(hex, 16); return parseInt(hex, 16);
} }
function pomello(user) {
return user.discriminator && user.discriminator != "0"
? `${user.username}#${user.discriminator}`
: `@${user.username}`;
}
function getTopColor(msg, id, fallback = 0x7289da) { function getTopColor(msg, id, fallback = 0x7289da) {
if (!msg.guildID) return fallback; if (!msg.guildID) return fallback;
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID); const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
@ -322,11 +328,7 @@ async function lookupUser(msg, str, filter) {
selection.push({ selection.push({
value: user, value: user,
key: user.id, key: user.id,
display: `${ display: `${pomello(user)}${user.nick ? ` (${user.nick})` : ""}`,
user.discriminator != "0"
? `${user.username}#${user.discriminator}`
: user.username
}${user.nick ? ` (${user.nick})` : ""}`,
}); });
} }
} }
@ -401,6 +403,7 @@ function getUploadLimit(guild) {
module.exports = { module.exports = {
pastelize, pastelize,
pomello,
getTopColor, getTopColor,
safeString, safeString,
formatTime, formatTime,

View file

@ -4,10 +4,11 @@ const CATEGORY = "misc";
const {librex} = require("../../config.json"); const {librex} = require("../../config.json");
const { const {
hastebin,
safeString,
parseHtmlEntities,
formatTime, formatTime,
hastebin,
parseHtmlEntities,
pomello,
safeString,
} = require("../lib/utils.js"); } = require("../lib/utils.js");
const GoogleImages = require("google-images"); const GoogleImages = require("google-images");
const {tinycolor, random: randomColor} = require("@ctrl/tinycolor"); const {tinycolor, random: randomColor} = require("@ctrl/tinycolor");
@ -233,11 +234,9 @@ poll.callback = async function (msg, line, [topic, ...options]) {
if (arrOptions.length < 2) return "A minimum of two options are required."; if (arrOptions.length < 2) return "A minimum of two options are required.";
const reactions = []; const reactions = [];
let displayString = `**${ let displayString = `**${pomello(
msg.author.discriminator != "0" msg.author
? `${msg.author.username}#${msg.author.discriminator}` )}** has started a poll:\n## __${topic}__\n`;
: msg.author.username
}** has started a poll:\n## __${topic}__\n`;
for (let i = 0; i < arrOptions.length; i++) { for (let i = 0; i < arrOptions.length; i++) {
displayString += displayString +=
(i === 9 ? "\ud83d\udd1f" : `${i + 1}\u20e3`) + (i === 9 ? "\ud83d\udd1f" : `${i + 1}\u20e3`) +
@ -263,11 +262,9 @@ vote.callback = async function (msg, line, topic, {maybe}) {
topic = topic.join(" "); topic = topic.join(" ");
return { return {
content: `**${ content: `**${pomello(
msg.author.discriminator != "0" msg.author
? `${msg.author.username}#${msg.author.discriminator}` )}** has started a vote:\n## __${topic}__\n<:ms_tick:503341995348066313>: Yes\n<:ms_cross:503341994974773250>: No${
: msg.author.username
}** has started a vote:\n## __${topic}__\n<:ms_tick:503341995348066313>: Yes\n<:ms_cross:503341994974773250>: No${
maybe ? "\n<:ms_tilda:581268710925271095>: Maybe/Uncertain" : "" maybe ? "\n<:ms_tilda:581268710925271095>: Maybe/Uncertain" : ""
}`, }`,
addReactions: [ addReactions: [

View file

@ -1,7 +1,7 @@
const Command = require("../lib/command.js"); const Command = require("../lib/command.js");
const CATEGORY = "moderation"; const CATEGORY = "moderation";
const {lookupUser} = require("../lib/utils.js"); const {lookupUser, pomello} = require("../lib/utils.js");
const tidy = new Command("tidy"); const tidy = new Command("tidy");
tidy.addAlias("prune"); tidy.addAlias("prune");
@ -25,11 +25,7 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
}); });
await msg.channel.deleteMessages( await msg.channel.deleteMessages(
messages.map((m) => m.id), messages.map((m) => m.id),
`Message purge by ${ `Message purge by ${pomello(msg.author)}`
msg.author.discriminator != "0"
? `${msg.author.username}#${msg.author.discriminator}`
: msg.author.username
}`
); );
return `Deleted ${messages.length} message(s).`; return `Deleted ${messages.length} message(s).`;
@ -45,15 +41,7 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
}); });
await msg.channel.deleteMessages( await msg.channel.deleteMessages(
messages.filter((m) => m.author.id == user.id).map((m) => m.id), messages.filter((m) => m.author.id == user.id).map((m) => m.id),
`Message purge by ${ `Message purge by ${pomello(msg.author)} targeting ${pomello(user)}`
msg.author.discriminator != "0"
? `${msg.author.username}#${msg.author.discriminator}`
: msg.author.username
} targeting ${
user.discriminator != "0"
? `${user.username}#${user.discriminator}`
: user.username
}`
); );
return `Deleted ${messages.length} message(s).`; return `Deleted ${messages.length} message(s).`;
@ -66,11 +54,7 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
}); });
await msg.channel.deleteMessages( await msg.channel.deleteMessages(
messages.filter((m) => msg.author.bot).map((m) => m.id), messages.filter((m) => msg.author.bot).map((m) => m.id),
`Message purge by ${ `Message purge by ${pomello(msg.author)} targeting bots`
msg.author.discriminator != "0"
? `${msg.author.username}#${msg.author.discriminator}`
: msg.author.username
} targeting bots`
); );
return `Deleted ${messages.length} message(s).`; return `Deleted ${messages.length} message(s).`;
@ -85,11 +69,7 @@ tidy.callback = async function (msg, line, [subcommand, count, extra]) {
}); });
await msg.channel.deleteMessages( await msg.channel.deleteMessages(
messages.filter((m) => m.content.indexOf(count) > -1).map((m) => m.id), messages.filter((m) => m.content.indexOf(count) > -1).map((m) => m.id),
`Message purge by ${ `Message purge by ${pomello(msg.author)} targeting "${count}"`
msg.author.discriminator != "0"
? `${msg.author.username}#${msg.author.discriminator}`
: msg.author.username
} targeting "${count}"`
); );
return `Deleted ${messages.length} message(s).`; return `Deleted ${messages.length} message(s).`;

View file

@ -6,8 +6,9 @@ const ffprobe = require("node-ffprobe");
const Command = require("../lib/command.js"); const Command = require("../lib/command.js");
const { const {
formatTime, formatTime,
selectionMessage,
parseHtmlEntities, parseHtmlEntities,
pomello,
selectionMessage,
} = require("../lib/utils.js"); } = require("../lib/utils.js");
const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/; const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/;
@ -753,11 +754,7 @@ command.callback = async function (
key: item.id, key: item.id,
display: (item.title ?? item.url).substr(0, 100), display: (item.title ?? item.url).substr(0, 100),
description: hasManageMessages description: hasManageMessages
? `Added by: ${ ? `Added by: ${pomello(user)}`
user.discriminator != "0"
? `${user.username}#${user.discriminator}`
: user.username
}`
: "", : "",
}; };
}), }),

View file

@ -6,9 +6,10 @@ const CATEGORY = "utility";
const sharp = require("sharp"); const sharp = require("sharp");
const { const {
formatTime,
hastebin, hastebin,
lookupUser, lookupUser,
formatTime, pomello,
safeString, safeString,
} = require("../lib/utils.js"); } = require("../lib/utils.js");
const {getNamesFromString} = require("../lib/unicode.js"); const {getNamesFromString} = require("../lib/unicode.js");
@ -235,11 +236,7 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
} }
const baseEmbed = { const baseEmbed = {
title: `Avatar for \`${ title: `Avatar for \`${pomello(member)}\``,
member.discriminator != "0"
? `${member.username}#${member.discriminator}`
: member.username
}\``,
}; };
const normalAvatar = member.user.avatar; const normalAvatar = member.user.avatar;
@ -284,11 +281,7 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID); const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const baseEmbed = { const baseEmbed = {
title: `Avatar for \`${ title: `Avatar for \`${pomello(msg.author)}\``,
msg.author.discriminator != "0"
? `${msg.author.username}#${msg.author.discriminator}`
: msg.author.username
}\``,
}; };
const normalAvatar = msg.author.avatar; const normalAvatar = msg.author.avatar;
@ -389,7 +382,7 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
return { return {
embeds: [ embeds: [
{ {
title: `Banner for \`${userObj.username}#${userObj.discriminator}\``, title: `Banner for \`${pomello(userObj)}\``,
url, url,
image: { image: {
url, url,
@ -457,11 +450,7 @@ lookupinvite.callback = async function (msg, line) {
const inviter = invite.inviter const inviter = invite.inviter
? { ? {
name: "Inviter", name: "Inviter",
value: `**${ value: `**${pomello(invite.inviter)}** (${invite.inviter.id})`,
invite.inviter.discriminator && invite.inviter.discriminator != "0"
? `${invite.inviter.username}#${invite.inviter.discriminator}`
: `@${invite.inviter.username}`
}** (${invite.inviter.id})`,
inline: false, inline: false,
} }
: null; : null;
@ -733,20 +722,16 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
if (!user) { if (!user) {
return "User not cached."; return "User not cached.";
} else { } else {
return `\`${ return `\`${pomello(user)}\`'s public flags:\n\`\`\`${flagFromInt(
user.discriminator != "0" user.publicFlags
? `${user.username}#${user.discriminator}` )}\`\`\``;
: user.username
}\`'s public flags:\n\`\`\`${flagFromInt(user.publicFlags)}\`\`\``;
} }
} else if (!isNaN(num)) { } else if (!isNaN(num)) {
return `\`\`\`\n${flagFromInt(num)}\`\`\``; return `\`\`\`\n${flagFromInt(num)}\`\`\``;
} else { } else {
return `\`${ return `\`${pomello(msg.author)}\`'s public flags:\n\`\`\`${flagFromInt(
msg.author.discriminator != "0" msg.author.publicFlags
? `${msg.author.username}#${msg.author.discriminator}` )}\`\`\``;
: msg.author.username
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
} }
}; };
hf.registerCommand(flagdump); hf.registerCommand(flagdump);
@ -902,12 +887,7 @@ presence.callback = async function (msg, line) {
} }
if (target) { if (target) {
if (!target.clientStatus) if (!target.clientStatus) return `**${pomello(target)}** is offline.`;
return `**${
target.discriminator != "0"
? `${target.username}#${target.discriminator}`
: target.username
}** is offline.`;
let icons = ""; let icons = "";
for (const platform of Object.keys(target.clientStatus)) { for (const platform of Object.keys(target.clientStatus)) {
@ -1121,11 +1101,7 @@ presence.callback = async function (msg, line) {
} }
return { return {
content: `Presence for **${ content: `Presence for **${pomello(target)}**: ${icons.trim()}`,
target.discriminator != "0"
? `${target.username}#${target.discriminator}`
: target.username
}**: ${icons.trim()}`,
embeds, embeds,
files, files,
}; };