all repos — python-meme-bot @ 3447e9999bfc6f5306b43b6575f6661d42f41bd3

Telegram Bot that uses PIL to compute light image processing.

python-meme-bot/constants.py (view raw)

  1from telegram import InlineKeyboardMarkup, InlineKeyboardButton, User, Chat
  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.2f}$ 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.2f}€ 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: User):
 89    if user.username is not None:
 90        return user.full_name + f" ({user.username})"
 91    return user.full_name
 92
 93def format_chat(chat: Chat):
 94    return chat.title + ("" if chat.username is None else f" ({chat.username})")
 95
 96def get_lang(context: CallbackContext):
 97    try:
 98        return context.chat_data["lang"]
 99    except KeyError:
100        context.chat_data["lang"] = default_lang
101        return default_lang
102
103def get_localized_string(text:str, context:CallbackContext):
104    lang = get_lang(context)
105    
106    try:
107        return localization[lang][text]
108    except KeyError:
109        logging.error("No text was found.")
110        return "localization error {}{}{}{}{}{}"
111
112slot_machine_value = {
113    1: (3, "bar"),
114    2: (2, "bar"),
115    3: (2, "bar"),
116    4: (2, "bar"),
117    5: None,
118    6: (2, "grape"),
119    7: None,
120    8: None,
121    9: None,
122    10: None,
123    11: (2, "lemon"),
124    12: None,
125    13: None,
126    14: None,
127    15: None,
128    16: (2, "seven"),
129    17: (2, "bar"),
130    18: None,
131    19: None,
132    20: None,
133    21: (2, "grape"),
134    22: (3, "grape"),
135    23: (2, "grape"),
136    24: (2, "grape"),
137    25: None,
138    26: None,
139    27: (2, "lemon"),
140    28: None,
141    29: None,
142    30: None,
143    31: None,
144    32: (2, "seven"),
145    33: (2, "bar"),
146    34: None,
147    35: None,
148    36: None,
149    37: None,
150    38: (2, "grape"),
151    39: None,
152    40: None,
153    41: (2, "lemon"),
154    42: (2, "lemon"),
155    43: (3, "lemon"),
156    44: (2, "lemon"),
157    45: None,
158    46: None,
159    47: None,
160    48: (2, "seven"),
161    49: (2, "bar"),
162    50: None,
163    51: None,
164    52: None,
165    53: None,
166    54: (2, "grape"),
167    55: None,
168    56: None,
169    57: None,
170    58: None,
171    59: (2, "lemon"),
172    60: None,
173    61: (2, "seven"),
174    62: (2, "seven"),
175    63: (2, "seven"),
176    64: (3, "seven"),
177}
178
179win_table = {
180    (3, "seven"): 20,
181    (3, "bar"): 5,
182    (3, "lemon"): 3,
183    (3, "grape"): 2,
184    
185    (2, "seven"): 2,
186    (2, "bar"): 1,
187    (2, "lemon"): 0.5,
188    (2, "grape"): 0.3
189}