dev #2
4 changed files with 48 additions and 22 deletions
|
@ -1,7 +1,20 @@
|
||||||
{
|
{
|
||||||
"guess_the_number": "Guess the number",
|
"minigames_hangman_game": "Word: {display_word()}\nWrong guesses: {wrong_guesses}/{max_wrong}",
|
||||||
"your_guess": "Your guess (1-10)",
|
"minigames_hangman_lost": "You lost! The word was:",
|
||||||
"memosry_file_valid": "The memory.json file is valid!",
|
"minigames_hangman_won": "You won! The word was:",
|
||||||
|
"minigames_hangman_already_guessed": "You already guessed",
|
||||||
|
"minigames_hangman_user_letter_guess": "Your letter guess",
|
||||||
|
"minigames_hangman_guess": "Guess a Letter",
|
||||||
|
"minigames_hangman_api_failed": "Failed to get a random word.",
|
||||||
|
"minigames_hangman": "Play Hangman with a random word",
|
||||||
|
"minigames_click_to_guess": "Click to guess a number from 1 to 10",
|
||||||
|
"minigames_guess_button": "Guess",
|
||||||
|
"minigames_wrong_number": "Wrong! The number was",
|
||||||
|
"minigames_correct": "Correct!",
|
||||||
|
"minigames_invalid_number": "Invalid number!",
|
||||||
|
"minigames_guess_the_number": "Guess the number",
|
||||||
|
"minigames_your_guess": "Your guess (1-10)",
|
||||||
|
"memory_file_valid": "The memory.json file is valid!",
|
||||||
"file_aint_uft8": "File is not valid UTF-8 text. Might be binary or corrupted.",
|
"file_aint_uft8": "File is not valid UTF-8 text. Might be binary or corrupted.",
|
||||||
"psutil_not_installed": "Memory check skipped.",
|
"psutil_not_installed": "Memory check skipped.",
|
||||||
"not_cloned": "Goober is not cloned! Please clone it from GitHub.",
|
"not_cloned": "Goober is not cloned! Please clone it from GitHub.",
|
||||||
|
|
|
@ -1,4 +1,19 @@
|
||||||
{
|
{
|
||||||
|
"minigames_hangman_game": "Parola: {display_word()}\nErrori: {wrong_guesses}/{max_wrong}",
|
||||||
|
"minigames_hangman_lost": "Hai perso! La parola era:",
|
||||||
|
"minigames_hangman_won": "Hai vinto! La parola era:",
|
||||||
|
"minigames_hangman_already_guessed": "Hai già indovinato",
|
||||||
|
"minigames_hangman_user_letter_guess": "La tua lettera",
|
||||||
|
"minigames_hangman_guess": "Indovina una lettera",
|
||||||
|
"minigames_hangman_api_failed": "Impossibile ottenere una parola casuale.",
|
||||||
|
"minigames_hangman": "Gioca all'impiccato con una parola casuale",
|
||||||
|
"minigames_click_to_guess": "Clicca per indovinare un numero da 1 a 10",
|
||||||
|
"minigames_guess_button": "Indovina",
|
||||||
|
"minigames_wrong_number": "Sbagliato! Il numero era",
|
||||||
|
"minigames_correct": "Corretto!",
|
||||||
|
"minigames_invalid_number": "Numero non valido!",
|
||||||
|
"minigames_guess_the_number": "Indovina il numero",
|
||||||
|
"minigames_your_guess": "Il tuo numero (1-10)",
|
||||||
"memory_file_valid": "Il file JSON è valido!",
|
"memory_file_valid": "Il file JSON è valido!",
|
||||||
"file_aint_utf8": "Il file non è un UTF-8 valido. Forse è binario?",
|
"file_aint_utf8": "Il file non è un UTF-8 valido. Forse è binario?",
|
||||||
"psutil_not_installed": "Controllo memoria saltato.",
|
"psutil_not_installed": "Controllo memoria saltato.",
|
||||||
|
|
|
@ -7,30 +7,30 @@ import asyncio
|
||||||
from modules.globalvars import bot
|
from modules.globalvars import bot
|
||||||
from modules.volta.main import _
|
from modules.volta.main import _
|
||||||
|
|
||||||
@bot.hybrid_command(description=_('guess_the_number'))
|
@bot.hybrid_command(description=_('minigames_guess_the_number'))
|
||||||
async def guessthenumber(ctx: commands.Context):
|
async def guessthenumber(ctx: commands.Context):
|
||||||
number = random.randint(1, 10)
|
number = random.randint(1, 10)
|
||||||
class GuessModal(ui.Modal, title=_('guess_the_number')):
|
class GuessModal(ui.Modal, title=_('minigames_guess_the_number')):
|
||||||
guess = ui.TextInput(label=_('your_guess'), style=TextStyle.short)
|
guess = ui.TextInput(label=_('minigames_your_guess'), style=TextStyle.short)
|
||||||
async def on_submit(self, interaction: Interaction):
|
async def on_submit(self, interaction: Interaction):
|
||||||
try:
|
try:
|
||||||
user_guess = int(self.guess.value)
|
user_guess = int(self.guess.value)
|
||||||
except:
|
except:
|
||||||
await interaction.response.send_message("Invalid number!", ephemeral=True)
|
await interaction.response.send_message(_('minigames_invalid_number'), ephemeral=True)
|
||||||
return
|
return
|
||||||
if user_guess == number:
|
if user_guess == number:
|
||||||
await interaction.response.send_message("Correct!", ephemeral=True)
|
await interaction.response.send_message(_('minigames_correct'), ephemeral=True)
|
||||||
else:
|
else:
|
||||||
await interaction.response.send_message(f"Wrong! The number was {number}.", ephemeral=True)
|
await interaction.response.send_message(f"{_('minigames_wrong_number')} {number}.", ephemeral=True)
|
||||||
async def button_callback(interaction: Interaction):
|
async def button_callback(interaction: Interaction):
|
||||||
await interaction.response.send_modal(GuessModal())
|
await interaction.response.send_modal(GuessModal())
|
||||||
button = ui.Button(label="Guess", style=discord.ButtonStyle.primary)
|
button = ui.Button(label=_('minigames_guess_button'), style=discord.ButtonStyle.primary)
|
||||||
button.callback = button_callback
|
button.callback = button_callback
|
||||||
view = ui.View()
|
view = ui.View()
|
||||||
view.add_item(button)
|
view.add_item(button)
|
||||||
await ctx.send("Click to guess a number from 1 to 10", view=view)
|
await ctx.send(_('minigames_click_to_guess'), view=view)
|
||||||
|
|
||||||
@bot.hybrid_command(description="Play Hangman with a random word")
|
@bot.hybrid_command(description=_('minigames_hangman'))
|
||||||
async def hangman(ctx: commands.Context):
|
async def hangman(ctx: commands.Context):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get("https://random-word-api.herokuapp.com/word?number=1") as resp:
|
async with session.get("https://random-word-api.herokuapp.com/word?number=1") as resp:
|
||||||
|
@ -45,23 +45,23 @@ async def hangman(ctx: commands.Context):
|
||||||
max_wrong = 6
|
max_wrong = 6
|
||||||
def display_word():
|
def display_word():
|
||||||
return " ".join([c if c in guessed_letters else "_" for c in word])
|
return " ".join([c if c in guessed_letters else "_" for c in word])
|
||||||
class GuessModal(ui.Modal, title="Guess a Letter"):
|
class GuessModal(ui.Modal, title=_('minigames_hangman_guess')):
|
||||||
letter = ui.TextInput(label="Your letter guess", style=TextStyle.short, max_length=1)
|
letter = ui.TextInput(label=_('minigames_hangman_user_letter_guess'), style=TextStyle.short, max_length=1)
|
||||||
async def on_submit(self, interaction: Interaction):
|
async def on_submit(self, interaction: Interaction):
|
||||||
nonlocal guessed_letters, wrong_guesses
|
nonlocal guessed_letters, wrong_guesses
|
||||||
guess = self.letter.value.lower()
|
guess = self.letter.value.lower()
|
||||||
if guess in guessed_letters:
|
if guess in guessed_letters:
|
||||||
await interaction.response.send_message(f"You already guessed '{guess}'!", ephemeral=True)
|
await interaction.response.send_message(f"{_('minigames_hangman_already_guessed')}'{guess}'!", ephemeral=True)
|
||||||
return
|
return
|
||||||
guessed_letters.add(guess)
|
guessed_letters.add(guess)
|
||||||
if guess not in word:
|
if guess not in word:
|
||||||
wrong_guesses += 1
|
wrong_guesses += 1
|
||||||
if all(c in guessed_letters for c in word):
|
if all(c in guessed_letters for c in word):
|
||||||
await interaction.response.edit_message(content=f"You won! The word was: **{word}**", view=None)
|
await interaction.response.edit_message(content=f"{_('minigames_hangman_won')} **{word}**", view=None)
|
||||||
elif wrong_guesses >= max_wrong:
|
elif wrong_guesses >= max_wrong:
|
||||||
await interaction.response.edit_message(content=f"You lost! The word was: **{word}**", view=None)
|
await interaction.response.edit_message(content=f"{_('minigames_hangman_lost')} **{word}**", view=None)
|
||||||
else:
|
else:
|
||||||
await interaction.response.edit_message(content=f"Word: {display_word()}\nWrong guesses: {wrong_guesses}/{max_wrong}", view=view)
|
await interaction.response.edit_message(content=_('minigames_hangman_game').format(display_word=display_word,wrong_guesses=wrong_guesses,max_wrong=max_wrong), view=view)
|
||||||
async def button_callback(interaction: Interaction):
|
async def button_callback(interaction: Interaction):
|
||||||
await interaction.response.send_modal(GuessModal())
|
await interaction.response.send_modal(GuessModal())
|
||||||
button = ui.Button(label="Guess a letter", style=discord.ButtonStyle.primary)
|
button = ui.Button(label="Guess a letter", style=discord.ButtonStyle.primary)
|
||||||
|
|
|
@ -7,6 +7,8 @@ import locale
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
import threading
|
import threading
|
||||||
|
import platform
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
@ -62,10 +64,6 @@ if working_dir != module_dir:
|
||||||
translations = {}
|
translations = {}
|
||||||
_file_mod_times = {}
|
_file_mod_times = {}
|
||||||
|
|
||||||
import locale
|
|
||||||
import platform
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def get_system_locale():
|
def get_system_locale():
|
||||||
system = platform.system() # fallback incase locale isnt set
|
system = platform.system() # fallback incase locale isnt set
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue