+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\DiscordBotCommand;
+use App\Models\User;
+use Illuminate\Console\Command;
+use Illuminate\Database\Eloquent\Builder;
+
+class SyncAvatars extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'sync:avatars';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Resync outdated avatars';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $users = User::whereNotNull('avatar')
+ ->where(function (Builder $query) {
+ $query->whereNull('avatar_cached');
+ $query->orWhereColumn('avatar_cached', '<', 'updated_at');
+ $query->orWhere('avatar_cached', '<', now()->subtract(30, 'days'));
+ })
+ ->get();
+
+ foreach ($users as $user) {
+ try {
+ DiscordBotCommand::syncUser($user->id);
+ } catch (\Exception $e) {
+ $this->error('error syncing avatar of user '.$user->id.': '.$e->getMessage());
+ }
+ }
+
+ return 0;
+ }
+}