@@ -135,6 +135,9 @@ def game_commands(bot, update):
135135
136136def error (bot , update , error ):
137137 """Log Errors caused by Updates."""
138+ if update is None :
139+ return
140+
138141 logger .warning ('Update "%s" caused error "%s"' , update , error )
139142
140143 db = DBwrapper .get_instance ()
@@ -203,7 +206,7 @@ def start_cmd(bot, update):
203206 if game .players [0 ].user_id == user_id :
204207 game .start_game ()
205208 else :
206- update . message .reply_text ("Only the creator can start the game" )
209+ message .reply_text ("Only the creator ({}) can start the game" . format ( game . players [ 0 ]. first_name ) )
207210
208211
209212def stop_cmd (bot , update ):
@@ -219,8 +222,6 @@ def stop_cmd(bot, update):
219222
220223def help_cmd (bot , update ):
221224 # Explains commands to user
222-
223- chat_id = update .message .chat_id
224225 db = DBwrapper .get_instance ()
225226 lang_id = db .get_lang_id (update .message .from_user .id )
226227
@@ -287,23 +288,21 @@ def language_cmd(bot, update):
287288 reply_markup = lang_keyboard , message_id = update .message .message_id )
288289
289290
290- def comment_cmd (bot , update ):
291+ def comment_cmd (bot , update , args ):
291292 user_id = update .message .from_user .id
292293 chat_id = update .message .chat_id
293294 first_name = update .message .from_user .first_name
294295 last_name = update .message .from_user .last_name
295296 username = update .message .from_user .username
296297 db = DBwrapper .get_instance ()
297298 lang_id = db .get_lang_id (user_id )
298- text = update .message .text
299- params = text .split ()
300299
301300 state_handler = StateHandler .get_instance ()
302301 user = state_handler .get_user (user_id )
303302
304303 if user .get_state () == UserState .IDLE :
305- if len (params ) > 1 :
306- text = " " .join (params [ 1 :] )
304+ if len (args ) > 1 :
305+ text = " " .join (args )
307306 logger .debug ("New comment! {}!" .format (user_id ))
308307
309308 bot .sendMessage (chat_id = chat_id , text = translate ("userComment" , lang_id ))
@@ -312,7 +311,6 @@ def comment_cmd(bot, update):
312311 "New comment:\n \n {}\n \n {} | {} | {} | @{} | {}" .format (text , user_id , first_name ,
313312 last_name , username ,
314313 lang_id ))
315- logger .debug ("Set {}'s state to IDLE!" .format (user_id ))
316314 user .set_state (UserState .IDLE )
317315 else :
318316 # The user just wrote "/comment" -> Ask him to send a message
@@ -345,9 +343,7 @@ def cancel_cmd(bot, update):
345343
346344def hide_cmd (bot , update ):
347345 """Hides the keyboard in the specified chat."""
348- chat_id = update .message .chat_id
349- reply_markup = ReplyKeyboardRemove ()
350- bot .sendMessage (chat_id = chat_id , text = "\U0001F44D " , reply_markup = reply_markup )
346+ update .message .reply_text ("\U0001F44D " , reply_markup = ReplyKeyboardRemove ())
351347
352348
353349def mentions_cmd (bot , update ):
@@ -444,7 +440,7 @@ def restart(bot, update):
444440hide_handler = CommandHandler ('hide' , hide_cmd )
445441stats_handler = CommandHandler ('stats' , stats_cmd )
446442language_handler = CommandHandler ('language' , language_cmd )
447- comment_handler = CommandHandler ('comment' , comment_cmd )
443+ comment_handler = CommandHandler ('comment' , comment_cmd , pass_args = True )
448444callback_handler = CallbackQueryHandler (callback_eval )
449445users_handler = CommandHandler ('users' , users )
450446answer_handler = CommandHandler ('answer' , answer )
0 commit comments