mirror of
https://github.com/house-of-vanity/doka2_info_bot.git
synced 2025-07-06 16:44:08 +00:00
Fix ordering. Add patch info.
This commit is contained in:
29
app.py
29
app.py
@ -45,8 +45,8 @@ def smart_append(line, text, lenght=4000):
|
||||
def shorten(text):
|
||||
max_len = 4000
|
||||
if len(text) > max_len:
|
||||
text = text[len(text)-max_len:]
|
||||
return 'Message too long...\n' + text
|
||||
text = 'Message too long...\n' + text[len(text)-max_len:]
|
||||
return text
|
||||
|
||||
def button(update, context):
|
||||
query = update.callback_query
|
||||
@ -68,11 +68,34 @@ def button(update, context):
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Back", callback_data='patches'),]])
|
||||
text = f'Patch *{patch}*\n'
|
||||
general_info = DB.get_general_history(patch)
|
||||
heroes_affected = DB.get_heroes_affected(patch)
|
||||
items_affected = DB.get_items_affected(patch)
|
||||
if len(general_info) == 0:
|
||||
text += f"There isn't general changes in {patch}\n"
|
||||
else:
|
||||
text += "*General changes:\n*"
|
||||
i = 1
|
||||
for change in general_info:
|
||||
text += f" {i} - {change[0]}\n"
|
||||
i += 1
|
||||
query.edit_message_text(text, parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
|
||||
if len(heroes_affected) == 0:
|
||||
text += f"There isn't heroes changed in {patch}"
|
||||
else:
|
||||
i = 1
|
||||
text += "*Heroes changed:\n*"
|
||||
for hero in heroes_affected:
|
||||
text += f" {i} - {hero[0]}\n"
|
||||
i += 1
|
||||
if len(items_affected) == 0:
|
||||
text += f"There isn't items changed in {patch}"
|
||||
else:
|
||||
i = 1
|
||||
text += "*Items changed:\n*"
|
||||
for item in items_affected:
|
||||
text += f" {i} - {item[0]}\n"
|
||||
i += 1
|
||||
|
||||
query.edit_message_text(shorten(text), parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
|
||||
if query.data.split('_')[0] == 'item':
|
||||
keyboard = [[InlineKeyboardButton("Back", callback_data='items')]]
|
||||
if 'expand' in query.data:
|
||||
|
27
database.py
27
database.py
@ -209,12 +209,33 @@ class DataBase:
|
||||
patches.append(patch[0])
|
||||
return patches
|
||||
|
||||
def get_items_affected(self, patch):
|
||||
patch = patch.replace("'", "''")
|
||||
patch = self.get_patch_id(patch)
|
||||
sql = f"""SELECT i.name FROM item_changes ic
|
||||
LEFT JOIN items i ON i.ROWID = ic.item
|
||||
WHERE ic.patch = {patch}
|
||||
GROUP BY i.name
|
||||
ORDER BY i.name"""
|
||||
return self.execute(sql)
|
||||
|
||||
def get_heroes_affected(self, patch):
|
||||
patch = patch.replace("'", "''")
|
||||
patch = self.get_patch_id(patch)
|
||||
sql = f"""SELECT h.name FROM hero_changes hc
|
||||
LEFT JOIN heroes h ON h.ROWID = hc.hero
|
||||
WHERE hc.patch = {patch}
|
||||
GROUP BY hero
|
||||
ORDER BY h.name"""
|
||||
return self.execute(sql)
|
||||
|
||||
def get_general_history(self, patch):
|
||||
patch = patch.replace("'", "''")
|
||||
patch = self.get_patch_id(patch)
|
||||
sql = f"""SELECT gc.info FROM general_changes gc
|
||||
LEFT JOIN patches p on p.ROWID = gc.patch
|
||||
WHERE gc.patch = '{patch}'"""
|
||||
WHERE gc.patch = '{patch}'
|
||||
ORDER BY p.version ASC"""
|
||||
return self.execute(sql)
|
||||
|
||||
def get_hero_history(self, hero):
|
||||
@ -228,7 +249,7 @@ class DataBase:
|
||||
LEFT JOIN patches p ON hc.patch = p.ROWID
|
||||
WHERE hc.hero = {hero}
|
||||
) a ON p.version = a.version
|
||||
ORDER BY p.rowid DESC;"""
|
||||
ORDER BY p.version ASC"""
|
||||
return self.execute(sql)
|
||||
|
||||
def get_item_history(self, item):
|
||||
@ -241,7 +262,7 @@ class DataBase:
|
||||
LEFT JOIN patches p ON p.rowid = ic.patch
|
||||
WHERE ic.item = {item}
|
||||
) a ON p.version = a.version
|
||||
ORDER BY p.rowid DESC"""
|
||||
ORDER BY p.version ASC"""
|
||||
return self.execute(sql)
|
||||
|
||||
def close(self, conn):
|
||||
|
Reference in New Issue
Block a user