reduce the amount of cache lookups

This commit is contained in:
Dmytro Meleshko 2021-01-29 21:12:53 +02:00
parent 0cba164f3d
commit 303e81cc37
3 changed files with 14 additions and 10 deletions

View File

@ -158,8 +158,7 @@ export default new Command({
permission: Command.PERMISSIONS.BOT_SUPPORT,
async run($: CommonLibrary): Promise<any> {
const nickName = $.args.join(" ");
const trav = $.guild?.members.cache.find((member) => member.id === $.client.user?.id);
await trav?.setNickname(nickName);
await $.guild?.me?.setNickname(nickName);
if (botHasPermission($.guild, Permissions.FLAGS.MANAGE_MESSAGES))
$.message.delete({timeout: 5000}).catch($.handler.bind($));
$.channel.send(`Nickname set to \`${nickName}\``).then((m) => m.delete({timeout: 5000}));

View File

@ -76,10 +76,13 @@ export default new Command({
description: "Displays info about the current guild.",
async run($: CommonLibrary): Promise<any> {
if ($.guild) {
const members = await $.guild.members.fetch({
withPresences: true,
force: true
});
const roles = $.guild.roles.cache
.sort((a, b) => b.position - a.position)
.map((role) => role.toString());
const members = $.guild.members.cache;
const channels = $.guild.channels.cache;
const emojis = $.guild.emojis.cache;
const iconURL = $.guild.iconURL({dynamic: true});

View File

@ -172,7 +172,7 @@ export function formatUTCTimestamp(now = new Date()) {
}
export function botHasPermission(guild: Guild | null, permission: number): boolean {
return !!(guild?.me?.hasPermission(permission));
return !!guild?.me?.hasPermission(permission);
}
export function updateGlobalEmoteRegistry(): void {
@ -216,20 +216,22 @@ $.paginate = async (
callback(page);
};
const BACKWARDS_EMOJI = "⬅️";
const FORWARDS_EMOJI = "➡️";
const handle = (emote: string, reacterID: string) => {
switch (emote) {
case "⬅️":
case BACKWARDS_EMOJI:
turn(-1);
break;
case "➡️":
case FORWARDS_EMOJI:
turn(1);
break;
}
};
// Listen for reactions and call the handler.
await message.react("⬅️");
await message.react("➡️");
let backwardsReaction = await message.react(BACKWARDS_EMOJI);
let forwardsReaction = await message.react(FORWARDS_EMOJI);
eventListeners.set(message.id, handle);
await message.awaitReactions(
(reaction, user) => {
@ -248,8 +250,8 @@ $.paginate = async (
);
// When time's up, remove the bot's own reactions.
eventListeners.delete(message.id);
message.reactions.cache.get("⬅️")?.users.remove(message.author);
message.reactions.cache.get("➡️")?.users.remove(message.author);
backwardsReaction.users.remove(message.author);
forwardsReaction.users.remove(message.author);
};
// Waits for the sender to either confirm an action or let it pass (and delete the message).