diff --git a/bemani/backend/popn/base.py b/bemani/backend/popn/base.py index a52af3d..f7d66ba 100644 --- a/bemani/backend/popn/base.py +++ b/bemani/backend/popn/base.py @@ -3,7 +3,7 @@ from typing import Dict, Optional, Sequence from bemani.backend.base import Base from bemani.backend.core import CoreHandler, CardManagerHandler, PASELIHandler -from bemani.common import Profile, ValidatedDict, Time, GameConstants, DBConstants +from bemani.common import Profile, ValidatedDict, Time, GameConstants, DBConstants, BroadcastConstants from bemani.data import UserID, Achievement, ScoreSaveException from bemani.protocol import Node @@ -289,3 +289,47 @@ class PopnMusicBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): # We saved successfully break + + def broadcast_score(self, userid: int, songid: int, chart: int, medal: int, points: int, combo: int, stats: Dict[str,int]) -> None: + # Generate scorecard + profile = self.get_profile(userid) + song = self.data.local.music.get_song(self.game, self.version, songid, chart) + + card_medal = { + self.PLAY_MEDAL_CIRCLE_FAILED: 'Failed', + self.PLAY_MEDAL_DIAMOND_FAILED: 'Failed', + self.PLAY_MEDAL_STAR_FAILED: 'Failed', + self.PLAY_MEDAL_EASY_CLEAR: 'Cleared', + self.PLAY_MEDAL_CIRCLE_CLEARED: 'Cleared', + self.PLAY_MEDAL_DIAMOND_CLEARED: 'Cleared', + self.PLAY_MEDAL_STAR_CLEARED: 'Cleared', + self.PLAY_MEDAL_CIRCLE_FULL_COMBO: 'Full Combo', + self.PLAY_MEDAL_DIAMOND_FULL_COMBO: 'Full Combo', + self.PLAY_MEDAL_STAR_FULL_COMBO: 'Full Combo', + self.PLAY_MEDAL_PERFECT: 'Perfect', + }[medal] + + card_chart = { + self.CHART_TYPE_EASY: 'Easy', + self.CHART_TYPE_NORMAL: 'Normal', + self.CHART_TYPE_HYPER: 'Hyper', + self.CHART_TYPE_EX: 'Ex', + }[chart] + + # Construct the dictionary for the broadcast + card_data = { + BroadcastConstants.PLAYER_NAME: profile.get_str('name', 'なし'), + BroadcastConstants.SONG_NAME: song.name, + BroadcastConstants.ARTIST_NAME: song.artist, + BroadcastConstants.DIFFICULTY: card_chart, + BroadcastConstants.SCORE: points, + BroadcastConstants.MEDAL: card_medal, + BroadcastConstants.COOLS: stats['cool'], + BroadcastConstants.GREATS: stats['great'], + BroadcastConstants.GOODS: stats['good'], + BroadcastConstants.BADS: stats['bad'], + BroadcastConstants.COMBO: combo, + } + + # Try to broadcast out the score to our webhook(s) + self.data.triggers.broadcast_score(card_data, self.game, song) diff --git a/bemani/backend/popn/eclale.py b/bemani/backend/popn/eclale.py index 53b1a63..bda2165 100644 --- a/bemani/backend/popn/eclale.py +++ b/bemani/backend/popn/eclale.py @@ -435,6 +435,10 @@ class PopnMusicEclale(PopnMusicBase): self.GAME_PLAY_MEDAL_PERFECT: self.PLAY_MEDAL_PERFECT, }[medal] self.update_score(userid, songid, chart, points, medal, combo=combo, stats=stats) + + if request.child_value('is_image_store') == 1: + self.broadcast_score(userid, songid, chart, medal, combo, stats) + return root def format_conversion(self, userid: UserID, profile: Profile) -> Node: @@ -551,6 +555,11 @@ class PopnMusicEclale(PopnMusicBase): account.add_child(Node.s16('total_days', statistics.total_days)) account.add_child(Node.s16('interval_day', 0)) + # eAmuse account link + eaappli = Node.void('eaappli') + root.add_child(eaappli) + eaappli.add_child(Node.s8('relation', 1)) + # Set up info node info = Node.void('info') root.add_child(info) diff --git a/bemani/backend/popn/usaneko.py b/bemani/backend/popn/usaneko.py index aecf89d..2b2f951 100644 --- a/bemani/backend/popn/usaneko.py +++ b/bemani/backend/popn/usaneko.py @@ -686,6 +686,10 @@ class PopnMusicUsaNeko(PopnMusicBase): self.GAME_PLAY_MEDAL_PERFECT: self.PLAY_MEDAL_PERFECT, }[medal] self.update_score(userid, songid, chart, points, medal, combo=combo, stats=stats) + + if request.child_value('is_image_store') == 1: + self.broadcast_score(userid, songid, chart, medal, combo, stats) + return root def handle_player24_start_request(self, request: Node) -> Node: @@ -922,7 +926,7 @@ class PopnMusicUsaNeko(PopnMusicBase): # eAmuse account link eaappli = Node.void('eaappli') root.add_child(eaappli) - eaappli.add_child(Node.s8('relation', -1)) + eaappli.add_child(Node.s8('relation', 1)) # Player info info = Node.void('info') diff --git a/bemani/common/constants.py b/bemani/common/constants.py index 60fd2f3..0cf472d 100644 --- a/bemani/common/constants.py +++ b/bemani/common/constants.py @@ -314,3 +314,10 @@ class BroadcastConstants(Enum): FASTS: Final[str] = 'Fast' GRADE: Final[str] = 'Grade' RATE: Final[str] = 'Score Rate' + + # Added for Pnm + PLAYER_NAME: Final[str] = 'Player Name' + SCORE: Final[str] = 'Your Score' + COOLS: Final[str] = 'Cools' + COMBO: Final[str] = 'Combo' + MEDAL: Final[str] = 'Medal' diff --git a/bemani/data/triggers.py b/bemani/data/triggers.py index 36801c7..7343f9b 100644 --- a/bemani/data/triggers.py +++ b/bemani/data/triggers.py @@ -33,7 +33,7 @@ class Triggers: self.broadcast_score_discord(data, game, song) def broadcast_score_discord(self, data: Dict[BroadcastConstants, str], game: GameConstants, song: Song) -> None: - if game == GameConstants.IIDX: + if game in [GameConstants.IIDX, GameConstants.POPN_MUSIC] : now = datetime.now() webhook = DiscordWebhook(url=self.config.webhooks.discord[game]) @@ -45,7 +45,7 @@ class Triggers: scoreembed.set_author(name=self.config.name, url=song_url) for item, value in data.items(): inline = True - if item in {BroadcastConstants.DJ_NAME, BroadcastConstants.SONG_NAME, BroadcastConstants.ARTIST_NAME, BroadcastConstants.PLAY_STATS_HEADER}: + if item in {BroadcastConstants.DJ_NAME, BroadcastConstants.PLAYER_NAME, BroadcastConstants.SONG_NAME, BroadcastConstants.ARTIST_NAME, BroadcastConstants.PLAY_STATS_HEADER}: inline = False scoreembed.add_embed_field(name=item.value, value=value, inline=inline) webhook.add_embed(scoreembed) diff --git a/bemani/frontend/popn/endpoints.py b/bemani/frontend/popn/endpoints.py index 3bea7a3..e318609 100644 --- a/bemani/frontend/popn/endpoints.py +++ b/bemani/frontend/popn/endpoints.py @@ -15,7 +15,7 @@ from bemani.frontend.types import g popn_pages = Blueprint( 'popn_pages', __name__, - url_prefix='/popn', + url_prefix='/pnm', template_folder=templates_location, static_folder=static_location, ) diff --git a/config/server.yaml b/config/server.yaml index 2c738d4..dbc05b9 100644 --- a/config/server.yaml +++ b/config/server.yaml @@ -40,7 +40,8 @@ webhooks: discord: iidx: - "https://discord.com/api/webhooks/1232122131321321321/eauihfafaewfhjaveuijaewuivhjawueihoi" - + pnm: + - "https://discord.com/api/webhooks/1232122131321321321/eauihfafaewfhjaveuijaewuivhjawueihoi" paseli: # Whether PASELI is enabled on the network. enabled: True