179 lines
6.2 KiB
TypeScript
179 lines
6.2 KiB
TypeScript
import { Client, TextChannel } from 'discord.js';
|
|
import * as fs from 'fs';
|
|
|
|
interface AnnouncementType {
|
|
hour: number;
|
|
randomizeMinute: boolean;
|
|
messages: string[],
|
|
messagesPrefix?: string
|
|
}
|
|
|
|
export const timeAnnouncements: Record<string, AnnouncementType> = {
|
|
morning: {
|
|
hour: 7,
|
|
randomizeMinute: true,
|
|
messages: [
|
|
'goob morning',
|
|
'gm besties',
|
|
'morning !!!',
|
|
'it is Morning',
|
|
'gm',
|
|
'goom morbning',
|
|
'goo morning',
|
|
'hiiiii besties ........',
|
|
'good morning!!!!',
|
|
'awake, but at what cost ... ehehe hi all',
|
|
'morning all!!!',
|
|
'rise and shine!! new day!!',
|
|
'mmm... morning',
|
|
'morning to all of my slime fellows!!!! oh and the rest of you, uhm.. good morning i guess 🙄',
|
|
'gm gamers... rise and grind',
|
|
'good morning!!!',
|
|
'morning!! don\'t forget to brush your teeth!! or else!!',
|
|
':) hi all',
|
|
'it is currently: Morning!!!!! f',
|
|
`🌞 ☁️ ☁️
|
|
☁️
|
|
☁️ ☁️
|
|
🟩🟩🟩🟩🟩🟩🟩
|
|
🟫 🟫🟫🟫🟫🟫🟫Morning.......`,
|
|
'https://tenor.com/view/good-morning-tweety-heart-gif-gif-26261249',
|
|
'g',
|
|
'hmmm....l... i don\'t think it\'s a very good morning today..... JUST KIDDING GREAT mornign ALL!!!!!',
|
|
'<a:slugloafspin:1012777725301370920> GoodMorning!! <a:slugloafspin:1012777725301370920>',
|
|
'Good Morning!!!!fell out of bed and broke a bone!!',
|
|
'Bed. Water Mel on. Swamp water. morning All !',
|
|
'Error: good morning\n' +
|
|
' at REPL7:1:7\n' +
|
|
' at Script.runInThisContext (node:vm:129:12)\n' +
|
|
' at REPLServer.defaultEval (node:repl:566:29)\n' +
|
|
' at bound (node:domain:421:15)\n' +
|
|
' at REPLServer.runBound [as eval] (node:domain:432:12)\n' +
|
|
' at REPLServer.onLine (node:repl:893:10)\n' +
|
|
' at REPLServer.emit (node:events:539:35)\n' +
|
|
' at REPLServer.emit (node:domain:475:12)\n' +
|
|
' at REPLServer.Interface._onLine (node:readline:487:10)\n' +
|
|
' at REPLServer.Interface._line (node:readline:864:8)',
|
|
'```\ngood morning...\n```',
|
|
'hello everyone! good morning :)',
|
|
]
|
|
},
|
|
evening: {
|
|
hour: 20,
|
|
randomizeMinute: true,
|
|
messages: [
|
|
'good night!!!!!!',
|
|
'nini all',
|
|
'goob night',
|
|
'goo night .....',
|
|
'sleep well everyone!!!!!',
|
|
'good night !! dont let the bugs bite',
|
|
'mmm....... goo night all',
|
|
'night night!!!!',
|
|
'have a good rest all!!! i will see you all tommorow :)',
|
|
'a new day awaits tommorow!!!! head to bed!!!!!',
|
|
'it\'s Getting Late... head To Bed....!',
|
|
'good night!! be sure to brush your teeth before u go to sleep :)!',
|
|
'mmmm... Sleepy.... bed bed time...!!',
|
|
'good night everyone!! besure to prepare the [',
|
|
'a good day awaits you all tommorow... so Go Hit The Bed and Get Some Rest!!!!',
|
|
'sweet dreams everyone!!!! i\'m going to be dreaming of cheese..',
|
|
'good night all!!',
|
|
'bed.. comfy cosy!!!! sleepy time',
|
|
'good night everyone....... hope u all stay warm and safe this night!!',
|
|
'it\'s Bed Time!!! time for sleepy time',
|
|
'https://tenor.com/view/night-goodnight-my-love-sweet-gif-26175663',
|
|
'going bedbed now... good night all',
|
|
'sweet dreams everyone!!!! i\'m going to be dreaming of ( )..',
|
|
'Night Time....... go sleeby!!! don\'t forget your alarm!!!',
|
|
'may ur dreams be as pleasant as uhm.... cheesecake ..... good night',
|
|
'too sleepy for witty messages... Bed time ...',
|
|
'<a:slugloafspin:1012777725301370920> Good Night!! <a:slugloafspin:1012777725301370920>',
|
|
]
|
|
},
|
|
sex: {
|
|
hour: 17,
|
|
randomizeMinute: false,
|
|
messages: [
|
|
'https://cdn.discordapp.com/attachments/838764449899872356/1088024173051387974/sex_time.png',
|
|
'sex. NO sleeping'
|
|
],
|
|
messagesPrefix: '<@&1088023310882836500>'
|
|
}
|
|
};
|
|
|
|
export function getNextAnnouncementTime(type: AnnouncementType) {
|
|
return getNextTime(type.hour, type.randomizeMinute);
|
|
}
|
|
|
|
function getNextTime(hour: number, randomMinute = true) {
|
|
const now = new Date();
|
|
const next = new Date();
|
|
if (now.getUTCHours() >= hour) {
|
|
next.setTime(next.getTime() + 1000 * 60 * 60 * 24);
|
|
}
|
|
next.setUTCHours(hour);
|
|
if (randomMinute) {
|
|
next.setUTCMinutes(Math.floor(Math.random() * 60));
|
|
next.setUTCSeconds(Math.floor(Math.random() * 60));
|
|
} else {
|
|
next.setUTCMinutes(0);
|
|
next.setUTCSeconds(0);
|
|
}
|
|
|
|
return next.getTime();
|
|
}
|
|
|
|
export let next: Record<string, number> = {};
|
|
export let subscriptions: Record<string, string[]> = {};
|
|
|
|
export function saveNext() {
|
|
fs.writeFileSync('./next.json', JSON.stringify(next));
|
|
}
|
|
export function saveSubscriptions() {
|
|
fs.writeFileSync('./subscriptions.json', JSON.stringify(subscriptions));
|
|
}
|
|
|
|
export function loadNext() {
|
|
if (fs.existsSync('./next.json')) {
|
|
next = JSON.parse(fs.readFileSync('./next.json', 'utf8'));
|
|
}
|
|
for (const k of Object.keys(timeAnnouncements)) {
|
|
if (!next[k]) next[k] = getNextAnnouncementTime(timeAnnouncements[k]);
|
|
}
|
|
saveNext();
|
|
}
|
|
export function loadSubscriptions() {
|
|
if (fs.existsSync('./subscriptions.json')) {
|
|
subscriptions = JSON.parse(fs.readFileSync('./subscriptions.json', 'utf8'));
|
|
}
|
|
saveSubscriptions();
|
|
}
|
|
|
|
export function initializeAnnouncements(bot: Client) {
|
|
setInterval(() => {
|
|
const current = new Date().getTime();
|
|
|
|
// console.log(current, next.morning, next.night);
|
|
|
|
for (const k of Object.keys(timeAnnouncements)) {
|
|
if (next[k] && current > next[k]) {
|
|
const announcement = timeAnnouncements[k];
|
|
next[k] = getNextAnnouncementTime(announcement);
|
|
saveNext();
|
|
|
|
if (subscriptions[k]) {
|
|
for (const channelID of subscriptions[k]) {
|
|
bot.channels.fetch(channelID, {allowUnknownGuild: true})
|
|
.then(c =>
|
|
(c as TextChannel).send(
|
|
`${announcement.messagesPrefix ? announcement.messagesPrefix : ''} ${announcement.messages[Math.floor(Math.random() * announcement.messages.length)]}`
|
|
)
|
|
)
|
|
.catch(err => `failed to send ${k} announcement to ${channelID}: ${err}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, 1000);
|
|
} |