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 = { | export const config = { | ||||||
| 	'name': 'Sweeper Bot', // Name of the bot
 | 	'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
 | 	'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
 | ||||||
|  |  | ||||||
|  | @ -3,20 +3,18 @@ import { | ||||||
| 	// Discordeno deps
 | 	// Discordeno deps
 | ||||||
| 	Bot, | 	Bot, | ||||||
| 	botId, | 	botId, | ||||||
|  | 	getReactions, | ||||||
| 	// Log4Deno deps
 | 	// Log4Deno deps
 | ||||||
| 	log, | 	log, | ||||||
| 	LT, | 	LT, | ||||||
| 	// Discordeno deps
 | 	// Discordeno deps
 | ||||||
| 	Message,getReactions, | 	Message, | ||||||
| } from '../../deps.ts'; | } from '../../deps.ts'; | ||||||
| import commands from '../commands/_index.ts'; | import commands from '../commands/_index.ts'; | ||||||
| import functions from '../functions/_index.ts'; | import functions from '../functions/_index.ts'; | ||||||
| import utils from '../utils.ts'; | import utils from '../utils.ts'; | ||||||
| 
 | 
 | ||||||
| export const messageCreate = async (bot: Bot, message: Message) => { | export const messageCreate = async (bot: Bot, message: Message) => { | ||||||
| 	// Ignore all other bots
 |  | ||||||
| 	if (message.isFromBot) return; |  | ||||||
| 
 |  | ||||||
| 	// Ignore all messages that are not commands
 | 	// Ignore all messages that are not commands
 | ||||||
| 	if (message.content.indexOf(config.prefix) !== 0) { | 	if (message.content.indexOf(config.prefix) !== 0) { | ||||||
| 		// Handle @bot messages
 | 		// Handle @bot messages
 | ||||||
|  | @ -29,13 +27,16 @@ export const messageCreate = async (bot: Bot, message: Message) => { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (config.raidCheckpointChannel.includes(message.channelId)) { | 		if (config.raidCheckpointChannel.includes(message.channelId)) { | ||||||
| 			console.log(message); | 			functions.cleanRaidCheckpointChannel(bot, message.channelId); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// return as we are done handling this command
 | 		// return as we are done handling this command
 | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// Ignore all other bots
 | ||||||
|  | 	if (message.isFromBot) return; | ||||||
|  | 
 | ||||||
| 	log(LT.LOG, `Handling ${config.prefix}command message: ${utils.jsonStringifyBig(message)}`); | 	log(LT.LOG, `Handling ${config.prefix}command message: ${utils.jsonStringifyBig(message)}`); | ||||||
| 
 | 
 | ||||||
| 	// Split into standard command + args format
 | 	// Split into standard command + args format
 | ||||||
|  | @ -81,7 +82,7 @@ export const messageCreate = async (bot: Bot, message: Message) => { | ||||||
| 				commands.sendMessage(bot, message, args); | 				commands.sendMessage(bot, message, args); | ||||||
| 			} | 			} | ||||||
| 			break; | 			break; | ||||||
| 		// case 'test':
 | 		// case 'emoji-test':
 | ||||||
| 		// 	const test = await bot.helpers.getMessage(413640605491658754n, 1016090989816987701n);
 | 		// 	const test = await bot.helpers.getMessage(413640605491658754n, 1016090989816987701n);
 | ||||||
| 		// 	console.log(test)
 | 		// 	console.log(test)
 | ||||||
| 		// 	if (test.reactions && test.reactions.length) {
 | 		// 	if (test.reactions && test.reactions.length) {
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,9 @@ | ||||||
| import { pollReactions } from './pollReactions.ts'; | import { pollReactions } from './pollReactions.ts'; | ||||||
| import { onlyOneReaction } from './onlyOneReaction.ts'; | import { onlyOneReaction } from './onlyOneReaction.ts'; | ||||||
|  | import { cleanRaidCheckpointChannel } from './cleanRaidCheckpointChannel.ts'; | ||||||
| 
 | 
 | ||||||
| export default { | export default { | ||||||
|  | 	cleanRaidCheckpointChannel, | ||||||
| 	pollReactions, | 	pollReactions, | ||||||
| 	onlyOneReaction, | 	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