jillo-bot/src/lib/subscriptions.ts

224 lines
8.4 KiB
TypeScript

import { Client, TextChannel } from 'discord.js';
import { ScheduledSubscription, Subscription, db } from './db';
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 :)',
'https://tenor.com/view/have-a-beautiful-day-sun-shining-day-good-day-morning-good-morning-gif-16351404',
'good morning!!!!!!! have a beautiful sunshining day!!!',
'<a:slugbutt:1097469103964442714>',
'it\'s waking up time... wake up!! :)',
'Jillo Says:.... goo morning :)',
'uneebied..',
'https://tenor.com/view/animated-greetings-gif-good-morning-sunshine-gif-15394817',
'i wish you all a very Joyous morning...',
'hehe',
'hmmm today is monday i think...',
'hmmm today is thursday i think..??...',
'huhhhhh... morning already? you know what this means...',
'i dreamt today about the glogger...... it was kind of fire',
'a day awaits... time for Day! Day Time!',
'check this out <https://minecraft.fandom.com/wiki/Daylight_cycle> this is a reference to morning (time of day!)',
'✨ 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>',
'eebied...',
'good morning!!!!!! ahahaha.... the joke is that!! it\'s night time!! sleep time!! bed time for you!!!!! goo night!!!!!',
'🎵 `OMORI OST - Welcome Again. Extended Version` Good night :)',
'don\'t tell anyone but i\'m gonna stay up a bit later today...... rest of you: bed time!!',
'time to Hit the Bed..',
'sleepy deeby time!!!',
'goob night!!',
'it\'s Sleepy time...',
'jillo currently eebied......... ehehehehe.... goo night',
'time to Fall Asleep and dream of if fish are real... (think abour it!',
'eebied up in the crib...',
'hmmm i\'m heading to bed... don\'t get up to anything too funny while i\'m gone!!! (i\'ll be sad!!) (just a bit though... you\'re allowed)',
':) bed time...',
'bed soft like pillow... pillow soft like bed... the cycle...',
'plopping myself directly into bed (maximum comfort achieved)',
'i wish everyone a good night!!!!',
'sleep soundly everyone!!!',
'✨ Good Night! ✨',
'g...'
]
},
/*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 async function subscribe(type: string, guild: string | undefined, channel: string) {
await db<Subscription>('subscriptions')
.insert({
key: type,
guild: guild,
channel: channel
});
}
export async function unsubscribe(type: string, channel: string) {
await db<Subscription>('subscriptions')
.delete()
.where('type', type).where('channel', channel);
}
export async function isSubscribed(type: string, channel: string): Promise<boolean> {
return await db<Subscription>('subscriptions')
.where('key', type).where('channel', channel)
.first() !== undefined;
}
export function initializeAnnouncements(bot: Client) {
setInterval(async () => {
const current = new Date().getTime();
for (const k of Object.keys(timeAnnouncements)) {
const announcement = timeAnnouncements[k];
const announcementObj = await db<ScheduledSubscription>('scheduledSubscriptions')
.select('*')
.where('name', k)
.first();
if (!announcementObj) {
await db<ScheduledSubscription>('scheduledSubscriptions')
.insert({
name: k,
next: getNextAnnouncementTime(announcement)
});
continue;
}
if (current < announcementObj.next) continue;
await db<ScheduledSubscription>('scheduledSubscriptions')
.where('name', k)
.update('next', getNextAnnouncementTime(announcement));
const subscriptions = await db<Subscription>('subscriptions')
.select('*')
.where('key', k);
for (const { channel } of subscriptions) {
bot.channels.fetch(channel, {allowUnknownGuild: true})
.then(c =>
(c as TextChannel).send(
`${announcement.messagesPrefix ? announcement.messagesPrefix : ''} ${announcement.messages[Math.floor(Math.random() * announcement.messages.length)]}`
)
)
.catch(err => console.error(`failed to send ${k} announcement to ${channel}: ${err}`));
}
}
}, 1000);
}