revenge-plugins/reminders/index.js
2026-08-01 14:40:03 +00:00

1 line
3.4 KiB
JavaScript

(function(u,v,c,s,p,i,l,w){"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 b(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 s.storage.reminders??=[],s.storage.reminders}function $(t,e){o().push({id:`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,dueAt:Date.now()+e,text:t})}function f(t){const e=o(),n=e.findIndex(function(r){return r.id===t});n!==-1&&e.splice(n,1)}function x(t){try{p.showConfirmationAlert({title:"\u23F0 Reminder",content:t.text,confirmText:"Got it"})}catch{c.showToast(`\u23F0 ${t.text}`,void 0)}}let a;function E(){m(),a=setInterval(function(){const t=Date.now(),e=o().filter(function(n){return n.dueAt<=t});e.length&&e.forEach(function(n){x(n),f(n.id)})},15e3)}function m(){a&&clearInterval(a),a=void 0}const h=3;function k(){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: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){c.showToast(`Couldn't parse "${e}" - try something like 10m, 2h, or 1d`,void 0);return}$(n,r),c.showToast(`Reminder set for ${e} from now`,void 0)}})]}const{ScrollView:S,View:T}=i.ReactNative;function P({children:t}){return i.React.createElement(S,{style:{flex:1}},t,i.React.createElement(T,{style:{height:24}}))}const{View:D,Text:F}=i.ReactNative;function y({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(F,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},t))}const{FormSection:M,FormRow:C}=w.Forms;function L({title:t,items:e,emptyText:n}){return i.React.createElement(M,{title:t},e.length===0?i.React.createElement(y,null,n):e.map(function(r){return i.React.createElement(C,{key:r.key,label:r.label,subLabel:r.subLabel,onPress:r.onPress})}))}function N(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 A(){l.useProxy(s.storage);const t=o();return l.useProxy(t),i.React.createElement(P,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:`${N(e.dueAt)} \u2022 Tap to cancel`,onPress:function(){return f(e.id)}}})}),i.React.createElement(y,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 V={onLoad:function(){g=k(),E()},onUnload:function(){g.forEach(function(t){return t()}),m()},settings:A};return u.default=V,Object.defineProperty(u,"__esModule",{value:!0}),u})({},vendetta.commands,vendetta.ui.toasts,vendetta.plugin,vendetta.ui.alerts,vendetta.metro.common,vendetta.storage,vendetta.ui.components);