V0.3.0 - Added cleanRaidCheckpointChannel
This function cleans up old messages from followed channels in the specified channel
This commit is contained in:
		
							parent
							
								
									92661ea575
								
							
						
					
					
						commit
						046eb1d33e
					
				|  | @ -1,6 +1,6 @@ | |||
| export const config = { | ||||
| 	'name': 'Sweeper Bot', // Name of the bot
 | ||||
| 	'version': '0.2.4', // Version of the bot
 | ||||
| 	'version': '0.3.0', // Version of the 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"
 | ||||
| 	'prefix': 's!', // Prefix for all commands
 | ||||
|  |  | |||
|  | @ -3,20 +3,18 @@ import { | |||
| 	// Discordeno deps
 | ||||
| 	Bot, | ||||
| 	botId, | ||||
| 	getReactions, | ||||
| 	// Log4Deno deps
 | ||||
| 	log, | ||||
| 	LT, | ||||
| 	// Discordeno deps
 | ||||
| 	Message,getReactions, | ||||
| 	Message, | ||||
| } from '../../deps.ts'; | ||||
| import commands from '../commands/_index.ts'; | ||||
| import functions from '../functions/_index.ts'; | ||||
| import utils from '../utils.ts'; | ||||
| 
 | ||||
| export const messageCreate = async (bot: Bot, message: Message) => { | ||||
| 	// Ignore all other bots
 | ||||
| 	if (message.isFromBot) return; | ||||
| 
 | ||||
| 	// Ignore all messages that are not commands
 | ||||
| 	if (message.content.indexOf(config.prefix) !== 0) { | ||||
| 		// Handle @bot messages
 | ||||
|  | @ -29,13 +27,16 @@ export const messageCreate = async (bot: Bot, message: Message) => { | |||
| 		} | ||||
| 
 | ||||
| 		if (config.raidCheckpointChannel.includes(message.channelId)) { | ||||
| 			console.log(message); | ||||
| 			functions.cleanRaidCheckpointChannel(bot, message.channelId); | ||||
| 		} | ||||
| 
 | ||||
| 		// return as we are done handling this command
 | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	// Ignore all other bots
 | ||||
| 	if (message.isFromBot) return; | ||||
| 
 | ||||
| 	log(LT.LOG, `Handling ${config.prefix}command message: ${utils.jsonStringifyBig(message)}`); | ||||
| 
 | ||||
| 	// Split into standard command + args format
 | ||||
|  | @ -81,7 +82,7 @@ export const messageCreate = async (bot: Bot, message: Message) => { | |||
| 				commands.sendMessage(bot, message, args); | ||||
| 			} | ||||
| 			break; | ||||
| 		// case 'test':
 | ||||
| 		// case 'emoji-test':
 | ||||
| 		// 	const test = await bot.helpers.getMessage(413640605491658754n, 1016090989816987701n);
 | ||||
| 		// 	console.log(test)
 | ||||
| 		// 	if (test.reactions && test.reactions.length) {
 | ||||
|  |  | |||
|  | @ -1,7 +1,9 @@ | |||
| import { pollReactions } from './pollReactions.ts'; | ||||
| import { onlyOneReaction } from './onlyOneReaction.ts'; | ||||
| import { cleanRaidCheckpointChannel } from './cleanRaidCheckpointChannel.ts'; | ||||
| 
 | ||||
| export default { | ||||
| 	cleanRaidCheckpointChannel, | ||||
| 	pollReactions, | ||||
| 	onlyOneReaction, | ||||
| }; | ||||
|  |  | |||
|  | @ -0,0 +1,19 @@ | |||
| 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); | ||||
| 
 | ||||
| 		// 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)); | ||||
| 		} | ||||
| 	} catch (e) { | ||||
| 		utils.commonLoggers.messageGetError('cleanRaidCheckpointChannel.ts:17', 'Something broke', e) | ||||
| 	} | ||||
| }; | ||||
		Loading…
	
		Reference in New Issue