decord/source/modules/chat_input/native/ApplicationCommandOptionValueParser.tsx

539 lines
20 KiB
TypeScript
Raw Normal View History

// Module ID: 12023
// Function ID: 12024
// Name: ApplicationCommandOptionValueParser
// Dependencies: [32, 19, 5520, 1961, 2012, 2021, 2015, 4222, 1371, 5014, 12, 1369, 4727, 5456, 1894, 7696, 2]
2026-07-29 08:29:29 +00:00
// Exports: getRoles, parseOptionValuesForSend, useApplicationCommandOptionValueParser
2026-07-20 16:05:17 +00:00
// Module 12023 (ApplicationCommandOptionValueParser)
import _modDef12 from "module_12" /* 12 */;
import GlobalUtils from "GlobalUtils" /* 1369 */;
import Server from "Server" /* 1894 */;
import useChannelName from "useChannelName" /* 4727 */;
import MessageParser from "MessageParser" /* 7696 */;
import _slicedToArray from "module_32" /* 32 */;
import noop from "module_19" /* 19 */;
import ActiveJoinedThreadsStore from "ActiveJoinedThreadsStore" /* 5520 */;
import GuildChannelStore from "GuildChannelStore" /* 2012 */;
import GuildMemberStore from "GuildMemberStore" /* 2021 */;
import GuildRoleStore from "GuildRoleStore" /* 2015 */;
import RelationshipStore from "RelationshipStore" /* 4222 */;
import UserStore from "UserStore" /* 1371 */;
2026-07-23 10:11:24 +00:00
const MessageParserDefault = MessageParser;
require = fn;
2026-07-20 16:05:17 +00:00
function getUsers(getGuildId) {
const guildId = getGuildId.getGuildId();
if (getGuildId.isPrivate()) {
let mapped = _modDef12(getGuildId.recipients).map((userId) => ({ userId }));
const arr3 = _modDef12(getGuildId.recipients);
2026-07-20 16:05:17 +00:00
} else if (null != guildId) {
mapped = _modDef12(GuildMemberStore.getMembers(guildId)).map((userId) => ({ userId: userId.userId }));
const tmp7Result = _modDef12(GuildMemberStore.getMembers(guildId));
2026-07-20 16:05:17 +00:00
} else {
mapped = _modDef12([]);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const mapped1 = mapped.map((userId) => user.getUser(userId.userId));
const found = mapped1.filter(GlobalUtils.isNotNullish);
2026-07-20 16:05:17 +00:00
return found.map((id) => ({ id: id.id, text: id.tag }));
}
function getChannels(getGuildId, arr) {
_require = arr;
2026-07-20 16:05:17 +00:00
const guildId = getGuildId.getGuildId();
if (null == guildId) {
const items = [];
if (tmp2) {
items.push(getGuildId);
}
2026-07-23 10:11:24 +00:00
tmp2 = null == arr || arr.includes(getGuildId.type);
2026-07-29 08:29:29 +00:00
return guildId(12)(items).map((id) => {
const obj = { id: id.id, text: closure_0(4727).computeChannelName(id, UserStore, RelationshipStore) };
2026-07-20 16:05:17 +00:00
return obj;
});
} else {
dependencyMap = GuildChannelStore.getTextChannelNameDisambiguations(guildId);
2026-07-29 08:29:29 +00:00
const tmp9 = guildId(12);
const tmp9Result = guildId(12)(require("AutocompleteUtils").COMMAND_SUPPORTED_CHANNEL_TYPE_KEYS);
const combined = guildId(12)(require("AutocompleteUtils").COMMAND_SUPPORTED_CHANNEL_TYPE_KEYS).flatMap((item) => GuildChannelStore.getChannels(guildId)[item].map((channel) => channel.channel)).concat(ActiveJoinedThreadsStore.computeAllActiveJoinedThreads(guildId));
2026-07-20 16:05:17 +00:00
const found = combined.filter((type) => {
2026-07-29 08:29:29 +00:00
let hasItem = null == closure_0;
2026-07-20 16:05:17 +00:00
if (!hasItem) {
2026-07-29 08:29:29 +00:00
hasItem = closure_0.includes(type.type);
2026-07-20 16:05:17 +00:00
}
return hasItem;
});
return found.map((id) => {
2026-07-29 08:29:29 +00:00
const obj = { id: id.id, text: null };
if (closure_6(id.type)) {
2026-07-29 08:29:29 +00:00
let name;
if (dependencyMap[id.id] != null) {
name = tmp7.name;
}
if (name == null) {
name = useChannelName.computeChannelName(id, UserStore, RelationshipStore);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let channelName = name;
} else {
channelName = useChannelName.computeChannelName(id, UserStore, RelationshipStore);
2026-07-20 16:05:17 +00:00
}
obj.text = channelName;
2026-07-20 16:05:17 +00:00
return obj;
});
}
}
let closure_6 = fn(1961).isGuildSelectableChannelType;
const ChannelAutocompleteConstants = fn(5014);
({ MENTION_SENTINEL: closure_12, CHANNEL_SENTINEL: map1 } = ChannelAutocompleteConstants);
2026-07-29 08:29:29 +00:00
function matchPrefix(arg0, arg1, arg2) {
}
const prototype = function ApplicationCommandOptionValueParser(channel) {
const obj = Object.create(new.target.prototype);
obj.parse = function parse(text, type) {
2026-08-28 06:19:39 +00:00
const trimmed = text.trim();
let arr7 = trimmed;
const arr2 = getUsers(obj.channel);
2026-08-28 06:19:39 +00:00
closure_1 = arr2;
const guild_id = obj.channel.guild_id;
2026-07-29 08:29:29 +00:00
if (null != guild_id) {
sortedRoles = sortedRoles.getSortedRoles(guild_id);
2026-07-29 08:29:29 +00:00
} else {
sortedRoles = [];
}
closure_2 = _modDef12(sortedRoles).map((id) => ({ id: id.id, text: id.name }));
2026-08-28 06:19:39 +00:00
closure_3 = arr2.map((text) => {
2026-08-24 06:08:38 +00:00
obj = {};
2026-07-29 08:29:29 +00:00
const merged = Object.assign(text);
obj.text = text.text.split("#")[0];
return obj;
2026-07-20 16:05:17 +00:00
});
2026-07-29 08:29:29 +00:00
function matchUser() {
const arr = closure_2_12;
if (typeof closure_2_14 === "function") {
let firstResult = null;
2026-07-29 08:29:29 +00:00
if (str[0] === arr) {
closure_1 = str.substr(arr.length);
const found = obj.sortBy((text) => -text.text.length).filter((text) => {
2026-07-29 08:29:29 +00:00
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
const mapped = found.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult = mapped.first();
const sortByResult = obj.sortBy((text) => -text.text.length);
2026-07-29 08:29:29 +00:00
}
let id;
if (firstResult != null) {
id = firstResult.id;
2026-07-29 08:29:29 +00:00
}
if (null != id) {
const obj2 = { type: "userMention", userId: firstResult.id };
let tmp7 = obj2;
} else {
if (typeof tmp === "function") {
let firstResult1 = null;
if (str[0] === arr) {
closure_1 = str.substr(arr.length);
const found1 = obj6.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
const mapped1 = found1.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult1 = mapped1.first();
const sortByResult1 = obj6.sortBy((text) => -text.text.length);
}
let id1;
if (firstResult1 != null) {
id1 = firstResult1.id;
}
if (null != id1) {
const obj3 = { type: "userMention", userId: firstResult1.id };
tmp7 = obj3;
}
} else {
throw new TypeError("Trying to call a non-function");
}
obj6 = closure_3;
2026-07-29 08:29:29 +00:00
}
return tmp7;
} else {
throw new TypeError("Trying to call a non-function");
2026-07-29 08:29:29 +00:00
}
obj = closure_1;
2026-07-29 08:29:29 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.USER) {
2026-07-29 08:29:29 +00:00
const matchUserResult = matchUser();
if (null != matchUserResult) {
return matchUserResult;
} else {
2026-08-28 06:19:39 +00:00
let str = trimmed;
if (trimmed[0] === closure_2_12) {
2026-08-28 06:19:39 +00:00
str = trimmed.slice(1);
}
[tmp7, tmp8] = str.split("#", 2);
2026-08-28 06:19:39 +00:00
if (null != tmp8) {
if ("0000" !== tmp8) {
obj = /^[0-9]{4}$/;
if (obj.test(tmp8)) {
let findByTagResult = UserStore.findByTag(tmp7, tmp8);
2026-08-28 06:19:39 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (null != findByTagResult) {
let obj2 = { type: "userMention", userId: findByTagResult.id };
return obj2;
2026-07-29 08:29:29 +00:00
}
}
findByTagResult = UserStore.findByTag(tmp7);
const tmp6 = _slicedToArray(str.split("#", 2), 2);
2026-07-29 08:29:29 +00:00
}
}
function matchRole() {
const arr = closure_2_12;
if (typeof closure_2_14 === "function") {
let firstResult = null;
if (str[0] === arr) {
closure_1 = str.substr(arr.length);
const found = obj.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
const mapped = found.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult = mapped.first();
const sortByResult = obj.sortBy((text) => -text.text.length);
}
let id;
if (firstResult != null) {
id = firstResult.id;
}
if (null != id) {
const obj2 = { type: "roleMention", roleId: firstResult.id };
let obj3 = obj2;
} else if ("@everyone" === str) {
obj3 = { type: "textMention", text: "@everyone" };
}
return obj3;
} else {
throw new TypeError("Trying to call a non-function");
2026-07-29 08:29:29 +00:00
}
obj = closure_2;
2026-07-29 08:29:29 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.ROLE) {
2026-07-29 08:29:29 +00:00
const matchRoleResult = matchRole();
if (null != matchRoleResult) {
return matchRoleResult;
}
}
if (type.type === channel(1894).ApplicationCommandOptionType.CHANNEL) {
arr7 = closure_2_13;
if (typeof matchPrefix === "function") {
let firstResult = null;
if (trimmed[0] === arr7) {
closure_1 = trimmed.substr(arr7.length);
let found = obj8.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
let mapped = found.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult = mapped.first();
let sortByResult = obj8.sortBy((text) => -text.text.length);
2026-07-29 08:29:29 +00:00
}
if (null != firstResult) {
if (null != firstResult.id) {
const obj4 = { type: "channelMention", channelId: firstResult.id };
return obj4;
}
}
} else {
throw new TypeError("Trying to call a non-function");
2026-07-29 08:29:29 +00:00
}
obj8 = getChannels(obj.channel, type.channelTypes);
2026-07-29 08:29:29 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.MENTIONABLE) {
2026-07-29 08:29:29 +00:00
const matchRoleResult1 = matchRole();
if (null != matchRoleResult1) {
return matchRoleResult1;
} else {
const matchUserResult1 = matchUser();
if (null != matchUserResult1) {
return matchUserResult1;
} else {
2026-08-28 06:19:39 +00:00
let str4 = trimmed;
if (trimmed[0] === closure_2_12) {
2026-08-28 06:19:39 +00:00
str4 = trimmed.slice(1);
}
[tmp16, tmp17] = str4.split("#", 2);
2026-08-28 06:19:39 +00:00
if (null != tmp17) {
if ("0000" !== tmp17) {
if (obj3.test(tmp17)) {
let findByTagResult1 = UserStore.findByTag(tmp16, tmp17);
2026-08-28 06:19:39 +00:00
}
obj3 = /^[0-9]{4}$/;
2026-08-28 06:19:39 +00:00
}
2026-07-29 08:29:29 +00:00
if (null != findByTagResult1) {
const obj5 = { type: "userMention", userId: findByTagResult1.id };
return obj5;
2026-07-29 08:29:29 +00:00
}
}
findByTagResult1 = UserStore.findByTag(tmp16);
const tmp15 = _slicedToArray(str4.split("#", 2), 2);
2026-07-29 08:29:29 +00:00
}
}
}
return { type: "text", text };
2026-07-29 08:29:29 +00:00
};
obj.channel = channel;
return obj;
}.prototype;
const size = fn(2);
const result = size.fileFinishedImporting("modules/chat_input/native/ApplicationCommandOptionValueParser.tsx");
2026-07-29 08:29:29 +00:00
export { getUsers };
export const getRoles = function getRoles(guild_id) {
guild_id = guild_id.guild_id;
if (null != guild_id) {
let sortedRoles = GuildRoleStore.getSortedRoles(guild_id);
2026-07-29 08:29:29 +00:00
} else {
sortedRoles = [];
2026-07-20 16:05:17 +00:00
}
return _modDef12(sortedRoles).map((id) => ({ id: id.id, text: id.name }));
2026-07-29 08:29:29 +00:00
};
export { getChannels };
export const ApplicationCommandOptionValueParser = prototype;
export const parseOptionValuesForSend = function parseOptionValuesForSend(channel, command, current) {
if (null == command.options) {
2026-07-29 08:29:29 +00:00
return {};
} else {
const obj3 = {};
const options = command.options;
const parserState = MessageParser.createParserState(channel);
2026-07-29 08:29:29 +00:00
const iter = options[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
let tmp4 = nextResult;
let tmp5 = current[nextResult.name];
let tmp6 = tmp5;
if (null != tmp5) {
if ("text" === tmp6[0].type) {
if (tmp4.type === Server.ApplicationCommandOptionType.STRING) {
2026-07-29 08:29:29 +00:00
if (null == tmp4.choices) {
if (!tmp4.autocomplete) {
let obj = { type: "text", text: null };
let obj2 = MessageParserDefault;
obj.text = obj2.parse(channel, tmp6[0].text, parserState).content;
2026-07-29 08:29:29 +00:00
let items = [obj];
obj3[tmp4.name] = items;
2026-07-29 08:29:29 +00:00
}
}
}
}
obj3[tmp4.name] = tmp6;
2026-07-29 08:29:29 +00:00
}
continue;
}
return obj3;
2026-07-29 08:29:29 +00:00
}
};
export const useApplicationCommandOptionValueParser = function useApplicationCommandOptionValueParser(channel) {
channel = channel.channel;
const items = [channel];
return noop.useMemo(() => {
if (typeof prototype === "function") {
let obj = Object.create(prototype.prototype);
obj.parse = function parse(text, type) {
const trimmed = text.trim();
let arr7 = trimmed;
const arr2 = getUsers(obj.channel);
closure_1 = arr2;
const guild_id = obj.channel.guild_id;
if (null != guild_id) {
sortedRoles = sortedRoles.getSortedRoles(guild_id);
2026-07-20 16:05:17 +00:00
} else {
sortedRoles = [];
2026-07-20 16:05:17 +00:00
}
closure_2 = _modDef12(sortedRoles).map((id) => ({ id: id.id, text: id.name }));
closure_3 = arr2.map((text) => {
obj = {};
const merged = Object.assign(text);
obj.text = text.text.split("#")[0];
return obj;
});
function matchUser() {
const arr = closure_2_12;
if (typeof closure_2_14 === "function") {
let firstResult = null;
if (str[0] === arr) {
closure_1 = str.substr(arr.length);
const found = obj.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
const mapped = found.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult = mapped.first();
const sortByResult = obj.sortBy((text) => -text.text.length);
}
let id;
if (firstResult != null) {
id = firstResult.id;
2026-08-28 06:19:39 +00:00
}
if (null != id) {
const obj2 = { type: "userMention", userId: firstResult.id };
let tmp7 = obj2;
} else {
if (typeof tmp === "function") {
let firstResult1 = null;
if (str[0] === arr) {
closure_1 = str.substr(arr.length);
const found1 = obj6.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
const mapped1 = found1.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult1 = mapped1.first();
const sortByResult1 = obj6.sortBy((text) => -text.text.length);
}
let id1;
if (firstResult1 != null) {
id1 = firstResult1.id;
}
if (null != id1) {
const obj3 = { type: "userMention", userId: firstResult1.id };
tmp7 = obj3;
}
} else {
throw new TypeError("Trying to call a non-function");
}
obj6 = closure_3;
2026-07-20 16:05:17 +00:00
}
return tmp7;
} else {
throw new TypeError("Trying to call a non-function");
2026-07-20 16:05:17 +00:00
}
obj = closure_1;
2026-07-29 08:29:29 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.USER) {
const matchUserResult = matchUser();
if (null != matchUserResult) {
return matchUserResult;
} else {
let str = trimmed;
if (trimmed[0] === closure_2_12) {
str = trimmed.slice(1);
}
[tmp7, tmp8] = str.split("#", 2);
if (null != tmp8) {
if ("0000" !== tmp8) {
obj = /^[0-9]{4}$/;
if (obj.test(tmp8)) {
let findByTagResult = UserStore.findByTag(tmp7, tmp8);
}
}
if (null != findByTagResult) {
let obj2 = { type: "userMention", userId: findByTagResult.id };
return obj2;
}
}
findByTagResult = UserStore.findByTag(tmp7);
const tmp6 = _slicedToArray(str.split("#", 2), 2);
}
2026-07-20 16:05:17 +00:00
}
function matchRole() {
const arr = closure_2_12;
if (typeof closure_2_14 === "function") {
let firstResult = null;
if (str[0] === arr) {
closure_1 = str.substr(arr.length);
const found = obj.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
const mapped = found.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult = mapped.first();
const sortByResult = obj.sortBy((text) => -text.text.length);
}
let id;
if (firstResult != null) {
id = firstResult.id;
}
if (null != id) {
const obj2 = { type: "roleMention", roleId: firstResult.id };
let obj3 = obj2;
} else if ("@everyone" === str) {
obj3 = { type: "textMention", text: "@everyone" };
}
return obj3;
} else {
throw new TypeError("Trying to call a non-function");
}
obj = closure_2;
2026-07-29 08:29:29 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.ROLE) {
const matchRoleResult = matchRole();
if (null != matchRoleResult) {
return matchRoleResult;
}
2026-07-29 08:29:29 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.CHANNEL) {
arr7 = closure_2_13;
if (typeof matchPrefix === "function") {
let firstResult = null;
if (trimmed[0] === arr7) {
closure_1 = trimmed.substr(arr7.length);
let found = obj8.sortBy((text) => -text.text.length).filter((text) => {
const formatted = closure_1.toLowerCase();
return formatted === text.text.toLowerCase();
});
let mapped = found.map((id) => ({ text: arr + id.text, id: id.id }));
firstResult = mapped.first();
let sortByResult = obj8.sortBy((text) => -text.text.length);
}
if (null != firstResult) {
if (null != firstResult.id) {
const obj4 = { type: "channelMention", channelId: firstResult.id };
return obj4;
}
}
} else {
throw new TypeError("Trying to call a non-function");
2026-07-20 16:05:17 +00:00
}
obj8 = getChannels(obj.channel, type.channelTypes);
2026-07-20 16:05:17 +00:00
}
if (type.type === channel(1894).ApplicationCommandOptionType.MENTIONABLE) {
const matchRoleResult1 = matchRole();
if (null != matchRoleResult1) {
return matchRoleResult1;
2026-07-20 16:05:17 +00:00
} else {
const matchUserResult1 = matchUser();
if (null != matchUserResult1) {
return matchUserResult1;
} else {
let str4 = trimmed;
if (trimmed[0] === closure_2_12) {
str4 = trimmed.slice(1);
2026-08-28 06:19:39 +00:00
}
[tmp16, tmp17] = str4.split("#", 2);
if (null != tmp17) {
if ("0000" !== tmp17) {
if (obj3.test(tmp17)) {
let findByTagResult1 = UserStore.findByTag(tmp16, tmp17);
}
obj3 = /^[0-9]{4}$/;
}
if (null != findByTagResult1) {
const obj5 = { type: "userMention", userId: findByTagResult1.id };
return obj5;
}
2026-07-20 16:05:17 +00:00
}
findByTagResult1 = UserStore.findByTag(tmp16);
const tmp15 = _slicedToArray(str4.split("#", 2), 2);
2026-07-20 16:05:17 +00:00
}
}
}
return { type: "text", text };
};
obj.channel = tmp;
return obj;
} else {
throw new TypeError("Trying to call a non-function");
}
2026-07-29 08:29:29 +00:00
}, items);
2026-07-20 16:05:17 +00:00
};