1
0
mirror of https://github.com/Burn-E99/SweeperBot.git synced 2026-06-04 07:53:50 -04:00

V0.4.0 - Added onlyOneReaction system

+deno fmt
This commit is contained in:
Ean Milligan (Bastion)
2022-09-09 00:46:40 -04:00
parent 6a52603be1
commit ba2e6d3b68
8 changed files with 36 additions and 26 deletions

View File

@@ -82,17 +82,6 @@ export const messageCreate = async (bot: Bot, message: Message) => {
commands.sendMessage(bot, message, args);
}
break;
// case 'emoji-test':
// const test = await bot.helpers.getMessage(413640605491658754n, 1016090989816987701n);
// console.log(test)
// if (test.reactions && test.reactions.length) {
// console.log(test.reactions[0])
// const what = `${test.reactions[0].emoji.name}${test.reactions[0].emoji.id ? `:${test.reactions[0].emoji.id}` : ''}`;
// console.log(what)
// await getReactions(bot, 413640605491658754n, 1016090989816987701n, what)
// }
// // bot.helpers
// break;
default:
// Non-standard commands
console.log(`${command} WIP`);

View File

@@ -11,11 +11,9 @@ export const reactionAdd = async (bot: Bot, payload: ReactionAdd) => {
if (config.pollChannels.includes(payload.channelId)) {
try {
const message = await bot.helpers.getMessage(payload.channelId, payload.messageId);
const onlyOneWordRX = /(only one)/g
const onlyOneWordRX = /(only one)/g;
if (message.content.toLowerCase().includes('clan poll') && message.content.toLowerCase().match(onlyOneWordRX)?.length) {
// functions.onlyOneReaction(bot, message);
// bot.helpers.getReactions()
functions.onlyOneReaction(bot, payload, message);
}
} catch (e) {
utils.commonLoggers.messageGetError('reactionAdd.ts:14', `failed to get message ${payload.channelId}-${payload.messageId}`, e);

View File

@@ -1,19 +1,19 @@
import { Bot } from "../../deps.ts";
import utils from "../utils.ts";
import { Bot } from '../../deps.ts';
import utils from '../utils.ts';
export const cleanRaidCheckpointChannel = async (bot: Bot, channelId: bigint) => {
try {
// Get messages in channel, sort them oldest=>newest, and filter to messages from followed servers
const messages = (await bot.helpers.getMessages(channelId)).array().sort((a, b) => a.timestamp - b.timestamp).filter(msg => msg.isFromBot && msg.messageReference);
const messages = (await bot.helpers.getMessages(channelId)).array().sort((a, b) => a.timestamp - b.timestamp).filter((msg) => msg.isFromBot && msg.messageReference);
// Remove most recent message from array
messages.pop();
// Delete all other messages
for (const message of messages) {
bot.helpers.deleteMessage(message.channelId, message.id, 'Old Checkpoint Message').catch(e => utils.commonLoggers.messageDeleteError('cleanRaidCheckpointChannel.ts:14', message, e));
bot.helpers.deleteMessage(message.channelId, message.id, 'Old Checkpoint Message').catch((e) => utils.commonLoggers.messageDeleteError('cleanRaidCheckpointChannel.ts:14', message, e));
}
} catch (e) {
utils.commonLoggers.messageGetError('cleanRaidCheckpointChannel.ts:17', 'Something broke', e)
utils.commonLoggers.messageGetError('cleanRaidCheckpointChannel.ts:17', 'Something broke', e);
}
};

View File

@@ -1,6 +1,29 @@
import {
// Discordeno deps
Bot,
} from "../../deps.ts";
Emoji,
Message,
} from '../../deps.ts';
import { ReactionAdd } from '../types/eventTypes.ts';
import utils from '../utils.ts';
export const onlyOneReaction = (bot: Bot) => { };
const emojiName = (emoji: Emoji) => {
const emojiId = emoji.id ? `:${emoji.id}` : '';
return `${emoji.name}${emojiId}`;
};
export const onlyOneReaction = async (bot: Bot, payload: ReactionAdd, message: Message) => {
const newEmoji = emojiName(payload.emoji);
if (message.reactions) {
for (const reaction of message.reactions) {
const otherEmoji = emojiName(reaction.emoji);
if (newEmoji !== otherEmoji) {
bot.helpers.deleteUserReaction(message.channelId, message.id, payload.userId, otherEmoji).catch((e) =>
utils.commonLoggers.reactionDeleteError('onlyOneReaction.ts:23', message, e, otherEmoji)
);
}
}
}
};

View File

@@ -40,7 +40,7 @@ export const pollReactions = async (bot: Bot, message: Message, update = false)
await bot.helpers.addReaction(message.channelId, message.id, emoji).catch(async (_err) => {
try {
const [animated, emojiName, emojiId] = emoji.split(':');
const newEmoji = await bot.helpers.createEmoji(config.devServer, {name: emojiName, image: `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'webp'}`})
const newEmoji = await bot.helpers.createEmoji(config.devServer, { name: emojiName, image: `https://cdn.discordapp.com/emojis/${emojiId}.${animated ? 'gif' : 'webp'}` });
await bot.helpers.addReaction(message.channelId, message.id, `:${newEmoji.name}:${newEmoji.id}`);
await bot.helpers.deleteEmoji(config.devServer, newEmoji.id || 0n);
} catch (e) {