Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- registerPlugin({
- name: 'Mail',
- version: '1.0',
- description: 'Allows you to leave mail for offline users!',
- author: 'Mashiro-chan',
- vars: {
- adminUids: {
- title: 'Comma-separated list of client-uids that the bot should accept admin commands from',
- type: 'string'
- }
- }
- }, function (sinusbot, config) {
- function toId(string) {
- return string.toLowerCase().replace(/[^a-z0-9]/g, '');
- }
- function checkTime(i) {
- if (i < 10) {
- i = "0" + i;
- }
- return i;
- }
- var store = require('store');
- var engine = require('engine');
- var event = require('event');
- var backend = require('backend');
- var dateFormat = require('dateformat');
- var mail = {};
- if (store.get('mail') != undefined)
- mail = store.get('mail');
- engine.log("Loaded mail: " + JSON.stringify(mail));
- var uids = [];
- if (config && config.adminUids) uids = config.adminUids.split(",");
- event.on('clientMove', function (ev) {
- var nick = toId(ev.clientNick);
- if (mail[nick] == undefined) {
- mail[nick] = [];
- store.set('mail', mail);
- }
- });
- event.on('chat', function (ev) {
- var parts = ev.msg.split(" ");
- var cmd = parts.shift();
- switch (cmd) {
- case '!mhelp':
- case '!mailhelp':
- case '!helpmail':
- sendMessage(ev.clientId, "[u]Commands[/u]:\n[b]!nicks[/b] - get a list of users you can mail\n[b]!read[/b] - read your mail if you have it, deletes immediately\n[b]!send <nick> <msg>[/b] - sends mail to a user in the mail system");
- break;
- case '!msg':
- case '!mail':
- case '!send':
- if (parts.length < 2) {
- sendMessage(ev.clientId, 'Usage: !send <nick|boxId> <message>');
- break;
- }
- var name = parts.shift();
- var id = toId(name);
- /*
- Put aliases here!
- For example, if their TeamSpeak username was "Infiniti | ??????"
- and you want users to be able to type simply "infin" or "bob":
- if (id == "infin" || id == "bob") id = "infiniti";
- */
- var msg = parts.join(' ');
- if (mail[id] == undefined) {
- sendMessage(ev.clientId, name + " either doesn't have an account with me or you spelled it wrong.\nUse !nicks to see the nicks that are registered with me.");
- } else if (mail[id].length >= 10) {
- sendMessage(ev.clientId, '[i][color=red]ERROR![/color] [color=gray]' + name + ' has no more room in their mailbox! ;~;[/color][/i]');
- } else {
- var today = new Date();
- var h = today.getHours();
- var m = today.getMinutes();
- var s = today.getSeconds();
- h = checkTime(h);
- m = checkTime(m);
- s = checkTime(s);
- msg = '[' + h + ':' + m + ':' + s + '] ' + ev.clientNick + ': ' + msg;
- mail[id].push(msg);
- sendMessage(ev.clientId, '[i][color=gray]Message sent![/color][/i]');
- }
- store.set('mail', mail);
- break;
- case '!nicks':
- if (mail != undefined && Object.keys(mail).length) {
- var sMsg = 'Registered users are:\n';
- for (var name in mail) {
- sMsg += name + '\n';
- }
- sendMessage(ev.clientId, sMsg);
- } else {
- sendMessage(ev.clientId, '[i][color=red]ERROR![/color] [color=gray]There are no users in the mail system! ;~;[/color][/i]');
- }
- break;
- case '!read':
- case '!checkmail':
- case '!mailbox':
- var nick = toId(ev.clientNick);
- if (mail[nick].length < 1) {
- sendMessage(ev.clientId, 'You have no messages.');
- } else {
- var mailTemp = 'You have mail!\n';
- while (msg = mail[nick].pop()) {
- mailTemp = mailTemp + msg + '\n';
- }
- sendMessage(ev.clientId, mailTemp);
- }
- store.set('mail', mail);
- break;
- case '!deleteall':
- if (uids.indexOf(ev.clientUid) < 0) return;
- mail = {};
- store.unset('mail');
- sendMessage("[color=gray][i]The mail system has been reset![/i][/color]");
- break;
- case '!viewmail':
- if (uids.indexOf(ev.clientUid) < 0) return;
- engine.log("Loaded mail: " + JSON.stringify(mail));
- break;
- }
- });
- });
Add Comment
Please, Sign In to add comment