From 83028183b6664c3f0ab4dd55efb4738d3767bfd3 Mon Sep 17 00:00:00 2001 From: mini <39670899+minisbett@users.noreply.github.com> Date: Fri, 29 Sep 2023 01:36:15 +0200 Subject: [PATCH] chore: remove experimental menu system (#535) * Remove experimental menu system * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/docs/wiki/Project-structure.md | 1 - .../locale/de-DE/Project-structure-de-DE.md | 1 - .../locale/zh-CN/Project-structure-zh-CN.md | 1 - app/api/domains/cho.py | 43 ------------- app/commands.py | 8 --- app/objects/__init__.py | 1 - app/objects/menu.py | 37 ----------- app/objects/player.py | 61 ------------------- 8 files changed, 153 deletions(-) delete mode 100644 app/objects/menu.py diff --git a/.github/docs/wiki/Project-structure.md b/.github/docs/wiki/Project-structure.md index 49699e3ec..ce568166a 100644 --- a/.github/docs/wiki/Project-structure.md +++ b/.github/docs/wiki/Project-structure.md @@ -34,7 +34,6 @@ | | ├── clan.py # representation of individual clans | | ├── collection.py # collections of dynamic objects (for in-memory storage) | | ├── match.py # individual multiplayer matches - | | ├── menu.py # (WIP) concept for interactive menus in chat channels | | ├── models.py # structures of api request bodies | | ├── player.py # representation of individual players | | └── score.py # representation of individual scores diff --git a/.github/docs/wiki/locale/de-DE/Project-structure-de-DE.md b/.github/docs/wiki/locale/de-DE/Project-structure-de-DE.md index 18fa9b5a9..30c59cdaa 100644 --- a/.github/docs/wiki/locale/de-DE/Project-structure-de-DE.md +++ b/.github/docs/wiki/locale/de-DE/Project-structure-de-DE.md @@ -34,7 +34,6 @@ | | ├── clan.py # Darstellung der einzelnen Clans | | ├── collection.py # Sammlungen von dynamischen Objekten (zur Speicherung im Speicher) | | ├── match.py # individuelle Multiplayer-Matches - | | ├── menu.py # (WIP) Konzept für interaktive Menüs in Chat-Kanälen | | ├── models.py # Strukturen von Api-Anfragekörpern | | ├── player.py # Darstellung der einzelnen Spieler | | └── score.py # Darstellung einzelner Spielstände diff --git a/.github/docs/wiki/locale/zh-CN/Project-structure-zh-CN.md b/.github/docs/wiki/locale/zh-CN/Project-structure-zh-CN.md index f9aa566b0..cd6dbfe13 100644 --- a/.github/docs/wiki/locale/zh-CN/Project-structure-zh-CN.md +++ b/.github/docs/wiki/locale/zh-CN/Project-structure-zh-CN.md @@ -34,7 +34,6 @@ | | ├── clan.py # 有关个人的地区(clans) | | ├── collection.py # 动态类的集合 (存储在内存中) | | ├── match.py # 多人比赛 - | | ├── menu.py # (-正在制作中-) 聊天频道中的交互菜单 | | ├── models.py # api请求主体(bodies)的结构 | | ├── player.py # 关于个人的players | | └── score.py # 有关个人的score diff --git a/app/api/domains/cho.py b/app/api/domains/cho.py index 2b409a802..9eab83b1e 100644 --- a/app/api/domains/cho.py +++ b/app/api/domains/cho.py @@ -48,9 +48,6 @@ from app.objects.match import MatchWinConditions from app.objects.match import Slot from app.objects.match import SlotStatus -from app.objects.menu import Menu -from app.objects.menu import MenuCommands -from app.objects.menu import MenuFunction from app.objects.player import Action from app.objects.player import ClientDetails from app.objects.player import OsuStream @@ -1370,36 +1367,6 @@ async def handle(self, player: Player) -> None: log(f"{player} created a new multiplayer match.") -async def execute_menu_option(player: Player, key: int) -> None: - if key not in player.current_menu.options: - return - - # this is one of their menu options, execute it. - cmd, data = player.current_menu.options[key] - - if app.settings.DEBUG: - print(f"\x1b[0;95m{cmd!r}\x1b[0m {data}") - - if cmd == MenuCommands.Reset: - # go back to the main menu - player.current_menu = player.previous_menus[0] - player.previous_menus.clear() - elif cmd == MenuCommands.Back: - # return one menu back - player.current_menu = player.previous_menus.pop() - player.send_current_menu() - elif cmd == MenuCommands.Advance: - # advance to a new menu - assert isinstance(data, Menu) - player.previous_menus.append(player.current_menu) - player.current_menu = data - player.send_current_menu() - elif cmd == MenuCommands.Execute: - # execute a function on the current menu - assert isinstance(data, MenuFunction) - await data.callback(player) - - @register(ClientPackets.JOIN_MATCH) class MatchJoin(BasePacket): def __init__(self, reader: BanchoPacketReader) -> None: @@ -1407,16 +1374,6 @@ def __init__(self, reader: BanchoPacketReader) -> None: self.match_passwd = reader.read_string() async def handle(self, player: Player) -> None: - is_menu_request = self.match_id >= 64 # max multi matches - - if is_menu_request or self.match_id < 0: - if is_menu_request: - # NOTE: this function is unrelated to mp. - await execute_menu_option(player, self.match_id) - - player.enqueue(app.packets.match_join_fail()) - return - match = app.state.sessions.matches[self.match_id] if not match: log(f"{player} tried to join a non-existant mp lobby?") diff --git a/app/commands.py b/app/commands.py index be180b116..a053a0922 100644 --- a/app/commands.py +++ b/app/commands.py @@ -1180,14 +1180,6 @@ async def wipemap(ctx: Context) -> str | None: return "Scores wiped." -@command(Privileges.DEVELOPER, hidden=True) -async def menu(ctx: Context) -> str | None: - """Temporary command to illustrate the menu option idea.""" - ctx.player.send_current_menu() - - return None - - @command(Privileges.DEVELOPER, aliases=["re"]) async def reload(ctx: Context) -> str | None: """Reload a python module.""" diff --git a/app/objects/__init__.py b/app/objects/__init__.py index a5b814724..3ece282b5 100644 --- a/app/objects/__init__.py +++ b/app/objects/__init__.py @@ -7,7 +7,6 @@ from . import clan from . import collections from . import match -from . import menu from . import models from . import player from . import score diff --git a/app/objects/menu.py b/app/objects/menu.py deleted file mode 100644 index fefe8a499..000000000 --- a/app/objects/menu.py +++ /dev/null @@ -1,37 +0,0 @@ -# note that this is still a very rough draft of -# the concept and is subject to major refactoring -from __future__ import annotations - -import random -from collections.abc import Awaitable -from collections.abc import Callable -from enum import IntEnum -from enum import unique -from typing import NamedTuple -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from app.objects.player import Player - - -@unique -class MenuCommands(IntEnum): - Reset = 0 # go to main menu - Back = 1 # go to previous menu - Advance = 2 # go to new menu - Execute = 3 # execute a function on current menu - - -class Menu(NamedTuple): - name: str - options: dict[int, tuple[MenuCommands, Menu | MenuFunction | None]] - - -class MenuFunction(NamedTuple): - name: str - callback: Callable[[Player], Awaitable[None]] - - -def menu_keygen() -> int: - return random.randint(64, 0x7FFFFFFF) # (max_matches, int32_max) diff --git a/app/objects/player.py b/app/objects/player.py index 6c504cab2..1b7ae2c1d 100644 --- a/app/objects/player.py +++ b/app/objects/player.py @@ -33,10 +33,6 @@ from app.objects.match import MatchTeamTypes from app.objects.match import Slot from app.objects.match import SlotStatus -from app.objects.menu import Menu -from app.objects.menu import menu_keygen -from app.objects.menu import MenuCommands -from app.objects.menu import MenuFunction from app.objects.score import Grade from app.repositories import stats as stats_repo from app.utils import escape_enum @@ -113,33 +109,6 @@ class Status: map_id: int = 0 -# temporary menu-related stuff -async def bot_hello(player: Player) -> None: - player.send_bot(f"hello {player.name}!") - - -async def notif_hello(player: Player) -> None: - player.enqueue(app.packets.notification(f"hello {player.name}!")) - - -MENU2 = Menu( - "Second Menu", - { - menu_keygen(): (MenuCommands.Back, None), - menu_keygen(): (MenuCommands.Execute, MenuFunction("notif_hello", notif_hello)), - }, -) - -MAIN_MENU = Menu( - "Main Menu", - { - menu_keygen(): (MenuCommands.Execute, MenuFunction("bot_hello", bot_hello)), - menu_keygen(): (MenuCommands.Execute, MenuFunction("notif_hello", notif_hello)), - menu_keygen(): (MenuCommands.Advance, MENU2), - }, -) - - class LastNp(TypedDict): bmap: Beatmap mode_vn: int @@ -312,10 +281,6 @@ def __init__( # store the last beatmap /np'ed by the user. self.last_np: LastNp | None = None - # TODO: document - self.current_menu = MAIN_MENU - self.previous_menus: list[Menu] = [] - # subject to possible change in the future, # although if anything, bot accounts will # probably just use the /api/ routes? @@ -1040,32 +1005,6 @@ async def stats_from_sql_full(self, db_conn: databases.core.Connection) -> None: }, ) - def send_menu_clear(self) -> None: - """Clear the user's osu! chat with the bot - to make room for a new menu to be sent.""" - # NOTE: the only issue with this is that it will - # wipe any messages the client can see from the bot - # (including any other channels). perhaps menus can - # be sent from a separate presence to prevent this? - self.enqueue(app.packets.user_silenced(app.state.sessions.bot.id)) - - def send_current_menu(self) -> None: - """Forward a standardized form of the user's - current menu to them via the osu! chat.""" - msg = [self.current_menu.name] - - for key, (cmd, data) in self.current_menu.options.items(): - val = data.name if data else "Back" - msg.append(f"[osump://{key}/ {val}]") - - chat_height = 10 - lines_used = len(msg) - if lines_used < chat_height: - msg += [chr(8192)] * (chat_height - lines_used) - - self.send_menu_clear() - self.send_bot("\n".join(msg)) - def update_latest_activity_soon(self) -> None: """Update the player's latest activity in the database.""" task = app.state.services.database.execute(