Browse Source

Merge branch 'master' of https://github.com/calexil/BansheeBot

tags/Beta0.1
calexil 1 year ago
parent
commit
07fd8824ab
10 changed files with 37 additions and 165 deletions
  1. 0
    3
      .gitignore
  2. 5
    7
      Commands.md
  3. 1
    1
      Procfile
  4. 3
    1
      README.md
  5. 12
    0
      bansheecheck.sh
  6. 15
    52
      bot.js
  7. 0
    61
      lib/BansheeBot.js
  8. 0
    17
      now-playing-bot.js
  9. 0
    21
      package-lock.json
  10. 1
    2
      package.json

+ 0
- 3
.gitignore View File

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

+ 5
- 7
Commands.md View File

@@ -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*

+ 1
- 1
Procfile View File

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

+ 3
- 1
README.md View File

@@ -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
- 0
bansheecheck.sh View File

@@ -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

+ 15
- 52
bot.js View File

@@ -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]);
}
});



+ 0
- 61
lib/BansheeBot.js View File

@@ -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;

+ 0
- 17
now-playing-bot.js View File

@@ -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();

+ 0
- 21
package-lock.json View File

@@ -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="
}
}
}

+ 1
- 2
package.json View File

@@ -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