all repos — python-meme-bot @ 4ec29db74a8529fff0ce3f9439f7c333d4749e44

Telegram Bot that uses PIL to compute light image processing.

Constants.py (view raw)

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