mirror of
https://github.com/the-programmers-hangout/Hermes.git
synced 2026-09-09 07:56:20 +02:00
init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Discord\Discord;
|
||||
use Discord\Parts\Channel\Message;
|
||||
use Discord\WebSockets\Event as Events;
|
||||
use Laracord\Events\Event;
|
||||
|
||||
class MessageCreate extends Event
|
||||
{
|
||||
/**
|
||||
* The event handler.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $handler = Events::MESSAGE_CREATE;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(Message $message, Discord $discord)
|
||||
{
|
||||
$this->console()->log('The Message Create event has fired!');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Emote;
|
||||
use App\Models\User;
|
||||
use Discord\Discord;
|
||||
use Discord\Parts\WebSockets\MessageReaction;
|
||||
use Discord\WebSockets\Event as Events;
|
||||
use Laracord\Events\Event;
|
||||
|
||||
class MessageReactionAdd extends Event
|
||||
{
|
||||
/**
|
||||
* The event handler.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $handler = Events::MESSAGE_REACTION_ADD;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(MessageReaction $reaction, Discord $discord)
|
||||
{
|
||||
|
||||
if ($reaction->user->bot || ! $reaction->guild_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($reaction->emoji && $reaction->emoji->id) {
|
||||
|
||||
if ($reaction->emoji->guild_id) {
|
||||
if ($reaction->emoji->guild_id !== $reaction->guild_id) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$guild = $discord->guilds->get('id', $reaction->guild_id);
|
||||
if (! $guild || ! $guild->emojis->get('id', $reaction->emoji->id)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$user = User::firstOrCreate(
|
||||
['discord_id' => $reaction->user_id],
|
||||
['username' => $reaction->user->username]
|
||||
);
|
||||
|
||||
$emoteId = $reaction->emoji->id ?? $reaction->emoji->name;
|
||||
$type = $reaction->emoji->id ? ($reaction->emoji->animated ? 'ANIMATED' : 'STATIC') : 'UNICODE';
|
||||
$guildId = $reaction->guild_id;
|
||||
|
||||
$emote = Emote::firstOrCreate(
|
||||
['emote_id' => $emoteId],
|
||||
[
|
||||
'guild_id' => $guildId,
|
||||
'emote_name' => $reaction->emoji->name,
|
||||
'type' => $type,
|
||||
]
|
||||
);
|
||||
|
||||
$emote->addReaction(
|
||||
user: $user,
|
||||
guildId: $reaction->guild_id,
|
||||
channelId: $reaction->channel_id,
|
||||
messageId: $reaction->message_id,
|
||||
unicodeEmoji: boolval($reaction->emoji->id) ? null : $reaction->emoji->name
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Emote;
|
||||
use App\Models\User;
|
||||
use Discord\Discord;
|
||||
use Discord\Parts\WebSockets\MessageReaction;
|
||||
use Discord\WebSockets\Event as Events;
|
||||
use Laracord\Events\Event;
|
||||
|
||||
class MessageReactionRemove extends Event
|
||||
{
|
||||
/**
|
||||
* The event handler.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $handler = Events::MESSAGE_REACTION_REMOVE;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(MessageReaction $reaction, Discord $discord)
|
||||
{
|
||||
if ($reaction->user->bot || ! $reaction->guild_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($reaction->emoji && $reaction->emoji->id) {
|
||||
|
||||
if ($reaction->emoji->guild_id) {
|
||||
if ($reaction->emoji->guild_id !== $reaction->guild_id) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$guild = $discord->guilds->get('id', $reaction->guild_id);
|
||||
if (! $guild || ! $guild->emojis->get('id', $reaction->emoji->id)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$user = User::where('discord_id', $reaction->user_id)->first();
|
||||
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$emoteId = $reaction->emoji->id ?? $reaction->emoji->name;
|
||||
$emote = Emote::where('emote_id', $emoteId)
|
||||
->where('guild_id', $reaction->guild_id)
|
||||
->first();
|
||||
|
||||
if ($emote) {
|
||||
$emote->removeReaction(
|
||||
$user,
|
||||
$reaction->guild_id,
|
||||
$reaction->message_id,
|
||||
boolval($reaction->emoji->id) ? null : $reaction->emoji->name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\EmoteGuildStat;
|
||||
use App\Models\EmoteLog;
|
||||
use Discord\Discord;
|
||||
use Discord\Parts\WebSockets\MessageReaction;
|
||||
use Discord\WebSockets\Event as Events;
|
||||
use Laracord\Events\Event;
|
||||
|
||||
class MessageReactionRemoveAll extends Event
|
||||
{
|
||||
/**
|
||||
* The event handler.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $handler = Events::MESSAGE_REACTION_REMOVE_ALL;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(MessageReaction $reaction, Discord $discord)
|
||||
{
|
||||
if ($reaction->user->bot || ! $reaction->guild_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($reaction->emoji && $reaction->emoji->id) {
|
||||
|
||||
if ($reaction->emoji->guild_id) {
|
||||
if ($reaction->emoji->guild_id !== $reaction->guild_id) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$guild = $discord->guilds->get('id', $reaction->guild_id);
|
||||
if (! $guild || ! $guild->emojis->get('id', $reaction->emoji->id)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$logs = EmoteLog::where('message_id', $reaction->message->id)
|
||||
->where('guild_id', $reaction->message->guild_id)
|
||||
->get();
|
||||
|
||||
foreach ($logs as $log) {
|
||||
EmoteGuildStat::where([
|
||||
'emote_id' => $log->emote_id,
|
||||
'guild_id' => $log->guild_id,
|
||||
])->decrement('usage_count');
|
||||
}
|
||||
|
||||
EmoteLog::where('message_id', $reaction->message->id)
|
||||
->where('guild_id', $reaction->message->guild_id)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user