66from telegram .ext import Updater , CommandHandler , CallbackQueryHandler , MessageHandler , Filters
77from telegram .inline .inlinekeyboardbutton import InlineKeyboardButton
88from telegram .inline .inlinekeyboardmarkup import InlineKeyboardMarkup
9- from telegram .keyboardbutton import KeyboardButton
10- from telegram .replykeyboardmarkup import ReplyKeyboardMarkup
9+ from telegram import ReplyKeyboardRemove
1110
1211from database .db_wrapper import DBwrapper
1312from database .statistics import get_user_stats
2423logger = logging .getLogger (__name__ )
2524logging .basicConfig (format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' , level = logging .DEBUG )
2625
27- if not re .match ("[0-9]+\ :[a-zA-Z0-9\-\ _]+" , BOT_TOKEN ):
26+ if not re .match ("[0-9]+:[a-zA-Z0-9\-_]+" , BOT_TOKEN ):
2827 logging .error ("Bot token not correct - please check." )
2928 exit (1 )
3029
3635lang_list = ["de" , "en" , "nl" , "eo" , "br" , "es" , "ru" , "fa" ]
3736
3837
39- def start (bot , update ):
38+ def start_cmd (bot , update ):
4039 chat_id = update .message .chat_id
4140 user_id = update .message .from_user .id
4241 message_id = update .message .message_id
@@ -53,7 +52,7 @@ def start(bot, update):
5352 db .add_user (user_id , "en" , first_name , last_name , username )
5453 if chat_id > 0 :
5554 # ask user for language:
56- language (bot , update )
55+ language_cmd (bot , update )
5756 return
5857
5958 # check if user already has got a game (in the same chat):
@@ -105,7 +104,7 @@ def join_secret(bot, update):
105104 # TODO send message that user joined
106105
107106
108- def stop (bot , update ):
107+ def stop_cmd (bot , update ):
109108 user_id = update .message .from_user .id
110109 state_handler = StateHandler .get_instance ()
111110 user = state_handler .get_user (user_id )
@@ -120,11 +119,11 @@ def help_def(bot, update):
120119 pass
121120
122121
123- def stats (bot , update ):
122+ def stats_cmd (bot , update ):
124123 bot .sendMessage (chat_id = update .message .chat_id , text = get_user_stats (update .message .from_user .id ))
125124
126125
127- def language (bot , update ):
126+ def language_cmd (bot , update ):
128127 lang_de_button = InlineKeyboardButton (text = "Deutsch \U0001F1E9 \U0001F1EA " , callback_data = "ch_lang_de" )
129128 lang_en_button = InlineKeyboardButton (text = "Englisch \U0001F1FA \U0001F1F8 " , callback_data = "ch_lang_en" )
130129 lang_nl_button = InlineKeyboardButton (text = "Nederlands \U0001F1F3 \U0001F1F1 " , callback_data = "ch_lang_nl" )
@@ -150,7 +149,7 @@ def language(bot, update):
150149 reply_markup = lang_keyboard , message_id = update .message .message_id )
151150
152151
153- def comment (bot , update ):
152+ def comment_cmd (bot , update ):
154153 user_id = update .message .from_user .id
155154 chat_id = update .message .chat_id
156155 first_name = update .message .from_user .first_name
@@ -188,10 +187,10 @@ def comment(bot, update):
188187
189188
190189def cancel (bot , update ):
191- user_id = update .callback_query . from_user .id
192- message_id = update .callback_query . message .message_id
190+ user_id = update .effective_user .id
191+ message_id = update .effective_message .message_id
193192 callback_query_id = update .callback_query .id
194- chat_id = update .message . chat_id
193+ chat_id = update .effective_chat . id
195194
196195 state_handler = StateHandler .get_instance ()
197196 user = state_handler .get_user (user_id )
@@ -234,6 +233,12 @@ def mentions(bot, update):
234233 pass
235234
236235
236+ def hide_cmd (bot , update ):
237+ chat_id = update .message .chat_id
238+ reply_markup = ReplyKeyboardRemove ()
239+ bot .sendMessage (chat_id = chat_id , text = "\U0001F44D " , reply_markup = reply_markup )
240+
241+
237242def change_language (bot , update , lang_id ):
238243 bot .editMessageText (chat_id = update .callback_query .message .chat_id , text = translate ("langChanged" , lang_id ),
239244 message_id = update .callback_query .message .message_id , reply_markup = None )
@@ -250,11 +255,12 @@ def callback_eval(bot, update):
250255 change_language (bot = bot , update = update , lang_id = lang_id )
251256
252257 elif query_data == "com_ch_lang" :
253- language (bot , update )
258+ language_cmd (bot , update )
254259
255260 elif query_data == "cancel_comment" :
256261 cancel (bot , update )
257262
263+
258264def send_message (chat_id , text , message_id = None , parse_mode = None , reply_markup = None , game_id = None ):
259265 tg_bot .sendMessage (chat_id = chat_id , text = text , reply_to_message_id = message_id , parse_mode = parse_mode ,
260266 reply_markup = reply_markup )
@@ -301,7 +307,7 @@ def game_commands(bot, update):
301307
302308 if chat_id > 0 :
303309 # ask user for language if it's a private chat:
304- language (bot , update )
310+ language_cmd (bot , update )
305311
306312 return
307313
@@ -322,12 +328,13 @@ def get_translations_of_string(string):
322328 return strings
323329
324330
325- start_handler = CommandHandler (get_translations_of_string ("startCmd" ), start )
326- stop_handler = CommandHandler (get_translations_of_string ("stopCmd" ), stop )
327- stats_handler = CommandHandler ('stats' , stats )
328- language_handler = CommandHandler ('language' , language )
331+ start_handler = CommandHandler (get_translations_of_string ("startCmd" ), start_cmd )
332+ stop_handler = CommandHandler (get_translations_of_string ("stopCmd" ), stop_cmd )
333+ hide_handler = CommandHandler ('hide' , hide_cmd )
334+ stats_handler = CommandHandler ('stats' , stats_cmd )
335+ language_handler = CommandHandler ('language' , language_cmd )
329336callback_handler = CallbackQueryHandler (callback_eval )
330- comment_handler = CommandHandler ('comment' , comment )
337+ comment_handler = CommandHandler ('comment' , comment_cmd )
331338cancel_handler = CommandHandler (get_translations_of_string ("cancel" ), cancel )
332339answer_handler = CommandHandler ('answer' , answer )
333340
@@ -346,6 +353,7 @@ def get_translations_of_string(string):
346353dispatcher .add_handler (join_sec )
347354dispatcher .add_handler (comment_handler )
348355dispatcher .add_handler (cancel_handler )
356+ dispatcher .add_handler (hide_handler )
349357dispatcher .add_handler (game_command_handler )
350358
351359updater .start_polling ()
0 commit comments