1 line
3.6 KiB
JavaScript
1 line
3.6 KiB
JavaScript
(function(s,y,o,u,p,i,l,R){"use strict";const w={s:1e3,sec:1e3,secs:1e3,second:1e3,seconds:1e3,m:6e4,min:6e4,mins:6e4,minute:6e4,minutes:6e4,h:36e5,hr:36e5,hrs:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5};function b(t){const e=t.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)\s*([a-z]+)$/);if(!e)return;const n=Number(e[1]),r=w[e[2]];if(!(!r||!Number.isFinite(n)||n<=0))return Math.round(n*r)}function a(){return u.storage.reminders??=[],u.storage.reminders}function x(t,e){a().push({id:`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,dueAt:Date.now()+e,text:t})}function f(t){const e=a(),n=e.findIndex(function(r){return r.id===t});n!==-1&&e.splice(n,1)}function $(t){try{p.showConfirmationAlert({title:"\u23F0 Reminder",content:t.text,confirmText:"Got it"})}catch{o.showToast(`\u23F0 ${t.text}`,void 0)}}let c;function E(){m(),c=setInterval(function(){const t=Date.now(),e=a().filter(function(n){return n.dueAt<=t});e.length&&e.forEach(function(n){$(n),f(n.id)})},15e3)}function m(){c&&clearInterval(c),c=void 0}const h=3;function k(){return[y.registerCommand({name:"remind",description:"Set a reminder, e.g. /remind 20m Walk the dog",options:[{name:"in",description:"e.g. 10m, 2h, 1d",type:h,required:!0},{name:"text",description:"What to remind you about",type:h,required:!0}],execute:function(t){const e=t.find(function(d){return d.name==="in"})?.value,n=t.find(function(d){return d.name==="text"})?.value,r=e?b(e):void 0;if(!r||!n){o.showToast(`Couldn't parse "${e}" - try something like 10m, 2h, or 1d`,void 0);return}x(n,r),o.showToast(`Reminder set for ${e} from now`,void 0)}})]}const{ScrollView:S,View:T}=i.ReactNative;function F({children:t}){return i.React.createElement(S,{style:{flex:1}},t,i.React.createElement(T,{style:{height:24}}))}const{View:D,Text:P}=i.ReactNative;function g({children:t,style:e}){return i.React.createElement(D,{style:[{marginHorizontal:16,marginVertical:8,padding:10,borderRadius:8,borderWidth:1,borderColor:"rgba(128,128,128,0.25)"},e]},i.React.createElement(P,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},t))}const{Text:M}=i.ReactNative,{FormSection:N,FormRow:C}=R.Forms;function L({title:t,items:e,emptyText:n}){return i.React.createElement(N,{title:t},e.length===0?i.React.createElement(g,null,n):e.map(function(r){return i.React.createElement(C,{key:r.key,label:r.label,subLabel:r.subLabel,onPress:r.onPress,trailing:i.React.createElement(M,{style:{color:"#F23F42",fontSize:20,fontWeight:"700"}},"\xD7")})}))}function W(t){const e=t-Date.now();if(e<=0)return"due now";const n=Math.round(e/6e4);if(n<60)return`in ${n}m`;const r=Math.round(n/60);return r<24?`in ${r}h`:`in ${Math.round(r/24)}d`}function z(){l.useProxy(u.storage);const t=a();return l.useProxy(t),i.React.createElement(F,null,i.React.createElement(L,{title:"Pending reminders",emptyText:'None yet. Set one from any chat with /remind, e.g. "/remind 20m Walk the dog".',items:t.map(function(e){return{key:e.id,label:e.text,subLabel:`${W(e.dueAt)} \u2022 Tap to cancel`,onPress:function(){f(e.id),o.showToast("Reminder cancelled",void 0)}}})}),i.React.createElement(g,null,"Reminders fire while Discord is open (foreground or background) - they can't wake the app up from fully closed, since that needs a native OS-level notification this plugin doesn't have access to."))}let v=[];var A={onLoad:function(){v=k(),E()},onUnload:function(){v.forEach(function(t){return t()}),m()},settings:z};return s.default=A,Object.defineProperty(s,"__esModule",{value:!0}),s})({},vendetta.commands,vendetta.ui.toasts,vendetta.plugin,vendetta.ui.alerts,vendetta.metro.common,vendetta.storage,vendetta.ui.components);
|