@2 - Gestion des commandes actives
This commit is contained in:
parent
ab7530024e
commit
deb5762956
2 changed files with 129 additions and 38 deletions
60
index.js
60
index.js
|
@ -175,32 +175,83 @@ const botSay = (where, what, dontDisplayRadio, forceSend) => {
|
|||
const actions = (where, message, from) => {
|
||||
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 unknowmCmd = () => {
|
||||
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
|
||||
if (exploded[0].indexOf(process.env.IRC_NICKNAME) === 0) {
|
||||
switch (exploded[1]) {
|
||||
case '!artist':
|
||||
case '!song':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!artist') !== -1) {
|
||||
artistSong.action(exploded[1].replace('!', ''), botSay, from, currentSong, exploded)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!song':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!song') !== -1) {
|
||||
artistSong.action(exploded[1].replace('!', ''), botSay, from, currentSong, exploded)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!help':
|
||||
Help.show(botSay, where, exploded)
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!help') !== -1) {
|
||||
Help.show(botSay, where, exploded, allowedCmds)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!when':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!when') !== -1) {
|
||||
when.action(botSay, where, exploded)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!stats':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stats') !== -1) {
|
||||
stats.action(botSay, where, exploded)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!list':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!list') !== -1) {
|
||||
list.action(botSay, where, exploded)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!notifications':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!notifications') !== -1) {
|
||||
preferences.notifications(botSay, where, from, exploded)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!stream':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stream') !== -1) {
|
||||
botSay(where, process.env.PUBLIC_RADIO_STREAM)
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
break
|
||||
case '!mute':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!mute') !== -1) {
|
||||
if (exploded[2] && ['on', 'off', 'state'].indexOf(exploded[2]) !== -1) {
|
||||
switch (exploded[2]) {
|
||||
case 'on':
|
||||
|
@ -217,10 +268,13 @@ const actions = (where, message, from) => {
|
|||
} else {
|
||||
botSay(where, '!help mute', false, true)
|
||||
}
|
||||
} else {
|
||||
unknowmCmd()
|
||||
}
|
||||
|
||||
break
|
||||
default:
|
||||
botSay(where, 'Commande inconnue, tape !help si tu es perdu', false, true)
|
||||
unknowmCmd()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
41
libs/Help.js
41
libs/Help.js
|
@ -9,47 +9,84 @@ class Help {
|
|||
* @param {Function} say
|
||||
* @param {String} where
|
||||
* @param {Array} args
|
||||
* @param {Array} allowedCmds
|
||||
*/
|
||||
static show (say, where, args) {
|
||||
static show (say, where, args, allowedCmds) {
|
||||
if (args.length > 2) {
|
||||
switch (args[2]) {
|
||||
case '!artist':
|
||||
case '!song':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!artist') !== -1) {
|
||||
Help.showArtistSong(say, where, args)
|
||||
}
|
||||
break
|
||||
case '!song':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!song') !== -1) {
|
||||
Help.showArtistSong(say, where, args)
|
||||
}
|
||||
break
|
||||
case '!stats':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stats') !== -1) {
|
||||
Help.showStats(say, where)
|
||||
}
|
||||
break
|
||||
case '!when':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!when') !== -1) {
|
||||
Help.showWhen(say, where)
|
||||
}
|
||||
break
|
||||
case '!list':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!list') !== -1) {
|
||||
Help.showList(say, where)
|
||||
}
|
||||
break
|
||||
case '!notifications':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!notifications') !== -1) {
|
||||
Help.showNotifications(say, where)
|
||||
}
|
||||
break
|
||||
case '!stream':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stream') !== -1) {
|
||||
Help.showStream(say, where)
|
||||
}
|
||||
break
|
||||
case '!mute':
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!mute') !== -1) {
|
||||
Help.showMute(say, where)
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
} else {
|
||||
this.say(say, where, 'IRC Radio Bot :: Help')
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!artist') !== -1) {
|
||||
this.say(say, where, '!artist <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
||||
}
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!song') !== -1) {
|
||||
this.say(say, where, '!song <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
||||
}
|
||||
if (allowedCmds[0] === 'ALL' || allowedCmds.indexOf('!stats') !== -1) {
|
||||
this.say(say, where, '!stats <period> {artist/song}')
|
||||
}
|
||||
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 __')
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue