mirror of
				https://github.com/keanuplayz/TravBot-v3.git
				synced 2024-08-15 02:33:12 +00:00 
			
		
		
		
	Added removing emotes in paginate if possible
This commit is contained in:
		
							parent
							
								
									77422538df
								
							
						
					
					
						commit
						53705e76c5
					
				
					 2 changed files with 18 additions and 5 deletions
				
			
		|  | @ -1,8 +1,9 @@ | ||||||
| import {GenericWrapper, NumberWrapper, ArrayWrapper} from "./wrappers"; | import {GenericWrapper, NumberWrapper, ArrayWrapper} from "./wrappers"; | ||||||
| import {Client, Message, TextChannel, DMChannel, NewsChannel, Guild, User, GuildMember} from "discord.js"; | import {Client, Message, TextChannel, DMChannel, NewsChannel, Guild, User, GuildMember, Permissions} from "discord.js"; | ||||||
| import chalk from "chalk"; | import chalk from "chalk"; | ||||||
| import FileManager from "./storage"; | import FileManager from "./storage"; | ||||||
| import {eventListeners} from "../events/messageReactionRemove"; | import {eventListeners} from "../events/messageReactionRemove"; | ||||||
|  | import {client} from "../index"; | ||||||
| 
 | 
 | ||||||
| /** A type that describes what the library module does. */ | /** A type that describes what the library module does. */ | ||||||
| export interface CommonLibrary | export interface CommonLibrary | ||||||
|  | @ -141,7 +142,6 @@ export function formatUTCTimestamp(now = new Date()) | ||||||
| // Define your own pages outside the function because this only manages the actual turning of pages.
 | // Define your own pages outside the function because this only manages the actual turning of pages.
 | ||||||
| $.paginate = async(message: Message, senderID: string, total: number, callback: (page: number) => void, duration = 60000) => { | $.paginate = async(message: Message, senderID: string, total: number, callback: (page: number) => void, duration = 60000) => { | ||||||
| 	let page = 0; | 	let page = 0; | ||||||
| 	 |  | ||||||
| 	const turn = (amount: number) => { | 	const turn = (amount: number) => { | ||||||
| 		page += amount; | 		page += amount; | ||||||
| 		 | 		 | ||||||
|  | @ -168,7 +168,14 @@ $.paginate = async(message: Message, senderID: string, total: number, callback: | ||||||
| 	await message.react('➡️'); | 	await message.react('➡️'); | ||||||
| 	eventListeners.set(message.id, handle); | 	eventListeners.set(message.id, handle); | ||||||
| 	await message.awaitReactions((reaction, user) => { | 	await message.awaitReactions((reaction, user) => { | ||||||
|  | 		// The reason this is inside the call is because it's possible to switch a user's permissions halfway and suddenly throw an error.
 | ||||||
|  | 		// This will dynamically adjust for that, switching modes depending on whether it currently has the "Manage Messages" permission.
 | ||||||
|  | 		const canDeleteEmotes = !!(client.user && message.guild?.members.resolve(client.user)?.hasPermission(Permissions.FLAGS.MANAGE_MESSAGES)); | ||||||
| 		handle(reaction.emoji.name, user.id); | 		handle(reaction.emoji.name, user.id); | ||||||
|  | 		 | ||||||
|  | 		if(canDeleteEmotes && user.id !== client.user?.id) | ||||||
|  | 			reaction.users.remove(user); | ||||||
|  | 		 | ||||||
| 		return false; | 		return false; | ||||||
| 	}, {time: duration}); | 	}, {time: duration}); | ||||||
| 	 | 	 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| import Event from "../core/event"; | import Event from "../core/event"; | ||||||
| import {MessageReaction, User, PartialUser} from "discord.js"; | import {MessageReaction, User, PartialUser, Permissions} from "discord.js"; | ||||||
|  | import {client} from "../index"; | ||||||
| 
 | 
 | ||||||
| // A list of message ID and callback pairs. You get the emote name and ID of the user reacting.
 | // A list of message ID and callback pairs. You get the emote name and ID of the user reacting.
 | ||||||
| export const eventListeners: Map<string, (emote: string, id: string) => void> = new Map(); | export const eventListeners: Map<string, (emote: string, id: string) => void> = new Map(); | ||||||
|  | @ -8,7 +9,12 @@ export const eventListeners: Map<string, (emote: string, id: string) => void> = | ||||||
| export default new Event({ | export default new Event({ | ||||||
| 	on(reaction: MessageReaction, user: User|PartialUser) | 	on(reaction: MessageReaction, user: User|PartialUser) | ||||||
| 	{ | 	{ | ||||||
| 		const callback = eventListeners.get(reaction.message.id); | 		const canDeleteEmotes = !!(client.user && reaction.message.guild?.members.resolve(client.user)?.hasPermission(Permissions.FLAGS.MANAGE_MESSAGES)); | ||||||
| 		callback && callback(reaction.emoji.name, user.id); | 		 | ||||||
|  | 		if(!canDeleteEmotes) | ||||||
|  | 		{ | ||||||
|  | 			const callback = eventListeners.get(reaction.message.id); | ||||||
|  | 			callback && callback(reaction.emoji.name, user.id); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| }); | }); | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue