mirror of
https://github.com/the-programmers-hangout/Hermes.git
synced 2026-09-04 09:15:59 +02:00
cache all guild emotes regardless if they're used or not
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Laracord\Services\Service;
|
||||
|
||||
class UpdateEmotes extends Service
|
||||
{
|
||||
/**
|
||||
* The service interval.
|
||||
*/
|
||||
protected int $interval = 5;
|
||||
|
||||
/**
|
||||
* Handle the service.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$guildId = env('GUILD_ID');
|
||||
$guild = $this->discord->guilds->get('id', $guildId);
|
||||
if (! $guild) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($guild->emojis as $emoji) {
|
||||
$emote = \App\Models\Emote::where('emote_id', $emoji->id)->first();
|
||||
|
||||
if (! $emote) {
|
||||
$emoteModel = \App\Models\Emote::create([
|
||||
'emote_id' => $emoji->id,
|
||||
'guild_id' => $guildId,
|
||||
'emote_name' => $emoji->name,
|
||||
'type' => $emoji->animated ? 'ANIMATED' : 'STATIC',
|
||||
]);
|
||||
|
||||
\App\Models\EmoteGuildStat::firstOrCreate(
|
||||
['emote_id' => $emoteModel->emote_id, 'guild_id' => $guildId],
|
||||
['usage_count' => 0]
|
||||
);
|
||||
} elseif ($emote->emote_name !== $emoji->name) {
|
||||
$emote->emote_name = $emoji->name;
|
||||
$emote->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user