From 37d04cf1770b63194cd06666a79fc5f1e9f99647 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 29 Jul 2023 22:16:09 +0200 Subject: [PATCH 1/3] Hide user discriminator for user's without discriminator --- php/request.inc.php | 99 ++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/php/request.inc.php b/php/request.inc.php index 049a9ee..c055e88 100644 --- a/php/request.inc.php +++ b/php/request.inc.php @@ -41,7 +41,6 @@ public function __construct($req_id) $this->checkEmote = getenv("CHECK_EMOTE"); $this->blockEmote = getenv("BLOCK_EMOTE"); - } function initializeRequest() @@ -60,9 +59,7 @@ function initializeRequest() $this->request = $qry->fetch(); $this->applicant_id = $this->request['by_discord_id']; $this->applicant = new User($this->applicant_id); - } - } #[Pure] function testInput($data): string @@ -84,7 +81,7 @@ function acceptRequest($login): bool $messageContent = '<@' . $applicant->getDiscordId() . '>'; if ($applicant->isModerator()) { - $messageContent .= "\n" . ($this->pingsEveryone() ? "@everyone" : ""); + $messageContent .= "\n" . ($this->pingsEveryone() ? "@everyone" : ""); } $devmarktEmbed = $this->generateDevmarktEmbed(); @@ -115,8 +112,6 @@ function getApplicant(): ?User $this->applicant = new User($this->getApplicantID()); return $this->applicant; - - } function getApplicantID(): ?string @@ -157,7 +152,6 @@ function generateDMEmbed(bool $accepted, User $login): array ['url' => $login->getAvatarURL()], date('c') ); - } function generateEmbed($title, $description, $fields, $footer, $footer_text, $footer_icon_url, $color, $thumbnail, $timestamp): array @@ -169,7 +163,6 @@ function generateEmbed($title, $description, $fields, $footer, $footer_text, $fo } return array("title" => $title, "description" => $description, "thumbnail" => $thumbnail, "color" => $color, "footer" => $footer_array, "fields" => $fields, "timestamp" => $timestamp); - } function generateField($name, $value, $inline): array @@ -180,12 +173,11 @@ function generateField($name, $value, $inline): array 'value' => $value, 'inline' => $inline, ]; - } function getUserInfo($user): string { - return $user->getUsername() . '#' . $user->getDiscriminator() . ' => ' . $user->getDiscordID(); + return "{$user->getUsername()}" . ($user->getDiscriminator() == "0" ? "" : "#{$user->getDiscriminator()}") . " => {$user->getDiscordID()}"; } function getUserAndDisc($user): string @@ -205,14 +197,17 @@ function generateProcessedEmbed($accepted, $login, $acceptsDMs): array $acceptsDMString = $acceptsDMs ? $this->checkEmote : $this->blockEmote; $color = ($accepted ? '3bd323' : 'f40909'); - return $this->generateEmbed($title, null, [ - $this->generateField('Bearbeitet von', $this->getUserInfo($login), false), - $this->generateField('Anfragesteller', $this->getUserInfo($this->getApplicant()), false), - $this->generateField('Akzeptiert DMs', $acceptsDMString, false), - $this->generateField('Pingt @everyone', $this->pingsEveryone() ? $this->checkEmote : $this->blockEmote, false), - $this->generateField('Case', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/case.php?req_id=' . $this->testInput($this->req_id) . ')', true), - $this->generateField('Nutzerinformationen', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/user.php?user_id=' . $this->getApplicant()->getDiscordId() . ')', true), - ], + return $this->generateEmbed( + $title, + null, + [ + $this->generateField('Bearbeitet von', $this->getUserInfo($login), false), + $this->generateField('Anfragesteller', $this->getUserInfo($this->getApplicant()), false), + $this->generateField('Akzeptiert DMs', $acceptsDMString, false), + $this->generateField('Pingt @everyone', $this->pingsEveryone() ? $this->checkEmote : $this->blockEmote, false), + $this->generateField('Case', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/case.php?req_id=' . $this->testInput($this->req_id) . ')', true), + $this->generateField('Nutzerinformationen', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/user.php?user_id=' . $this->getApplicant()->getDiscordId() . ')', true), + ], true, $this->getUserAndDisc($login), $login->getAvatarURL(), @@ -220,15 +215,16 @@ function generateProcessedEmbed($accepted, $login, $acceptsDMs): array array('url' => $this->getApplicant()->getAvatarURL()), date('c') ); - } function pingsEveryone(): bool { - if (!$this->valid + if ( + !$this->valid || !$this->getApplicant()->isModerator() - || !str_contains($this->getOptions(), 'everyone')) { + || !str_contains($this->getOptions(), 'everyone') + ) { return false; } @@ -246,7 +242,6 @@ function getOptions(): ?string } return $this->request['options']; - } function generateDevmarktEmbed(): array @@ -294,7 +289,6 @@ function getURL() return null; } return $this->request['link']; - } function getTitle(): ?string @@ -307,7 +301,6 @@ function getTitle(): ?string $this->request['title'] = str_replace('"', "", $this->request['title']); $this->request['title'] = str_replace("'", "", $this->request['title']); return $this->testInput($this->request['title']); - } function getColor() @@ -329,7 +322,6 @@ function getDescription(): ?string $this->request['description'] = str_replace('"', "", $this->request['description']); $this->request['description'] = str_replace("'", "", $this->request['description']); return $this->testInput($this->request['description']); - } function getMessageID() @@ -353,7 +345,6 @@ function updateRequest($status, $processedBy, $dateProcessed, $messageId): bool $qry->bindValue(":req_id", $this->req_id); $qry->bindValue(":reason", $this->getReason()); return $qry->execute(); - } function getDate() @@ -366,14 +357,15 @@ function getDate() #[Pure] function getReason(): ?string { - if (!$this->valid + if ( + !$this->valid && !$this->isProcessed() - && $this->isAccepted()) { + && $this->isAccepted() + ) { return null; } return $this->request['reason']; - } #[Pure] function isProcessed(): bool @@ -386,13 +378,15 @@ function getDate() if ($processed_qry == "unprocessed") { return false; } - return true; + return true; } #[Pure] function isAccepted(): bool { - if (!$this->valid - || !($this->isProcessed())) { + if ( + !$this->valid + || !($this->isProcessed()) + ) { return false; } @@ -432,31 +426,28 @@ function rejectRequest(User $login, $reason, $create_thread): bool $acceptsDMs = false; } - if($create_thread) { + if ($create_thread) { - $thread_id = $this->getApplicant()->createRejectThread(); + $thread_id = $this->getApplicant()->createRejectThread(); - try { - sendMessage($thread_id, null, $dmEmbed, null); - } catch(Exception $e) { - $this->getApplicant()->thread = null; - $thread_id = $this->getApplicant()->createRejectThread(); - sendMessage($thread_id, null, $dmEmbed, null); - } - try { - - $login->addMemberToThread($thread_id, $this->getApplicantID()); - $login->addMemberToThread($thread_id, $login->getDiscordId()); - sendMessage($thread_id, "<@" . $this->getApplicant()->getDiscordId() .">", null, false); - $devmarktRequestEmbed = $this->generateProcessedEmbed(false, $login, $acceptsDMs); - - } catch(Exception $e) { - - header('Location: ' . $this->caseUrl . "&error=" . urlencode($e->getMessage())); - return true; + try { + sendMessage($thread_id, null, $dmEmbed, null); + } catch (Exception $e) { + $this->getApplicant()->thread = null; + $thread_id = $this->getApplicant()->createRejectThread(); + sendMessage($thread_id, null, $dmEmbed, null); + } + try { - } + $login->addMemberToThread($thread_id, $this->getApplicantID()); + $login->addMemberToThread($thread_id, $login->getDiscordId()); + sendMessage($thread_id, "<@" . $this->getApplicant()->getDiscordId() . ">", null, false); + $devmarktRequestEmbed = $this->generateProcessedEmbed(false, $login, $acceptsDMs); + } catch (Exception $e) { + header('Location: ' . $this->caseUrl . "&error=" . urlencode($e->getMessage())); + return true; + } } $devmarktRequestEmbed = $this->generateProcessedEmbed(false, $login, $acceptsDMs); @@ -478,7 +469,6 @@ function getStatus(): ?string } $this->status = $this->request['status']; return $this->status; - } function getProcessedDate() @@ -514,5 +504,4 @@ function getProcessorID(): ?string $this->processor_id = $this->request['processed_by']; return $this->processor_id; } - } From 909300ab674f9dc5656b5e0420e2ca2f8876b4c9 Mon Sep 17 00:00:00 2001 From: Dominik Date: Mon, 31 Jul 2023 13:03:37 +0200 Subject: [PATCH 2/3] Remove formatting stuff --- php/request.inc.php | 99 +++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/php/request.inc.php b/php/request.inc.php index c055e88..d63dd0a 100644 --- a/php/request.inc.php +++ b/php/request.inc.php @@ -41,6 +41,7 @@ public function __construct($req_id) $this->checkEmote = getenv("CHECK_EMOTE"); $this->blockEmote = getenv("BLOCK_EMOTE"); + } function initializeRequest() @@ -59,7 +60,9 @@ function initializeRequest() $this->request = $qry->fetch(); $this->applicant_id = $this->request['by_discord_id']; $this->applicant = new User($this->applicant_id); + } + } #[Pure] function testInput($data): string @@ -81,7 +84,7 @@ function acceptRequest($login): bool $messageContent = '<@' . $applicant->getDiscordId() . '>'; if ($applicant->isModerator()) { - $messageContent .= "\n" . ($this->pingsEveryone() ? "@everyone" : ""); + $messageContent .= "\n" . ($this->pingsEveryone() ? "@everyone" : ""); } $devmarktEmbed = $this->generateDevmarktEmbed(); @@ -112,6 +115,8 @@ function getApplicant(): ?User $this->applicant = new User($this->getApplicantID()); return $this->applicant; + + } function getApplicantID(): ?string @@ -152,6 +157,7 @@ function generateDMEmbed(bool $accepted, User $login): array ['url' => $login->getAvatarURL()], date('c') ); + } function generateEmbed($title, $description, $fields, $footer, $footer_text, $footer_icon_url, $color, $thumbnail, $timestamp): array @@ -163,6 +169,7 @@ function generateEmbed($title, $description, $fields, $footer, $footer_text, $fo } return array("title" => $title, "description" => $description, "thumbnail" => $thumbnail, "color" => $color, "footer" => $footer_array, "fields" => $fields, "timestamp" => $timestamp); + } function generateField($name, $value, $inline): array @@ -173,6 +180,7 @@ function generateField($name, $value, $inline): array 'value' => $value, 'inline' => $inline, ]; + } function getUserInfo($user): string @@ -197,17 +205,14 @@ function generateProcessedEmbed($accepted, $login, $acceptsDMs): array $acceptsDMString = $acceptsDMs ? $this->checkEmote : $this->blockEmote; $color = ($accepted ? '3bd323' : 'f40909'); - return $this->generateEmbed( - $title, - null, - [ - $this->generateField('Bearbeitet von', $this->getUserInfo($login), false), - $this->generateField('Anfragesteller', $this->getUserInfo($this->getApplicant()), false), - $this->generateField('Akzeptiert DMs', $acceptsDMString, false), - $this->generateField('Pingt @everyone', $this->pingsEveryone() ? $this->checkEmote : $this->blockEmote, false), - $this->generateField('Case', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/case.php?req_id=' . $this->testInput($this->req_id) . ')', true), - $this->generateField('Nutzerinformationen', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/user.php?user_id=' . $this->getApplicant()->getDiscordId() . ')', true), - ], + return $this->generateEmbed($title, null, [ + $this->generateField('Bearbeitet von', $this->getUserInfo($login), false), + $this->generateField('Anfragesteller', $this->getUserInfo($this->getApplicant()), false), + $this->generateField('Akzeptiert DMs', $acceptsDMString, false), + $this->generateField('Pingt @everyone', $this->pingsEveryone() ? $this->checkEmote : $this->blockEmote, false), + $this->generateField('Case', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/case.php?req_id=' . $this->testInput($this->req_id) . ')', true), + $this->generateField('Nutzerinformationen', '[**KLICK**](' . getenv('BOT_BASE_URI') . '/user.php?user_id=' . $this->getApplicant()->getDiscordId() . ')', true), + ], true, $this->getUserAndDisc($login), $login->getAvatarURL(), @@ -215,16 +220,15 @@ function generateProcessedEmbed($accepted, $login, $acceptsDMs): array array('url' => $this->getApplicant()->getAvatarURL()), date('c') ); + } function pingsEveryone(): bool { - if ( - !$this->valid + if (!$this->valid || !$this->getApplicant()->isModerator() - || !str_contains($this->getOptions(), 'everyone') - ) { + || !str_contains($this->getOptions(), 'everyone')) { return false; } @@ -242,6 +246,7 @@ function getOptions(): ?string } return $this->request['options']; + } function generateDevmarktEmbed(): array @@ -289,6 +294,7 @@ function getURL() return null; } return $this->request['link']; + } function getTitle(): ?string @@ -301,6 +307,7 @@ function getTitle(): ?string $this->request['title'] = str_replace('"', "", $this->request['title']); $this->request['title'] = str_replace("'", "", $this->request['title']); return $this->testInput($this->request['title']); + } function getColor() @@ -322,6 +329,7 @@ function getDescription(): ?string $this->request['description'] = str_replace('"', "", $this->request['description']); $this->request['description'] = str_replace("'", "", $this->request['description']); return $this->testInput($this->request['description']); + } function getMessageID() @@ -345,6 +353,7 @@ function updateRequest($status, $processedBy, $dateProcessed, $messageId): bool $qry->bindValue(":req_id", $this->req_id); $qry->bindValue(":reason", $this->getReason()); return $qry->execute(); + } function getDate() @@ -357,15 +366,14 @@ function getDate() #[Pure] function getReason(): ?string { - if ( - !$this->valid + if (!$this->valid && !$this->isProcessed() - && $this->isAccepted() - ) { + && $this->isAccepted()) { return null; } return $this->request['reason']; + } #[Pure] function isProcessed(): bool @@ -378,15 +386,13 @@ function getDate() if ($processed_qry == "unprocessed") { return false; } - return true; + return true; } #[Pure] function isAccepted(): bool { - if ( - !$this->valid - || !($this->isProcessed()) - ) { + if (!$this->valid + || !($this->isProcessed())) { return false; } @@ -426,28 +432,31 @@ function rejectRequest(User $login, $reason, $create_thread): bool $acceptsDMs = false; } - if ($create_thread) { - - $thread_id = $this->getApplicant()->createRejectThread(); + if($create_thread) { - try { - sendMessage($thread_id, null, $dmEmbed, null); - } catch (Exception $e) { - $this->getApplicant()->thread = null; $thread_id = $this->getApplicant()->createRejectThread(); - sendMessage($thread_id, null, $dmEmbed, null); - } - try { - $login->addMemberToThread($thread_id, $this->getApplicantID()); - $login->addMemberToThread($thread_id, $login->getDiscordId()); - sendMessage($thread_id, "<@" . $this->getApplicant()->getDiscordId() . ">", null, false); - $devmarktRequestEmbed = $this->generateProcessedEmbed(false, $login, $acceptsDMs); - } catch (Exception $e) { + try { + sendMessage($thread_id, null, $dmEmbed, null); + } catch(Exception $e) { + $this->getApplicant()->thread = null; + $thread_id = $this->getApplicant()->createRejectThread(); + sendMessage($thread_id, null, $dmEmbed, null); + } + try { + + $login->addMemberToThread($thread_id, $this->getApplicantID()); + $login->addMemberToThread($thread_id, $login->getDiscordId()); + sendMessage($thread_id, "<@" . $this->getApplicant()->getDiscordId() .">", null, false); + $devmarktRequestEmbed = $this->generateProcessedEmbed(false, $login, $acceptsDMs); + + } catch(Exception $e) { + + header('Location: ' . $this->caseUrl . "&error=" . urlencode($e->getMessage())); + return true; + + } - header('Location: ' . $this->caseUrl . "&error=" . urlencode($e->getMessage())); - return true; - } } $devmarktRequestEmbed = $this->generateProcessedEmbed(false, $login, $acceptsDMs); @@ -469,6 +478,7 @@ function getStatus(): ?string } $this->status = $this->request['status']; return $this->status; + } function getProcessedDate() @@ -504,4 +514,5 @@ function getProcessorID(): ?string $this->processor_id = $this->request['processed_by']; return $this->processor_id; } -} + +} \ No newline at end of file From 4083b6ccafba316fe8fd1efd3f517cd20e7624a0 Mon Sep 17 00:00:00 2001 From: Dominik Date: Mon, 31 Jul 2023 13:04:23 +0200 Subject: [PATCH 3/3] Add last line --- php/request.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/request.inc.php b/php/request.inc.php index d63dd0a..911f50c 100644 --- a/php/request.inc.php +++ b/php/request.inc.php @@ -515,4 +515,4 @@ function getProcessorID(): ?string return $this->processor_id; } -} \ No newline at end of file +}