revenge-plugins/reminders/index.js
2026-08-01 14:22:29 +00:00

1 line
2.9 KiB
JavaScript

(function(a,v,d,c,p,w,s,y){"use strict";const R={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 $(t){const e=t.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)\s*([a-z]+)$/);if(!e)return;const n=Number(e[1]),r=R[e[2]];if(!(!r||!Number.isFinite(n)||n<=0))return Math.round(n*r)}function o(){return c.storage.reminders??=[],c.storage.reminders}function x(t,e){o().push({id:`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,dueAt:Date.now()+e,text:t})}function m(t){const e=o(),n=e.findIndex(function(r){return r.id===t});n!==-1&&e.splice(n,1)}function b(t){try{p.showConfirmationAlert({title:"\u23F0 Reminder",content:t.text,confirmText:"Got it"})}catch{d.showToast(`\u23F0 ${t.text}`,void 0)}}let i;function k(){l(),i=setInterval(function(){const t=Date.now(),e=o().filter(function(n){return n.dueAt<=t});e.length&&e.forEach(function(n){b(n),m(n.id)})},15e3)}function l(){i&&clearInterval(i),i=void 0}const f=3;function E(){return[v.registerCommand({name:"remind",description:"Set a reminder, e.g. /remind 20m Walk the dog",options:[{name:"in",description:"e.g. 10m, 2h, 1d",type:f,required:!0},{name:"text",description:"What to remind you about",type:f,required:!0}],execute:function(t){const e=t.find(function(u){return u.name==="in"})?.value,n=t.find(function(u){return u.name==="text"})?.value,r=e?$(e):void 0;if(!r||!n){d.showToast(`Couldn't parse "${e}" - try something like 10m, 2h, or 1d`,void 0);return}x(n,r),d.showToast(`Reminder set for ${e} from now`,void 0)}})]}const{ScrollView:S,View:F}=w.ReactNative,{FormSection:D,FormRow:M,FormText:h}=y.Forms;function T(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 P(){s.useProxy(c.storage);const t=o();return s.useProxy(t),React.createElement(S,{style:{flex:1}},React.createElement(D,{title:"Pending reminders"},t.length===0&&React.createElement(h,{style:{marginHorizontal:16,marginVertical:8}},'None yet. Set one from any chat with /remind, e.g. "/remind 20m Walk the dog".'),t.map(function(e){return React.createElement(M,{key:e.id,label:e.text,subLabel:`${T(e.dueAt)} \u2022 Tap to cancel`,onPress:function(){return m(e.id)}})})),React.createElement(F,{style:{paddingHorizontal:16,paddingVertical:8}},React.createElement(h,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 g=[];var A={onLoad:function(){g=E(),k()},onUnload:function(){g.forEach(function(t){return t()}),l()},settings:P};return a.default=A,Object.defineProperty(a,"__esModule",{value:!0}),a})({},vendetta.commands,vendetta.ui.toasts,vendetta.plugin,vendetta.ui.alerts,vendetta.metro.common,vendetta.storage,vendetta.ui.components);