Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 5 additions & 70 deletions app-modules/bot-discord/phpstan.ignore.neon
Original file line number Diff line number Diff line change
@@ -1,55 +1,10 @@
parameters:
ignoreErrors:
-
message: '#^Access to an undefined property Discord\\Parts\\Guild\\Guild::\$icon\.$#'
identifier: property.notFound
count: 1
path: src/SlashCommands/DontAskCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\Guild\\Guild::\$icon\.$#'
identifier: property.notFound
count: 1
path: src/SlashCommands/EditProfileCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\Guild\\Guild::\$icon\.$#'
identifier: property.notFound
count: 1
path: src/SlashCommands/IntroductionCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\Guild\\Guild::\$icon\.$#'
identifier: property.notFound
count: 1
path: src/SlashCommands/ProfileCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\User\\Member::\$user\.$#'
identifier: property.notFound
count: 7
path: src/Events/WelcomeMember.php
-
message: '#^Access to an undefined property Discord\\Parts\\User\\User::\$avatar\.$#'
identifier: property.notFound
count: 1
path: src/SlashCommands/EditProfileCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\User\\User::\$avatar\.$#'
identifier: property.notFound
count: 2
path: src/SlashCommands/IntroductionCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\WebSockets\\VoiceStateUpdate::\$channel_id\.$#'
identifier: property.notFound
count: 1
path: src/Events/DynamicVoiceEvent.php
-
message: '#^Method He4rt\\BotDiscord\\Tasks\\RichPresence::makeActivities\(\) should return array<Discord\\Parts\\User\\Activity> but returns array<int, Discord\\Parts\\Part\|Discord\\Repository\\AbstractRepository>\.$#'
identifier: return.type
count: 1
path: src/Tasks/RichPresence.php
-
message: '#^Parameter \#1 \$guild of method Discord\\Repository\\Guild\\ChannelRepository::build\(\) expects Discord\\Repository\\Guild\\Guild\|string, Discord\\Parts\\Guild\\Guild\|null given\.$#'
identifier: argument.type
count: 1
path: src/SlashCommands/DynamicVoiceCommand.php
-
message: '#^Unable to resolve the template type TKey in call to function collect$#'
identifier: argument.templateType
Expand All @@ -60,38 +15,18 @@ parameters:
identifier: argument.templateType
count: 1
path: src/SlashCommands/EditVoiceChannelLimitCommand.php
-
message: '#^Access to an undefined property Discord\\Parts\\WebSockets\\VoiceStateUpdate::\$channel_id\.$#'
identifier: property.notFound
count: 1
path: src/Tasks/VoiceExperienceTask.php
-
message: '#^Access to an undefined property Discord\\Parts\\WebSockets\\VoiceStateUpdate::\$member\.$#'
identifier: property.notFound
count: 1
path: src/Tasks/VoiceExperienceTask.php
-
message: '#^Using nullsafe property access "\?->user" on left side of \?\? is unnecessary. Use -> instead\.$#'
identifier: nullsafe.neverNull
count: 1
path: src/Tasks/VoiceExperienceTask.php
-
message: '#^Cannot call method find\(\) on array<Discord\\Parts\\Guild\\Role>\|\(Discord\\Helpers\\ExCollectionInterface&iterable<Discord\\Parts\\Guild\\Role>\)\.$#'
identifier: method.nonObject
count: 3
message: '#^Parameter \#1 \$roles of method Discord\\Parts\\User\\Member::setRoles\(\) expects#'
identifier: argument.type
count: 1
path: src/SlashCommands/CargoDelasCommand.php
-
message: '#^Cannot call method find\(\) on array<Discord\\Parts\\Guild\\Role>\|\(Discord\\Helpers\\ExCollectionInterface&iterable<Discord\\Parts\\Guild\\Role>\)\.$#'
identifier: method.nonObject
message: '#^Parameter \#1 \$roles of method Discord\\Parts\\User\\Member::setRoles\(\) expects#'
identifier: argument.type
count: 1
path: src/SlashCommands/IntroductionCommand.php
-
message: '#^Cannot call method get\(\) on array<Discord\\Parts\\User\\User>\|\(Discord\\Helpers\\ExCollectionInterface&iterable<Discord\\Parts\\User\\User>\)\.$#'
identifier: method.nonObject
count: 1
path: src/SlashCommands/DontAskCommand.php
-
message: '#^Cannot call method get\(\) on array<Discord\\Parts\\User\\User>\|\(Discord\\Helpers\\ExCollectionInterface&iterable<Discord\\Parts\\User\\User>\)\.$#'
identifier: method.nonObject
count: 1
path: src/SlashCommands/ProfileCommand.php
3 changes: 3 additions & 0 deletions app-modules/bot-discord/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ includes:
- phpstan.ignore.neon

parameters:
stubFiles:
- stubs/discord-php.stub

