1 line
4.2 KiB
JavaScript
1 line
4.2 KiB
JavaScript
(function(f,p,S,o,v,e,g,y){"use strict";function d(){return v.storage.snippets??={},v.storage.snippets}function h(t,i){d()[t.trim()]=i}function m(t){delete d()[t]}const u=3,R=S.findByProps("sendMessage","sendBotMessage");function x(){const t=p.registerCommand({name:"snippet",description:"Send a saved text snippet",options:[{name:"name",description:"Snippet name",type:u,required:!0}],execute:function(r,s){const l=r.find(function(H){return H.name==="name"})?.value,c=l?d()[l]:void 0;if(!c){o.showToast(`No snippet named "${l}"`,void 0);return}if(!R?.sendMessage){o.showToast("Couldn't send the snippet - message action not found",void 0);return}R.sendMessage(s.channel.id,{content:c})}}),i=p.registerCommand({name:"snippet-save",description:"Save a text snippet",options:[{name:"name",description:"Snippet name",type:u,required:!0},{name:"text",description:"Snippet content",type:u,required:!0}],execute:function(r){const s=r.find(function(c){return c.name==="name"})?.value,l=r.find(function(c){return c.name==="text"})?.value;!s||!l||(h(s,l),o.showToast(`Saved snippet "${s}"`,void 0))}}),n=p.registerCommand({name:"snippet-delete",description:"Delete a saved text snippet",options:[{name:"name",description:"Snippet name",type:u,required:!0}],execute:function(r){const s=r.find(function(l){return l.name==="name"})?.value;s&&(m(s),o.showToast(`Deleted snippet "${s}"`,void 0))}}),a=p.registerCommand({name:"snippet-list",description:"List your saved snippet names",options:[],execute:function(){const r=Object.keys(d());o.showToast(r.length?r.join(", "):"No snippets saved yet",void 0)}});return[t,i,n,a]}const{ScrollView:T,View:w}=e.ReactNative;function $({children:t}){return e.React.createElement(T,{style:{flex:1}},t,e.React.createElement(w,{style:{height:24}}))}const{View:P,Text:C}=e.ReactNative;function F({children:t,style:i}){return e.React.createElement(P,{style:[{marginHorizontal:16,marginVertical:8,padding:10,borderRadius:8,borderWidth:1,borderColor:"rgba(128,128,128,0.25)"},i]},e.React.createElement(C,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},t))}const{Text:N}=e.ReactNative,{FormSection:k,FormRow:L}=y.Forms;function M({title:t,items:i,emptyText:n}){return e.React.createElement(k,{title:t},i.length===0?e.React.createElement(F,null,n):i.map(function(a){return e.React.createElement(L,{key:a.key,label:a.label,subLabel:a.subLabel,onPress:a.onPress,trailing:e.React.createElement(N,{style:{color:"#F23F42",fontSize:20,fontWeight:"700"}},"\xD7")})}))}const{TouchableOpacity:V,Text:j}=e.ReactNative;function q({label:t,onPress:i,disabled:n,style:a}){return e.React.createElement(V,{disabled:n,onPress:i,style:[{backgroundColor:"#5865F2",borderRadius:8,padding:10,alignItems:"center",opacity:n?.5:1},a]},e.React.createElement(j,{style:{color:"white",fontWeight:"600"}},t))}const{View:z}=e.ReactNative,{FormSection:D,FormInput:b}=y.Forms;function O(){const[t,i]=e.React.useState(""),[n,a]=e.React.useState(""),r=!!t.trim()&&!!n.trim();return e.React.createElement(z,{style:{paddingHorizontal:16,paddingBottom:12}},e.React.createElement(b,{title:"Name",placeholder:"e.g. rules",value:t,onChange:i}),e.React.createElement(b,{title:"Text",placeholder:"What /snippet should send",value:n,onChange:a,multiline:!0}),e.React.createElement(q,{label:"Save snippet",disabled:!r,style:{marginTop:8},onPress:function(){h(t.trim(),n),o.showToast(`Saved snippet "${t.trim()}"`,void 0),i(""),a("")}}))}function W(){g.useProxy(v.storage);const t=d();g.useProxy(t);const i=Object.keys(t);return e.React.createElement($,null,e.React.createElement(D,{title:"Add a snippet"},e.React.createElement(O,null)),e.React.createElement(M,{title:"Saved snippets",emptyText:"None yet. Add one above, then send it anywhere with /snippet name.",items:i.map(function(n){return{key:n,label:n,subLabel:`${t[n].slice(0,60)}${t[n].length>60?"\u2026":""} \u2022 Tap to delete`,onPress:function(){m(n),o.showToast(`Deleted snippet "${n}"`,void 0)}}})}))}let E=[];var B={onLoad:function(){E=x()},onUnload:function(){return E.forEach(function(t){return t()})},settings:W};return f.default=B,Object.defineProperty(f,"__esModule",{value:!0}),f})({},vendetta.commands,vendetta.metro,vendetta.ui.toasts,vendetta.plugin,vendetta.metro.common,vendetta.storage,vendetta.ui.components);
|