localized slot machine
Marco Andronaco andronacomarco@gmail.com
Mon, 12 Sep 2022 13:30:43 +0200
2 files changed,
101 insertions(+),
88 deletions(-)
M
Constants.py
→
Constants.py
@@ -10,7 +10,17 @@ 'enabled' : "enabled",
'disabled' : "disabled", 'unknown' : "Sorry, I didn't understand that command.", 'error': "An error has occurred. Please retry.", - 'failed_effect': "Couldn't apply effect." + 'failed_effect': "Couldn't apply effect.", + 'not_enough_cash': "You don't have enough money!", + 'you_lost': "You lost...", + 'you_won': "You won {:0.2f}$!", + 'cash_result': " Your money: {:0.2f}$.", + 'reroll': "Reroll (-{:0.2f}$)", + 'summary': "You bet {}$ and won a total of {}$.", + 'current_bet': "{}, your current bet is {:0.2f}$.", + 'current_cash': "{}, you currently have {:0.2f}$ in your account.", + 'no_autospin': "Sorry, multiple spins are disabled in group chats." + }, 'it': { 'welcome' : "Benvenuto da PILuAnimeBot!",@@ -21,7 +31,16 @@ 'enabled' : "abilitata",
'disabled' : "disabilitata", 'unknown' : "Non ho capito.", 'error': "Qualcosa è andato storto, riprova.", - 'failed_effect': "Impossibile applicare l'effetto." + 'failed_effect': "Impossibile applicare l'effetto.", + 'not_enough_cash': "Saldo insufficiente!", + 'you_lost': "Hai perso...", + 'you_won': "Hai vinto {:0.2f}€!", + 'cash_result': " Saldo: {:0.2f}€.", + 'reroll': "Riprova (-{:0.2f}€)", + 'summary': "Hai giocato {}€ e vinto un totale di {}€.", + 'current_bet': "{}, il tuo bet attuale è {:0.2f}€.", + 'current_cash': "{}, il tuo saldo attuale è {:0.2f}€.", + 'no_autospin': "Gli spin multipli sono disabilitati nelle chat di gruppo." }, }@@ -38,79 +57,71 @@ except KeyError:
logging.error("No text was found.") return "localization error {}{}{}{}{}{}" - -symbols = { - "grape", - "lemon", - "bar", - "seven" -} - slot_machine_value = { - 1: ("bar", "bar", "bar"), - 2: ("grape", "bar", "bar"), - 3: ("lemon", "bar", "bar"), - 4: ("seven", "bar", "bar"), - 5: ("bar", "grape", "bar"), - 6: ("grape", "grape", "bar"), - 7: ("lemon", "grape", "bar"), - 8: ("seven", "grape", "bar"), - 9: ("bar", "lemon", "bar"), - 10: ("grape", "lemon", "bar"), - 11: ("lemon", "lemon", "bar"), - 12: ("seven", "lemon", "bar"), - 13: ("bar", "seven", "bar"), - 14: ("grape", "seven", "bar"), - 15: ("lemon", "seven", "bar"), - 16: ("seven", "seven", "bar"), - 17: ("bar", "bar", "grape"), - 18: ("grape", "bar", "grape"), - 19: ("lemon", "bar", "grape"), - 20: ("seven", "bar", "grape"), - 21: ("bar", "grape", "grape"), - 22: ("grape", "grape", "grape"), - 23: ("lemon", "grape", "grape"), - 24: ("seven", "grape", "grape"), - 25: ("bar", "lemon", "grape"), - 26: ("grape", "lemon", "grape"), - 27: ("lemon", "lemon", "grape"), - 28: ("seven", "lemon", "grape"), - 29: ("bar", "seven", "grape"), - 30: ("grape", "seven", "grape"), - 31: ("lemon", "seven", "grape"), - 32: ("seven", "seven", "grape"), - 33: ("bar", "bar", "lemon"), - 34: ("grape", "bar", "lemon"), - 35: ("lemon", "bar", "lemon"), - 36: ("seven", "bar", "lemon"), - 37: ("bar", "grape", "lemon"), - 38: ("grape", "grape", "lemon"), - 39: ("lemon", "grape", "lemon"), - 40: ("seven", "grape", "lemon"), - 41: ("bar", "lemon", "lemon"), - 42: ("grape", "lemon", "lemon"), - 43: ("lemon", "lemon", "lemon"), - 44: ("seven", "lemon", "lemon"), - 45: ("bar", "seven", "lemon"), - 46: ("grape", "seven", "lemon"), - 47: ("lemon", "seven", "lemon"), - 48: ("seven", "seven", "lemon"), - 49: ("bar", "bar", "seven"), - 50: ("grape", "bar", "seven"), - 51: ("lemon", "bar", "seven"), - 52: ("seven", "bar", "seven"), - 53: ("bar", "grape", "seven"), - 54: ("grape", "grape", "seven"), - 55: ("lemon", "grape", "seven"), - 56: ("seven", "grape", "seven"), - 57: ("bar", "lemon", "seven"), - 58: ("grape", "lemon", "seven"), - 59: ("lemon", "lemon", "seven"), - 60: ("seven", "lemon", "seven"), - 61: ("bar", "seven", "seven"), - 62: ("grape", "seven", "seven"), - 63: ("lemon", "seven", "seven"), - 64: ("seven", "seven", "seven"), + 1: (3, "bar"), + 2: (2, "bar"), + 3: (2, "bar"), + 4: (2, "bar"), + 5: None, + 6: (2, "grape"), + 7: None, + 8: None, + 9: None, + 10: None, + 11: (2, "lemon"), + 12: None, + 13: None, + 14: None, + 15: None, + 16: (2, "seven"), + 17: (2, "bar"), + 18: None, + 19: None, + 20: None, + 21: (2, "grape"), + 22: (3, "grape"), + 23: (2, "grape"), + 24: (2, "grape"), + 25: None, + 26: None, + 27: (2, "lemon"), + 28: None, + 29: None, + 30: None, + 31: None, + 32: (2, "seven"), + 33: (2, "bar"), + 34: None, + 35: None, + 36: None, + 37: None, + 38: (2, "grape"), + 39: None, + 40: None, + 41: (2, "lemon"), + 42: (2, "lemon"), + 43: (3, "lemon"), + 44: (2, "lemon"), + 45: None, + 46: None, + 47: None, + 48: (2, "seven"), + 49: (2, "bar"), + 50: None, + 51: None, + 52: None, + 53: None, + 54: (2, "grape"), + 55: None, + 56: None, + 57: None, + 58: None, + 59: (2, "lemon"), + 60: None, + 61: (2, "seven"), + 62: (2, "seven"), + 63: (2, "seven"), + 64: (3, "seven"), } win_table = {
M
Games.py
→
Games.py
@@ -1,6 +1,7 @@
from telegram import Update, Dice, InlineKeyboardMarkup, InlineKeyboardButton from telegram.ext import CallbackContext from datetime import date +from Constants import get_localized_string as l import Constants as c import time@@ -9,6 +10,7 @@ lastreset_default = date(1970, 1, 1)
cash_default = 5000 bet_default = 50 slot_emoji = '🎰' +lang = 'us' def read_arg(context: CallbackContext, default=None, cast=int): try:@@ -61,7 +63,7 @@ bet = get_bet(context)
cash = get_cash(context) if cash < bet: - context.bot.send_message(chat_id=id, text="Saldo insufficiente!") + context.bot.send_message(chat_id=id, text=l("not_enough_cash", lang)) return None cash = set_cash(context, cash - bet)@@ -74,9 +76,9 @@ win = bet * multiplier
cash = set_cash(context, cash + win) - text = "Hai perso..." if win == 0 else "Hai vinto {:0.2f}€!".format(win / 100) + text = l("you_lost", lang) if win == 0 else l("you_won", lang).format(win / 100) - text += " Saldo: {:0.2f}€.".format(cash / 100) + text += l("cash_result", lang).format(cash / 100) time.sleep(2) context.bot.send_message(chat_id=id, text=text, reply_markup=markup)@@ -88,11 +90,15 @@ bet = get_bet(context) / 100
amount = read_arg(context, 1) + if amount > 1 and update.effective_chat.type != 'private': + amount = 1 + context.bot.send_message(chat_id=update.effective_chat.id, text=l("no_autospin", lang)) + if amount == 1: - markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="Reroll (-{:0.2f}€)".format(bet), callback_data="callback_1")]]) + markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=l("reroll", lang).format(bet), callback_data="callback_1")]]) _spin(context=context, id=update.effective_chat.id, markup=markup) else: - amount = min(amount, autospin_cap) + amount = max(1, min(amount, autospin_cap)) count = 0 total_win = 0 for i in range(amount):@@ -104,7 +110,7 @@
count += 1 total_win += win - result = "Hai giocato {}€ e vinto un totale di {}€".format(count * bet, total_win / 100) + result = l("summary", lang).format(count * bet, total_win / 100) markup = "" #InlineKeyboardMarkup([[InlineKeyboardButton(text="Altri {} spin (-{}€)".format(amount, bet * amount), callback_data="callback_2")]]) context.bot.send_message(chat_id=update.effective_chat.id, text=result, reply_markup=markup)@@ -117,12 +123,12 @@ bet = set_bet(context, int(amount * 100))
else: bet = get_bet(context) - result = "{}, il tuo bet attuale è {:0.2f}€.".format(c.format_author(update.effective_user), bet / 100) + result = l("current_bet", lang).format(c.format_author(update.effective_user), bet / 100) context.bot.send_message(chat_id=update.effective_chat.id, text=result) def cash(update: Update, context: CallbackContext): cash = get_cash(context) / 100 - result = "{}, il tuo saldo attuale è {:0.2f}€.".format(c.format_author(update.effective_user), cash) + result = l("current_cash", lang).format(c.format_author(update.effective_user), cash) context.bot.send_message(chat_id=update.effective_chat.id, text=result) def get_multiplier(value: int):@@ -130,13 +136,9 @@
try: values = c.slot_machine_value[value] except IndexError: - values = c.slot_machine_value[50] - - values_count = {i:values.count(i) for i in values} - symbol = max(values_count, key=values_count.get) - count = values_count[symbol] + values = c.slot_machine_value[5] try: - return c.win_table[(count, symbol)] + return c.win_table[values] except KeyError: return 0