bugs module: fix bug url and add support for arguments

parent 88e289fc
...@@ -2,3 +2,4 @@ from . import start as start_keyboards ...@@ -2,3 +2,4 @@ from . import start as start_keyboards
from . import menu as menu_keyboards from . import menu as menu_keyboards
from . import profile as profile_keyboards from . import profile as profile_keyboards
from . import watch as watch_keyboards from . import watch as watch_keyboards
from . import bugs as bugs_keyboards
from telegrinder import InlineKeyboard, InlineButton
def bugs_more_kb(maintainer: str):
kb = InlineKeyboard()
kb.add(
InlineButton(
"Полный список",
url=f"https://packages.altlinux.org/ru/sisyphus/maintainers/{maintainer}/bugs",
)
)
return kb.get_markup()
from telegrinder import Dispatch, Message from telegrinder import Dispatch, Message
from telegrinder.rules import Command, Text, IsUser from telegrinder.rules import Command, Argument, Text, IsPrivate
from telegrinder.tools.formatting import HTMLFormatter from telegrinder.tools.formatting import HTMLFormatter
from api import api from api import api
from database.models import User from database.models import User
from data.keyboards import bugs_keyboards
from config import BUGS_URL from config import BUGS_URL
dp = Dispatch() dp = Dispatch()
dp.message.auto_rules = IsUser()
@dp.message(Command("bugs", Argument("maintainer", optional=True)))
@dp.message(Command("bugs") | Text(["bugs", "ошибки"], ignore_case=True)) @dp.message(Text(["bugs", "ошибки"], ignore_case=True), IsPrivate())
async def watch_handler(m: Message, user: User | None) -> None: async def watch_handler(m: Message, user: User | None, maintainer: str | None) -> None:
if user is None: if maintainer:
maintainer = maintainer.lower()
maintainer_data = await api.site.all_maintainers("sisyphus")
if not any(
_m.packager_nickname == maintainer for _m in maintainer_data.maintainers
):
await m.answer(f"Сопровождающий {maintainer} не найден.")
else:
if user:
maintainer = user.maintainer
else:
return return
bugs_data = await api.bug.bugzilla_by_maintainer(user.maintainer) bugs_data = await api.bug.bugzilla_by_maintainer(maintainer)
unresolved_bugs = [bug for bug in bugs_data.bugs if bug.status not in ["RESOLVED", "CLOSED"]] unresolved_bugs = [bug for bug in bugs_data.bugs if bug.status not in ["RESOLVED", "CLOSED"]]
if not len(unresolved_bugs): if not len(unresolved_bugs):
await m.answer( await m.answer(
"У вас нет открытых багов" "Нет открытых багов"
) )
return return
...@@ -34,10 +44,12 @@ async def watch_handler(m: Message, user: User | None) -> None: ...@@ -34,10 +44,12 @@ async def watch_handler(m: Message, user: User | None) -> None:
for i, bug in enumerate(unresolved_bugs): for i, bug in enumerate(unresolved_bugs):
if i == 20: if i == 20:
break break
bugs_message += HTMLFormatter(f"<a href='{BUGS_URL}/{bug.id}'>#{bug.id}</a>") + \ bugs_message += HTMLFormatter(f"<a href='{BUGS_URL}{bug.id}'>#{bug.id}</a>") + \
f" | {bug.product} - {bug.component} | {bug.severity}\n" f" | {bug.product} - {bug.component} | {bug.severity}\n"
markup = None
if len(unresolved_bugs) > 20: if len(unresolved_bugs) > 20:
bugs_message += "\n..." bugs_message += "\n..."
markup = bugs_keyboards.bugs_more_kb(maintainer)
await m.answer(bugs_message) await m.answer(bugs_message, reply_markup=markup)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment