Skip to content

Commit bd750b1

Browse files
committed
Fix excessive length descriptions to Discord
1 parent e3f2c6b commit bd750b1

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

src/Controllers/Document/Create.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ protected function handlePost(): void
9999
'Brief' => $brief,
100100
'Markdown' => $markdown ? ':white_check_mark:' : ':x:',
101101
]);
102-
$embed->setDescription($markdown ? $content : '```' . \PHP_EOL . $content . \PHP_EOL . '```');
102+
$desc = \substr($content, 0, \min(\BNETDocs\Libraries\Discord\Embed::MAX_DESCRIPTION - 13, \strlen($content) - 13));
103+
if (\strlen($desc) != \strlen($content)) $desc .= '';
104+
if (!$markdown) $desc = '```' . \PHP_EOL . $desc . \PHP_EOL . '```';
105+
$embed->setDescription($desc);
103106
Logger::logToDiscord($event, $embed);
104107
}
105108
}

src/Controllers/Document/Delete.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public function invoke(?array $args): bool
6767
'Authored by' => !\is_null($user) ? $user->getAsMarkdown() : '*Anonymous*',
6868
'Deleted by' => $this->model->active_user->getAsMarkdown(),
6969
]);
70-
$embed->setDescription($markdown ? $content : '```' . \PHP_EOL . $content . \PHP_EOL . '```');
70+
$desc = \substr($content, 0, \min(\BNETDocs\Libraries\Discord\Embed::MAX_DESCRIPTION - 13, \strlen($content) - 13));
71+
if (\strlen($desc) != \strlen($content)) $desc .= '';
72+
if (!$markdown) $desc = '```' . \PHP_EOL . $desc . \PHP_EOL . '```';
73+
$embed->setDescription($desc);
7174
Logger::logToDiscord($event, $embed);
7275
}
7376
}

src/Controllers/Document/Edit.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ protected function handlePost(): void
117117
'Authored by' => !\is_null($user) ? $user->getAsMarkdown() : '*Anonymous*',
118118
'Edited by' => $this->model->active_user->getAsMarkdown(),
119119
]);
120-
$embed->setDescription($markdown ? $content : '```' . \PHP_EOL . $content . \PHP_EOL . '```');
120+
$desc = \substr($content, 0, \min(\BNETDocs\Libraries\Discord\Embed::MAX_DESCRIPTION - 13, \strlen($content) - 13));
121+
if (\strlen($desc) != \strlen($content)) $desc .= '';
122+
if (!$markdown) $desc = '```' . \PHP_EOL . $desc . \PHP_EOL . '```';
123+
$embed->setDescription($desc);
121124
Logger::logToDiscord($event, $embed);
122125
}
123126
}

src/Controllers/News/Create.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ protected function handlePost(): void
124124
'Markdown' => $this->model->markdown ? ':white_check_mark:' : ':x:',
125125
'RSS exempt' => $this->model->rss_exempt ? ':white_check_mark:' : ':x:',
126126
]);
127-
$embed->setDescription($this->model->markdown ? $this->model->content : '```' . \PHP_EOL . $this->model->content . \PHP_EOL . '```');
127+
$desc = \substr($this->model->content, 0, \min(\BNETDocs\Libraries\Discord\Embed::MAX_DESCRIPTION - 13, \strlen($this->model->content) - 13));
128+
if (\strlen($desc) != \strlen($this->model->content)) $desc .= '';
129+
if (!$this->model->markdown) $desc = '```' . \PHP_EOL . $desc . \PHP_EOL . '```';
130+
$embed->setDescription($desc);
128131
Logger::logToDiscord($event, $embed);
129132
}
130133
}

src/Controllers/News/Delete.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ protected function tryDelete(): void
7373
'Authored by' => !\is_null($this->model->news_post->getUserId()) ? $this->model->news_post->getUser()->getAsMarkdown() : '*Anonymous*',
7474
'Deleted by' => $this->model->active_user->getAsMarkdown(),
7575
]);
76-
$embed->setDescription($this->model->news_post->isMarkdown() ? $content : '```' . \PHP_EOL . $content . \PHP_EOL . '```');
76+
$desc = \substr($content, 0, \min(\BNETDocs\Libraries\Discord\Embed::MAX_DESCRIPTION - 13, \strlen($content) - 13));
77+
if (\strlen($desc) != \strlen($content)) $desc .= '';
78+
if (!$this->model->news_post->isMarkdown()) $desc = '```' . \PHP_EOL . $desc . \PHP_EOL . '```';
79+
$embed->setDescription($desc);
7780
Logger::logToDiscord($event, $embed);
7881
}
7982
}

src/Controllers/News/Edit.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ protected function handlePost(): void
117117
'Authored by' => !\is_null($this->model->news_post->getUserId()) ? $this->model->news_post->getUser()->getAsMarkdown() : '*Anonymous*',
118118
'Edited by' => $this->model->active_user->getAsMarkdown(),
119119
]);
120-
$embed->setDescription($this->model->news_post->isMarkdown() ? $content : '```' . \PHP_EOL . $content . \PHP_EOL . '```');
120+
$desc = \substr($content, 0, \min(\BNETDocs\Libraries\Discord\Embed::MAX_DESCRIPTION - 13, \strlen($content) - 13));
121+
if (\strlen($desc) != \strlen($content)) $desc .= '';
122+
if (!$this->model->news_post->isMarkdown()) $desc = '```' . \PHP_EOL . $desc . \PHP_EOL . '```';
123+
$embed->setDescription($desc);
121124
Logger::logToDiscord($event, $embed);
122125
}
123126
}

0 commit comments

Comments
 (0)