Better logging, sql related patches
This commit is contained in:
parent
b5bd9f262a
commit
12602f9f84
@ -39,6 +39,8 @@ class Help(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
|
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton("All commands", callback_data="all"),
|
InlineKeyboardButton("All commands", callback_data="all"),
|
||||||
|
@ -40,6 +40,7 @@ class Lists(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
lists = self.db.lists.select()
|
lists = self.db.lists.select()
|
||||||
sl = [l.name for l in lists]
|
sl = [l.name for l in lists]
|
||||||
keyboard = [[InlineKeyboardButton(k, callback_data="list-"+k)] for k in sl] + [[InlineKeyboardButton("New list", callback_data="new")]]
|
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 = update.callback_query
|
||||||
query.answer()
|
query.answer()
|
||||||
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
||||||
content = it.content.split("<-->")
|
if it:
|
||||||
content = "\n".join(content)
|
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")]]
|
keyboard = [[InlineKeyboardButton("Add an item", callback_data="add"), InlineKeyboardButton("Back to the menu", callback_data="overview")]]
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
query.edit_message_text("Content of " + self.current_name + ":\n" + content, reply_markup=reply_markup)
|
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:
|
def list_add_item(self, update: Update, context: CallbackContext) -> None:
|
||||||
item = update.message.text
|
item = update.message.text
|
||||||
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
||||||
sl = it.content
|
if it:
|
||||||
|
sl = it.content
|
||||||
|
else:
|
||||||
|
sl = ""
|
||||||
sl += item + "<-->"
|
sl += item + "<-->"
|
||||||
self.db.lists.update(content=sl).where(self.db.lists.name == self.current_name).execute()
|
self.db.lists.update(content=sl).where(self.db.lists.name == self.current_name).execute()
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ class Plain(BotFunc):
|
|||||||
return h
|
return h
|
||||||
|
|
||||||
def add_to_log(self, update: Update, context: CallbackContext) -> None:
|
def add_to_log(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
super().log_activity(
|
super().log_activity(
|
||||||
read = True,
|
read = True,
|
||||||
send = False,
|
send = False,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from re import U
|
||||||
from .template import *
|
from .template import *
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class Joke(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
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)]]
|
keyboard = [[InlineKeyboardButton(str(i), callback_data=str(i)) for i in range(1,11)]]
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
super().log_activity(read=True, execute=True, send=True) # at this point every step has been fulfilled
|
super().log_activity(read=True, execute=True, send=True) # at this point every step has been fulfilled
|
||||||
|
@ -25,7 +25,7 @@ class Search(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
update.message.reply_text("What are we searching?")
|
update.message.reply_text("What are we searching?")
|
||||||
return SEARCH
|
return SEARCH
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class Status(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton("And the log?", callback_data="full"),
|
InlineKeyboardButton("And the log?", callback_data="full"),
|
||||||
|
@ -23,14 +23,22 @@ class BotFunc():
|
|||||||
|
|
||||||
def log_activity(self, **kwargs):
|
def log_activity(self, **kwargs):
|
||||||
# mark that a new command has been executed
|
# mark that a new command has been executed
|
||||||
data = self.db.chats(
|
try:
|
||||||
time=datetime.datetime.now(),
|
data = self.db.chats(
|
||||||
**kwargs
|
time=datetime.datetime.now(),
|
||||||
)
|
**kwargs
|
||||||
# kwargs can look like
|
)
|
||||||
# receive=True,
|
# kwargs can look like
|
||||||
# execute=True,
|
# receive=True,
|
||||||
# send=False,
|
# execute=True,
|
||||||
data.save()
|
# 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))
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class Weather(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
"""Reacts the call of the command. Prints the first buttons"""
|
"""Reacts the call of the command. Prints the first buttons"""
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
|
@ -27,6 +27,7 @@ class Zvv(BotFunc):
|
|||||||
|
|
||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
super().entry_point(update, context)
|
||||||
update.message.reply_text("What is the start point?")
|
update.message.reply_text("What is the start point?")
|
||||||
return START
|
return START
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ class DBModel(Model):
|
|||||||
logger.error(e)
|
logger.error(e)
|
||||||
# db.atomic().rollback()
|
# db.atomic().rollback()
|
||||||
|
|
||||||
def get(self, *query, **filters):
|
# def get(self, *query, **filters):
|
||||||
try:
|
# try:
|
||||||
return super().get(*query, **filters)
|
# return super().get(*query, **filters)
|
||||||
except:
|
# except Exception as e:
|
||||||
logger.error("Error while 'getting' from db.")
|
# logger.error("Error while executing get: {}".format(e))
|
||||||
print(query, filters)
|
# print(query, filters)
|
||||||
|
|
||||||
|
|
||||||
class Metric(DBModel):
|
class Metric(DBModel):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user