Permalink
Browse files

Adding a more general card plugin, but still keeping sw for now

  • Loading branch information...
1 parent 0d94152 commit c4eee47192142563d1320d35ff7c9e8e872ab5fd @draggor committed Jul 25, 2012
Showing with 171 additions and 3 deletions.
  1. +1 −1 example/furnet.js
  2. +1 −1 package.json
  3. +89 −0 plugins/card/cmd.js
  4. +47 −0 plugins/card/decks.js
  5. +32 −0 plugins/card/index.js
  6. +1 −1 plugins/sw/index.js
View
@@ -18,7 +18,7 @@ b = new bot('irc.furnet.org', 'nodeboy1184', {
channels: ['#turtleshell']
});
-b.loadPlugin('admin', {nick: ['draggor', 'turtle']});
+b.loadPlugin('admin', {nick: ['draggor', 'turtle'], cmdprefix: [';']});
//b.loadPlugin('dice');
var r = repl.start();
View
@@ -1,6 +1,6 @@
{
"name" : "ircbot",
- "version" : "0.0.3",
+ "version" : "0.0.4",
"description" : "A simple irc bot with a reloadable plugin system",
"main" : "./index.js",
"homepage" : "http://github.com/draggor/node-ircbot/",
View
@@ -0,0 +1,89 @@
+var util = require('../../util')
+ , decks = require('./decks')
+ ;
+
+var cmds = {};
+
+exports.run = function(info) {
+ var cmd = cmds[info.cmdstr];
+ if(cmd) {
+ cmd(info);
+ }
+};
+
+var selectedDeck;// = cardp.options.deck && decks[cardp.options.deck[0]] ? decks[cardp.options.deck[0]] : decks[52]; //Don't modify this!
+var deck;// = util.randomize(selectedDeck.slice());
+var nicksToDecks = {};
+
+exports.setDefaultDeck = function(defaultDeck) {
+ selectedDeck = defaultDeck && decks[defaultDeck[0]] ? decks[defaultDeck[0]] : decks[52];
+ deck = util.randomize(selectedDeck.slice());
+};
+
+cmds.card = function(info) {
+ var c = selectedDeck[Math.floor(Math.random() * selectedDeck.length)];
+ info.bot.say(info.to, info.from + '\'s random card is: ' + c);
+};
+
+cmds.list = function(info) {
+ var str = 'Available decks: ';
+ for(var k in decks) {
+ str += k + ' ';
+ }
+ info.bot.say(info.to, str);
+};
+
+cmds.init = function(info) {
+ var c = '';
+ if(info.rest) {
+ var num = parseInt(info.rest);
+ if(num > deck.length) {
+ deck = util.randomize(selectedDeck.slice());
+ info.bot.say(info.to, 'Not enough cards left, shuffling initiative deck!');
+ }
+ for(var i = 0; i < num; i++) {
+ c += deck.pop() + ' ';
+ }
+ } else {
+ c = deck.pop();
+ }
+ info.bot.say(info.to, info.from + ' drew: ' + c);
+ if(deck.length == 0) {
+ deck = util.randomize(selectedDeck.slice());
+ info.bot.say(info.to, 'Last card drawn, shuffling initiative deck!');
+ }
+};
+
+cmds.initshuffle = function(info) {
+ deck = util.randomize(selectedDeck.slice());
+ info.bot.say(info.to, 'Initiative deck shuffled.');
+};
+
+cmds.shuffle = function(info) {
+ nicksToDecks[info.from] = util.randomize(selectedDeck.slice());
+ info.bot.say(info.to, info.from + '\'s deck shuffled.');
+};
+
+cmds.draw = function(info) {
+ var c = ''
+ , d = nicksToDecks[info.from] = nicksToDecks[info.from] || util.randomize(selectedDeck.slice())
+ ;
+
+ if(info.rest) {
+ var num = parseInt(info.rest);
+ if(num > d.length) {
+ d = nicksToDecks[info.from] = util.randomize(selectedDeck.slice());
+ info.bot.say(info.to, 'Not enough cards left, shuffling ' + info.from + '\'s deck!');
+ }
+ for(var i = 0; i < num; i++) {
+ c += d.pop() + ' ';
+ }
+ } else {
+ c = d.pop();
+ }
+ info.bot.say(info.to, info.from + ' drew: ' + c);
+ if(d.length == 0) {
+ d = nicksToDecks[info.from] = util.randomize(selectedDeck.slice());
+ info.bot.say(info.to, 'Last card drawn, shuffling ' + info.from + '\'s deck!');
+ }
+};
View
@@ -0,0 +1,47 @@
+var cardValues = [ 2,3,4,5,6,7,8,9,'T','J','Q','K','A' ];
+var cardSuits = [ 'D', 'C', 'H', 'S' ];
+var cardSuitSymbols = {
+ 'D': '&diams;'
+, 'C': '&clubs;'
+, 'H': '&hearts;'
+, 'S': '&spades;'
+, 'R': 'R'
+, 'B': 'B'
+};
+var d54 = [ '\u000304JR\u000f', 'JB' ];
+var d52 = [];
+for(var val in cardValues) {
+ for(var suit in cardSuits) {
+ if(cardSuits[suit] === 'D' || cardSuits[suit] == 'H') {
+ var card = '\u000304' + cardValues[val] + cardSuits[suit] + '\u000f';
+ d54.push(card);
+ d52.push(card);
+ } else {
+ var card = cardValues[val] + cardSuits[suit];
+ d54.push(card);
+ d52.push(card);
+ }
+ }
+}
+
+function buildBaseDeck(deck, types, n) {
+ for(var type in types) {
+ for(var i = 0; i < n; i++) {
+ deck.push(types[type]);
+ }
+ }
+ return deck;
+}
+
+var types7 = ['Air', 'Stone', 'Water', 'Darkness', 'Electricity', 'Fire', 'Light'];
+var types3 = ['Anima', 'Aether'];
+var dBalance = [];
+
+buildBaseDeck(dBalance, types7, 7);
+buildBaseDeck(dBalance, types3, 3);
+
+module.exports = {
+ 54: d54
+, 52: d52
+, balance: dBalance
+};
View
@@ -0,0 +1,32 @@
+var commands = require('./cmd')
+ , util = require('../../util')
+ ;
+
+function parseLine(from, to, msg) {
+ if(msg[0] === cardp.cmdPrefix) {
+ var sp = util.split(msg, ' ', 2)
+ , info = {
+ from: from,
+ to: to,
+ msg: msg,
+ cmdstr: sp[0].substr(1),
+ rest: sp[1],
+ bot: cardp.bot
+ }
+ ;
+
+ commands.run(info);
+ }
+}
+
+var cardp = {
+ listeners: {
+ message: parseLine
+ }
+, reload: ['./cmd', './decks'].map(require.resolve)
+, initPlugin: function() {
+ commands.setDefaultDeck(cardp.options.deck);
+ }
+};
+
+module.exports = cardp;
View
@@ -3,7 +3,7 @@ var commands = require('./cmd')
;
function parseLine(from, to, msg) {
- if(msg[0] === '!') {
+ if(msg[0] === swp.cmdPrefix) {
var sp = util.split(msg, ' ', 2)
, info = {
from: from,

0 comments on commit c4eee47

Please sign in to comment.