diff --git a/bot/commands/help.py b/bot/commands/help.py index d96949c..6f7ccc6 100644 --- a/bot/commands/help.py +++ b/bot/commands/help.py @@ -39,6 +39,8 @@ class Help(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: + super().entry_point(update, context) + keyboard = [ [ InlineKeyboardButton("All commands", callback_data="all"), diff --git a/bot/commands/lists.py b/bot/commands/lists.py index 8dbe771..5355701 100644 --- a/bot/commands/lists.py +++ b/bot/commands/lists.py @@ -40,6 +40,7 @@ class Lists(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: + super().entry_point(update, context) lists = self.db.lists.select() sl = [l.name for l in lists] keyboard = [[InlineKeyboardButton(k, callback_data="list-"+k)] for k in sl] + [[InlineKeyboardButton("New list", callback_data="new")]] @@ -151,8 +152,12 @@ class Lists(BotFunc): query = update.callback_query query.answer() it = self.db.lists.get(self.db.lists.name == self.current_name) - content = it.content.split("<-->") - content = "\n".join(content) + if it: + content = it.content.split("<-->") + content = "\n".join(content) + else: + content = "List empty" + keyboard = [[InlineKeyboardButton("Add an item", callback_data="add"), InlineKeyboardButton("Back to the menu", callback_data="overview")]] reply_markup = InlineKeyboardMarkup(keyboard) query.edit_message_text("Content of " + self.current_name + ":\n" + content, reply_markup=reply_markup) @@ -162,7 +167,10 @@ class Lists(BotFunc): def list_add_item(self, update: Update, context: CallbackContext) -> None: item = update.message.text it = self.db.lists.get(self.db.lists.name == self.current_name) - sl = it.content + if it: + sl = it.content + else: + sl = "" sl += item + "<-->" self.db.lists.update(content=sl).where(self.db.lists.name == self.current_name).execute() diff --git a/bot/commands/plaintext.py b/bot/commands/plaintext.py index 55a74be..60e4942 100644 --- a/bot/commands/plaintext.py +++ b/bot/commands/plaintext.py @@ -11,6 +11,7 @@ class Plain(BotFunc): return h def add_to_log(self, update: Update, context: CallbackContext) -> None: + super().entry_point(update, context) super().log_activity( read = True, send = False, diff --git a/bot/commands/reddit.py b/bot/commands/reddit.py index 88c10e0..cab6dc4 100644 --- a/bot/commands/reddit.py +++ b/bot/commands/reddit.py @@ -1,3 +1,4 @@ +from re import U from .template import * @@ -24,7 +25,7 @@ class Joke(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: - + super().entry_point(update, context) keyboard = [[InlineKeyboardButton(str(i), callback_data=str(i)) for i in range(1,11)]] reply_markup = InlineKeyboardMarkup(keyboard) super().log_activity(read=True, execute=True, send=True) # at this point every step has been fulfilled diff --git a/bot/commands/search.py b/bot/commands/search.py index ac3ab66..ae91270 100644 --- a/bot/commands/search.py +++ b/bot/commands/search.py @@ -25,7 +25,7 @@ class Search(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: - + super().entry_point(update, context) update.message.reply_text("What are we searching?") return SEARCH diff --git a/bot/commands/status.py b/bot/commands/status.py index ffe2da1..bbd4f34 100644 --- a/bot/commands/status.py +++ b/bot/commands/status.py @@ -33,6 +33,7 @@ class Status(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: + super().entry_point(update, context) keyboard = [ [ InlineKeyboardButton("And the log?", callback_data="full"), diff --git a/bot/commands/template.py b/bot/commands/template.py index 33477fc..ad174e4 100644 --- a/bot/commands/template.py +++ b/bot/commands/template.py @@ -23,14 +23,22 @@ class BotFunc(): def log_activity(self, **kwargs): # mark that a new command has been executed - data = self.db.chats( - time=datetime.datetime.now(), - **kwargs - ) - # kwargs can look like - # receive=True, - # execute=True, - # send=False, - data.save() + try: + data = self.db.chats( + time=datetime.datetime.now(), + **kwargs + ) + # kwargs can look like + # receive=True, + # execute=True, + # send=False, + data.save() + except Exception as e: + self.logger.error("sql error: {}".format(e)) + def entry_point(self, update: Update, context: CallbackContext) -> None: + if update.message.text: + self.logger.info("Chat said: {}".format(update.message.text)) + else: + self.logger.info("Chat said: {}".format(update.message)) diff --git a/bot/commands/weather.py b/bot/commands/weather.py index e524303..dea6789 100644 --- a/bot/commands/weather.py +++ b/bot/commands/weather.py @@ -30,6 +30,7 @@ class Weather(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: + super().entry_point(update, context) """Reacts the call of the command. Prints the first buttons""" keyboard = [ [ diff --git a/bot/commands/zvv.py b/bot/commands/zvv.py index 6c7cef1..23a89d9 100644 --- a/bot/commands/zvv.py +++ b/bot/commands/zvv.py @@ -27,6 +27,7 @@ class Zvv(BotFunc): def entry_point(self, update: Update, context: CallbackContext) -> None: + super().entry_point(update, context) update.message.reply_text("What is the start point?") return START diff --git a/persistence/models.py b/persistence/models.py index f37cc17..0fc0303 100644 --- a/persistence/models.py +++ b/persistence/models.py @@ -39,12 +39,12 @@ class DBModel(Model): logger.error(e) # db.atomic().rollback() - def get(self, *query, **filters): - try: - return super().get(*query, **filters) - except: - logger.error("Error while 'getting' from db.") - print(query, filters) + # def get(self, *query, **filters): + # try: + # return super().get(*query, **filters) + # except Exception as e: + # logger.error("Error while executing get: {}".format(e)) + # print(query, filters) class Metric(DBModel):