Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging 5/5/2013 Master Upstream into DavidLeeBot #22

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4f4717a
Removed weather commands
sharedferret Aug 28, 2012
fb7d480
Improve table name configuration
scotte Oct 7, 2012
09ce5f3
Merge pull request #88 from scotte/master
sharedferret Oct 7, 2012
6375beb
Fix .quake
sharedferret Oct 7, 2012
f1c4b73
Version checking, enforcement toggle command
sharedferret Oct 7, 2012
0fed29e
Update README.md
sharedferret Oct 7, 2012
856c6fb
Small changes/fixes
sharedferret Oct 8, 2012
a9c0643
Allow users to actually see their welcome message
sharedferret Dec 5, 2012
96e7888
-added idle enforcement
taylor-new-user Dec 9, 2012
aa80ff8
-added a vote type called OPTIMIZE, votes up if everyone does, votes …
taylor-new-user Dec 9, 2012
5baa490
-add 'IF NOT EXISTS' to table creation queries so it would not fail o…
taylor-new-user Dec 9, 2012
d6f63c7
-added laptop to botinfo
taylor-new-user Dec 11, 2012
55078a1
Merge pull request #89 from taylorhakes/master
sharedferret Dec 20, 2012
86b803f
-added lastplayed command for the current song
taylor-new-user Dec 21, 2012
d78def6
Update README.md
sharedferret Dec 23, 2012
248cdef
Fix banning to insert to correct table
scotte Dec 26, 2012
dae4e7e
Merge pull request #90 from scotte/master
sharedferret Dec 26, 2012
53d8305
-fix a bug with turntable and stepping down at the beginning of a song
taylor-new-user Jan 16, 2013
2aafda2
Merge pull request #91 from taylorhakes/master
sharedferret Feb 4, 2013
77fd285
Update README.md
sharedferret Mar 17, 2013
d8a6501
Require node-mysql 0.9.6 or earlier
sharedferret Mar 24, 2013
66255f7
Require ttapi 2.1.8 or later
sharedferret Mar 26, 2013
74c7a3a
No longer require 0.9.x branch of mysql
sharedferret Mar 26, 2013
13c529e
Don't welcome Guests
sharedferret Mar 28, 2013
d395b97
Add new commands
May 1, 2013
3667bf9
Fallback for boot.js error message
May 1, 2013
4b506bb
Add error catching, so process doesn't die on errors in non-critical …
May 2, 2013
d8bf1de
Merge pull request #109 from pr0ton/master
sharedferret May 6, 2013
541a291
Update config.sample.json
SpaceLegends Jun 12, 2013
2803715
Fix getpicture
sharedferret Jun 14, 2013
c69ffc7
Small changes
sharedferret Jun 14, 2013
f7321b5
Cleanup from pull requests
sharedferret Jun 18, 2013
0e196d4
Fix mysql setup bug when no db is present, change idle wording
sharedferret Dec 1, 2013
7fbb888
Merge pull request #117 from adamfontenot/patch-2
sharedferret Dec 1, 2013
8499b08
Bump version
sharedferret Dec 1, 2013
df6b81b
Merge branch 'master' of https://github.com/sharedferret/Sparkle-Turn…
sharedferret Dec 1, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
config.json
driver.js
node_modules
setup.js
setup.js
.idea
.DS_Store
config/
db/sparkle.sqlite
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ config.json
driver.js
node_modules/
setup.js
.DS_Store
config/
db/sparkle.sqlite
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

