This commit is contained in:
Win81VMUser 2025-07-19 10:46:55 +02:00
parent 8dcec398f2
commit f852852b34
2 changed files with 4 additions and 0 deletions

View file

@ -0,0 +1,3 @@
(function(h,c,B,p){"use strict";const w=p.findByProps("sendMessage","receiveMessage"),i=p.findByProps("sendBotMessage");let m={},g={},M,D,y;function C(n,s,t){const e=`${n}:${t}`,o=t-Date.now();return g[e]={content:s,at:t},m[e]=setTimeout(function(){const a=s;w.sendMessage(n,{content:a}),delete m[e],delete g[e],B.showToast("\u{1F4E4} Scheduled message sent.")},o),e}function v(){Object.values(m).forEach(clearTimeout),m={},g={}}function I(n){const s=new Date;n=n.toLowerCase();const t=/(\d+)(h|m|s)/g;let e=0,o;for(;(o=t.exec(n))!==null;){const d=parseInt(o[1]),r=o[2];r==="h"?e+=d*3600*1e3:r==="m"?e+=d*60*1e3:r==="s"&&(e+=d*1e3)}if(e>0)return Date.now()+e;const a=/^(\d{1,2}):(\d{2})(am|pm)?$/,u=n.match(a);if(u){let d=parseInt(u[1]);const r=parseInt(u[2]),f=u[3];f&&(f==="pm"&&d<12?d+=12:f==="am"&&d===12&&(d=0));const l=new Date(s);return l.setHours(d,r,0,0),l.getTime()<=s.getTime()&&l.setDate(l.getDate()+1),l.getTime()}return 0}function $(){M=c.registerCommand({name:"schedule",displayName:"schedule",description:"Schedule a message after a delay or at a time",options:[{name:"time",description:"Delay (e.g. 10s, 1h30m) or time (3:30pm, 15:30)",type:3,required:!0},{name:"message",description:"Message to send",type:3,required:!0}],execute:function(n,s){const t=s.channel.id,e=n[0]?.value,o=n[1]?.value;if(typeof e!="string"||e.trim()==="")return i.sendBotMessage(t,"\u26D4 Invalid time value!");if(typeof o!="string"||o.trim()==="")return i.sendBotMessage(t,"\u26D4 Message cannot be empty!");const a=I(e);if(a===0||a<=Date.now())return i.sendBotMessage(t,"\u26D4 Invalid or past time specified!");C(t,o,a);const u=Math.round((a-Date.now())/1e3);i.sendBotMessage(t,`\u{1F553} Scheduled message in ${u}s.`)}}),D=c.registerCommand({name:"scheduled",displayName:"scheduled",description:"List scheduled messages",execute:function(n,s){const t=s.channel.id,e=Object.entries(g).map(function([o,a]){return`\u2022 **In ${Math.round((a.at-Date.now())/1e3)}s** \u2192 ${a.content}`});e.length===0?i.sendBotMessage(t,"No scheduled messages."):i.sendBotMessage(t,`Scheduled messages:
${e.join(`
`)}`)}}),y=c.registerCommand({name:"cancel-scheduled",displayName:"cancel-scheduled",description:"Cancel all scheduled messages",execute:function(n,s){const t=s.channel.id;v(),i.sendBotMessage(t,"All scheduled messages cancelled.")}})}function T(){v(),c.unregisterCommand(M),c.unregisterCommand(D),c.unregisterCommand(y)}return h.onLoad=$,h.onUnload=T,h})({},vendetta.commands,vendetta.ui.toasts,vendetta.metro);

View file

@ -0,0 +1 @@
{"name":"Message Scheduler","description":"Schedule messages to be sent at specific time or after a delay with /schedule.","authors":[{"name":"VMuser","id":"1258451646850007042"}],"main":"index.js","vendetta":{"icon":"ic_edit_24px"},"hash":"6d5ae8cb554883faca8aae1255458492b9a748e46498d0d30e3021ef775b7464"}