shoddy sex impl

This commit is contained in:
Jill 2023-03-22 12:11:32 +03:00
parent bee954f15f
commit 2f6f415c0d
Signed by: oat
GPG Key ID: 33489AA58A955108
1 changed files with 32 additions and 24 deletions

View File

@ -6,32 +6,22 @@ import { initializeCounter } from './lib/counter';
const morningHour = 7;
const eveningHour = 20;
const sexHour = 17;
function getNextMorning() {
function getNextTime(hour: number, randomMinute = true) {
const now = new Date();
const next = new Date();
if (now.getUTCHours() >= morningHour) {
if (now.getUTCHours() >= hour) {
next.setTime(next.getTime() + 1000 * 60 * 60 * 24);
}
next.setUTCHours(morningHour);
next.setUTCMinutes(Math.floor(Math.random() * 60));
next.setUTCSeconds(Math.floor(Math.random() * 60));
console.log('next morning set to ' + next);
return next.getTime();
}
function getNextNight() {
const now = new Date();
const next = new Date();
if (now.getUTCHours() >= eveningHour) {
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);
}
next.setUTCHours(eveningHour);
next.setUTCMinutes(Math.floor(Math.random() * 60));
next.setUTCSeconds(Math.floor(Math.random() * 60));
console.log('next night set to ' + next);
return next.getTime();
}
@ -39,6 +29,7 @@ function getNextNight() {
interface DaytimeSchedule {
morning: number;
night: number;
sex: number;
}
let next: DaytimeSchedule;
@ -49,10 +40,14 @@ function save() {
if (fs.existsSync('./next.json')) {
next = JSON.parse(fs.readFileSync('./next.json', 'utf8'));
if (!next.morning) next.morning = getNextTime(morningHour);
if (!next.night) next.night = getNextTime(eveningHour);
if (!next.sex) next.sex = getNextTime(sexHour, false);
} else {
next = {
morning: getNextMorning(),
night: getNextNight()
morning: getNextTime(morningHour),
night: getNextTime(eveningHour),
sex: getNextTime(sexHour, false)
};
save();
}
@ -147,6 +142,13 @@ const night = [
'<a:slugloafspin:1012777725301370920> Good Night!! <a:slugloafspin:1012777725301370920>',
];
const sexRole = '<@&1088023310882836500>';
const sexMessages = [
'https://cdn.discordapp.com/attachments/838764449899872356/1088024173051387974/sex_time.png',
'sex. NO sleeping'
];
const sexChannel = '789023763396165633';
bot.on('ready', async () => {
initializeCounter();
@ -156,7 +158,7 @@ bot.on('ready', async () => {
// console.log(current, next.morning, next.night);
if (current > next.morning && !disableDaytimeAnnouncements) {
next.morning = getNextMorning();
next.morning = getNextTime(morningHour);
channels.forEach(c => {
bot.channels.fetch(c)
.then(channel => (channel as Discord.TextBasedChannel).send(morning[Math.floor(Math.random() * morning.length)]))
@ -165,7 +167,7 @@ bot.on('ready', async () => {
save();
}
if (current > next.night && !disableDaytimeAnnouncements) {
next.night = getNextNight();
next.night = getNextTime(eveningHour);
channels.forEach(c => {
bot.channels.fetch(c)
.then(channel => (channel as Discord.TextBasedChannel).send(night[Math.floor(Math.random() * night.length)]))
@ -173,6 +175,12 @@ bot.on('ready', async () => {
});
save();
}
if (current > next.sex && !disableDaytimeAnnouncements) {
next.sex = getNextTime(sexHour, false);
bot.channels.fetch(sexChannel)
.then(channel => (channel as Discord.TextBasedChannel).send(sexRole + ' ' + sexMessages[Math.floor(Math.random() * sexMessages.length)]))
.catch(err => console.log('couldnt find channel ' + sexChannel + ': ' + err));
}
}, 1000);
bot.commands = new Discord.Collection();