paths:
- src/
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class JoiningChannelAction
{
/**
* @param array<string, mixed> $activeChannels
* @param list<VoiceChannelDTO> $activeChannels
*/
public function execute(string $channelId, array $activeChannels, string $user): void
{
Expand All @@ -27,7 +27,7 @@ public function execute(string $channelId, array $activeChannels, string $user):
}

/**
* @param array<string, mixed> $activeChannels
* @param list<VoiceChannelDTO> $activeChannels
*/
private function saveActiveChannels(array $activeChannels): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
final class LeftChannelAction
{
/**
* @param array<string, mixed> $activeChannels
* @param list<VoiceChannelDTO> $activeChannels
*/
public function execute(array $activeChannels, string $user): void
{
foreach ($activeChannels as $index => $channel) {
/** @var VoiceChannelDTO $channel */
if (in_array($user, $channel->users)) {
$activeChannels[$index]->users = array_values(array_filter($channel->users, fn ($userId) => $userId !== $user));
if (in_array($user, $channel->users, true)) {
$activeChannels[$index]->users = array_values(array_filter($channel->users, fn (string $userId) => $userId !== $user));
$activeChannels[$index]->usersCount--;

$this->saveActiveChannels($activeChannels);
Expand All @@ -26,7 +26,7 @@ public function execute(array $activeChannels, string $user): void
}

/**
* @param array<string, mixed> $activeChannels
* @param list<VoiceChannelDTO> $activeChannels
*/
private function saveActiveChannels(array $activeChannels): void
{
Expand Down
3 changes: 3 additions & 0 deletions app-modules/bot-discord/src/Commands/PingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Discord\Parts\Interactions\Interaction;
use Laracord\Commands\Command;

/**
* @method \Laracord\Discord\Message message(string $content = '')
*/
class PingCommand extends Command
{
/**
Expand Down
2 changes: 1 addition & 1 deletion app-modules/bot-discord/src/DTO/VoiceChannelDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
public readonly string $channelId,
public readonly string $ownerId,
public int $usersCount,
/** @var array<string, mixed> */
/** @var list<string> */
public array $users,
public ?CarbonInterface $lastJoinedAt = null,
) {}
Expand Down
12 changes: 8 additions & 4 deletions app-modules/bot-discord/src/Events/RawGatewayEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@

final class RawGatewayEvent
{
/** @param object{t?: string, d?: object} $payload */
public function handle(object $payload): void
{
if (!isset($payload->t, $payload->d)) {
return;
}

$encodedPayload = json_encode($payload->d);
/** @var object{guild_id?: string, user_id?: string, channel_id?: string} $data */
$data = $payload->d;

$encodedPayload = json_encode($data);

throw_if($encodedPayload === false, RuntimeException::class, 'Failed to encode Discord gateway payload to JSON.');

DiscordEventLog::query()->create([
'event_type' => $payload->t,
'guild_id' => $payload->d->guild_id ?? null,
'user_id' => $payload->d->user_id ?? $payload->d->author->id ?? null,
'channel_id' => $payload->d->channel_id ?? null,
'guild_id' => $data->guild_id ?? null,
'user_id' => $data->user_id ?? data_get($payload->d, 'author.id'),
'channel_id' => $data->channel_id ?? null,
'payload' => json_decode($encodedPayload, true),
]);
}
Expand Down
4 changes: 4 additions & 0 deletions app-modules/bot-discord/src/Events/WelcomeMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
use He4rt\Identity\User\Actions\ResolveUserContext;
use He4rt\Identity\User\Models\User;
use Illuminate\Support\Facades\Log;
use Laracord\Discord\Message;
use Laracord\Events\Event;
use Throwable;

/**
* @method Message message(string $content = '')
*/
class WelcomeMember extends Event
{
protected $handler = Events::GUILD_MEMBER_ADD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
use Illuminate\Pipeline\Pipeline;
use Laracord\Commands\Middleware\Context;
use Laracord\Commands\SlashCommand;
use Laracord\Discord\Message;

/**
* @method Message message(string $content = '')
*/
abstract class AbstractSlashCommand extends SlashCommand
{
protected ?ExternalIdentity $memberProvider = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function handle(Interaction $interaction): void

private function validateTarget(Interaction $interaction, string $targetUserId): ?Member
{
/** @var Member|null $targetMember */
$targetMember = $interaction->guild->members->get('id', $targetUserId);

if (!$targetMember) {
Expand Down
6 changes: 5 additions & 1 deletion app-modules/bot-discord/src/SlashCommands/DontAskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Discord\Parts\Interactions\Command\Option;
use Discord\Parts\Interactions\Interaction;
use Discord\Parts\User\User;
use Illuminate\Support\Facades\Date;

class DontAskCommand extends AbstractSlashCommand
Expand Down Expand Up @@ -57,11 +58,14 @@ class DontAskCommand extends AbstractSlashCommand
*/
public function handle(Interaction $interaction): void
{
/** @var User $targetUser */
$targetUser = $interaction->data->resolved->users->get('id', $this->value('user'));

Comment thread
gvieira18 marked this conversation as resolved.
$this
->message()
->title('Não peça para perguntar.')
->footerIcon($interaction->guild->icon)
->thumbnailUrl($interaction->data->resolved->users->get('id', $this->value('user'))->avatar)
->thumbnailUrl($targetUser->avatar)
->footerText(Date::now()->format('Y').' © He4rt Developers')
->imageUrl('https://media.discordapp.net/attachments/546151895010508827/1046092564513701909/Frame_1282_1.png')
->timestamp(now())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Discord\Parts\Interactions\Command\Option;
use Discord\Parts\Interactions\Interaction;
use He4rt\BotDiscord\DTO\VoiceChannelDTO;
use React\Promise\PromiseInterface;

use function React\Async\await;

Expand Down Expand Up @@ -63,13 +64,15 @@ class DynamicVoiceCommand extends AbstractSlashCommand
*/
public function handle(Interaction $interaction): void
{
$channel = await($interaction->guild->channels->build(
/** @var PromiseInterface<Channel> $buildPromise */
$buildPromise = $interaction->guild->channels->build(
$interaction->guild,
ChannelBuilder::new($this->value('tipo'))
->setType(Channel::TYPE_GUILD_VOICE)
->setUserLimit($this->value('quantidade'))
->setParentId(config('he4rt.channels.dynamic_voice_category')),
));
);
$channel = await($buildPromise);
$channels = cache()->tags(['voice_channels'])->get('active_voice_channels_keys', []);

$channelDto = VoiceChannelDTO::make([
Expand All @@ -84,7 +87,9 @@ public function handle(Interaction $interaction): void

cache()->tags(['voice_channels'])->put('active_voice_channels_keys', $channels);

await($interaction->guild->channels->freshen());
/** @var PromiseInterface<mixed> $freshenPromise */
$freshenPromise = $interaction->guild->channels->freshen();
await($freshenPromise);

$this->interactionWithUser($interaction, $channel);
}
Expand Down
13 changes: 10 additions & 3 deletions app-modules/bot-discord/src/SlashCommands/EditProfileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,16 @@ private function persistData(
Interaction $interaction,
Collection $components
): void {
$name = $components->get('custom_id', 'name')?->value;
$nickname = $components->get('custom_id', 'nickname')?->value;
$about = $components->get('custom_id', 'about')?->value;
/** @var object{value: string}|null $nameComponent */
$nameComponent = $components->get('custom_id', 'name');
/** @var object{value: string}|null $nicknameComponent */
$nicknameComponent = $components->get('custom_id', 'nickname');
/** @var object{value: string}|null $aboutComponent */
$aboutComponent = $components->get('custom_id', 'about');

$name = $nameComponent->value ?? '';
$nickname = $nicknameComponent->value ?? '';
$about = $aboutComponent->value ?? '';

try {
$this->memberProvider->user->update(['name' => $name]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace He4rt\BotDiscord\SlashCommands;

use Discord\Parts\Channel\Channel;
use Discord\Parts\Interactions\Command\Option;
use Discord\Parts\Interactions\Interaction;
use Exception;
use React\Promise\PromiseInterface;

use function React\Async\await;

Expand Down Expand Up @@ -52,6 +54,7 @@ public function handle(Interaction $interaction): void
return;
}

/** @var Channel|null $voiceChannel */
$voiceChannel = $interaction->guild->channels->get('id', $channelId);

if (!$voiceChannel) {
Expand All @@ -65,8 +68,10 @@ public function handle(Interaction $interaction): void
$newLimit = $this->value('limite');

try {
$voiceChannel->user_limit = $newLimit;
await($interaction->guild->channels->save($voiceChannel));
$voiceChannel->user_limit = (int) $newLimit;
/** @var PromiseInterface<Channel> $promise */
$promise = $interaction->guild->channels->save($voiceChannel);
await($promise);

$this->message()
->content(sprintf('✅ Limite da sala atualizado para **%d** membros!', $newLimit))
Expand Down
13 changes: 10 additions & 3 deletions app-modules/bot-discord/src/SlashCommands/IntroductionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,16 @@ private function persistData(Interaction $interaction, Collection $components):

$userContext = resolve(ResolveUserContext::class)->handle($userDto);

$name = $components->get('custom_id', 'name')->value;
$nickname = $components->get('custom_id', 'nickname')->value;
$about = $components->get('custom_id', 'about')->value;
/** @var object{value: string} $nameComponent */
$nameComponent = $components->get('custom_id', 'name');
/** @var object{value: string} $nicknameComponent */
$nicknameComponent = $components->get('custom_id', 'nickname');
/** @var object{value: string} $aboutComponent */
$aboutComponent = $components->get('custom_id', 'about');

$name = $nameComponent->value;
$nickname = $nicknameComponent->value;
$about = $aboutComponent->value;
Comment thread
gvieira18 marked this conversation as resolved.

$userContext->user->update(['name' => $name]);

Expand Down
Loading