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

@ -1,4 +1,4 @@
# Sweeper Bot | V0.2.0 - 2022/09/03 # Sweeper Bot | V0.4.0 - 2022/09/09
[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-orange.svg)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-orange.svg)](https://sonarcloud.io/summary/new_code?id=SweeperBot)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=bugs)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=bugs)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=SweeperBot) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=SweeperBot&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=SweeperBot)

View File

@ -1,6 +1,6 @@
export const config = { export const config = {
'name': 'Sweeper Bot', // Name of the bot 'name': 'Sweeper Bot', // Name of the bot
'version': '0.3.0', // Version of the bot 'version': '0.4.0', // Version of the bot
'token': 'the_bot_token', // Discord API Token for this bot 'token': 'the_bot_token', // Discord API Token for this bot
'localtoken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token" 'localtoken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
'prefix': 's!', // Prefix for all commands 'prefix': 's!', // Prefix for all commands

View File

@ -4,7 +4,7 @@ import config from './config.ts';
import { LOCALMODE } from './flags.ts'; import { LOCALMODE } from './flags.ts';
export const botId = getBotIdFromToken(LOCALMODE ? config.localtoken : config.token); export const botId = getBotIdFromToken(LOCALMODE ? config.localtoken : config.token);
export { ActivityTypes, createBot, editBotMember, editBotStatus, Intents, sendMessage, startBot, getReactions } from 'https://deno.land/x/discordeno@14.0.1/mod.ts'; export { ActivityTypes, createBot, editBotMember, editBotStatus, getReactions, Intents, sendMessage, startBot } from 'https://deno.land/x/discordeno@14.0.1/mod.ts';
export type { Bot, CreateMessage, Emoji, EventHandlers, Guild, Member, Message, User } from 'https://deno.land/x/discordeno@14.0.1/mod.ts'; export type { Bot, CreateMessage, Emoji, EventHandlers, Guild, Member, Message, User } from 'https://deno.land/x/discordeno@14.0.1/mod.ts';

View File

@ -82,17 +82,6 @@ export const messageCreate = async (bot: Bot, message: Message) => {
commands.sendMessage(bot, message, args); commands.sendMessage(bot, message, args);
} }
break; 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: default:
// Non-standard commands // Non-standard commands
console.log(`${command} WIP`); console.log(`${command} WIP`);

View File

@ -11,11 +11,9 @@ export const reactionAdd = async (bot: Bot, payload: ReactionAdd) => {
if (config.pollChannels.includes(payload.channelId)) { if (config.pollChannels.includes(payload.channelId)) {
try { try {
const message = await bot.helpers.getMessage(payload.channelId, payload.messageId); 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) { if (message.content.toLowerCase().includes('clan poll') && message.content.toLowerCase().match(onlyOneWordRX)?.length) {
// functions.onlyOneReaction(bot, message); functions.onlyOneReaction(bot, payload, message);
// bot.helpers.getReactions()
} }
} catch (e) { } catch (e) {
utils.commonLoggers.messageGetError('reactionAdd.ts:14', `failed to get message ${payload.channelId}-${payload.messageId}`, 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 { Bot } from '../../deps.ts';
import utils from "../utils.ts"; import utils from '../utils.ts';
export const cleanRaidCheckpointChannel = async (bot: Bot, channelId: bigint) => { export const cleanRaidCheckpointChannel = async (bot: Bot, channelId: bigint) => {
try { try {
// Get messages in channel, sort them oldest=>newest, and filter to messages from followed servers // 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 // Remove most recent message from array
messages.pop(); messages.pop();
// Delete all other messages // Delete all other messages
for (const message of 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) { } 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 { import {
// Discordeno deps // Discordeno deps
Bot, 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) => { await bot.helpers.addReaction(message.channelId, message.id, emoji).catch(async (_err) => {
try { try {
const [animated, emojiName, emojiId] = emoji.split(':'); 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.addReaction(message.channelId, message.id, `:${newEmoji.name}:${newEmoji.id}`);
await bot.helpers.deleteEmoji(config.devServer, newEmoji.id || 0n); await bot.helpers.deleteEmoji(config.devServer, newEmoji.id || 0n);
} catch (e) { } catch (e) {