Skip to content

Commit

Permalink
Merge branch 'master' into api/get-comments-descending
Browse files Browse the repository at this point in the history
  • Loading branch information
ioslife authored Jan 30, 2025
2 parents 81a3b27 + 5ba697d commit cf537ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ DISCORD_INVITE_ID=
# public feeds
DISCORD_WEBHOOK_ACHIEVEMENTS=
DISCORD_WEBHOOK_CLAIMS=
DISCORD_WEBHOOK_NAME_CHANGES=
DISCORD_WEBHOOK_NEWS=
DISCORD_WEBHOOK_USERS=
# moderation feeds
Expand Down
27 changes: 27 additions & 0 deletions app/Community/Actions/ApproveNewDisplayNameAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

use App\Models\User;
use App\Models\UserUsername;
use GuzzleHttp\Client;
use Throwable;

class ApproveNewDisplayNameAction
{
public function execute(User $user, UserUsername $changeRequest): void
{
$oldDisplayName = $user->display_name;

// Automatically mark conflicting requests as denied.
UserUsername::where('username', $changeRequest->username)
->where('id', '!=', $changeRequest->id)
Expand All @@ -24,5 +28,28 @@ public function execute(User $user, UserUsername $changeRequest): void
$user->save();

sendDisplayNameChangeConfirmationEmail($user, $changeRequest->username);

$this->notifyDiscord($user, $oldDisplayName, $changeRequest->username);
}

private function notifyDiscord(User $user, string $oldName, string $newName): void
{
$webhookUrl = config('services.discord.webhook.name-changes');

if (!$webhookUrl) {
return;
}

$profileUrl = "https://retroachievements.org/user/{$user->username}";
$payload = [
'content' => "[{$user->username}]({$profileUrl}) - Display name changed from **{$oldName}** to **{$newName}**.",
];

try {
(new Client())->post($webhookUrl, ['json' => $payload]);
} catch (Throwable $e) {
// Similar to our other Discord notifications, do nothing.
// But don't flash a server error to the user.
}
}
}
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// public
'achievements' => env('DISCORD_WEBHOOK_ACHIEVEMENTS'),
'claims' => env('DISCORD_WEBHOOK_CLAIMS'),
'name-changes' => env('DISCORD_WEBHOOK_NAME_CHANGES'), // available to many privileged roles
'news' => env('DISCORD_WEBHOOK_NEWS'),
'users' => env('DISCORD_WEBHOOK_USERS'),
// moderation
Expand Down

0 comments on commit cf537ce

Please sign in to comment.