mirror of
https://github.com/the-programmers-hangout/Hermes.git
synced 2026-09-09 16:06:23 +02:00
also save images for a later project
This commit is contained in:
@@ -11,6 +11,7 @@ class Emote extends Model
|
|||||||
'guild_id',
|
'guild_id',
|
||||||
'emote_name',
|
'emote_name',
|
||||||
'type',
|
'type',
|
||||||
|
'image',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Laracord\Services\Service;
|
||||||
|
|
||||||
|
class UpdateEmoteImages extends Service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The service interval.
|
||||||
|
*/
|
||||||
|
protected int $interval = 600; // 10 minutes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
$type = $emoji->animated ? 'ANIMATED' : 'STATIC';
|
||||||
|
$emote = \App\Models\Emote::where('emote_id', $emoji->id)->where('type', $type)->whereNull('image')->first();
|
||||||
|
if (! $emote) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ext = $emoji->animated ? 'gif' : 'png';
|
||||||
|
$url = "https://cdn.discordapp.com/emojis/{$emoji->id}.{$ext}";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$client = new \GuzzleHttp\Client;
|
||||||
|
$response = $client->get($url);
|
||||||
|
if ($response->getStatusCode() === 200) {
|
||||||
|
$imageData = $response->getBody()->getContents();
|
||||||
|
$emote->image = $imageData;
|
||||||
|
$emote->save();
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('emotes', function (Blueprint $table) {
|
||||||
|
$table->binary('image')->nullable()->after('type');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('emotes', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('image');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user