156 lines
4.4 KiB
TypeScript
156 lines
4.4 KiB
TypeScript
// Metro module 6038 (f6039).
|
|
import ReferencedMessageStore, { ReferencedMessageState } from "../replies/ReferencedMessageStore";
|
|
import UserRecord from "../../records/UserRecord";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { LOCAL_BOT_ID, MessageFlags, MessageStates, MessageTypes, NON_USER_BOT_DISCRIMINATOR } from "../../Constants";
|
|
import Module38 from "../../_bundle/Module38";
|
|
import { createNonce } from "./createNonce";
|
|
export default function createMessage(a0) {
|
|
let author, boostingPrompt, changelogId, flags, giftingPrompt, mediaMention, mentionGames, mentions, messageReference, nonce, poll, sharedCustomTheme, state;
|
|
const { channelId, content, tts = false, type = MessageTypes.DEFAULT } = a0;
|
|
L11: {
|
|
messageReference = a0.messageReference;
|
|
const allowedMentions = a0.allowedMentions;
|
|
author = a0.author;
|
|
flags = a0.flags;
|
|
nonce = a0.nonce;
|
|
poll = a0.poll;
|
|
sharedCustomTheme = a0.sharedCustomTheme;
|
|
changelogId = a0.changelogId;
|
|
giftingPrompt = a0.giftingPrompt;
|
|
boostingPrompt = a0.boostingPrompt;
|
|
state = a0.state;
|
|
mediaMention = a0.mediaMention;
|
|
mentionGames = a0.mentionGames;
|
|
mentions = [];
|
|
if (type === MessageTypes.REPLY) {
|
|
Module38(messageReference != null, "Replies must have a message reference");
|
|
if (allowedMentions != null && !allowedMentions.replied_user) {
|
|
break L11;
|
|
}
|
|
const messageByReference = ReferencedMessageStore.getMessageByReference(messageReference);
|
|
if (messageByReference?.state === ReferencedMessageState.LOADED) {
|
|
const author2 = messageByReference.message.author;
|
|
mentions.push({
|
|
id: author2.id,
|
|
username: author2.username,
|
|
avatar: author2.avatar,
|
|
discriminator: author2.discriminator,
|
|
bot: author2.bot,
|
|
global_name: author2.globalName,
|
|
primary_guild: author2.primaryGuild
|
|
});
|
|
}
|
|
}
|
|
}
|
|
if (author == null) {
|
|
author = UserStore.getCurrentUser();
|
|
}
|
|
const author3 = author instanceof UserRecord ? {
|
|
id: author.id,
|
|
username: author.username,
|
|
avatar: author.avatar,
|
|
discriminator: author.discriminator,
|
|
bot: author.bot,
|
|
global_name: author.globalName,
|
|
primary_guild: author.primaryGuild
|
|
} : author;
|
|
Module38(author3 != null, "createMessage: author cannot be undefined");
|
|
let id = nonce;
|
|
if (id == null) {
|
|
id = createNonce();
|
|
}
|
|
const r81 = {
|
|
id,
|
|
type,
|
|
content,
|
|
channel_id: channelId,
|
|
author: author3,
|
|
attachments: [],
|
|
embeds: [],
|
|
pinned: false,
|
|
mentions,
|
|
mention_channels: [],
|
|
mention_roles: [],
|
|
mention_everyone: false,
|
|
mention_games: mentionGames,
|
|
timestamp: new Date().toISOString(),
|
|
state: null,
|
|
tts: null,
|
|
message_reference: null,
|
|
message_snapshots: null,
|
|
flags: null,
|
|
nonce: null,
|
|
poll: null,
|
|
shared_client_theme: null,
|
|
changelog_id: null,
|
|
gifting_prompt: null,
|
|
boosting_prompt: null,
|
|
media_mention: null
|
|
};
|
|
if (state == null) {
|
|
state = MessageStates.SENDING;
|
|
}
|
|
r81.state = state;
|
|
r81.tts = tts;
|
|
r81.message_reference = messageReference;
|
|
r81.message_snapshots = [];
|
|
r81.flags = flags;
|
|
r81.nonce = nonce;
|
|
r81.poll = poll;
|
|
r81.shared_client_theme = sharedCustomTheme;
|
|
r81.changelog_id = changelogId;
|
|
r81.gifting_prompt = giftingPrompt;
|
|
r81.boosting_prompt = boostingPrompt;
|
|
r81.media_mention = mediaMention;
|
|
return r81;
|
|
};
|
|
export function userRecordToServer(a0) {
|
|
return {
|
|
id: a0.id,
|
|
username: a0.username,
|
|
avatar: a0.avatar,
|
|
discriminator: a0.discriminator,
|
|
bot: a0.bot,
|
|
global_name: a0.globalName,
|
|
primary_guild: a0.primaryGuild
|
|
};
|
|
}
|
|
export function createBotMessage(a0) {
|
|
let messageId = a0.messageId;
|
|
const { channelId, content } = a0;
|
|
let embeds = a0.embeds;
|
|
const loggingName = a0.loggingName;
|
|
if (messageId == null) {
|
|
messageId = createNonce();
|
|
}
|
|
if (embeds == null) {
|
|
embeds = [];
|
|
}
|
|
return {
|
|
id: messageId,
|
|
type: MessageTypes.DEFAULT,
|
|
flags: MessageFlags.EPHEMERAL,
|
|
content,
|
|
channel_id: channelId,
|
|
author: {
|
|
id: LOCAL_BOT_ID,
|
|
username: "Clyde",
|
|
discriminator: NON_USER_BOT_DISCRIMINATOR,
|
|
avatar: "clyde",
|
|
bot: true
|
|
},
|
|
attachments: [],
|
|
embeds,
|
|
pinned: false,
|
|
mentions: [],
|
|
mention_channels: [],
|
|
mention_roles: [],
|
|
mention_everyone: false,
|
|
timestamp: new Date().toISOString(),
|
|
state: MessageStates.SENT,
|
|
tts: false,
|
|
loggingName
|
|
};
|
|
}
|