Resolve "!mute !loud" #11
2 changed files with 102 additions and 57 deletions
30
index.js
30
index.js
|
@ -16,6 +16,8 @@ const stats = new Statistics(models)
|
||||||
const list = new List(models)
|
const list = new List(models)
|
||||||
const preferences = new Preferences(models)
|
const preferences = new Preferences(models)
|
||||||
|
|
||||||
|
let isMute = false
|
||||||
|
|
||||||
let titlePath = null
|
let titlePath = null
|
||||||
let artistPath = null
|
let artistPath = null
|
||||||
if (process.env.STREAM_PATH_TITLE) {
|
if (process.env.STREAM_PATH_TITLE) {
|
||||||
|
@ -73,7 +75,7 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') {
|
||||||
|
|
||||||
// Listener on new song
|
// Listener on new song
|
||||||
stream.on('metadata', function (data) {
|
stream.on('metadata', function (data) {
|
||||||
console.log('RAW DATA:', data)
|
console.info('RAW DATA:', data)
|
||||||
// let song = data.replace(/[^A-Za-z 0-9 .,?""!@#$%^&*()-_=+;:<>/\\|}{[\]`~]*/g, '')
|
// let song = data.replace(/[^A-Za-z 0-9 .,?""!@#$%^&*()-_=+;:<>/\\|}{[\]`~]*/g, '')
|
||||||
const song = data.substring(13, data.length - 1).replace(/\0/g, '').replace('\';', '')
|
const song = data.substring(13, data.length - 1).replace(/\0/g, '').replace('\';', '')
|
||||||
|
|
||||||
|
@ -155,10 +157,13 @@ bot.addListener('error', function (message) {
|
||||||
* @param {String} where
|
* @param {String} where
|
||||||
* @param {String} what
|
* @param {String} what
|
||||||
* @param {Boolean} dontDisplayRadio
|
* @param {Boolean} dontDisplayRadio
|
||||||
|
* @param {Boolean} forceSend
|
||||||
*/
|
*/
|
||||||
const botSay = (where, what, dontDisplayRadio) => {
|
const botSay = (where, what, dontDisplayRadio, forceSend) => {
|
||||||
|
if (!isMute || forceSend || where.indexOf('#') !== 0) {
|
||||||
const message = `${(!dontDisplayRadio ? `${process.env.RADIO_ALIAS} : ` : '')}${what}`
|
const message = `${(!dontDisplayRadio ? `${process.env.RADIO_ALIAS} : ` : '')}${what}`
|
||||||
bot.say(where, message)
|
bot.say(where, message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,8 +200,25 @@ const actions = (where, message, from) => {
|
||||||
case '!stream':
|
case '!stream':
|
||||||
botSay(where, process.env.PUBLIC_RADIO_STREAM)
|
botSay(where, process.env.PUBLIC_RADIO_STREAM)
|
||||||
break
|
break
|
||||||
|
case '!mute':
|
||||||
|
if (exploded[2] && ['on', 'off', 'state'].exploded[2] !== -1) {
|
||||||
|
switch (exploded[2]) {
|
||||||
|
case 'on':
|
||||||
|
isMute = true
|
||||||
|
break
|
||||||
|
case 'off':
|
||||||
|
isMute = false
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
botSay(where, 'Commande inconnue, tape !help si tu es perdu')
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
botSay(where, 'Commande inconnue, tape !help si tu es perdu', false, true)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +237,7 @@ if (process.env.SAY_HELLO && process.env.SAY_HELLO === 'true') {
|
||||||
bot.addListener('join', (channel, who) => {
|
bot.addListener('join', (channel, who) => {
|
||||||
// Welcome them in!
|
// Welcome them in!
|
||||||
if (who !== process.env.IRC_NICKNAME) {
|
if (who !== process.env.IRC_NICKNAME) {
|
||||||
botSay(process.env.IRC_CHANNEL, 'Hello ' + who + '! Have a metal day! \\m/(-.-)\\m/', true)
|
botSay(process.env.IRC_CHANNEL, 'Hello ' + who + '! Have a metal day! \\m/(-.-)\\m/', true, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
125
libs/Help.js
125
libs/Help.js
|
@ -1,5 +1,9 @@
|
||||||
|
|
||||||
class Help {
|
class Help {
|
||||||
|
static helpSay (say, where, message) {
|
||||||
|
say(where, message, true, true)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fonction affichant l'aide générale
|
* Fonction affichant l'aide générale
|
||||||
* @param {Function} say
|
* @param {Function} say
|
||||||
|
@ -28,21 +32,25 @@ class Help {
|
||||||
case '!stream':
|
case '!stream':
|
||||||
Help.showStream(say, where)
|
Help.showStream(say, where)
|
||||||
break
|
break
|
||||||
|
case '!mute':
|
||||||
|
Help.showMute(say, where)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
say(where, 'IRC Radio Bot :: Help')
|
this.say(say, where, 'IRC Radio Bot :: Help')
|
||||||
say(where, '!artist <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}')
|
||||||
say(where, '!song <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
this.say(say, where, '!song <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
||||||
say(where, '!stats <period> {artist/song}')
|
this.say(say, where, '!stats <period> {artist/song}')
|
||||||
say(where, '!when <period> <artist/song>')
|
this.say(say, where, '!when <period> <artist/song>')
|
||||||
say(where, '!list <period> <artist/song>')
|
this.say(say, where, '!list <period> <artist/song>')
|
||||||
say(where, '!help {command}')
|
this.say(say, where, '!help {command}')
|
||||||
say(where, '!notifications <on/off/state>')
|
this.say(say, where, '!notifications <on/off/state>')
|
||||||
say(where, '!stream')
|
this.say(say, where, '!stream')
|
||||||
|
this.say(say, where, '!mute <on/off/state>')
|
||||||
}
|
}
|
||||||
say(where, '__ END __')
|
this.say(say, where, '__ END __')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,8 +60,23 @@ class Help {
|
||||||
* @param {Array} args
|
* @param {Array} args
|
||||||
*/
|
*/
|
||||||
static showStream (say, where, args) {
|
static showStream (say, where, args) {
|
||||||
say(where, 'IRC Radio Bot :: Stream')
|
this.say(say, where, 'IRC Radio Bot :: Stream', false, true)
|
||||||
say(where, '!stream < Affiche l\'url du flux radio pour ton player favoris')
|
this.say(say, where, 'Affiche l\'url du flux radio pour ton player favoris', false, true)
|
||||||
|
this.say(say, where, '!stream')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fonction affichant l'aide sur la commande !mute
|
||||||
|
* @param {Function} say
|
||||||
|
* @param {String} where
|
||||||
|
* @param {Array} args
|
||||||
|
*/
|
||||||
|
static showMute (say, where, args) {
|
||||||
|
this.say(say, where, 'IRC Radio Bot :: Mute')
|
||||||
|
this.say(say, where, 'Permet d\'activer ou de désactiver les messages publics du bot')
|
||||||
|
this.say(say, where, '!mute on')
|
||||||
|
this.say(say, where, '!mute off')
|
||||||
|
this.say(say, where, '!mute state')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,9 +86,9 @@ class Help {
|
||||||
* @param {Array} args
|
* @param {Array} args
|
||||||
*/
|
*/
|
||||||
static showArtistSong (say, where, args) {
|
static showArtistSong (say, where, args) {
|
||||||
say(where, 'IRC Radio Bot :: Artist/Song')
|
this.say(say, where, 'IRC Radio Bot :: Artist/Song')
|
||||||
say(where, `${args[2]} add {[facultatif] nom} < Permet de rajouter une notification sur ${args[2] === '!artist' ? 'cet artiste' : 'ce morceau'}`)
|
this.say(say, where, `${args[2]} add {[facultatif] nom} < Permet de rajouter une notification sur ${args[2] === '!artist' ? 'cet artiste' : 'ce morceau'}`)
|
||||||
say(where, `${args[2]} del {[facultatif] nom} < Permet de supprimer une notification sur ${args[2] === '!artist' ? 'cet artiste' : 'ce morceau'}`)
|
this.say(say, where, `${args[2]} del {[facultatif] nom} < Permet de supprimer une notification sur ${args[2] === '!artist' ? 'cet artiste' : 'ce morceau'}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,17 +97,17 @@ class Help {
|
||||||
* @param {String} where
|
* @param {String} where
|
||||||
*/
|
*/
|
||||||
static showStats (say, where) {
|
static showStats (say, where) {
|
||||||
say(where, 'IRC Radio Bot :: Stats')
|
this.say(say, where, 'IRC Radio Bot :: Stats')
|
||||||
say(where, 'Permet d\'afficher le nombre de passage à l\'antenne d\'un artiste/morceau sur une période donnée')
|
this.say(say, where, 'Permet d\'afficher le nombre de passage à l\'antenne d\'un artiste/morceau sur une période donnée')
|
||||||
say(where, '!stats day <title>')
|
this.say(say, where, '!stats day <title>')
|
||||||
say(where, '!stats week <title>')
|
this.say(say, where, '!stats week <title>')
|
||||||
say(where, '!stats month <title>')
|
this.say(say, where, '!stats month <title>')
|
||||||
say(where, '!stats year <title>')
|
this.say(say, where, '!stats year <title>')
|
||||||
say(where, '!stats lastday <title>')
|
this.say(say, where, '!stats lastday <title>')
|
||||||
say(where, '!stats lastweek <title>')
|
this.say(say, where, '!stats lastweek <title>')
|
||||||
say(where, '!stats lastmonth <title>')
|
this.say(say, where, '!stats lastmonth <title>')
|
||||||
say(where, '!stats lastyear <title>')
|
this.say(say, where, '!stats lastyear <title>')
|
||||||
say(where, 'Si <title> n\'est pas spécifie la stats concerne le nombre d\'artistes différents pour cette période')
|
this.say(say, where, 'Si <title> n\'est pas spécifie la stats concerne le nombre d\'artistes différents pour cette période')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,16 +116,16 @@ class Help {
|
||||||
* @param {String} where
|
* @param {String} where
|
||||||
*/
|
*/
|
||||||
static showWhen (say, where) {
|
static showWhen (say, where) {
|
||||||
say(where, 'IRC Radio Bot :: When')
|
this.say(say, where, 'IRC Radio Bot :: When')
|
||||||
say(where, 'Permet d\'afficher la dernier passage d\'un artiste/morceau sur une période donnée')
|
this.say(say, where, 'Permet d\'afficher la dernier passage d\'un artiste/morceau sur une période donnée')
|
||||||
say(where, '!when day <title>')
|
this.say(say, where, '!when day <title>')
|
||||||
say(where, '!when week <title>')
|
this.say(say, where, '!when week <title>')
|
||||||
say(where, '!when month <title>')
|
this.say(say, where, '!when month <title>')
|
||||||
say(where, '!when year <title>')
|
this.say(say, where, '!when year <title>')
|
||||||
say(where, '!when lastday <title>')
|
this.say(say, where, '!when lastday <title>')
|
||||||
say(where, '!when lastweek <title>')
|
this.say(say, where, '!when lastweek <title>')
|
||||||
say(where, '!when lastmonth <title>')
|
this.say(say, where, '!when lastmonth <title>')
|
||||||
say(where, '!when lastyear <title>')
|
this.say(say, where, '!when lastyear <title>')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,16 +134,16 @@ class Help {
|
||||||
* @param {String} where
|
* @param {String} where
|
||||||
*/
|
*/
|
||||||
static showList (say, where) {
|
static showList (say, where) {
|
||||||
say(where, 'IRC Radio Bot :: List')
|
this.say(say, where, 'IRC Radio Bot :: List')
|
||||||
say(where, 'Permet d\'afficher la liste des titres joués pour un artiste sr une période donnée')
|
this.say(say, where, 'Permet d\'afficher la liste des titres joués pour un artiste sr une période donnée')
|
||||||
say(where, '!list day <artist>')
|
this.say(say, where, '!list day <artist>')
|
||||||
say(where, '!list week <artist>')
|
this.say(say, where, '!list week <artist>')
|
||||||
say(where, '!list month <artist>')
|
this.say(say, where, '!list month <artist>')
|
||||||
say(where, '!list year <artist>')
|
this.say(say, where, '!list year <artist>')
|
||||||
say(where, '!list lastday <artist>')
|
this.say(say, where, '!list lastday <artist>')
|
||||||
say(where, '!list lastweek <artist>')
|
this.say(say, where, '!list lastweek <artist>')
|
||||||
say(where, '!list lastmonth <artist>')
|
this.say(say, where, '!list lastmonth <artist>')
|
||||||
say(where, '!list lastyear <artist>')
|
this.say(say, where, '!list lastyear <artist>')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,11 +152,11 @@ class Help {
|
||||||
* @param {String} where
|
* @param {String} where
|
||||||
*/
|
*/
|
||||||
static showNotifications (say, where) {
|
static showNotifications (say, where) {
|
||||||
say(where, 'IRC Radio Bot :: Notifications')
|
this.say(say, where, 'IRC Radio Bot :: Notifications')
|
||||||
say(where, 'Permet d\'activer et de désactiver les notifications pour soit')
|
this.say(say, where, 'Permet d\'activer et de désactiver les notifications pour soit')
|
||||||
say(where, '!notifications off')
|
this.say(say, where, '!notifications off')
|
||||||
say(where, '!notifications off')
|
this.say(say, where, '!notifications off')
|
||||||
say(where, '!notifications state < Permet de voir si l\'on a désactivé ou non les notifications')
|
this.say(say, where, '!notifications state < Permet de voir si l\'on a désactivé ou non les notifications')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue