Skip to content

Commit cd822db

Browse files
committed
Merge pull request #45 from d-Rickyy-b/bugfixes
Bugfixes
2 parents 6a2ff14 + 0e6168d commit cd822db

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

lang/language.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import os
66

77
__author__ = 'Rico'
8+
dir_path = os.path.dirname(os.path.abspath(__file__))
9+
file_path = os.path.join(dir_path, "translations.ini")
810

9-
path = os.path.dirname(os.path.abspath(__file__))
1011
translations = configparser.ConfigParser()
11-
translations.read_file(codecs.open(path + "/translations.ini", "r", "UTF-8"))
12+
translations.read_file(codecs.open(file_path, encoding="UTF-8"))
1213

1314

1415
# translate returns the translation for a specific string

main.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, MessageHandler, Filters
77
from telegram.inline.inlinekeyboardbutton import InlineKeyboardButton
88
from telegram.inline.inlinekeyboardmarkup import InlineKeyboardMarkup
9-
from telegram.keyboardbutton import KeyboardButton
10-
from telegram.replykeyboardmarkup import ReplyKeyboardMarkup
9+
from telegram import ReplyKeyboardRemove
1110

1211
from database.db_wrapper import DBwrapper
1312
from database.statistics import get_user_stats
@@ -24,7 +23,7 @@
2423
logger = logging.getLogger(__name__)
2524
logging.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

@@ -36,7 +35,7 @@
3635
lang_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

190189
def 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+
237242
def 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+
258264
def 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)
329336
callback_handler = CallbackQueryHandler(callback_eval)
330-
comment_handler = CommandHandler('comment', comment)
337+
comment_handler = CommandHandler('comment', comment_cmd)
331338
cancel_handler = CommandHandler(get_translations_of_string("cancel"), cancel)
332339
answer_handler = CommandHandler('answer', answer)
333340

@@ -346,6 +353,7 @@ def get_translations_of_string(string):
346353
dispatcher.add_handler(join_sec)
347354
dispatcher.add_handler(comment_handler)
348355
dispatcher.add_handler(cancel_handler)
356+
dispatcher.add_handler(hide_handler)
349357
dispatcher.add_handler(game_command_handler)
350358

351359
updater.start_polling()

tests/test_blackJack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest import TestCase
44

55
from database.db_wrapper import DBwrapper
6+
from game.blackJack import BlackJack
67

78

89
class TestBlackJack(TestCase):
@@ -179,7 +180,7 @@ def pick_one_card(self):
179180
return card
180181

181182
def get_card_name(self, card):
182-
symbol = self.symbols[card//13]
183+
symbol = self.symbols[card // 13]
183184
value = self.value_str[card % 13]
184185
card_name = "|" + symbol + " " + value + "|"
185186
return card_name

userstate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
34
class UserState(object):
45
IDLE = 0
56
COMMENTING = 1

0 commit comments

Comments
 (0)