calexil 5 years ago
parent
commit
07fd8824ab
  1. 3
      .gitignore
  2. 12
      Commands.md
  3. 2
      Procfile
  4. 4
      README.md
  5. 12
      bansheecheck.sh
  6. 67
      bot.js
  7. 61
      lib/BansheeBot.js
  8. 17
      now-playing-bot.js
  9. 21
      package-lock.json
  10. 3
      package.json

3
.gitignore vendored

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
# JetBrains IDEs
/.idea
/node_modules

12
Commands.md

@ -1,19 +1,17 @@ @@ -1,19 +1,17 @@
## Commands
You say: **ping**
I say: *pong*
You say: **test**
I say: *it worked...*
I say: *It worked!*
You say: **best girl, best girl? best grill, best grill?**
I say: *Big Band...*
I say: *Big Band.*
You say: **hi**
I say: *hello there, you can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md*
I say: *Hello there, I'm a dumb bot written by @calexil#9270, you can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md*
You say: **commands**
I say: *you can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md*
I say: *You can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md*
You say: **song**
I say: *currently playing: https://wagnaria.xyz/now/calexil*
I say: *Currently playing: https://wagnaria.xyz/now/calexil*

2
Procfile

@ -1 +1 @@ @@ -1 +1 @@
worker: node now-playing-bot.js
worker: node bot.js

4
README.md

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
# ![icon](https://u.teknik.io/znQBF.png) BansheeBot [![CodeFactor](https://www.codefactor.io/repository/github/calexil/bansheebot/badge)](https://www.codefactor.io/repository/github/calexil/bansheebot) [![Build Status](https://travis-ci.org/calexil/BansheeBot.svg?branch=master)](https://travis-ci.org/calexil/BansheeBot)[![GitHub issues](https://img.shields.io/github/issues/calexil/BansheeBot.svg)](https://github.com/calexil/BansheeBot/issues)
A simple bot that reads the song info from the current track scrobble on a user's last.fm account and displays it in a Discord channel.
A simple bot that reads the song info from the currently playing track and displays it in a Discord channel.
Work in progress

12
bansheecheck.sh

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
#!/bin/bash
currentTrack="Calexil is listening to $title by $artist on $album"
while :
do
title=$(banshee --query-title | sed 's/title: //')
artist=$(banshee --query-artist | sed 's/artist: //')
album=$(banshee --query-album | sed 's/album: //')
echo "Calexil is listening to $title by $artist on $album"
sleep 6
done

67
bot.js

@ -1,62 +1,25 @@ @@ -1,62 +1,25 @@
const Discord = require('discord.js');
const client = new Discord.Client();
const responseObject = {
"test": "It worked!",
"best girl?": "Big Band.",
"best girl": "Big Band.",
"best grill": "Big Band.",
"best grill?": "Big Band.",
"hi": "Hello there, I'm a dumb bot written by @calexil#9270, you can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md",
"commands": "You can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md",
"song": "Currently playing: https://wagnaria.xyz/now/calexil"
};
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
if (message.content === 'ping') {
message.reply('pong');
}
});
client.on('message', message => {
if (message.content === 'test') {
message.reply('it worked...');
}
});
client.on('message', message => {
if (message.content === 'best girl?') {
message.reply('Big Band...');
}
});
client.on('message', message => {
if (message.content === 'best girl') {
message.reply('Big Band...');
}
});
client.on('message', message => {
if (message.content === 'best grill?') {
message.reply('Big Band...');
}
});
client.on('message', message => {
if (message.content === 'best grill') {
message.reply('Big Band...');
}
});
client.on('message', message => {
if (message.content === 'hi') {
message.reply('hello there, you can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md');
}
});
client.on('message', message => {
if (message.content === 'commands') {
message.reply('you can see my commands here: https://github.com/calexil/BansheeBot/blob/master/Commands.md');
}
});
client.on('message', message => {
if (message.content === 'song') {
message.reply('currently playing: https://wagnaria.xyz/now/calexil');
}
client.on("message", (message) => {
if(responseObject[message.content]) {
message.channel.send(responseObject[message.content]);
}
});

61
lib/BansheeBot.js

@ -1,61 +0,0 @@ @@ -1,61 +0,0 @@
/**
* @author Timur Kuzhagaliyev <tim.kuzh@gmail.com>
* @copyright 2017
* @license MIT
*/
const Discord = require("discord.js");
const LastFmNode = require('lastfm').LastFmNode;
class BansheeBot {
/**
* @param {{discordToken: string, lastFmApiKey: string, lastFmSecret: string, lastFmUserAgent: string, lastFmUsername: string}} config
*/
constructor(config) {
this.config = config;
this.client = new Discord.Client();
this.lastfm = new LastFmNode({
api_key: this.config.lastFmApiKey,
secret: this.config.lastFmSecret,
useragent: this.config.lastFmUserAgent,
});
}
start() {
return Promise.resolve()
.then(() => console.log('Connecting to Discord...'))
.then(() => this.client.login(this.config.discordToken))
.then(() => console.log('Connected!'))
.then(() => console.log('Bootstrapping Last.fm...'))
.then(() => this.findMusicChannel())
.then(musicChannel => this.prepareLastFm(musicChannel))
.then(() => console.log('Done!'))
.catch(error => console.error(error));
}
findMusicChannel() {
return Promise.resolve()
.then(() => this.client.channels.find(channel => channel.name && channel.name.match(/^music/i)))
.then(channel => {
if (!channel) throw new Error('Could not find the music channel!');
return channel;
});
}
prepareLastFm(musicChannel) {
return Promise.resolve()
.then(() => this.lastfm.stream(this.config.lastFmUsername))
.then(lastFmStream => {
lastFmStream.on('nowPlaying', (track) => {
musicChannel.send('Now playing: ' + track.name);
});
})
}
}
module.exports = BansheeBot;

17
now-playing-bot.js

@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
/**
* @author Timur Kuzhagaliyev <tim.kuzh@gmail.com>
* @copyright 2017
* @license MIT
*/
const BansheeBot = require('./lib/BansheeBot');
let config = {
discordToken: process.env.BOT_TOKEN,
lastFmApiKey: process.env.LASTFM_API_KEY,
lastFmSecret: process.env.LASTFM_SECRET,
lastFmUserAgent: process.env.LASTFM_USER_AGENT,
lastFmUsername: process.env.LASTFM_USERNAME
};
let bot = new BansheeBot(config);
bot.start();

21
package-lock.json generated

@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
{
"name": "BansheeBot",
"version": "0.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"lastfm": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/lastfm/-/lastfm-0.9.2.tgz",
"integrity": "sha1-0Ayi47MOtITlEHkodVJZAOTXfYg=",
"requires": {
"underscore": "1.6.0"
}
},
"underscore": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz",
"integrity": "sha1-izixDKze9jM3uLJOT/htRa6lKag="
}
}
}

3
package.json

@ -4,11 +4,10 @@ @@ -4,11 +4,10 @@
"version": "0.0.0",
"main": "bot.js",
"scripts": {
"start": "node now-playing-bot.js"
"start": "node bot.js"
},
"dependencies": {
"discord.js": "11.1.0",
"lastfm": "^0.9.2",
"request": "2.81.0"
}
}

Loading…
Cancel
Save