import * as Discord from 'discord.js'


export const bootstrapDiscord = (delegate: DiscordDelegate) => {
    const authToken: string = process.env.DISCORD_TOKEN

    const discordConfig: Discord.ClientOptions = {
        intents: [
            Discord.Intents.FLAGS.GUILDS,
            Discord.Intents.FLAGS.GUILD_MESSAGES
        ]
    }

    const client = new Discord.Client(discordConfig)

    client.on('messageCreate', msg =>
        delegate.didReceiveMessage(msg)
    )

    client.on('ready', () => {
        console.log('WOKE UP AND READY TO ROCK')
    })

    client.login(authToken)
}

export const sendMessage = (msg: string, channel: Channel) => {
    console.log(`sent: ${msg}`)
    channel.send(msg)
}
interface DiscordDelegate {
    didReceiveMessage(msg: Discord.Message): void
}
type Channel = Discord.TextChannel | Discord.DMChannel | Discord.PartialDMChannel | Discord.NewsChannel | Discord.ThreadChannel