MCPcopy Create free account
hub / github.com/Botloader/botloader / toOpMessageFields

Function toOpMessageFields

components/runtime/src/ts/discord/dapi.ts:214–264  ·  view source on GitHub ↗
(fields: CreateMessageFields)

Source from the content-addressed store, hash-verified

212 * @internal
213 */
214export function toOpMessageFields(fields: CreateMessageFields): Internal.OpCreateMessageFields {
215 let allowedMentions: Internal.AllowedMentions;
216 if (fields.allowedMentions) {
217 allowedMentions = {
218 parse: fields.allowedMentions.parse,
219 users: fields.allowedMentions.users ?? [],
220 roles: fields.allowedMentions.roles ?? [],
221 repliedUser: fields.allowedMentions.repliedUser ?? false,
222 }
223 } else {
224 allowedMentions = {
225 parse: ["Users"],
226 users: [],
227 roles: [],
228 repliedUser: false,
229 }
230 }
231
232 const userProvidedIds = (fields.attachments ?? []).map(v => v.id).filter(v => v !== undefined) as number[]
233 let idIncrementer = 0
234 // Provides automatic id generation for attachments, avoiding collisions with user provided ids
235 const nextAutoId = () => {
236 while (true) {
237 idIncrementer++
238
239 let next = idIncrementer
240 if (userProvidedIds.includes(next)) {
241 continue
242 }
243
244 return next
245 }
246 }
247
248 const attachments: Internal.OpCreateMessageFields["attachments"] = (fields.attachments ?? []).map(a => ({
249 dataB64: typeof a.data === "string"
250 ? base64Encode(encodeText(a.data))
251 : base64Encode(new Uint8Array(a.data)),
252
253 description: a.description ?? null,
254 filename: a.filename,
255 id: a.id ?? nextAutoId(),
256 }))
257
258 return {
259 ...fields,
260 allowedMentions: allowedMentions!,
261 attachments,
262 flags: fields.flags ?? {}
263 }
264}
265
266export type MentionParseTypes = "Everyone" | "Roles" | "Users";
267

Callers 12

ackWithMessageMethod · 0.90
ackWithUpdateMessageMethod · 0.90
ackWithUpdateMessageMethod · 0.90
createMessageFunction · 0.85
editMessageFunction · 0.85
createForumThreadFunction · 0.85
executeWebhookFunction · 0.85
editWebhookMessageFunction · 0.85

Calls 3

base64EncodeFunction · 0.90
encodeTextFunction · 0.90
nextAutoIdFunction · 0.85

Tested by

no test coverage detected