feat/40-reroll-on-disinterest #54
@@ -13,6 +13,7 @@ import addDays from "date-fns/addDays"
 | 
			
		||||
import isAfter from "date-fns/isAfter"
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					kenobi marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				 | 
			||||
import { ExtendedClient } from "../structures/client"
 | 
			
		||||
import { JellyfinHandler } from "../jellyfin/handler"
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					kenobi marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		duplicate check. already checked before call in handleMessageReactionAdd duplicate check. already checked before call in handleMessageReactionAdd 
			
			
		
				
					
						kenobi
						commented  
			
		removed removed 
			
			
		 | 
			||||
import { ObjectGroupUpdateToJSON } from "../jellyfin"
 | 
			
		||||
 | 
			
		||||
export type Vote = {
 | 
			
		||||
	emote: string, //todo habs nicht hinbekommen hier Emotes zu nutzen
 | 
			
		||||
@@ -52,8 +53,8 @@ export default class VoteController {
 | 
			
		||||
			messageReaction.message.edit((messageReaction.message.content ?? "").concat('\nDiese Abstimmung muss wiederholt werden.'))
 | 
			
		||||
			// get movies that _had_ votes
 | 
			
		||||
			//const oldMovieNames: Vote[] = this.parseVotesFromVoteMessage(messageReaction.message, requestId)
 | 
			
		||||
			const eventId = this.parseEventIdFromMessage(messageReaction.message, requestId)
 | 
			
		||||
			const eventStartDate: Date = this.fetchEventStartDateByEventId(eventId, requestId) //TODO
 | 
			
		||||
			const parsedIds = this.parseGuildIdAndEventIdFromWholeMessage(messageReaction.message.cleanContent ?? '')
 | 
			
		||||
			const eventStartDate: Date = this.fetchEventStartDateByEventId(parsedIds.eventId, requestId) //TODO
 | 
			
		||||
			//
 | 
			
		||||
			// get movies from jellyfin to fill the remaining slots
 | 
			
		||||
			const newMovieCount = config.bot.random_movie_count //- oldMovieNames.length
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					magnetotail marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		Parameter die eine Message sind heißen oft "message", manchmal aber auch "msg". sollte vereinheitlicht sein Parameter die eine Message sind heißen oft "message", manchmal aber auch "msg". sollte vereinheitlicht sein 
			
			
		
				
					
						kenobi
						commented  
			
		66507cb08fa50ba3a7be28388c55b21227fb2261 
			
			
		
				
					
						kenobi
						commented  
			
		Jetzt sollten alle Occurences beseitigt sein. fc64728a780f99b56aebff7f0a7c5d24a901d90d
Jetzt sollten alle Occurences beseitigt sein. 
			
			
		 | 
			||||
@@ -64,7 +65,7 @@ export default class VoteController {
 | 
			
		||||
 | 
			
		||||
			// create new message
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					magnetotail marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		above WHAT threshold? What does it do?? above WHAT threshold? What does it do?? 
			
			
		
				
					
						kenobi
						commented  
			
		20da25f2bf9a473704f8b4660e5f05183679ba39 
			
			
		
				
					
						kenobi
						commented  
			
		Mit einem Kommentar versehen und entsprechend deines vorschlags umbenannt Mit einem Kommentar versehen und entsprechend deines vorschlags umbenannt 
			
			
		 | 
			||||
			await this.closePoll(messageReaction.message.guild, requestId)
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					magnetotail marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		threshold seems to be a magic number threshold seems to be a magic number 
			
			
		
				
					
						magnetotail
						commented  
			
		Or rename method to "hasAtLeastOneVote" Or rename method to "hasAtLeastOneVote" 
			
			
		
				
					
						kenobi
						commented  
			
		296a490e935cbdb79b70d73d2df9bc12a5774c53 
			
			
		
				
					
						kenobi
						commented  
			
		done done 
			
			
		 | 
			||||
			const message = this.createVoteMessageText(eventId, eventStartDate, movies, guildId, requestId)
 | 
			
		||||
			const message = this.createVoteMessageText(parsedIds.guildId, eventStartDate, movies, guildId, requestId)
 | 
			
		||||
			const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
 | 
			
		||||
			if (!announcementChannel) {
 | 
			
		||||
				logger.error(`No announcementChannel found for ${guildId}, can't post poll`)
 | 
			
		||||
@@ -75,26 +76,23 @@ export default class VoteController {
 | 
			
		||||
		}
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					magnetotail marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		maybe extract this if-else to a method to keep code more compact maybe extract this if-else to a method to keep code more compact 
			
			
		
				
					
						kenobi
						commented  
			
		
 7d794a8001a66d068f949c893d689a068c3caeed
done 
			
			
		 | 
			||||
		logger.info(`No reroll`, { requestId, guildId })
 | 
			
		||||
	}
 | 
			
		||||
	parseEventIdFromMessage(message: Message<boolean> | PartialMessage, requestId: string): string {
 | 
			
		||||
		throw new Error("Method not implemented.")
 | 
			
		||||
	}
 | 
			
		||||
	private fetchEventStartDateByEventId(eventId: string, requestId: string): Date {
 | 
			
		||||
		throw new Error("Method not implemented.")
 | 
			
		||||
	}
 | 
			
		||||
	public parseGuildIdAndEventIdFromWholeMessage(message: string) {
 | 
			
		||||
		const idmatch = RegExp(/(?:http|https):\/\/discord\.com\/events\/(\d*)\/(\d*)/)
 | 
			
		||||
		const matches = message.match(idmatch)
 | 
			
		||||
		if (matches && matches.length == 3)
 | 
			
		||||
			return { guildId: matches[1], eventId: matches[2] }
 | 
			
		||||
		throw Error(`Could not find eventId in Vote Message`)
 | 
			
		||||
	}
 | 
			
		||||
	public parseVotesFromVoteMessage(message: VoteMessage, requestId: string): VoteMessageInfo {
 | 
			
		||||
		const lines = message.cleanContent.split('\n')
 | 
			
		||||
		let eventId = ""
 | 
			
		||||
		let eventDate: Date = new Date()
 | 
			
		||||
		let parsedIds = this.parseGuildIdAndEventIdFromWholeMessage(message.cleanContent)
 | 
			
		||||
		let eventDate: Date = this.parseEventDateFromMessage(message.cleanContent)
 | 
			
		||||
		let votes: Vote[] = []
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					magnetotail marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		is not a message, only messagetext is not a message, only messagetext 
			
			
		
				
					
						kenobi
						commented  
			
		a455fd8ff7e6b8ffb032fb4aed9389da68ee513b 
			
			
		
				
					
						kenobi
						commented  
			
		done done 
			
			
		 | 
			||||
		for (const line of lines) {
 | 
			
		||||
			if (line.includes('https://discord.com/events')) {
 | 
			
		||||
				const urlMatcher = RegExp(/(http|https|ftp):\/\/(\S*)/ig)
 | 
			
		||||
				const result = line.match(urlMatcher)
 | 
			
		||||
				if (!result) throw Error('No event url found in Message')
 | 
			
		||||
				eventId = result?.[0].split('/').at(-1) ?? ""
 | 
			
		||||
			} else if (!line.slice(0, 5).includes(':')) {
 | 
			
		||||
				eventDate = this.parseEventDateFromLine(line)
 | 
			
		||||
			} else if (line.slice(0, 5).includes(':')) {
 | 
			
		||||
			if (line.slice(0, 5).includes(':')) {
 | 
			
		||||
				const splitLine = line.split(":")
 | 
			
		||||
				const [emoji, movie] = splitLine
 | 
			
		||||
				const fetchedVoteFromMessage = message.reactions.cache.get(emoji)
 | 
			
		||||
@@ -109,13 +107,13 @@ export default class VoteController {
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					magnetotail marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						magnetotail
						commented  
			
		why not pin message in method above? why not pin message in method above? 
			
			
		
				
					
						kenobi
						commented  
			
		
 7d794a8001a66d068f949c893d689a068c3caeed
should have been moved to prepareAndSendVoteMessage() 
			
			
		 | 
			||||
		}
 | 
			
		||||
		return <VoteMessageInfo>{ eventId, eventDate, votes }
 | 
			
		||||
		return <VoteMessageInfo>{ eventId: parsedIds.eventId, eventDate, votes }
 | 
			
		||||
	}
 | 
			
		||||
	public parseEventDateFromLine(line: string): Date {
 | 
			
		||||
		const datematcher = RegExp(/((0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012]))(\ um\ )(([012][0-9]:[0-5][0-9]))/i)
 | 
			
		||||
		const result: RegExpMatchArray | null = line.match(datematcher)
 | 
			
		||||
	public parseEventDateFromMessage(message: string): Date {
 | 
			
		||||
		const datematcher = RegExp(/((?:0[1-9]|[12][0-9]|3[01])\.(?:0[1-9]|1[012])\.)(?:\ um\ )((?:(?:[01][0-9]|[2][0-3])\:[0-5][0-9])|(?:[2][4]\:00))!/i)
 | 
			
		||||
		const result: RegExpMatchArray | null = message.match(datematcher)
 | 
			
		||||
		const timeFromResult = result?.at(-1)
 | 
			
		||||
		const dateFromResult = result?.at(1)?.concat(format(new Date(), '.yyyy')).concat(" " + timeFromResult) ?? ""
 | 
			
		||||
		const dateFromResult = result?.at(1)?.concat(format(new Date(), 'yyyy')).concat(" " + timeFromResult) ?? ""
 | 
			
		||||
		return new Date(dateFromResult)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user
	
Move check to handleMessageReactionAdd
moved