A customizable Turntable.fm bot written in node.js utilizing [ttapi](https://github.com/alaingilbert/Turntable-API).

This project is no longer in development. If you have new features or bugfixes, feel free to submit a pull request.
This project is still maintained, but I don't have a lot of time for development (so updates will probably be slow). If you have new features or bugfixes, please submit a pull request.

## Installation

npm install sparklebot

Check out the new [Get Started guide](https://github.com/sharedferret/Sparkle-Turntable-Bot/wiki/Get-Started) over on the project's [Wiki page](https://github.com/sharedferret/Sparkle-Turntable-Bot/wiki) for detailed installation instructions.
Check out the [Get Started guide](https://github.com/sharedferret/Sparkle-Turntable-Bot/wiki/Get-Started) over on the project's [Wiki page](https://github.com/sharedferret/Sparkle-Turntable-Bot/wiki) for detailed installation instructions.

## Features

Expand All @@ -25,7 +25,3 @@ The bot can:
* Log song statistics and chat entries in a MySQL database
* Receive and respond to commands via a HTTP RESTful API
* Manage a waitlist/queue for a room

## Help

If you have a **nontrivial** question, feel free to contact me. I'm usually hanging out in the [Indie/Classic Alt 1+Done room](http://turntable.fm/indieclassic_alternative_1_done) on Turntable.
4 changes: 2 additions & 2 deletions commands/addban.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ exports.handler = function(data) {
}

function addToBanList(userid, name, bannedby) {
client.query('INSERT INTO BANNED_USERS SET userid = ?, banned_by = ?, timestamp = NOW()',
client.query('INSERT INTO ' + config.database.dbname + '.' + config.database.tablenames.banned + ' SET userid = ?, banned_by = ?, timestamp = NOW()',
[userid, bannedby]);
bot.speak(name + ' (UID ' + userid + ') has been banned by ' + bannedby + '.');
bot.boot(userid, 'You have been banned by ' + bannedby + '.');
}
}
14 changes: 7 additions & 7 deletions commands/addtoplaylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports.hidden = true;
exports.enabled = true;
exports.matchStart = false;
exports.handler = function(data) {
if(admincheck(data.userid)) {
bot.playlistAll(function (data) {
bot.playlistAdd(currentsong.id, data.list.length);
});
bot.snag();
output({text: 'Snagging this song, ' + data.name + '!', destination: data.source, userid: data.userid});
}
if(admincheck(data.userid)) {
bot.snag();
bot.playlistAll(function (data) {
bot.playlistAdd(currentsong._id, data.list.length);
});
output({text: 'Snagging this song, ' + data.name + '!', destination: data.source, userid: data.userid});
}
}
28 changes: 28 additions & 0 deletions commands/betrippy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
exports.name = 'betrippy';
exports.hidden = false;
exports.enabled = true;
exports.matchStart = false;

global.isTrippy = false;

exports.handler = function(data) {
if (admincheck(data.userid, data)) {
var botSay = function(txt) {
output({text: txt, destination: data.source, userid: data.userid});
}
var avatarIds = [9, 10, 11, 12, 13, 14, 15, 16, 17];
var avChanger = function() {
if (isTrippy) {
var avId = avatarIds[parseInt(Math.random() * avatarIds.length)];
bot.setAvatar(avId, function(data, err) {
setTimeout(avChanger, 3100);
});
}
}
if (!isTrippy) {
isTrippy = true;
botSay("Imma be trippy on " + ["DMT", "Bromo-Dragon Fly", "LSD", "Cocaine", "Ecstacy"][ parseInt(Math.random() * 5) ]);
avChanger();
}
}
}
19 changes: 19 additions & 0 deletions commands/boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports.name = 'bootuser';
exports.hidden = true;
exports.enabled = true;
exports.matchStart = true;

exports.handler = function(data) {
if (admincheck(data.userid, data)) {
var nameforid = data.text.substring(10);
bot.getUserId(nameforid, function(d) {
if (d.success) {
var urls = global.booturls;
var msg = urls && urls.length > 0? urls[ parseInt(Math.random() * urls.length) ] : "You've been booted by the bot";
bot.boot(d.userid, msg);
} else {
output({text: "User id not found!", destination: 'pm', userid: data.userid});
}
});
}
};
4 changes: 2 additions & 2 deletions commands/catfact.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM CATFACTS ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['fact']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
4 changes: 2 additions & 2 deletions commands/catfact2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM CATFACTS ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['fact']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
4 changes: 2 additions & 2 deletions commands/catfact3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM CATFACTS ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['fact']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
4 changes: 2 additions & 2 deletions commands/catfact4.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM CATFACTS ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['fact']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
23 changes: 23 additions & 0 deletions commands/enforcementtoggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//Toggles the waitlist on/off

exports.name = '.enforcement';
exports.hidden = true;
exports.enabled = true;
exports.matchStart = true;
exports.handler = function(data) {
if (admincheck(data.userid)) {
if (data.text.substring(13) == 'on') {
config.enforcement.enforceroom = true;
bot.speak('Room enforcement has been turned on.');
for (i in djs) {
djs[i].remaining = config.enforcement.songstoplay;
}
} else if (data.text.substring(13) == 'off') {
config.enforcement.enforceroom = false;
bot.speak('Room enforcement has been turned off.');
for (i in djs) {
djs[i].remaining = config.enforcement.songstoplay - djs[i].remaining;
}
}
}
}
35 changes: 0 additions & 35 deletions commands/forecast.js

This file was deleted.

20 changes: 4 additions & 16 deletions commands/getpicture.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@ exports.handler = function(data) {
bot.getUserId(nameforid, function(iddata) {
if (iddata.success) {
bot.getProfile(iddata.userid, function(d) {
var response;
var response = '';
console.log('profile', d);

//Try Facebook
//TODO: Re-add Twitter profile picture check (requires 1.1 OAuth)
if (d.facebook != null && d.facebook != '') {
var loc = d.facebook.indexOf('facebook.com/');
if (loc >= 0) {
var innerloc = d.facebook.indexOf('profile.php?id=');
var profileid = d.facebook.substring(loc + 13);
if (innerloc >= 0) {
profileid = d.facebook.substring(innerloc + 15);
}
response = d.name + '\'s picture: https://graph.facebook.com/' + profileid + '/picture?type=large';
}
}

//Try Twitter
else if (d.twitter != null && d.twitter != '') {
response = d.name + '\'s picture: https://api.twitter.com/1'
+ '/users/profile_image?screen_name=' + d.twitter + '&size=bigger';
response = d.name + '\'s picture: https://graph.facebook.com/' + d.facebook + '/picture?type=large';
} else {

response = 'I can\'t find one.';
Expand Down
22 changes: 22 additions & 0 deletions commands/lastplayed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exports.name = 'lastplayed';
exports.hidden = false;
exports.enabled = true;
exports.matchStart = false;
exports.handler = function(data) {
if (config.database.usedb && currentsong._id) {
client.query('SELECT started FROM '
+ config.database.dbname + '.' + config.database.tablenames.song + ' WHERE (songid = \''+ currentsong._id +'\') ORDER BY started DESC LIMIT 1',
function select(error, results, fields) {
var response = '';

if(results && results.length > 0) {
response = 'Last played ' + results[0]['started'] + '.';
} else {
console.log(error);
response = 'This song has not been played before.';
}

output({text: response, destination: data.source, userid: data.userid});
});
}
}
8 changes: 6 additions & 2 deletions commands/listbans.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT banned_by, DATE_FORMAT(timestamp, '
+ '\'%c/%d/%y\') AS date, username FROM (SELECT * FROM '
+ '`BANNED_USERS`) a INNER JOIN (SELECT * FROM (SELECT *'
+ ' FROM USERS ORDER BY lastseen DESC) as test GROUP BY '
+ config.database.dbname + '.'
+ config.database.tablenames.banned + ') a INNER JOIN '
+ ' (SELECT * FROM (SELECT *'
+ ' FROM ' + config.database.dbname + '.'
+ config.database.tablenames.user
+ ' ORDER BY lastseen DESC) as test GROUP BY '
+ 'userid) b ON a.userid = b.userid',
function cb (error, results, fields) {
var rp = 'Banned users: ';
Expand Down
20 changes: 20 additions & 0 deletions commands/notrippy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Ping bot
//Useful for users that use the iPhone app

exports.name = 'notrippy';
exports.hidden = false;
exports.enabled = true;
exports.matchStart = false;


exports.handler = function(data) {
if (admincheck(data.userid, data)) {
var botSay = function(txt) {
output({text: txt, destination: data.source, userid: data.userid});
}
if (isTrippy) {
isTrippy = false;
botSay("Whoa that was one helluva trip. So messed up right now.");
}
}
}
4 changes: 2 additions & 2 deletions commands/ohmygodmeow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//Bot freakout

exports.name = 'oh my god meow';
exports.name = 'oh my god ' + config.botinfo.botname;
exports.hidden = false;
exports.enabled = true;
exports.matchStart = false;
Expand All @@ -20,4 +20,4 @@ exports.handler = function(data) {
output({text: reptarCall(), destination: data.source, userid: data.userid});
}, 5600);
}
}
}
4 changes: 2 additions & 2 deletions commands/pilgrim.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM SCOTT_PILGRIM ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['quote']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
4 changes: 2 additions & 2 deletions commands/pilgrim2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM SCOTT_PILGRIM ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['quote']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
4 changes: 2 additions & 2 deletions commands/pilgrim3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports.handler = function(data) {
if (config.database.usedb) {
client.query('SELECT * FROM SCOTT_PILGRIM ORDER BY RAND() LIMIT 1',
function selectCb(error, results, fields) {
if (results[0] != null) {
if (results != null && results[0] != null) {
var response = (results[0]['quote']);
output({text: response, destination: data.source, userid: data.userid});
}
});
}
}
}
Loading