Compare commits

...

2 Commits

Author SHA1 Message Date
8f9d261507 add handleSpam 2019-12-23 07:22:36 -05:00
17b3cc0c42 add error handling for reset, fix .flat() not supported 2019-12-23 05:54:26 -05:00
3 changed files with 20 additions and 9 deletions

11
src/handleSpam.js Normal file
View File

@ -0,0 +1,11 @@
const phrases = [
'Did you know? Zhachev is a twat.',
'Zhachev is a poor lonely baby who has been stalking this IRC for over a year. anti-civ 4 lyfe!',
]
const handleSpam = event => {
const phrase = phrases[Math.floor(Math.random() * phrases.length)]
return event.reply(phrase)
}
module.exports = handleSpam

View File

@ -45,9 +45,9 @@ const clearAllPlaylists = event => {
}
const addAllPlaylists = async event => {
const files = fs.readdirSync('./playlists')
const tracks = readPlaylists(files)
try {
const files = fs.readdirSync('./playlists')
const tracks = readPlaylists(files)
await Promise.all(
tracks.map(t => insertTrackAsync(t.split(' # ')[0]))
).then(() => {
@ -61,13 +61,8 @@ const addAllPlaylists = async event => {
const readPlaylists = files =>
files
.map(f =>
fs
.readFileSync('./playlists/' + f)
.toString()
.split('\n')
)
.flat()
.map(f => fs.readFileSync('./playlists/' + f, 'utf-8').split('\n'))
.reduce((a, b) => a.concat(b))
const handleError = (err, event) => {
console.log(err)

View File

@ -3,6 +3,9 @@ const chalk = require('chalk')
require('dotenv').config()
const { insertTrack } = require('./mpc-commands')
let request = ''
const handleSpam = require('./handleSpam')
const CLIENT_ID = process.env.CLIENT_ID
const CLIENT_SECRET = process.env.CLIENT_SECRET
@ -47,6 +50,8 @@ const searchTrack = event => {
}
const requestTrack = event => {
if (event.message === request) return handleSpam(event)
request = event.message
let pattern = /^!request "(.+?)"( artist "(.+?)")?/
let match = event.message.match(pattern)
if (!match)