first commit
This commit is contained in:
commit
295c9b09b6
9
.eslintrc
Normal file
9
.eslintrc
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2016,
|
||||||
|
"sourceType": "module",
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"jsx": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
old
|
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
trailingComma: "es5"
|
||||||
|
tabWidth: 2
|
||||||
|
semi: false
|
||||||
|
singleQuote: true
|
1062
package-lock.json
generated
Normal file
1062
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
Normal file
16
package.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "apradiobot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "a bot",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node ./src"
|
||||||
|
},
|
||||||
|
"author": "notnull",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^3.0.0",
|
||||||
|
"eslint": "^6.7.1",
|
||||||
|
"irc-framework": "^4.5.2"
|
||||||
|
}
|
||||||
|
}
|
1
src/index.js
Normal file
1
src/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
require('./irc-bot')
|
69
src/irc-bot.js
Normal file
69
src/irc-bot.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
const IRC = require('irc-framework')
|
||||||
|
const bot = new IRC.Client()
|
||||||
|
|
||||||
|
const { getPlaylist, getCurrentTrack } = require('./index')
|
||||||
|
const chalk = require('chalk')
|
||||||
|
|
||||||
|
const host = 'irc.anarchyplanet.org'
|
||||||
|
const port = 6667
|
||||||
|
const nick = 'bobnot'
|
||||||
|
|
||||||
|
const owners = ['notnull']
|
||||||
|
const autojoin = ['#anarchybots']
|
||||||
|
|
||||||
|
console.log(chalk.green('\n***********************************\n'))
|
||||||
|
console.log(chalk.green(`Connecting to ${host}\n`))
|
||||||
|
console.log(chalk.green('***********************************\n'))
|
||||||
|
|
||||||
|
bot.connect({ host, port, nick })
|
||||||
|
|
||||||
|
bot.on('message', event => logEvent(event))
|
||||||
|
bot.on('connected', () => autojoin.map(c => bot.join(c)))
|
||||||
|
|
||||||
|
bot.on('socket close', event => console.log('bot has disconnected.'))
|
||||||
|
|
||||||
|
bot.matchMessage(/^!hello/, event => event.reply('Hi!'))
|
||||||
|
|
||||||
|
/** ADMIN COMMANDS **/
|
||||||
|
bot.matchMessage(/^!join/, event => handleJoin(event))
|
||||||
|
bot.matchMessage(/^!part/, event => handlePart(event))
|
||||||
|
bot.matchMessage(/^!quit/, event => handleQuit(event))
|
||||||
|
|
||||||
|
/** RADIO COMMANDS**/
|
||||||
|
bot.matchMessage(/^!playlist/, event => sendPlaylist(event))
|
||||||
|
bot.matchMessage(/^!np/, event => sendCurrentTrack(event))
|
||||||
|
|
||||||
|
const handleJoin = event => {
|
||||||
|
if (!owners.includes(event.nick)) return
|
||||||
|
bot.join(event.message.split(' ')[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePart = event => {
|
||||||
|
if (!owners.includes(event.nick)) return
|
||||||
|
bot.part(event.message.split(' ')[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleQuit = event => {
|
||||||
|
if (!owners.includes(event.nick)) return
|
||||||
|
bot.quit(["You'll cowards, don't even smoke crack."])
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendPlaylist = event => {
|
||||||
|
const { error, playlist } = getPlaylist()
|
||||||
|
if (error) return event.reply('Something went wrong.')
|
||||||
|
const splitPlaylist = playlist.split('\n').slice(0, 5)
|
||||||
|
splitPlaylist.map(s => bot.say(event.nick, s))
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendCurrentTrack = event => {
|
||||||
|
const { error, track } = getCurrentTrack()
|
||||||
|
if (error) return event.reply('Something went wrong.')
|
||||||
|
if (track.length === 0) return event.reply('Nothing is currently playing.')
|
||||||
|
event.reply(track)
|
||||||
|
}
|
||||||
|
|
||||||
|
const logEvent = event => {
|
||||||
|
if (event.type === 'notice') console.log(event.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = bot
|
12
src/mpc-commands.js
Normal file
12
src/mpc-commands.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const { spawnSync } = require('child_process')
|
||||||
|
const getPlaylist = () => {
|
||||||
|
const { stderr, stdout } = spawnSync('mpc', ['playlist'])
|
||||||
|
return { error: stderr.toString(), playlist: stdout.toString() }
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCurrentTrack = () => {
|
||||||
|
const { stderr, stdout } = spawnSync('mpc', ['current'])
|
||||||
|
return { error: stderr.toString(), track: stdout.toString() }
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { getPlaylist, getCurrentTrack }
|
Loading…
Reference in New Issue
Block a user