Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
greet = (source, user) => {
if (this.lastGreeted === user.id ||
// guest users
user.username === '') {
return
}
this.lastGreeted = user.id
const greeting = random(this.options.greetings)
const message = greeting.replace(/@/g, `@${user.username}`) +
` ${random(this.options.emoji)}`
setTimeout(() => {
source.send(message)
}, 2 * 1000)
}
}
greet = (source, user) => {
if (this.lastGreeted === user.id ||
// guest users
user.username === '') {
return
}
this.lastGreeted = user.id
const greeting = random(this.options.greetings)
const message = greeting.replace(/@/g, `@${user.username}`) +
` ${random(this.options.emoji)}`
setTimeout(() => {
source.send(message)
}, 2 * 1000)
}
}
async onEnd () {
this.running = false
clearTimeout(this.timer)
this.timer = null
const players = await this.getPlayers()
if (this.players.length === 0) {
this.source.send('Nobody participated in the raffle... Do I get to win now?')
} else if (players.length === 0) {
this.source.send('Nobody is eligible to win the raffle... Too bad!')
} else {
const winner = random(this.players)
debug('winner', winner.toString())
this.source.send(
this.options.winMessage.replace(/\$winner/g, winner.username)
)
const waitlist = this.source.getWaitlist()
await waitlist.move(winner, this.options.winnerPosition - 1)
}
this.players = []
this.source = null
}
}
async fistbump (message) {
const reasonList = await Karma.find({ target: message.user.id, reason: { $ne: null } })
.where('amount').gt(0)
.populate('giver')
if (reasonList.length === 0) {
message.reply('no one can explain your mysterious allure.')
}
let chosen = random(reasonList)
message.reply(`you were bumped by @${chosen.giver.username} ` +
`${chosen.reason}" ${moment(chosen.date).fromNow()}`)
}
onEnd () {
this._running = false
this._timer = null
let roulette = this._roulette
let players = this.players()
roulette.entrants = this._players.map((p) => p.id)
if (this._players.length === 0) {
this.source.send('Nobody participated in the roulette... Do I get to win now?')
} else if (players.length === 0) {
this.source.send('Nobody is eligible to win the roulette... Too bad!')
} else {
let winner = random(players)
debug('winner', winner.username)
this.source.send(`Roulette winner: @${winner.username}. Congratulations! https://i.imgur.com/TXKz7mt.gif`)
this.bot.moveDJ(winner.id, this.options.winnerPosition - 1, () => {
debug('winner moved')
})
roulette.winner = winner.id
}
RouletteHistory.create(roulette)
this._players = []
}
async fistbump (message) {
const User = this.model('User')
const Karma = this.model('Karma')
const user = await User.from(message.user)
const reasonList = await Karma.find({ target: user._id, reason: { $ne: null } })
.where('amount').gt(0)
.populate('giver')
if (reasonList.length > 0) {
let chosen = random(reasonList)
message.reply(`you were bumped by @${chosen.giver.username} ` +
`"${chosen.reason}" ${moment(chosen.createdAt).fromNow()}`)
} else {
message.reply('no one can explain your mysterious allure.')
}
}
async fistthump (message) {
const User = this.model('User')
const Karma = this.model('Karma')
const user = await User.from(message.user)
const reasonList = await Karma.find({ target: user._id, reason: { $ne: null } })
.where('amount').lt(0)
.populate('giver')
if (reasonList.length > 0) {
let chosen = random(reasonList)
message.reply(`you were thumped by @${chosen.giver.username} ` +
`"${chosen.reason}" ${moment(chosen.createdAt).fromNow()}`)
} else {
message.reply('no reason was ever given.')
}
}
}
nextQuestion () {
if (this.isRunning()) {
let question
do {
question = random(this.questions)
} while (this._history.indexOf(question) !== -1)
return this.askQuestion(question)
}
return Promise.reject(new Error('Trivia is not running'))
}
async fistthump (message) {
const reasonList = await Karma.find({ target: message.user.id, reason: { $ne: null } })
.where('amount').lt(0)
.populate('giver')
if (reasonList.length === 0) {
message.reply('no reason was ever given.')
}
let chosen = random(reasonList)
message.reply(`you were thumped by @${chosen.giver.username} ` +
`"${chosen.reason}" ${moment(chosen.date).fromNow()}`)
}
}