Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MAX_REQUESTS = 2;
- var requests = 0;
- function resetRequests()
- {
- if (requests > 0)
- requests--;
- }
- context.CreateTimer("resetRequests", null, 5);
- var dao = load('scripts/dao.js');
- function onprivtext()
- {
- var args = text.split(' ');
- var t = args.slice(1).join(' ');
- process_command(user, args[0], t);
- }
- function oncommand()
- {
- process_command(user, command, text);
- }
- function process_command(user, command, text)
- {
- if (requests >= MAX_REQUESTS)
- return;
- if (!user.hasop('#maroc'))
- return;
- var args = text.split(' ');
- switch (command.toLowerCase())
- {
- case "find":
- find(args);
- break;
- case "add":
- add(args);
- break;
- case "del":
- del(args);
- break;
- }
- }
- function find(args)
- {
- var target = args.join('*');
- var notes = dao.select(target);
- if (notes.length == 0)
- {
- user.notice('No match for ' + target);
- }
- else
- {
- if (notes.length > 1)
- {
- user.notice(notes.length + ' entries found. Use \002/dcc chat prog.ma\002 with password \002test\002 and perform your request there to get the whole information.');
- }
- var i = 0;
- user.notice('Latest note: (' + notes[i].id + ') [' + new Date(notes[i].date).format('yyyy/MM/dd HH:mm:ss') + '] by <' + notes[i].author + '> on <' + notes[i].target + '> ' + notes[i].comment);
- }
- }
- function del(args)
- {
- try
- {
- for (var i = 0; i < args.length; i++)
- {
- dao.del(args[i]);
- }
- user.notice('Deletion OK');
- }
- catch (e)
- {
- user.notice(e.description);
- }
- }
- function add(args)
- {
- try
- {
- dao.insert(user.nickname, args[0], 'plain', args.slice(1).join(' '));
- user.notice('Note successfully added.');
- }
- catch (e)
- {
- user.notice(e.description);
- }
- }
- String.repeat = function(chr,count)
- {
- var str = "";
- for(var x=0;x<count;x++) {str += chr};
- return str;
- }
- String.prototype.padL = function(width,pad)
- {
- if (!width ||width<1)
- return this;
- if (!pad) pad=" ";
- var length = width - this.length
- if (length < 1) return this.substr(0,width);
- return (String.repeat(pad,length) + this).substr(0,width);
- }
- String.prototype.padR = function(width,pad)
- {
- if (!width || width<1)
- return this;
- if (!pad) pad=" ";
- var length = width - this.length
- if (length < 1) this.substr(0,width);
- return (this + String.repeat(pad,length)).substr(0,width);
- }
- Date.prototype.format = function (fmt)
- {
- var date = this;
- if (!fmt)
- fmt="MM/dd/yyyy";
- var month = date.getMonth() + 1;
- var year = date.getFullYear();
- fmt = fmt.replace("MM",month.toString().padL(2,"0"));
- if (fmt.indexOf("yyyy") > -1)
- fmt = fmt.replace("yyyy",year.toString());
- else if (fmt.indexOf("yy") > -1)
- fmt = fmt.replace("yy",year.toString().substr(2,2));
- fmt = fmt.replace("dd",date.getDate().toString().padL(2,"0"));
- var hours = date.getHours();
- if (fmt.indexOf("t") > -1)
- {
- if (hours > 11)
- fmt = fmt.replace("t","pm")
- else
- fmt = fmt.replace("t","am")
- }
- if (fmt.indexOf("HH") > -1)
- fmt = fmt.replace("HH",hours.toString().padL(2,"0"));
- if (fmt.indexOf("hh") > -1) {
- if (hours > 12) hours - 12;
- if (hours == 0) hours = 12;
- fmt = fmt.replace("hh",hours.toString().padL(2,"0"));
- }
- if (fmt.indexOf("mm") > -1)
- fmt = fmt.replace("mm",date.getMinutes().toString().padL(2,"0"));
- if (fmt.indexOf("ss") > -1)
- fmt = fmt.replace("ss",date.getSeconds().toString().padL(2,"0"));
- return fmt;
- }
Add Comment
Please, Sign In to add comment