Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: announcement length/formatting #172

Merged
merged 3 commits into from
Feb 22, 2023
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
3 changes: 1 addition & 2 deletions classes/components/EmbedBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export class EmbedBase extends MessageEmbed {
this.description &&= truncate(this.description.trim(), { length: 4095, omission: '\u2026' });
// I'd like to split the embeds before slicing fields, if possible
this.fields = this.fields
.map((f) => this.splitField(f))
.flat()
.flatMap((f) => this.splitField(f))
.slice(0, 25)
.map((f) => ({
...f,
Expand Down
14 changes: 10 additions & 4 deletions classes/services/AnnouncementService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { decode } from 'html-entities';
import { EmbedBase, Firebase, Logger } from '..';
import bot from '../../bot';

Expand Down Expand Up @@ -92,10 +93,15 @@ export class AnnouncementService {
fields: [
{
name: 'Message',
value: announcement.content
.replaceAll('<br>', '\n')
.replaceAll('</p><p>', '\n') //this is kinda hacky ngl
.replace(/<\/?[^>]+(>|$)/g, ''),
value: decode(
announcement.content
.replaceAll('<br>', '\n')
.replaceAll('</p><p>', '\n') //this is kinda hacky ngl
.replaceAll('<li>', '\n\t\u2022 ')
.replaceAll('</ol>', '\n')
.replaceAll('</ul>', '\n')
.replace(/<\/?[^>]+(>|$)/g, '')
),
},
//TODO: cleanup dry code
...(!!announcement.resources.filter(({ kind }) => kind !== 'URL').length
Expand Down
14 changes: 10 additions & 4 deletions classes/services/GradeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { decode } from 'html-entities';
import { round } from 'lodash-es';
import { EmbedBase, Firebase, Logger } from '..';
import bot from '../../bot';
Expand Down Expand Up @@ -106,10 +107,15 @@ export class GradeService {
{
name: `Feedback:`,
value: !!finalComment?.comment
? finalComment.comment
.replaceAll('<br>', '\n')
.replaceAll('</p><p>', '\n') //this is kinda hacky ngl
.replace(/<\/?[^>]+(>|$)/g, '')
? decode(
finalComment.comment
.replaceAll('<br>', '\n')
.replaceAll('</p><p>', '\n') //this is kinda hacky ngl
.replaceAll('<li>', '\n\t\u2022 ')
.replaceAll('</ol>', '\n')
.replaceAll('</ul>', '\n')
.replace(/<\/?[^>]+(>|$)/g, '')
)
: 'None',
},
...(show_overall_grade
Expand Down
16 changes: 11 additions & 5 deletions classes/services/InboxMessageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { EmbedBase, Firebase, Logger } from '..';
import { decode } from 'html-entities';
import { EmbedBase, Logger } from '..';
import bot from '../../bot';

export class InboxMessageService {
Expand Down Expand Up @@ -79,10 +80,15 @@ export class InboxMessageService {
content: `New message received from **${firstName} ${lastName}**:`,
embeds: [
new EmbedBase({
description: inbox_message.content
.replaceAll('<br>', '\n')
.replaceAll('</p><p>', '\n') //this is kinda hacky ngl
.replace(/<\/?[^>]+(>|$)/g, ''),
description: decode(
inbox_message.content
.replaceAll('<br>', '\n')
.replaceAll('</p><p>', '\n') //this is kinda hacky ngl
.replaceAll('<li>', '\n\t\u2022 ')
.replaceAll('</ol>', '\n')
.replaceAll('</ul>', '\n')
.replace(/<\/?[^>]+(>|$)/g, '')
),
fields: [
...(!!inbox_message.resources.filter(({ kind }) => kind !== 'URL').length
? [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dotenv": "16.0.3",
"firebase-admin": "11.5.0",
"graphql-request": "5.1.0",
"html-entities": "2.3.3",
"klaw": "4.1.0",
"lodash-es": "4.17.21",
"moment": "2.29.4",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.