Skip to content

Commit

Permalink
Fixed discord helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Aug 6, 2023
1 parent 09ff3b5 commit 667a2e1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/Helpers/DiscordHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class DiscordHelper
{
private $discordClient;
private ?DiscordClient $discordClient;

private $guildId;
private int $guildId;

public function __construct()
{
Expand All @@ -19,15 +19,15 @@ public function __construct()
$this->guildId = intval(config('services.discord.server_id'));
}

public function getServer()
public function getServer(): \RestCord\Model\Guild\Guild
{
return $this->discordClient->guild->getGuild([
'guild.id' => $this->guildId,
'with_counts' => true,
]);
}

public static function countMembers()
public static function countMembers(): ?int
{
$client = new self();
try {
Expand All @@ -39,12 +39,12 @@ public static function countMembers()
}
}

public static function getServerRoles()
public static function getServerRoles(): \Exception|array
{
$client = new self();
try {
return $client->discordClient->guild->getGuildRoles([
'guild.id' => $this->guildId,
'guild.id' => $client->guildId,
]);
} catch (\Exception $exception) {
logger()->error($exception->getMessage());
Expand All @@ -53,12 +53,12 @@ public static function getServerRoles()
}
}

public static function getMemberRoles(int $user_id)
public static function getMemberRoles(int $user_id): \RestCord\Model\Guild\GuildMember|\Exception
{
$client = new self();
try {
return $client->discordClient->guild->getGuildMember([
'guild.id' => $this->guildId,
'guild.id' => $client->guildId,
'user.id' => $user_id,
]);
} catch (\Exception $exception) {
Expand All @@ -68,16 +68,18 @@ public static function getMemberRoles(int $user_id)
}
}

public static function setMemberRole(int $user_id, int $role_id)
public static function setMemberRole(int $user_id, int $role_id): array|string
{
$client = new self();
try {
return $client->discordClient->guild->addGuildMemberRole([
'guild.id' => $this->guildId,
'guild.id' => $client->guildId,
'user.id' => $user_id,
'role.id' => $role_id,
]);
} catch (\Exception $exception) {
logger()->error($exception->getMessage());

return $exception->getMessage();
}
}
Expand Down

0 comments on commit 667a2e1

Please sign in to comment.