2022-06-08 02:57:15 +02:00
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' ;
2022-07-19 21:39:34 +02:00
import { initializeCounter } from './lib/counter' ;
2022-06-08 01:28:20 +02:00
2022-09-18 11:02:02 +02:00
const morningHour = 7 ;
const eveningHour = 20 ;
2022-06-08 01:28:20 +02:00
function getNextMorning() {
2022-06-08 03:46:00 +02:00
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 ( ) ;
2022-06-08 01:28:20 +02:00
}
function getNextNight() {
2022-06-08 03:46:00 +02:00
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 ( ) ;
2022-06-08 01:28:20 +02:00
}
2022-06-08 02:57:15 +02:00
interface DaytimeSchedule {
morning : number ;
night : number ;
}
let next : DaytimeSchedule ;
2022-06-08 01:28:20 +02:00
function save() {
2022-06-08 03:46:00 +02:00
fs . writeFileSync ( './next.json' , JSON . stringify ( next ) ) ;
2022-06-08 01:28:20 +02:00
}
if ( fs . existsSync ( './next.json' ) ) {
2022-06-08 03:46:00 +02:00
next = JSON . parse ( fs . readFileSync ( './next.json' , 'utf8' ) ) ;
2022-06-08 01:28:20 +02:00
} else {
2022-06-08 03:46:00 +02:00
next = {
morning : getNextMorning ( ) ,
night : getNextNight ( )
} ;
save ( ) ;
2022-06-08 01:28:20 +02:00
}
const bot = new Discord . Client ( {
2022-06-08 03:46:00 +02:00
intents : [
Discord . Intents . FLAGS . GUILDS ,
Discord . Intents . FLAGS . GUILD_MESSAGES ,
Discord . Intents . FLAGS . GUILD_VOICE_STATES ,
Discord . Intents . FLAGS . GUILD_MESSAGE_REACTIONS ,
2022-07-16 21:24:13 +02:00
Discord . Intents . FLAGS . GUILD_MEMBERS ,
2022-06-08 03:46:00 +02:00
] ,
2022-06-08 01:28:20 +02:00
} ) ;
const channels = [
2022-06-08 03:46:00 +02:00
'587108210683412493'
2022-06-08 01:28:20 +02:00
] ;
const morning = [
2022-06-08 03:46:00 +02:00
'goob morning' ,
'gm besties' ,
'morning !!!' ,
'it is Morning' ,
'gm' ,
2022-09-18 10:53:03 +02:00
'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 :)'
2022-06-08 01:28:20 +02:00
] ;
const night = [
2022-06-08 03:46:00 +02:00
'good night!!!!!!' ,
'nini all' ,
'goob night' ,
'goo night .....' ,
'sleep well everyone!!!!!' ,
2022-09-18 10:53:03 +02:00
'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>' ,
2022-06-08 01:28:20 +02:00
] ;
2022-06-08 02:57:15 +02:00
bot . on ( 'ready' , async ( ) = > {
2022-07-19 21:39:34 +02:00
initializeCounter ( ) ;
2022-06-08 03:46:00 +02:00
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' ) ) ;
2022-06-08 01:28:20 +02:00
for ( const file of cmdFiles ) {
2022-06-08 02:57:15 +02:00
const cmd = ( await import ( ` ./commands/ ${ file } ` ) ) ;
2022-06-08 01:28:20 +02:00
bot . commands . set ( cmd . data . name , cmd ) ;
2022-06-08 03:46:00 +02:00
if ( cmd . onClientReady ) cmd . onClientReady ( bot ) ;
2022-06-08 01:28:20 +02:00
}
2022-07-19 20:48:02 +02:00
console . log ( 'jillo online' ) ;
2022-06-08 01:28:20 +02:00
} ) ;
bot . on ( 'interactionCreate' , async ( interaction ) = > {
2022-06-08 03:46:00 +02:00
if ( ! interaction . isCommand ( ) ) return ;
2022-06-08 01:28:20 +02:00
2022-06-08 03:46:00 +02:00
const command = interaction . client . commands . get ( interaction . commandName ) ;
if ( ! command ) return ;
2022-06-08 01:28:20 +02:00
2022-06-08 03:46:00 +02:00
try {
await command . execute ( interaction , interaction . member ) ;
} catch ( error ) {
interaction . reply ( { content : '`ERROR`' , ephemeral : true } ) ;
console . error ( error ) ;
}
2022-06-08 01:28:20 +02:00
} ) ;
2023-01-20 22:00:16 +01:00
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 } ` ) ;
} ) ;
2022-06-08 01:28:20 +02:00
bot . login ( token ) ;