all repos — python-meme-bot @ f9c41ff46b6517d714d6196ab022b624ac73b937

Telegram Bot that uses PIL to compute light image processing.

Constants.py (view raw)

  1from telegram import InlineKeyboardMarkup, InlineKeyboardButton
  2from telegram.ext import CallbackContext
  3import logging
  4
  5localization = {
  6    'en': {
  7        'name' : "English",
  8        'emoji' : "🇬🇧",
  9        'welcome' : "Welcome to PILuAnimeBot!",
 10        'sauce' : "Sauce 🍝",
 11        'no_caption' : "No caption detected.",
 12        'lewd_toggle' : "Lewd content was {} for this chat.",
 13        'enabled' : "enabled",
 14        'disabled' : "disabled",
 15        'unknown' : "Sorry, I didn't understand that command.",
 16        'error': "An error has occurred. Please retry.",
 17        'failed_effect': "Couldn't apply effect.",
 18        'not_enough_cash': "You don't have enough money! Type /cash to reset it.",
 19        'you_lost': "You lost...",
 20        'you_won': "You won {:0.2f}$!",
 21        'cash_result': " Your money: {:0.2f}$.",
 22        'reroll': "Reroll (-{:0.2f}$)",
 23        'summary': "You bet {}$ and won a total of {}$.",
 24        'current_bet': "{}, your current bet is {:0.2f}$.",
 25        'current_cash': "{}, you currently have {:0.2f}$ in your account.",
 26        'cash_reset': "{}, your cash has been reset to {:0.2f}$. You can do this once per day.",
 27        'cash_reset_fail': "{}, you have 0$ in your account and you cannot reset it today. Come back tomorrow.",
 28        'no_autospin': "Sorry, multiple spins are disabled in group chats.",
 29        'current_language': "Current language: {}.\nChoices: {}\nTo change it, type \"/lang <code>\" or use one of the buttons below.",
 30        'invalid_language': "Invalid language.",
 31        'language_set': "Language set: {}",
 32    },
 33    'it': {
 34        'name': "Italiano",
 35        'emoji' : "🇮🇹",
 36        'welcome' : "Benvenuto da PILuAnimeBot!",
 37        'sauce' : "Salsa 🍝",
 38        'no_caption' : "Scrivi un testo per favore.",
 39        'lewd_toggle' : "La roba lewd è stata {} per questa chat.",
 40        'enabled' : "abilitata",
 41        'disabled' : "disabilitata",
 42        'unknown' : "Non ho capito.",
 43        'error': "Qualcosa è andato storto, riprova.",
 44        'failed_effect': "Impossibile applicare l'effetto.",
 45        'not_enough_cash': "Saldo insufficiente! Usa /cash per ripristinarlo.",
 46        'you_lost': "Hai perso...",
 47        'you_won': "Hai vinto {:0.2f}€!",
 48        'cash_result': " Saldo: {:0.2f}€.",
 49        'reroll': "Riprova (-{:0.2f}€)",
 50        'summary': "Hai giocato {}€ e vinto un totale di {}€.",
 51        'current_bet': "{}, il tuo bet attuale è {:0.2f}€.",
 52        'current_cash': "{}, il tuo saldo attuale è {:0.2f}€.",
 53        'cash_reset': "{}, il tuo saldo è stato ripristinato a {:0.2f}€. Puoi farlo una volta al giorno.",
 54        'cash_reset_fail': "{}, il tuo saldo è 0€ e non puoi più resettarlo oggi. Riprova domani.",
 55        'no_autospin': "Gli spin multipli sono disabilitati nelle chat di gruppo.",
 56        'current_language': "Lingua attuale: {}.\nAltre lingue: {}\nPer cambiarla, scrivi \"/lang <codice>\" o usa uno dei tasti qui sotto.",
 57        'invalid_language': "Questa lingua non esiste.",
 58        'language_set': "Lingua impostata: {}",
 59    },
 60}
 61langs = localization.keys()
 62default_lang = "en"
 63
 64n_entries = len(localization[default_lang].keys())
 65        
 66#markup = InlineKeyboardMarkup([[button, button][button, button]])
 67
 68def format_lang(lang: str):
 69    try:
 70        return f"{localization[lang]['name']} {localization[lang]['emoji']}"
 71    except KeyError:
 72        return 'Unknown'
 73
 74buttons = []
 75for i in langs:
 76    assert(n_entries == len(localization[i].keys()))
 77    buttons.append(InlineKeyboardButton(text=format_lang(i), callback_data=f"set_lang_{i}"))
 78
 79N = 2
 80lang_markup = InlineKeyboardMarkup([buttons[n:n+N] for n in range(0, len(buttons), N)])
 81
 82def format_author(user):
 83    
 84    if user.username is not None:
 85        return user.full_name + f" ({user.username})"
 86    return user.full_name
 87
 88def get_lang(context: CallbackContext):
 89    try:
 90        return context.chat_data["lang"]
 91    except KeyError:
 92        context.chat_data["lang"] = default_lang
 93        return default_lang
 94
 95def get_localized_string(text:str, context:CallbackContext):
 96    lang = get_lang(context)
 97    
 98    try:
 99        return localization[lang][text]
100    except KeyError:
101        logging.error("No text was found.")
102        return "localization error {}{}{}{}{}{}"
103
104slot_machine_value = {
105    1: (3, "bar"),
106    2: (2, "bar"),
107    3: (2, "bar"),
108    4: (2, "bar"),
109    5: None,
110    6: (2, "grape"),
111    7: None,
112    8: None,
113    9: None,
114    10: None,
115    11: (2, "lemon"),
116    12: None,
117    13: None,
118    14: None,
119    15: None,
120    16: (2, "seven"),
121    17: (2, "bar"),
122    18: None,
123    19: None,
124    20: None,
125    21: (2, "grape"),
126    22: (3, "grape"),
127    23: (2, "grape"),
128    24: (2, "grape"),
129    25: None,
130    26: None,
131    27: (2, "lemon"),
132    28: None,
133    29: None,
134    30: None,
135    31: None,
136    32: (2, "seven"),
137    33: (2, "bar"),
138    34: None,
139    35: None,
140    36: None,
141    37: None,
142    38: (2, "grape"),
143    39: None,
144    40: None,
145    41: (2, "lemon"),
146    42: (2, "lemon"),
147    43: (3, "lemon"),
148    44: (2, "lemon"),
149    45: None,
150    46: None,
151    47: None,
152    48: (2, "seven"),
153    49: (2, "bar"),
154    50: None,
155    51: None,
156    52: None,
157    53: None,
158    54: (2, "grape"),
159    55: None,
160    56: None,
161    57: None,
162    58: None,
163    59: (2, "lemon"),
164    60: None,
165    61: (2, "seven"),
166    62: (2, "seven"),
167    63: (2, "seven"),
168    64: (3, "seven"),
169}
170
171win_table = {
172    (3, "seven"): 20,
173    (3, "bar"): 5,
174    (3, "lemon"): 3,
175    (3, "grape"): 2,
176    
177    (2, "seven"): 4,
178    (2, "bar"): 2,
179    (2, "lemon"): 1,
180    (2, "grape"): 0.5
181}