MCPcopy Create free account
hub / github.com/FxEmbed/FxEmbed / getStatusText

Function getStatusText

src/embed/activity.ts:137–200  ·  view source on GitHub ↗
(status: APIStatus)

Source from the content-addressed store, hash-verified

135}
136
137const getStatusText = (status: APIStatus): StatusTextResult => {
138 let text: string;
139
140 // Check if is Twitter so we can detect article
141 if (status.provider === DataProvider.Twitter) {
142 const twitterStatus = status as APITwitterStatus;
143 if (twitterStatus.article) {
144 const articleResult = renderArticleToHtml(twitterStatus.article.content, {
145 maxLength: DISCORD_ARTICLE_MAX_LENGTH,
146 fullRenderer: false,
147 mediaEntities: twitterStatus.article.media_entities
148 });
149
150 // Prepend article title
151 text = `<b>📰 ${twitterStatus.article.title}</b>${articleResult.html}`;
152
153 return { text, articleMedia: articleResult.collectedMedia };
154 }
155 }
156
157 const convertedStatusText = status.text.trim().replace(/\n/g, '<br>︀︀');
158
159 if (status.translation) {
160 console.log('translation', JSON.stringify(status.translation));
161 const { translation } = status;
162
163 const formatText = `<b>📑 {translation}</b>`.format({
164 translation: i18next.t('translatedFrom').format({
165 language: i18next.t(`language_${translation?.source_lang}`)
166 })
167 });
168
169 text = `${formatText}<br><br>${formatStatus(translation?.text ?? '', status)}<br><br>`;
170 text += `<blockquote><b>${i18next.t('ivOriginalText')}</b><br>${formatStatus(convertedStatusText, status)}</blockquote>`;
171 } else {
172 text = formatStatus(convertedStatusText, status) + '<br><br>';
173 }
174 if (status.quote) {
175 if (isTombstone(status.quote)) {
176 text += `<blockquote><i>${status.quote.message}</i></blockquote>`;
177 } else {
178 const quoteText = (status.quote.translation?.text ?? status.quote.text)
179 .trim()
180 .replace(/\n/g, '<br>︀︀');
181 text += `<blockquote><b>${i18next.t('ivQuoteHeader').format({
182 authorName: status.quote.author.name,
183 authorURL: status.quote.author.url,
184 authorHandle: status.quote.author.screen_name,
185 url: status.quote.url
186 })}</b><br>︀<br>${formatStatus(quoteText, status.quote)}</blockquote>`;
187 }
188 }
189 if (status.replying_to) {
190 text = `<sub>↩ <a href="${status.replying_to.profile_url}" class="u-url mention">${status.replying_to.display_name ?? ''} (@${status.replying_to.screen_name})</a></sub><br>${text}`;
191 }
192 if (status.poll) {
193 text += `${generatePoll(status.poll)}`;
194 }

Callers 1

handleActivityFunction · 0.85

Calls 6

renderArticleToHtmlFunction · 0.90
isTombstoneFunction · 0.90
getActivitySocialProofFunction · 0.90
formatStatusFunction · 0.85
formatMethod · 0.80
generatePollFunction · 0.70

Tested by

no test coverage detected