Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolved several bugs #2530

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/discord/SkyraEmbed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ZeroWidthSpace } from '#utils/constants';
import { EmbedBuilder } from '@discordjs/builders';
import { isNullishOrEmpty } from '@sapphire/utilities';

export class SkyraEmbed extends EmbedBuilder {
public splitFields(contentOrTitle: string | string[], rawContent?: string | string[]) {
if (typeof contentOrTitle === 'undefined') return this;
if (isNullishOrEmpty(contentOrTitle)) return this;

let title: string;
let content: string | string[];
Expand Down
18 changes: 16 additions & 2 deletions src/listeners/guilds/members/notMutedMemberAddInitialRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { GuildSettings, readSettings, writeSettings } from '#lib/database';
import { Events } from '#lib/types';
import { ApplyOptions } from '@sapphire/decorators';
import { Listener } from '@sapphire/framework';
import type { GuildMember } from 'discord.js';
import { isNullish } from '@sapphire/utilities';
import { PermissionFlagsBits, type GuildMember } from 'discord.js';

@ApplyOptions<Listener.Options>({ event: Events.NotMutedMemberAdd })
export class UserListener extends Listener {
public async run(member: GuildMember) {
// If the bot cannot manage roles, do not proceed:
if (!this.canGiveRoles(member)) return;

const [initial, initialHumans, initialBots] = await readSettings(member, [
GuildSettings.Roles.Initial,
GuildSettings.Roles.InitialHumans,
Expand All @@ -22,6 +26,16 @@ export class UserListener extends Listener {
return member.roles.add(role);
}

return writeSettings(member, [[GuildSettings.Roles.Initial, null]]);
const key = role //
? GuildSettings.Roles.Initial
: member.user.bot
? GuildSettings.Roles.InitialBots
: GuildSettings.Roles.InitialHumans;
return writeSettings(member, [[key, null]]);
}

private canGiveRoles(member: GuildMember) {
const permissions = member.guild.members.me?.permissions;
return !isNullish(permissions) && permissions.has(PermissionFlagsBits.ManageRoles);
}
}
19 changes: 12 additions & 7 deletions src/listeners/messages/guildMessageDeleteNotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EmbedBuilder } from '@discordjs/builders';
import { ApplyOptions } from '@sapphire/decorators';
import { isNsfwChannel } from '@sapphire/discord.js-utilities';
import { Listener } from '@sapphire/framework';
import { cutText, isNullish } from '@sapphire/utilities';
import { cutText, isNullish, isNullishOrEmpty } from '@sapphire/utilities';

@ApplyOptions<Listener.Options>({ event: Events.GuildMessageDelete })
export class UserListener extends Listener {
Expand All @@ -26,14 +26,19 @@ export class UserListener extends Listener {
if (ignoredDeletes.some((id) => id === message.channel.id && message.channel.parentId === id)) return;
if (ignoredAll.some((id) => id === message.channel.id || message.channel.parentId === id)) return;

this.container.client.emit(Events.GuildMessageLog, message.guild, logChannelId, key, () =>
new EmbedBuilder()
this.container.client.emit(Events.GuildMessageLog, message.guild, logChannelId, key, () => {
const embed = new EmbedBuilder()
.setColor(Colors.Red)
.setAuthor(getFullEmbedAuthor(message.author, message.url))
.setDescription(cutText(getContent(message) || '', 1900))
.setFooter({ text: t(LanguageKeys.Events.Messages.MessageDelete, { channel: `#${message.channel.name}` }) })
.setImage(getImage(message)!)
.setTimestamp()
);
.setTimestamp();

const content = getContent(message);
if (!isNullishOrEmpty(content)) embed.setDescription(cutText(content, 1900));
const image = getImage(message);
if (!isNullish(image)) embed.setImage(image);

return embed;
});
}
}
13 changes: 11 additions & 2 deletions src/listeners/reactions/rawReactionAddNotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { getEmojiId, getEmojiReactionFormat, getEncodedTwemoji, getTwemojiUrl, t
import { getFullEmbedAuthor } from '#utils/util';
import { EmbedBuilder } from '@discordjs/builders';
import { ApplyOptions } from '@sapphire/decorators';
import type { GuildTextBasedChannelTypes } from '@sapphire/discord.js-utilities';
import { Listener } from '@sapphire/framework';
import { isNullish } from '@sapphire/utilities';
import { Collection } from 'discord.js';
import { Collection, PermissionFlagsBits } from 'discord.js';

@ApplyOptions<Listener.Options>({ event: Events.RawReactionAdd })
export class UserListener extends Listener {
Expand All @@ -19,6 +20,9 @@ export class UserListener extends Listener {
private kTimerSweeper: NodeJS.Timeout | null = null;

public async run(data: LLRCData, emoji: SerializedEmoji) {
// If the bot cannot fetch messages, do not proceed:
if (!this.canFetchMessages(data.channel)) return;

const key = GuildSettings.Channels.Logs.Reaction;
const [allowedEmojis, logChannelId, twemojiEnabled, ignoreChannels, ignoreReactionAdd, ignoreAllEvents, t] = await readSettings(
data.guild,
Expand Down Expand Up @@ -76,7 +80,12 @@ export class UserListener extends Listener {
if (this.kTimerSweeper) clearInterval(this.kTimerSweeper);
}

protected async retrieveCount(data: LLRCData, emoji: SerializedEmoji) {
private canFetchMessages(channel: GuildTextBasedChannelTypes) {
const permissions = channel.permissionsFor(this.container.client.id!);
return !isNullish(permissions) && permissions.has(PermissionFlagsBits.ReadMessageHistory);
}

private async retrieveCount(data: LLRCData, emoji: SerializedEmoji) {
const id = `${data.messageId}.${getEmojiId(emoji)}`;

// Pull from sync queue, and if it exists, await
Expand Down