Last active
August 29, 2015 14:10
-
-
Save panpawn/238305e19628b224763c to your computer and use it in GitHub Desktop.
A reminder command for PS bots.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Bot Reminders Command | |
* Credits: panpawn | |
* | |
* Steps to add in this command: | |
* 1. Create a file named "reminders.txt" in the main directory. | |
* 2. Copy in the command below into commands.js. | |
* 3. Edit the command for "remind_view_users" and "remind_edit_users" accordingly. | |
* 4. Reload chat commands. | |
* 5. PM the bot: .r add, hi | |
* 6. PM the bot: .r v | |
* 7. The bot should have returned a hastebin of the new reminder you just added. If it didn't then: 1. Your bot is outdated or 2. Something else went wrong. To delete this reminder, do .r d | |
* For any questions, please feel FREE to PM panpawn. | |
* | |
* @license MIT license | |
*/ | |
r: 'reminders', | |
remind: 'reminders', | |
reminders: function(arg, by, room, con) { | |
var remind_view_users = []; //Enter in the ids of whose allowed to view the reminders (view, num) | |
var remind_edit_users = []; //Enter in the ids of whose allowed to edit the reminders (del, add) | |
var reminders_file_name = 'reminders.txt'; //Default name of the file that holds reminders - variable to be incorperated better soon | |
if (remind_view_users.indexOf(toId(by)) === -1) return false; | |
try { | |
var reminders = fs.readFileSync('reminders.txt','utf8'); | |
var remind_commands = ['view','del','add','num'].join(', '); | |
if (!arg) return this.say(con,room,"Valid targets are: " + remind_commands); | |
if (toId(arg) === 'view' || toId(arg) === 'v') { | |
if (fs.readFileSync('reminders.txt','utf8') === '' || fs.readFileSync('reminders.txt','utf8') === ' ') return this.say(con,room,"Huh, that's odd... " + reminders_file_name + " is empty. o.o..."); | |
this.uploadToHastebin(con,room,by,"Current reminders are: \n\n" + reminders); | |
} | |
else if (toId(arg) === 'del' || toId(arg) === 'delete' || toId(arg) === 'd') { | |
if (remind_edit_users.indexOf(toId(by)) === -1) return false; | |
//var remind_del_users = []; Another optional permission for those who can and cannot delete all the reminders | |
//if (remind_del_users.indexOf(toId(by)) === -1) return false; | |
fs.writeFile('reminders.txt',' ', 'utf8'); | |
this.say(con,room,"All reminders have been deleted. RIP ;_;7"); | |
console.log(by + " has deleted all the reminders... RIP"); | |
} | |
else if (toId(arg) === 'numberoflines' || toId(arg) === 'num') { | |
var rows = reminders.split('\n').length - 1; | |
var label1 = ""; | |
var label2 = ""; | |
if (rows === 1) { | |
label1 = " reminder"; | |
label2 = " is "; | |
} else if (rows >= 2) { | |
label1 = " reminders"; | |
label2 = " are "; | |
} | |
this.say(con,room,"There " + label2 + " currently " + rows + label1 + "."); | |
} else { | |
var commaIndex = arg.indexOf(','); | |
var arg1 = toId(arg.slice(0, commaIndex)); | |
var arg2 = arg.slice(commaIndex + 1).trim(); | |
if (toId(arg1) === 'add') { | |
if (remind_edit_users.indexOf(toId(by)) === -1) return false; | |
if (toId(reminders).match(toId(arg2))) return this.say(con,room,"Uhm, excuse me m8, I think that one is already in there n_n..."); | |
if (toId(arg2) === '' || toId(arg2) === ' ') return this.say(con,room,"**ERROR**: your reminder cannot be blank!"); | |
if (arg.length > 500) return this.say(con,room,"**ERROR**: reminders cannot be over 500 characters."); | |
var data = fs.readFileSync('reminders.txt','utf8') | |
fs.writeFile('reminders.txt',data + '\n' + arg2, 'utf8', function(err, data){}); | |
this.say(con,room,"Reminder \"" + arg2 + "\" has been added."); | |
} | |
} | |
} catch (e) { | |
this.say(con,room,"An error has occurred. Are you sure that you made a file called \"" + reminders_file_name + "\"?"); //This shouldn't happen if reminders.txt exists in the right directory | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice.