Build 584177stable
Module 870748
8,692 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{A:()=>L,t:()=>y}),n(321073),n(667532);var i=n(485845),r=n(155718),a=n(721768),s=n(459016),l=n(842209),o=n(861382),d=n(392054),c=n(168186),u=n(203779),_=n(649671),E=n(853145),A=n(734057),h=n(317525),I=n(287809),f=n(317681),p=n(186306),T=n(323350),m=n(35277),g=n(820066),S=n(551483),N=n(652215);n(827669);let C=new Set(["applicationCommandOption"]),O=new Set([r.n4.ATTACHMENT]),R=new Set(["line","applicationCommand"]);function L(e,t){let{insertData:n,isInline:u,isVoid:A,onChange:h,deleteBackward:I,deleteForward:N,deleteFragment:L}=e;e.insertData=i=>{if(null!=t&&g.VW.isEditorEmpty(e)&&i.types.includes("application/x-discord-interaction-data")){let e=JSON.parse(i.getData("application/x-discord-interaction-data")),{commandKey:n,interactionOptions:r}=(0,c.Ez)(e),{application:o,command:u}=l.EW({channel:t,type:"channel"},n);if(null!=u){let e=null!=o?{type:d.Hf.APPLICATION,id:o.id,icon:o.icon,name:o.bot?.username??o.name,application:o}:null;return a.Gf({channelId:t.id,command:u,section:e,location:d.Oh.PASTE,initialValues:(0,s.getInitialValuesFromInteractionOptions)(u,r??[])}),null}}return n(i)},e.isInline=e=>!!C.has(e.type)||u(e),e.isVoid=e=>!!("applicationCommandOption"===e.type&&O.has(e.optionType))||A(e),e.deleteBackward=t=>{M(e,()=>I(t))},e.deleteForward=t=>{M(e,()=>N(t))},e.deleteFragment=t=>{M(e,()=>L(t))};let U=null,w=null,G=null,x=null,k=null;return e.onChange=()=>{if(null!=t){let n=o.A.getState(t.id),s=l.j8({channel:t,type:"channel"});if(g.VW.richValue(e)!==U||!g.Ot.equals(e.selection,w)||n.activeCommand!==G||null==k||s.some((e,t)=>k[t]!==e)){let o=p.o.withMergedEntry(e,()=>(function(e){let{editor:t,storeCommandState:n,channel:s,commandChanged:o,previousOptionValues:c}=e,{command:u,commandText:A}=b(t),h=n.activeCommand,I=t.chatInputType.commands?.enabled===!0,p=null!=E.A.getPendingReply(s.id);if(!I&&h?.integration_types?.includes(i.b.GUILD_INSTALL)||p&&h?.inputType!==d.y$.BUILT_IN_TEXT&&h?.inputType!==d.y$.BUILT_IN_INTEGRATION)return null!=u&&y(t,s.id,h,!0),null;if(null!=u){if(g.VW.isEditorEmpty(t)||null==h)return y(t,s.id,h,!1),null;let e=`/${u.displayName}`;if(null==A||!A.startsWith(e)||0===f.O7(t).length&&(A.length<e.length+1||" "!==A[e.length]))return y(t,s.id,h,!0),null}else{if(null!=h&&o){let e=function(e,t,n){let i,{initialValues:r,activeCommand:a}=n;if(null==a)return null;let s=(a.options?.length??0)>0?f.pY(e,a):null,l=(0,T.WO)(g.VW.richValue(e),{mode:"raw",range:{anchor:g.VW.start(e,[]),focus:s?.[0]?.keyRange.anchor??g.VW.end(e,[])}}),o="",d=l.toLocaleLowerCase(),c=`/${a.displayName} `.toLocaleLowerCase(),u=`/${a.untranslatedName} `.toLocaleLowerCase();d.startsWith(c)?o=l.substring(c.length).trim():d.startsWith(u)&&(o=l.substring(u.length).trim());let _=[],E=null,A=null;if(null!=a.options){let e=new Set;if(null!=s)for(let i of s){e.add(i.name);let r=P(n,t,i.name)??i.text,a={type:"applicationCommandOption",optionName:i.name,optionDisplayName:i.displayName,optionType:i.type,children:[{text:r}]};_.push(a),0===i.text.length&&null==E&&(E=a)}for(let i of a.options)if(!e.has(i.name)&&(i.required||null!=r[i.name])){let e,r;o.length>0&&!O.has(i.type)?(e=o,o=""):e=(r=P(n,t,i.name))??"";let a={type:"applicationCommandOption",optionName:i.name,optionDisplayName:i.displayName,optionType:i.type,children:[{text:e}]};_.push(a),0===e.length&&null==E&&(E=a),null==r&&(A=a)}}i=o.length>0?`/${a.displayName} ${o.replace(/\r|\n/g," ")}`:0===_.length?`/${a.displayName} `:`/${a.displayName}`,_.unshift({text:i});let h={type:"applicationCommand",children:_,command:{id:a.id,name:a.untranslatedName,displayName:a.displayName}};g.VW.withoutNormalizing(e,()=>{for(let[,t]of(m.b.insertNodes(e,[h],{at:S.Xg}),g.VW.blocks(e).reverse()))g.PW.isAfter(t,S.Xg)&&m.b.removeNodes(e,{at:t,voids:!0})});let I=null;return null!=E?(m.b.selectCommandOption(e,E.optionName),I=E.optionName):null!=A?(m.b.selectCommandOption(e,A.optionName,!1),I=A.optionName):m.b.resetSelectionToEditorEnd(e),null==A&&D(e,a),I}(t,s,n),i=f.SQ(t,h,s.id);return v({guildId:s.guild_id,channelId:s.id,command:h,activeOption:e,currentOptionValues:i,previousOptionValues:null,validateAll:!0,allowEmpty:!0}),{commandId:h.id,optionValues:i}}if(null!=h&&!o)return a.Gf({channelId:s.id,command:null,section:null}),null;let e=g.VW.richValue(t)[0],i=e.children[0];if(R.has(e.type)&&g.l5.isText(i)){let e=function(e,t){if(!e.startsWith("/"))return null;let n=(0,_.Yn)(t,e.substring(1));if(!n.hasSpaceTerminator)return null;let{commands:i,sections:a}=l.v7({channel:t,type:"channel"},r.kc.CHAT,n.text);if(0===i.length)return null;let s=n.text.trim(),o=s+" ",c=i.filter(e=>e.inputType!==d.y$.PLACEHOLDER&&(e.displayName===s||e.displayName.startsWith(o)));if(1===c.length&&c[0].displayName===s){let e=c[0],t=a.find(t=>t.application?.id===e.applicationId);return{command:e,section:t}}return null}(i.text,s);if(null!=e)return a.Gf({channelId:s.id,command:e.command,section:e.section}),null}}if(null!=h&&null!=u){!function(e,t){if(null==t.options||0===t.options.length)return!1;let n=f.pY(e,t);return 0!==n.length&&(g.VW.withoutNormalizing(e,()=>{for(let t=n.length-1;t>=0;t--){let i=n[t];m.b.textToInline(e,{type:"applicationCommandOption",optionName:i.name,optionDisplayName:i.displayName,optionType:i.type,children:[{text:i.text}]},{anchor:i.keyRange.anchor,focus:i.valueRange.focus})}let t=g.VW.getFirstText(e);if(null==t)return!1;let i=t.text.trim();t.text!==i&&m.b.textToText(e,i,{anchor:{path:S.fP,offset:0},focus:{path:S.fP,offset:t.text.length}})}),!0)}(t,h)&&D(t,h);let e=f.SQ(t,h,s.id),n=g.VW.above(t,{match:e=>g.VW.isInline(t,e)&&"applicationCommandOption"===e.type,mode:"lowest"}),i=n?.[0].optionName??null;return v({guildId:s.guild_id,channelId:s.id,command:h,activeOption:i,currentOptionValues:e,previousOptionValues:c,validateAll:!1,allowEmpty:!1}),{commandId:u.id,optionValues:e}}return null})({editor:e,storeCommandState:n,channel:t,commandChanged:n.activeCommand?.id!==G?.id,previousOptionValues:x}));if(null!=o){let t=p.o.currentEntry(e);null!=t&&(t.commandId=o.commandId),x=o.optionValues}else x=null;U=g.VW.richValue(e),w=e.selection,G=n.activeCommand,k=s}}h()},e}function y(e,t,n,i){let[r]=g.VW.blocks(e)[0],s=(i?(0,T.IQ)(r,{mode:"plain"}).trimEnd():"").split("\n").map(e=>({type:"line",children:[{text:e}]})),l=[s.length-1];for(let[,t]of(m.b.insertNodes(e,s,{at:S.Xg}),g.VW.blocks(e).reverse()))g.PW.isAfter(t,l)&&m.b.removeNodes(e,{at:t,voids:!0});null!=n&&a.Gf({channelId:t,command:null,section:null})}function D(e,t){if(null==t.options||1!==t.options.length||!0===t.options[0].required||O.has(t.options[0].type)||f.O7(e).length>0||null==f.n$(e))return!1;let n=g.VW.getFirstText(e);if(null==n)return!1;let i=t.options[0],r={path:S.fP,offset:t.displayName.length+2},a={path:S.fP,offset:n.text.length};return!(!n.text.startsWith(`/${t.displayName} `.toLocaleLowerCase())||g.Kh.equals(r,a))&&(m.b.textToInline(e,{type:"applicationCommandOption",optionName:i.name,optionDisplayName:i.displayName,optionType:i.type,children:[{text:n.text.substring(t.displayName.length+2)}]},{anchor:r,focus:a}),!0)}function v(e){let{guildId:t,channelId:n,command:i,activeOption:r,currentOptionValues:s,previousOptionValues:l,validateAll:d,allowEmpty:c}=e;if(null==i.options)return!1;let _=d?null:o.A.getActiveOptionName(n),E={},A=o.A.getOptionStates(n),h=!1;for(let e of i.options){let i=A[e.name],a=d||e.name===_&&_!==r||i?.lastValidationResult?.success===!1&&s?.[e.name]!==l?.[e.name],o={hasValue:null!=s&&e.name in s,isActive:e.name===r,lastValidationResult:a?(0,u.J)({option:e,content:s?.[e.name]??null,guildId:t,channelId:n,allowEmptyValues:c}):i?.lastValidationResult};(null==i||i.hasValue!==o.hasValue||i.isActive!==o.isActive||a&&i.lastValidationResult?.success===!1)&&(E[e.name]=o,h=!0)}h&&a.H2(n,E)}function b(e){let t=f.n$(e);if(null==t)return{command:null,commandText:null};let[n]=t,i=n.children[0];return g.l5.isText(i)?{command:n.command,commandText:i.text}:{command:n.command,commandText:null}}function M(e,t){let n=f.O7(e)[0];t();let i=g.ZF.toPoint(e.selection);if(null==i||n===f.O7(e)[0])return;let{command:r,commandText:a}=b(e);!(null==r||null==a||a.endsWith(" "))&&g.Kh.equals(i,{path:S.fP,offset:r.displayName.length+1})&&m.b.insertText(e," ")}function P(e,t,n){let i=e.activeCommand?.options?.find(e=>e.name===n),a=e.initialValues[n];if(null==i||null==a)return null;if(null!=i.choices)return i.choices.find(e=>e.value===a.value)?.displayName;let s=a.value?.toString();return i.type===r.n4.CHANNEL||i.type===r.n4.MENTIONABLE&&null!=A.A.getChannel(s)?`<#${s}> `:i.type===r.n4.USER||i.type===r.n4.MENTIONABLE&&null!=I.default.getUser(s)?`<@${s}>`:i.type===r.n4.ROLE||i.type===r.n4.MENTIONABLE&&null!=h.A.getRole(t.guild_id,s??N.dJq)?`<@&${s}>`:s}}