Merge branch '2-gestion-des-commandes-actives' into 'develop'
Resolve "Gestion des commandes actives" Closes #2 See merge request dbroqua/irc-radio-bot!2
This commit is contained in:
commit
d0d4ffef6d
2 changed files with 129 additions and 38 deletions
96
index.js
96
index.js
|
@ -175,52 +175,106 @@ const botSay = (where, what, dontDisplayRadio, forceSend) => {
|
||||||
const actions = (where, message, from) => {
|
const actions = (where, message, from) => {
|
||||||
const exploded = message.split(' ')
|
const exploded = message.split(' ')
|
||||||
|
|
||||||
|
let allowedCmds = ['ALL']
|
||||||
|
if (process.env.AVAILABLE_CMD) {
|
||||||
|
allowedCmds = process.env.AVAILABLE_CMD.split(',')
|
||||||
|
}
|
||||||
|
if (where.indexOf('#') === 0 && process.env[`AVAILABLE_CMD_${where.replace('#', '')}`]) {
|
||||||
|
allowedCmds = process.env[`AVAILABLE_CMD_${where.replace('#', '')}`].split(',')
|
||||||
|
}
|
||||||
|
|
||||||
|
const unknownCmd = () => {
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!help') !== -1) {
|
||||||
|
botSay(where, 'Commande inconnue, tape !help si tu es perdu', false, true)
|
||||||
|
} else {
|
||||||
|
botSay(where, 'Commande inconnue...', false, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Le message publié est pour le bot
|
// Le message publié est pour le bot
|
||||||
if (exploded[0].indexOf(process.env.IRC_NICKNAME) === 0) {
|
if (exploded[0].indexOf(process.env.IRC_NICKNAME) === 0) {
|
||||||
switch (exploded[1]) {
|
switch (exploded[1]) {
|
||||||
case '!artist':
|
case '!artist':
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!artist') !== -1) {
|
||||||
|
artistSong.action(exploded[1].replace('!', ''), botSay, from, currentSong, exploded)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
|
break
|
||||||
case '!song':
|
case '!song':
|
||||||
artistSong.action(exploded[1].replace('!', ''), botSay, from, currentSong, exploded)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!song') !== -1) {
|
||||||
|
artistSong.action(exploded[1].replace('!', ''), botSay, from, currentSong, exploded)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!help':
|
case '!help':
|
||||||
Help.show(botSay, where, exploded)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!help') !== -1) {
|
||||||
|
Help.show(botSay, where, exploded, allowedCmds)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!when':
|
case '!when':
|
||||||
when.action(botSay, where, exploded)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!when') !== -1) {
|
||||||
|
when.action(botSay, where, exploded)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!stats':
|
case '!stats':
|
||||||
stats.action(botSay, where, exploded)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stats') !== -1) {
|
||||||
|
stats.action(botSay, where, exploded)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!list':
|
case '!list':
|
||||||
list.action(botSay, where, exploded)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!list') !== -1) {
|
||||||
|
list.action(botSay, where, exploded)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!notifications':
|
case '!notifications':
|
||||||
preferences.notifications(botSay, where, from, exploded)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!notifications') !== -1) {
|
||||||
|
preferences.notifications(botSay, where, from, exploded)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!stream':
|
case '!stream':
|
||||||
botSay(where, process.env.PUBLIC_RADIO_STREAM)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stream') !== -1) {
|
||||||
|
botSay(where, process.env.PUBLIC_RADIO_STREAM)
|
||||||
|
} else {
|
||||||
|
unknownCmd()
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!mute':
|
case '!mute':
|
||||||
if (exploded[2] && ['on', 'off', 'state'].indexOf(exploded[2]) !== -1) {
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!mute') !== -1) {
|
||||||
switch (exploded[2]) {
|
if (exploded[2] && ['on', 'off', 'state'].indexOf(exploded[2]) !== -1) {
|
||||||
case 'on':
|
switch (exploded[2]) {
|
||||||
isMute = true
|
case 'on':
|
||||||
botSay(where, "Pff ! c'est toujours pareil ici :'(", false, true)
|
isMute = true
|
||||||
break
|
botSay(where, "Pff ! c'est toujours pareil ici :'(", false, true)
|
||||||
case 'off':
|
break
|
||||||
isMute = false
|
case 'off':
|
||||||
botSay(where, "Merci ! j'avais tellement de chose à te dire...", false, true)
|
isMute = false
|
||||||
break
|
botSay(where, "Merci ! j'avais tellement de chose à te dire...", false, true)
|
||||||
default:
|
break
|
||||||
botSay(where, isMute ? 'Je ne dirais rien !' : "T'inquiète ! tu vas l'avoir ta notif !", false, true)
|
default:
|
||||||
|
botSay(where, isMute ? 'Je ne dirais rien !' : "T'inquiète ! tu vas l'avoir ta notif !", false, true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
botSay(where, '!help mute', false, true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
botSay(where, '!help mute', false, true)
|
unknownCmd()
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
botSay(where, 'Commande inconnue, tape !help si tu es perdu', false, true)
|
unknownCmd()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
71
libs/Help.js
71
libs/Help.js
|
@ -9,46 +9,83 @@ class Help {
|
||||||
* @param {Function} say
|
* @param {Function} say
|
||||||
* @param {String} where
|
* @param {String} where
|
||||||
* @param {Array} args
|
* @param {Array} args
|
||||||
|
* @param {Array} allowedCmds
|
||||||
*/
|
*/
|
||||||
static show (say, where, args) {
|
static show (say, where, args, allowedCmds) {
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
switch (args[2]) {
|
switch (args[2]) {
|
||||||
case '!artist':
|
case '!artist':
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!artist') !== -1) {
|
||||||
|
Help.showArtistSong(say, where, args)
|
||||||
|
}
|
||||||
|
break
|
||||||
case '!song':
|
case '!song':
|
||||||
Help.showArtistSong(say, where, args)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!song') !== -1) {
|
||||||
|
Help.showArtistSong(say, where, args)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!stats':
|
case '!stats':
|
||||||
Help.showStats(say, where)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stats') !== -1) {
|
||||||
|
Help.showStats(say, where)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!when':
|
case '!when':
|
||||||
Help.showWhen(say, where)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!when') !== -1) {
|
||||||
|
Help.showWhen(say, where)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!list':
|
case '!list':
|
||||||
Help.showList(say, where)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!list') !== -1) {
|
||||||
|
Help.showList(say, where)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!notifications':
|
case '!notifications':
|
||||||
Help.showNotifications(say, where)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!notifications') !== -1) {
|
||||||
|
Help.showNotifications(say, where)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!stream':
|
case '!stream':
|
||||||
Help.showStream(say, where)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stream') !== -1) {
|
||||||
|
Help.showStream(say, where)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case '!mute':
|
case '!mute':
|
||||||
Help.showMute(say, where)
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!mute') !== -1) {
|
||||||
|
Help.showMute(say, where)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.say(say, where, 'IRC Radio Bot :: Help')
|
this.say(say, where, 'IRC Radio Bot :: Help')
|
||||||
this.say(say, where, '!artist <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!artist') !== -1) {
|
||||||
this.say(say, where, '!song <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
this.say(say, where, '!artist <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
||||||
this.say(say, where, '!stats <period> {artist/song}')
|
}
|
||||||
this.say(say, where, '!when <period> <artist/song>')
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!song') !== -1) {
|
||||||
this.say(say, where, '!list <period> <artist/song>')
|
this.say(say, where, '!song <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
||||||
this.say(say, where, '!help {command}')
|
}
|
||||||
this.say(say, where, '!notifications <on/off/state>')
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stats') !== -1) {
|
||||||
this.say(say, where, '!stream')
|
this.say(say, where, '!stats <period> {artist/song}')
|
||||||
this.say(say, where, '!mute <on/off/state>')
|
}
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!when') !== -1) {
|
||||||
|
this.say(say, where, '!when <period> <artist/song>')
|
||||||
|
}
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!list') !== -1) {
|
||||||
|
this.say(say, where, '!list <period> <artist/song>')
|
||||||
|
}
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!help') !== -1) {
|
||||||
|
this.say(say, where, '!help {command}')
|
||||||
|
}
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!notifications') !== -1) {
|
||||||
|
this.say(say, where, '!notifications <on/off/state>')
|
||||||
|
}
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stream') !== -1) {
|
||||||
|
this.say(say, where, '!stream')
|
||||||
|
}
|
||||||
|
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!mute') !== -1) {
|
||||||
|
this.say(say, where, '!mute <on/off/state>')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.say(say, where, '__ END __')
|
this.say(say, where, '__ END __')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue