console.log(`Server with ID "${conf.serverID}" not found! I can't function without a valid server and channel.\nPlease add the correct server ID to your conf file, or if the conf data is correct, ensure I have proper access.\nYou may need to add me to your server using this link:\n https://discordapp.com/api/oauth2/authorize?client_id=${bot.user.id}&permissions=0&scope=bot`)
process.exit()
}elseif(!channel){
console.log(`Channel with ID "${conf.channelID}" not found! I can't function without a valid channel.\nPlease add the correct channel ID to your conf file, or if the conf data is correct, ensure I have proper access.`)
process.exit()
}elseif(!conf.boardIDs||conf.boardIDs.length<1){
console.log(`No board IDs provided! Please add at least one to your conf file. Check the readme if you need help finding a board ID.`)
fs.writeFileSync('conf.json',JSON.stringify(conf,null,4),(err,data)=>console.log(`Updated conf file with default prefix ('.')`))
}
// logInitializationData()
console.log(`== Bot logged in as @${bot.user.tag}. Ready for action! ==`)
events.start()
})
bot.on('message',(msg)=>{
if(msg.channel.type!=="text")return
if(msg.content.startsWith(`${conf.prefix}ping`)){
letnow=Date.now()
msg.channel.send(`Ping!`).then(m=>{
m.edit(`Pong! (took ${Date.now()-now}ms)`)
})
}
})
/*
**====================================
**Trelloeventhandlersandfunctions.
**====================================
*/
// Fired when a card is created
events.on('createCard',(event,board)=>{
if(!eventEnabled(`cardCreated`))return
letembed=getEmbedBase(event)
.setTitle(`New card created under __${event.data.list.name}__!`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card created under __${event.data.list.name}__ by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card due date changed to __${event.data.card.due?newDate(event.data.card.due).toUTCString():`[No due date]`}__ from __${event.data.old.due?newDate(event.data.old.due).toUTCString():`[No due date]`}__ by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card position in list __${event.data.list.name}__ changed by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card moved to list __${event.data.listAfter.name}__ from list __${event.data.listBefore.name}__ by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** *[See below for card name]* — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card name changed (see below) by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card unarchived and returned to list __${event.data.list.name}__ by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card under list __${event.data.list.name}__ archived by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**EVENT:** Card deleted from list __${event.data.list.name}__ by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card comment edited (see below for comment text) by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card comment added (see below for comment text) by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
editedEmbed.setDescription(editedEmbed.description+` added themselves to card.`)
send(editedEmbed)
}else{
if(!eventEnabled(`memberAddedToCard`))return
editedEmbed.setDescription(editedEmbed.description+` added to card by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
editedEmbed.setDescription(editedEmbed.description+` removed themselves from card.`)
send(editedEmbed)
}else{
if(!eventEnabled(`memberRemovedFromCard`))return
editedEmbed.setDescription(editedEmbed.description+` removed from card by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**EVENT:** List __${event.data.list.name}__ created by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
// Fired when a list is renamed, moved, archived, or unarchived
events.on('updateList',(event,board)=>{
letembed=getEmbedBase(event)
if(event.data.old.hasOwnProperty("name")){
if(!eventEnabled(`listNameChanged`))return
embed
.setTitle(`List name changed!`)
.setDescription(`**EVENT:** List renamed to __${event.data.list.name}__ from __${event.data.old.name}__ by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**EVENT:** List __${event.data.list.name}__ position changed by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**EVENT:** List __${event.data.list.name}__ unarchived by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**EVENT:** List __${event.data.list.name}__ archived by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Attachment named \`${event.data.attachment.name}\` added to card by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Attachment named \`${event.data.attachment.name}\` removed from card by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
// Fired when a checklist is added to a card (same thing as created)
events.on('addChecklistToCard',(event,board)=>{
if(!eventEnabled(`checklistAddedToCard`))return
letembed=getEmbedBase(event)
.setTitle(`Checklist added to card!`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Checklist named \`${event.data.checklist.name}\` added to card by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
.setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Checklist named \`${event.data.checklist.name}\` removed from card by **[${conf.realNames?event.memberCreator.fullName:event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`)
// Converts Trello @username mentions in titles to Discord mentions, finds channel and role mentions, and mirros Discord user mentions outside the embed