<commit_before>
import discord
from discord.ext import commands, menus

import collections
import copy
import random
import tempfile

from modules.maze import Maze
from utilities import checks
from utilities import errors

def setup(bot):
	bot.add_cog(Reactions(bot))
	
	async def process_reactions(reaction, user):
		if user == bot.user:
			return
		await bot.cogs["Reactions"].reaction_messages[reaction.message.id](reaction, user)
		await bot.db.execute(
			"""
			UPDATE meta.stats
			SET reaction_responses = reaction_responses + 1
			WHERE timestamp = $1
			""", 
			bot.online_time
		)
		# Count fixed to stop counting own reactions on 2019-10-25
	
	@bot.event
	async def on_reaction_add(reaction, user):
		if "Reactions" in bot.cogs and reaction.message.id in bot.cogs["Reactions"].reaction_messages:
			await process_reactions(reaction, user)

	@bot.event
	async def on_reaction_remove(reaction, user):
		if "Reactions" in bot.cogs and reaction.message.id in bot.cogs["Reactions"].reaction_messages:
			await process_reactions(reaction, user)

async def increment_menu_reaction_count(bot):
	await bot.db.execute(
		"""
		UPDATE meta.stats
		SET menu_reactions = menu_reactions + 1
		WHERE timestamp = $1
		""", 
		bot.online_time
	)

class GuessMenu(menus.Menu):
	
	def __init__(self):
		super().__init__(timeout = None, check_embeds = True)
		self.numbers = {str(number) + '\N{COMBINING ENCLOSING KEYCAP}': number for number in range(1, 10)}
		self.numbers['\N{KEYCAP TEN}'] = 10
		for emote, number in self.numbers.items():
			self.add_button(menus.Button(emote, self.process_reaction, position = number))
	
	# TODO: Track number of tries
	
	async def send_initial_message(self, ctx, channel):
		self.answer = random.randint(1, 10)
		return await ctx.embed_reply(f"{ctx.author.mention}: Guess a number between 1 to 10")
	
	async def process_reaction(self, payload):
		embed = self.message.embeds[0]
		if (number := self.numbers[str(payload.emoji)]) == self.answer:
			embed.description = f"{self.ctx.author.mention}: It was {number}!"
			self.stop()
		else:
			embed.description = (f"{self.ctx.author.mention}: Guess a number between 1 to 10\n"
									f"No, it's not {number}")
		await self.message.edit(embed = embed)
		await increment_menu_reaction_count(self.bot)

class MazeMenu(menus.Menu):
	
	def __init__(self, width, height, random_start, random_end):
		super().__init__(timeout = None, clear_reactions_after = True, check_embeds = True)
		self.maze = Maze(width, height, random_start = random_start, random_end = random_end)
		self.arrows = {'\N{LEFTWARDS BLACK ARROW}': 'W', '\N{UPWARDS BLACK ARROW}': 'N', '\N{DOWNWARDS BLACK ARROW}': 'S', '\N{BLACK RIGHTWARDS ARROW}': 'E'}
		for number, emote in enumerate(self.arrows.keys(), start = 1):
			self.add_button(menus.Button(emote, self.on_direction, position = number))
	
	async def send_initial_message(self, ctx, channel):
		return await ctx.embed_reply(ctx.bot.CODE_BLOCK.format(self.maze.print_visible()), 
										footer_text = f"Your current position: {self.maze.column + 1}, {self.maze.row + 1}")
	
	async def on_direction(self, payload):
		embed = self.message.embeds[0]
		moved = self.maze.move(self.arrows[str(payload.emoji)].lower())<commit_msg>[Discord] Optimize emoji to direction mapping in Maze Menu<commit_after>
import discord
from discord.ext import commands, menus

import collections
import copy
import random
import tempfile

from modules.maze import Maze
from utilities import checks
from utilities import errors

def setup(bot):
	bot.add_cog(Reactions(bot))
	
	async def process_reactions(reaction, user):
		if user == bot.user:
			return
		await bot.cogs["Reactions"].reaction_messages[reaction.message.id](reaction, user)
		await bot.db.execute(
			"""
			UPDATE meta.stats
			SET reaction_responses = reaction_responses + 1
			WHERE timestamp = $1
			""", 
			bot.online_time
		)
		# Count fixed to stop counting own reactions on 2019-10-25
	
	@bot.event
	async def on_reaction_add(reaction, user):
		if "Reactions" in bot.cogs and reaction.message.id in bot.cogs["Reactions"].reaction_messages:
			await process_reactions(reaction, user)

	@bot.event
	async def on_reaction_remove(reaction, user):
		if "Reactions" in bot.cogs and reaction.message.id in bot.cogs["Reactions"].reaction_messages:
			await process_reactions(reaction, user)

async def increment_menu_reaction_count(bot):
	await bot.db.execute(
		"""
		UPDATE meta.stats
		SET menu_reactions = menu_reactions + 1
		WHERE timestamp = $1
		""", 
		bot.online_time
	)

class GuessMenu(menus.Menu):
	
	def __init__(self):
		super().__init__(timeout = None, check_embeds = True)
		self.numbers = {str(number) + '\N{COMBINING ENCLOSING KEYCAP}': number for number in range(1, 10)}
		self.numbers['\N{KEYCAP TEN}'] = 10
		for emote, number in self.numbers.items():
			self.add_button(menus.Button(emote, self.process_reaction, position = number))
	
	# TODO: Track number of tries
	
	async def send_initial_message(self, ctx, channel):
		self.answer = random.randint(1, 10)
		return await ctx.embed_reply(f"{ctx.author.mention}: Guess a number between 1 to 10")
	
	async def process_reaction(self, payload):
		embed = self.message.embeds[0]
		if (number := self.numbers[str(payload.emoji)]) == self.answer:
			embed.description = f"{self.ctx.author.mention}: It was {number}!"
			self.stop()
		else:
			embed.description = (f"{self.ctx.author.mention}: Guess a number between 1 to 10\n"
									f"No, it's not {number}")
		await self.message.edit(embed = embed)
		await increment_menu_reaction_count(self.bot)

class MazeMenu(menus.Menu):
	
	def __init__(self, width, height, random_start, random_end):
		super().__init__(timeout = None, clear_reactions_after = True, check_embeds = True)
		self.maze = Maze(width, height, random_start = random_start, random_end = random_end)
		self.arrows = {'\N{LEFTWARDS BLACK ARROW}': 'w', '\N{UPWARDS BLACK ARROW}': 'n', '\N{DOWNWARDS BLACK ARROW}': 's', '\N{BLACK RIGHTWARDS ARROW}': 'e'}
		for number, emote in enumerate(self.arrows.keys(), start = 1):
			self.add_button(menus.Button(emote, self.on_direction, position = number))
	
	async def send_initial_message(self, ctx, channel):
		return await ctx.embed_reply(ctx.bot.CODE_BLOCK.format(self.maze.print_visible()), 
										footer_text = f"Your current position: {self.maze.column + 1}, {self.maze.row + 1}")
	
	async def on_direction(self, payload):
		embed = self.message.embeds[0]
		moved = self.maze.move(self.arrows[str(payload.emoji)])
{'fraction_non_alphanumeric': 0.1254425119285824, 'fraction_numerical': 0.009542865938125289, 'mean_word_length': 4.630849220103986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '324519', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2179, 'n_words': 551}