jillo-bot/src/index.ts

209 lines
6.7 KiB
TypeScript

import * as Discord from 'discord.js';
import * as fs from 'fs';
const { token, disableDaytimeAnnouncements } = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
import * as path from 'path';
import { initializeCounter } from './lib/counter';
const morningHour = 7;
const eveningHour = 20;
function getNextMorning() {
const now = new Date();
const next = new Date();
if (now.getUTCHours() >= morningHour) {
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(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();
}
interface DaytimeSchedule {
morning: number;
night: number;
}
let next: DaytimeSchedule;
function save() {
fs.writeFileSync('./next.json', JSON.stringify(next));
}
if (fs.existsSync('./next.json')) {
next = JSON.parse(fs.readFileSync('./next.json', 'utf8'));
} else {
next = {
morning: getNextMorning(),
night: getNextNight()
};
save();
}
const bot = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_VOICE_STATES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
],
});
const channels = [
'587108210683412493'
];
const morning = [
'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 :)'
];
const night = [
'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>',
];
bot.on('ready', async () => {
initializeCounter();
setInterval(() => {
const current = new Date().getTime();
// console.log(current, next.morning, next.night);
if (current > next.morning && !disableDaytimeAnnouncements) {
next.morning = getNextMorning();
channels.forEach(c => {
bot.channels.fetch(c)
.then(channel => (channel as Discord.TextBasedChannel).send(morning[Math.floor(Math.random() * morning.length)]))
.catch(err => console.log('couldnt find channel ' + c + ': ' + err));
});
save();
}
if (current > next.night && !disableDaytimeAnnouncements) {
next.night = getNextNight();
channels.forEach(c => {
bot.channels.fetch(c)
.then(channel => (channel as Discord.TextBasedChannel).send(night[Math.floor(Math.random() * night.length)]))
.catch(err => console.log('couldnt find channel ' + c + ': ' + err));
});
save();
}
}, 1000);
bot.commands = new Discord.Collection();
const cmdFiles = fs.readdirSync(path.join(__dirname, './commands')).filter((file) => file.endsWith('.js'));
for (const file of cmdFiles) {
const cmd = (await import(`./commands/${file}`));
bot.commands.set(cmd.data.name, cmd);
if (cmd.onClientReady) cmd.onClientReady(bot);
}
console.log('jillo online');
});
bot.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, interaction.member);
} catch (error) {
interaction.reply({ content: '`ERROR`', ephemeral: true });
console.error(error);
}
});
bot.on('messageDelete', (msg) => {
console.log(`${msg.author?.username}#${msg.author?.discriminator} in #${msg.channel instanceof Discord.TextChannel ? msg.channel.name : '?'} at ${msg.createdAt.toISOString()}`);
console.log(`${msg.content}`);
});
bot.login(token);