mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Properly order reaction roles
This commit is contained in:
parent
7124898568
commit
43c23263f0
7 changed files with 41 additions and 9 deletions
|
@ -24,6 +24,9 @@ export class GuildReactionRoles extends BaseGuildRepository {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
message_id: messageId,
|
message_id: messageId,
|
||||||
},
|
},
|
||||||
|
order: {
|
||||||
|
order: "ASC",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +53,14 @@ export class GuildReactionRoles extends BaseGuildRepository {
|
||||||
await this.reactionRoles.delete(criteria);
|
await this.reactionRoles.delete(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
async add(channelId: string, messageId: string, emoji: string, roleId: string, exclusive?: boolean) {
|
async add(
|
||||||
|
channelId: string,
|
||||||
|
messageId: string,
|
||||||
|
emoji: string,
|
||||||
|
roleId: string,
|
||||||
|
exclusive?: boolean,
|
||||||
|
position?: number,
|
||||||
|
) {
|
||||||
await this.reactionRoles.insert({
|
await this.reactionRoles.insert({
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
channel_id: channelId,
|
channel_id: channelId,
|
||||||
|
@ -58,6 +68,7 @@ export class GuildReactionRoles extends BaseGuildRepository {
|
||||||
emoji,
|
emoji,
|
||||||
role_id: roleId,
|
role_id: roleId,
|
||||||
is_exclusive: Boolean(exclusive),
|
is_exclusive: Boolean(exclusive),
|
||||||
|
order: position,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,6 @@ export class ReactionRole {
|
||||||
@Column() role_id: string;
|
@Column() role_id: string;
|
||||||
|
|
||||||
@Column() is_exclusive: boolean;
|
@Column() is_exclusive: boolean;
|
||||||
|
|
||||||
|
@Column() order: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ connect().then(async () => {
|
||||||
intents: [
|
intents: [
|
||||||
// Privileged
|
// Privileged
|
||||||
Intents.FLAGS.GUILD_MEMBERS,
|
Intents.FLAGS.GUILD_MEMBERS,
|
||||||
// "guildPresences",
|
// Intents.FLAGS.GUILD_PRESENCES,
|
||||||
Intents.FLAGS.GUILD_MESSAGE_TYPING,
|
Intents.FLAGS.GUILD_MESSAGE_TYPING,
|
||||||
|
|
||||||
// Regular
|
// Regular
|
||||||
|
|
18
backend/src/migrations/1622939525343-OrderReactionRoles.ts
Normal file
18
backend/src/migrations/1622939525343-OrderReactionRoles.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
||||||
|
|
||||||
|
export class OrderReactionRoles1622939525343 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.addColumn(
|
||||||
|
"reaction_roles",
|
||||||
|
new TableColumn({
|
||||||
|
name: "order",
|
||||||
|
type: "int",
|
||||||
|
isNullable: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.dropColumn("reaction_roles", "order");
|
||||||
|
}
|
||||||
|
}
|
|
@ -103,6 +103,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
||||||
const progressMessage = msg.channel.send("Adding reaction roles...");
|
const progressMessage = msg.channel.send("Adding reaction roles...");
|
||||||
|
|
||||||
// Save the new reaction roles to the database
|
// Save the new reaction roles to the database
|
||||||
|
let pos = 0;
|
||||||
for (const pair of emojiRolePairs) {
|
for (const pair of emojiRolePairs) {
|
||||||
await pluginData.state.reactionRoles.add(
|
await pluginData.state.reactionRoles.add(
|
||||||
args.message.channel.id,
|
args.message.channel.id,
|
||||||
|
@ -110,7 +111,9 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
||||||
pair[0],
|
pair[0],
|
||||||
pair[1],
|
pair[1],
|
||||||
args.exclusive,
|
args.exclusive,
|
||||||
|
pos,
|
||||||
);
|
);
|
||||||
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the reactions themselves
|
// Apply the reactions themselves
|
||||||
|
|
|
@ -61,7 +61,7 @@ export const AddReactionRoleEvt = reactionRolesEvt({
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
pluginData.state.reactionRemoveQueue.add(async () => {
|
pluginData.state.reactionRemoveQueue.add(async () => {
|
||||||
const wait = sleep(1500);
|
const wait = sleep(1500);
|
||||||
await meta.args.reaction.remove().catch(noop);
|
await meta.args.reaction.users.remove(userId).catch(noop);
|
||||||
await wait;
|
await wait;
|
||||||
});
|
});
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
|
@ -71,18 +71,16 @@ export async function applyReactionRoleReactionsToMessage(
|
||||||
emojisToAdd.push(CLEAR_ROLES_EMOJI);
|
emojisToAdd.push(CLEAR_ROLES_EMOJI);
|
||||||
|
|
||||||
for (const rawEmoji of emojisToAdd) {
|
for (const rawEmoji of emojisToAdd) {
|
||||||
const emoji = isSnowflake(rawEmoji) ? `foo:${rawEmoji}` : rawEmoji;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await targetMessage.reactions.add(emoji);
|
await targetMessage.react(rawEmoji);
|
||||||
await sleep(1250); // Make sure we don't hit rate limits
|
await sleep(750); // Make sure we don't hit rate limits
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e)) {
|
if (isDiscordRESTError(e)) {
|
||||||
if (e.code === 10014) {
|
if (e.code === 10014) {
|
||||||
pluginData.state.reactionRoles.removeFromMessage(messageId, rawEmoji);
|
pluginData.state.reactionRoles.removeFromMessage(messageId, rawEmoji);
|
||||||
errors.push(`Unknown emoji: ${emoji}`);
|
errors.push(`Unknown emoji: ${rawEmoji}`);
|
||||||
logs.log(LogType.BOT_ALERT, {
|
logs.log(LogType.BOT_ALERT, {
|
||||||
body: `Could not add unknown reaction role emoji ${emoji} to message ${channelId}/${messageId}`,
|
body: `Could not add unknown reaction role emoji ${rawEmoji} to message ${channelId}/${messageId}`,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
} else if (e.code === 50013) {
|
} else if (e.code === 50013) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue