From c4eedec190b914ddcb93b51338d163ca9bf1cedb Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Sat, 18 Mar 2023 14:04:30 +0100 Subject: [PATCH] Update Translate, Labels and SafetyLabels to use the current design language --- commands/message/google/labels.js | 11 +- commands/message/google/safetylabels.js | 16 +-- commands/message/utils/translate.js | 8 +- labscore/constants.js | 137 +++++++++++++++++++++++- 4 files changed, 154 insertions(+), 18 deletions(-) diff --git a/commands/message/google/labels.js b/commands/message/google/labels.js index 54e7e24..9017e70 100644 --- a/commands/message/google/labels.js +++ b/commands/message/google/labels.js @@ -1,6 +1,7 @@ const { googleVisionLabels } = require("../../../labscore/api"); const { getRecentImage } = require("../../../labscore/utils/attachment"); const { createEmbed } = require("../../../labscore/utils/embed"); +const { pill } = require("../../../labscore/utils/markdown"); const { editOrReply } = require("../../../labscore/utils/message"); const { STATICS } = require("../../../labscore/utils/statics"); @@ -22,21 +23,17 @@ module.exports = { let labels = [] for(const l of label.response.body.labels){ - labels.push({ - name: l.name, - value: `${l.score.toString().substr(2,2)}.${l.score.toString().substr(3,1)}%`, - inline: true - }) + labels.push(pill(`${l.score.toString().substr(2,2)}.${l.score.toString().substr(3,1)}%`) + ' ​ ​' + pill(l.name)) } return editOrReply(context, { embeds: [createEmbed("default", context, { - fields: labels, + description: labels.join('\n'), thumbnail: { url: image }, footer: { iconUrl: STATICS.google, - text: `Google Cloud Vision • ${context.application.name} • Took ${label.timings}s` + text: `Google Cloud Vision • ${context.application.name}` } })] }) diff --git a/commands/message/google/safetylabels.js b/commands/message/google/safetylabels.js index 75d8acd..ebb30c6 100644 --- a/commands/message/google/safetylabels.js +++ b/commands/message/google/safetylabels.js @@ -1,6 +1,8 @@ const { googleVisionSafetyLabels } = require("../../../labscore/api"); +const { GOOGLE_CLOUD_SAFETY_LABELS, GOOGLE_CLOUD_SAFETY_LABELS_NAMES } = require("../../../labscore/constants"); const { getRecentImage } = require("../../../labscore/utils/attachment"); const { createEmbed } = require("../../../labscore/utils/embed"); +const { icon, pill, iconPill } = require("../../../labscore/utils/markdown"); const { editOrReply } = require("../../../labscore/utils/message"); const { STATICS } = require("../../../labscore/utils/statics"); @@ -22,21 +24,21 @@ module.exports = { let labels = [] for(const l of Object.keys(label.response.body.labels)){ - labels.push({ - name: l.charAt(0).toUpperCase() + l.slice(1), - value: label.response.body.labels[l], - inline: true - }) + let rating = GOOGLE_CLOUD_SAFETY_LABELS[label.response.body.labels[l]] + labels.push([ + pill(GOOGLE_CLOUD_SAFETY_LABELS_NAMES[l]), + iconPill(rating.icon, rating.name) + ].join(' ​ ​')) } return editOrReply(context, { embeds: [createEmbed("default", context, { - fields: labels, + description: labels.join('\n'), thumbnail: { url: image }, footer: { iconUrl: STATICS.google, - text: `Google Cloud Vision • ${context.application.name} • Took ${label.timings}s` + text: `Google Cloud Vision • ${context.application.name}` } })] }) diff --git a/commands/message/utils/translate.js b/commands/message/utils/translate.js index 76abe52..0e4c2e4 100644 --- a/commands/message/utils/translate.js +++ b/commands/message/utils/translate.js @@ -1,11 +1,12 @@ const { createEmbed } = require('../../../labscore/utils/embed') const { editOrReply } = require('../../../labscore/utils/message') -const { codeblock, highlight, icon } = require('../../../labscore/utils/markdown'); +const { codeblock, highlight, icon, pill } = require('../../../labscore/utils/markdown'); const { isSupported } = require('../../../labscore/utils/translate'); const { googleTranslate } = require('../../../labscore/api'); const { STATICS } = require('../../../labscore/utils/statics'); +const { TRANSLATE_LANGUAGES, TRANSLATE_LANGUAGE_MAPPINGS } = require('../../../labscore/constants'); module.exports = { name: 'translate', @@ -38,8 +39,11 @@ module.exports = { try{ let translate = await googleTranslate(context, content, args.to, args.from) + + let fromFlag = TRANSLATE_LANGUAGE_MAPPINGS[translate.response.body.language.from || args.from] || '' + let toFlag = TRANSLATE_LANGUAGE_MAPPINGS[translate.response.body.language.to] || '' return editOrReply(context, createEmbed("default", context, { - description: `${icon("locale")} ${highlight(`${translate.response.body.language.from} -> ${translate.response.body.language.to}`)}\n${codeblock("ansi", [translate.response.body.translation])}`, + description: `${icon("locale")} ​ ${fromFlag} ${pill(TRANSLATE_LANGUAGES[translate.response.body.language.from || args.from])} ​ ​ ​​${icon("arrow_right")} ​ ​ ​ ​${toFlag} ${pill(TRANSLATE_LANGUAGES[translate.response.body.language.to])}\n${codeblock("ansi", [translate.response.body.translation])}`, footer: { iconUrl: STATICS.google, text: `Google Translator • ${context.application.name} • Took ${translate.timings}s` diff --git a/labscore/constants.js b/labscore/constants.js index 3937a3b..36ca4d8 100644 --- a/labscore/constants.js +++ b/labscore/constants.js @@ -81,7 +81,17 @@ module.exports.ICONS = Object.freeze({ "like": "<:ico_like:1086443586700181514>", "message": "<:ico_message:1086443588784758844>", "eye": "<:ico_eye:1086443585337036860>", - "videos": "<:ico_videos:1086449271609503764>" + "videos": "<:ico_videos:1086449271609503764>", + "question_large": "<:ico_question:1086624956235919391>", + "exclaim_0": "<:ico_w0:1086624957586489364>", + "exclaim_1": "<:ico_w1:1086624959142580275>", + "exclaim_2": "<:ico_w2:1086624961025810485>", + "exclaim_3": "<:ico_w3:1086624963047460874>", + "exclaim_4": "<:ico_w4:1086624964284788787>", + "arrow_up": "<:ico_arrowup:980237911171674193>", + "arrow_down": "<:ico_arrowdown:980237911008092160>", + "arrow_left": "<:ico_arrowleft:1086628775644647464>", + "arrow_right": "<:ico_arrowright:1086628777880191016>", }) const GUILD_FEATURE_ICONS = Object.freeze({ @@ -267,6 +277,94 @@ module.exports.IMTRANSLATOR_VOICES = [ { name: "Korean (Female)", value: "ko" } ] +module.exports.TRANSLATE_LANGUAGE_MAPPINGS = Object.freeze({ + 'af': '🇿🇦', + 'sq': '🇦🇱', + 'am': '🇪🇹', + 'hy': '🇦🇲', + 'az': '🇦🇿', + 'eu': 'Basque', + 'be': '🇧🇾', + 'bn': '🇧🇩', + 'bs': '🇧🇦', + 'bg': '🇧🇬', + 'ceb': '🇵🇭', + 'ny': '🇲🇼', + 'zh-cn': '🇨🇳', + 'zh-tw': '🇨🇳', + 'hr': '🇭🇷', + 'cs': '🇨🇿', + 'da': '🇩🇰', + 'nl': '🇳🇱', + 'en': '🇺🇸', + 'et': '🇪🇪', + 'tl': '🇵🇭', + 'fi': '🇫🇮', + 'fr': '🇫🇷', + 'ka': '🇬🇪', + 'de': '🇩🇪', + 'el': '🇬🇷', + 'ht': '🇭🇹', + 'ha': '🇳🇬', + 'iw': '🇮🇱', + 'hi': '🇮🇳', + 'hu': '🇭🇺', + 'is': '🇮🇸', + 'ig': '🇳🇬', + 'id': '🇮🇩', + 'ga': '🇮🇪', + 'it': '🇮🇹', + 'ja': '🇯🇵', + 'jw': '🇮🇩', + 'kk': '🇰🇿', + 'km': '🇰🇭', + 'ko': '🇰🇷', + 'ky': '🇰🇬', + 'lo': '🇱🇦', + 'lv': '🇱🇻', + 'lt': '🇱🇹', + 'lb': '🇱🇺', + 'mk': '🇲🇰', + 'mg': '🇲🇬', + 'ms': '🇲🇾', + 'mt': '🇲🇹', + 'mi': '🇳🇿', + 'mr': '🇮🇳', + 'mn': '🇲🇳', + 'my': '🇲🇲', + 'ne': '🇳🇵', + 'no': '🇳🇴', + 'ps': '🇦🇫', + 'fa': '🇮🇷', + 'pl': '🇵🇱', + 'pt': '🇵🇹', + 'ro': '🇷🇴', + 'ru': '🇷🇺', + 'sm': '🇼🇸', + 'gd': '🏴󠁧󠁢󠁳󠁣󠁴󠁿', + 'sr': '🇷🇸', + 'st': '🇱🇸', + 'sn': '🇿🇼', + 'si': '🇱🇰', + 'sk': '🇸🇰', + 'sl': '🇸🇮', + 'so': '🇸🇴', + 'es': '🇪🇸', + 'su': '🇸🇩', + 'sw': '🇰🇪', + 'sv': '🇸🇪', + 'tg': '🇹🇯', + 'te': '🇮🇳', + 'th': '🇹🇭', + 'tr': '🇹🇷', + 'uk': '🇺🇦', + 'ur': '🇵🇰', + 'uz': '🇺🇿', + 'vi': '🇻🇳', + 'cy': '🏴󠁧󠁢󠁷󠁬󠁳󠁿', + 'xh': '🇿🇦', +}) + module.exports.TRANSLATE_LANGUAGES = Object.freeze({ 'auto': 'Automatic', 'af': 'Afrikaans', @@ -407,4 +505,39 @@ module.exports.EMOJIPEDIA_PLATFORM_TYPE_ALIASES = { "fluent": "microsoft-teams", "twemoji": "twitter", "playstation": "sony" -} \ No newline at end of file +} + +module.exports.GOOGLE_CLOUD_SAFETY_LABELS_NAMES = Object.freeze({ + "adult": "Explicit Content ", + "spoof": "Modified Image ", + "medical": "Medical Image ", + "violence": "Contains Violence", + "racy": "Lewd Content " +}) + +module.exports.GOOGLE_CLOUD_SAFETY_LABELS = Object.freeze({ + "UNKNOWN": { + icon: "question_large", + name: "Unknown " + }, + "VERY_UNLIKELY": { + icon: "exclaim_0", + name: "Very Unlikely" + }, + "UNLIKELY": { + icon: "exclaim_1", + name: "Unlikely " + }, + "POSSIBLE": { + icon: "exclaim_2", + name: "Possible " + }, + "LIKELY": { + icon: "exclaim_3", + name: "Likely " + }, + "VERY_LIKELY": { + icon: "exclaim_4", + name: "Very Likely " + } +}) \ No newline at end of file