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