all repos — python-meme-bot @ 6cb1f2a6c6b0fef96d4e08b11833b2b4b55f71d9

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        'none_callback': "This button does nothing.",
 33        'fast_output': "Win: {:0.2f}$",
 34        'repeat_autospin': "Spin {} times again (-{:0.2f}$)"
 35    },
 36    'it': {
 37        'name': "Italiano",
 38        'emoji' : "🇮🇹",
 39        'welcome' : "Benvenuto da PILuAnimeBot!",
 40        'sauce' : "Salsa 🍝",
 41        'no_caption' : "Scrivi un testo per favore.",
 42        'lewd_toggle' : "La roba lewd è stata {} per questa chat.",
 43        'enabled' : "abilitata",
 44        'disabled' : "disabilitata",
 45        'unknown' : "Non ho capito.",
 46        'error': "Qualcosa è andato storto, riprova.",
 47        'failed_effect': "Impossibile applicare l'effetto.",
 48        'not_enough_cash': "Saldo insufficiente! Usa /cash per ripristinarlo.",
 49        'you_lost': "Hai perso...",
 50        'you_won': "Hai vinto {:0.2f}€!",
 51        'cash_result': " Saldo: {:0.2f}€.",
 52        'reroll': "Riprova (-{:0.2f}€)",
 53        'summary': "Hai giocato {}€ e vinto un totale di {}€.",
 54        'current_bet': "{}, il tuo bet attuale è {:0.2f}€.",
 55        'current_cash': "{}, il tuo saldo attuale è {:0.2f}€.",
 56        'cash_reset': "{}, il tuo saldo è stato ripristinato a {:0.2f}€. Puoi farlo una volta al giorno.",
 57        'cash_reset_fail': "{}, il tuo saldo è 0€ e non puoi più resettarlo oggi. Riprova domani.",
 58        'no_autospin': "Gli spin multipli sono disabilitati nelle chat di gruppo.",
 59        'current_language': "Lingua attuale: {}.\nAltre lingue: {}\nPer cambiarla, scrivi \"/lang <codice>\" o usa uno dei tasti qui sotto.",
 60        'invalid_language': "Questa lingua non esiste.",
 61        'language_set': "Lingua impostata: {}",
 62        'none_callback': "Questo tasto non fa nulla.",
 63        'fast_output': "Vinto: {:0.2f}",
 64        'repeat_autospin': "Altri {} spin (-{:0.2f}€)"
 65    },
 66}
 67langs = localization.keys()
 68default_lang = "en"
 69
 70n_entries = len(localization[default_lang].keys())
 71        
 72#markup = InlineKeyboardMarkup([[button, button][button, button]])
 73
 74def format_lang(lang: str):
 75    try:
 76        return f"{localization[lang]['name']} {localization[lang]['emoji']}"
 77    except KeyError:
 78        return 'Unknown'
 79
 80buttons = []
 81for i in langs:
 82    assert(n_entries == len(localization[i].keys()))
 83    buttons.append(InlineKeyboardButton(text=format_lang(i), callback_data=f"set_lang_{i}"))
 84
 85N = 2
 86lang_markup = InlineKeyboardMarkup([buttons[n:n+N] for n in range(0, len(buttons), N)])
 87
 88def format_author(user):
 89    
 90    if user.username is not None:
 91        return user.full_name + f" ({user.username})"
 92    return user.full_name
 93
 94def get_lang(context: CallbackContext):
 95    try:
 96        return context.chat_data["lang"]
 97    except KeyError:
 98        context.chat_data["lang"] = default_lang
 99        return default_lang
100
101def get_localized_string(text:str, context:CallbackContext):
102    lang = get_lang(context)
103    
104    try:
105        return localization[lang][text]
106    except KeyError:
107        logging.error("No text was found.")
108        return "localization error {}{}{}{}{}{}"
109
110slot_machine_value = {
111    1: (3, "bar"),
112    2: (2, "bar"),
113    3: (2, "bar"),
114    4: (2, "bar"),
115    5: None,
116    6: (2, "grape"),
117    7: None,
118    8: None,
119    9: None,
120    10: None,
121    11: (2, "lemon"),
122    12: None,
123    13: None,
124    14: None,
125    15: None,
126    16: (2, "seven"),
127    17: (2, "bar"),
128    18: None,
129    19: None,
130    20: None,
131    21: (2, "grape"),
132    22: (3, "grape"),
133    23: (2, "grape"),
134    24: (2, "grape"),
135    25: None,
136    26: None,
137    27: (2, "lemon"),
138    28: None,
139    29: None,
140    30: None,
141    31: None,
142    32: (2, "seven"),
143    33: (2, "bar"),
144    34: None,
145    35: None,
146    36: None,
147    37: None,
148    38: (2, "grape"),
149    39: None,
150    40: None,
151    41: (2, "lemon"),
152    42: (2, "lemon"),
153    43: (3, "lemon"),
154    44: (2, "lemon"),
155    45: None,
156    46: None,
157    47: None,
158    48: (2, "seven"),
159    49: (2, "bar"),
160    50: None,
161    51: None,
162    52: None,
163    53: None,
164    54: (2, "grape"),
165    55: None,
166    56: None,
167    57: None,
168    58: None,
169    59: (2, "lemon"),
170    60: None,
171    61: (2, "seven"),
172    62: (2, "seven"),
173    63: (2, "seven"),
174    64: (3, "seven"),
175}
176
177win_table = {
178    (3, "seven"): 20,
179    (3, "bar"): 5,
180    (3, "lemon"): 3,
181    (3, "grape"): 2,
182    
183    (2, "seven"): 4,
184    (2, "bar"): 2,
185    (2, "lemon"): 1,
186    (2, "grape"): 0.5
187}