From b2937ec62e178ae807a47484787f6038c9dbe75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 20 Dec 2024 14:40:55 +0100 Subject: [PATCH] Refactor event formatting to be maybe better --- app/Models/Event.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/Models/Event.php b/app/Models/Event.php index 2909f953f50..1a58e0372f3 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -92,11 +92,10 @@ public static function generate($type, $options) $userParams = static::userParams($options['beatmapset']->user); $approval = e($beatmapset->status()); - $textClean = "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}] by [{$userParams['url_clean']} {$userParams['username']}] has just been {$approval}!"; - + $template = '%s by %s has just been %s!'; $params = [ - 'text' => "{$beatmapsetParams['title']} by {$userParams['username']} has just been {$approval}!", - 'text_clean' => $textClean, + 'text' => sprintf($template, "{$beatmapsetParams['title']}", "{$userParams['username']}", $approval), + 'text_clean' => sprintf($template, "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]", "[{$userParams['url_clean']} {$userParams['username']}]", $approval), 'beatmap_id' => 0, 'beatmapset_id' => $beatmapset->getKey(), 'user_id' => $beatmapset->user->getKey(), @@ -125,11 +124,10 @@ public static function generate($type, $options) $beatmapsetParams = static::beatmapsetParams($beatmapset); $userParams = static::userParams($beatmapset->user); - $textClean = "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}] has been revived from eternal slumber by [{$userParams['url_clean']} {$userParams['username']}]."; - + $template = '%s has been revived from eternal slumber by %s.'; $params = [ - 'text' => "{$beatmapsetParams['title']} has been revived from eternal slumber by {$userParams['username']}.", - 'text_clean' => $textClean, + 'text' => sprintf($template, "{$beatmapsetParams['title']}", "{$userParams['username']}"), + 'text_clean' => sprintf($template, "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]", "[{$userParams['url_clean']} {$userParams['username']}]"), 'beatmapset_id' => $beatmapset->getKey(), 'user_id' => $beatmapset->user->getKey(), 'private' => false, @@ -146,11 +144,10 @@ public static function generate($type, $options) $user = $options['user']; $userParams = static::userParams($user); - $textClean = "[{$userParams['url_clean']} {$userParams['username']}] has updated the beatmap [{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]"; - + $template = '%s has updated the beatmap "%s"'; $params = [ - 'text' => "{$userParams['username']} has updated the beatmap \"{$beatmapsetParams['title']}\"", - 'text_clean' => $textClean, + 'text' => sprintf($template, "{$userParams['username']}", "{$beatmapsetParams['title']}"), + 'text_clean' => sprintf($template, "[{$userParams['url_clean']} {$userParams['username']}]", "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]"), 'beatmapset_id' => $beatmapset->getKey(), 'user_id' => $user->getKey(), 'private' => false, @@ -164,11 +161,10 @@ public static function generate($type, $options) $beatmapsetParams = static::beatmapsetParams($beatmapset); $userParams = static::userParams($beatmapset->user); - $textClean = "[{$userParams['url_clean']} {$userParams['username']}] has submitted a new beatmap [{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]"; - + $template = '%s has submitted a new beatmap "%s"'; $params = [ - 'text' => "{$userParams['username']} has submitted a new beatmap \"{$beatmapsetParams['title']}\"", - 'text_clean' => $textClean, + 'text' => sprintf($template, "{$userParams['username']}", "{$beatmapsetParams['title']}"), + 'text_clean' => sprintf($template, "[{$userParams['url_clean']} {$userParams['username']}]", "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]"), 'beatmapset_id' => $beatmapset->getKey(), 'user_id' => $beatmapset->user->getKey(), 'private' => false,