Browse files

Nothing works, but it's getting there

  • Loading branch information...
1 parent 89f385a commit f81919a4f295e6d5265bd69622141c55102546ca Christopher Joel committed Aug 23, 2011
View
1 .gitignore
@@ -1,4 +1,5 @@
.env/
+*.swp
node_modules
support/skypekit/skype
support/skypekit/sdk
View
134 lib/adapter/index.js
@@ -0,0 +1,134 @@
+var events = require('events'),
+ child = require('child_process'),
+ path = require('path'),
+ log = require('../log');
+
+function watch(name, process) {
+
+ function log(data) {
+
+ console.log(data.toString().replace(/\n$/, ''));
+ }
+
+ process.stdout.on(
+ 'data',
+ function(data) {
+
+ log(data);
+ }
+ );
+
+ process.stderr.on(
+ 'data',
+ function(data) {
+
+ log(data);
+ }
+ );
+
+ process.on(
+ 'exit',
+ function() {
+
+ log('Process "' + name + '" has shut down!');
+ }
+ );
+
+}
+
+exports.createAdapter = function(type, options) {
+
+ var eventer = new events.EventEmitter();
+
+ switch(type) {
+
+ default:
+ case 'skype':
+
+ (function() {
+
+ var adapter = child.spawn(
+ 'python',
+ [path.join(__dirname, './skype.py'), options.port]
+ );
+
+ adapter.on(
+ 'exit',
+ function() {
+
+ eventer.emit('dead');
+ }
+ );
+
+ watch("Skype Bridge", adapter);
+ })();
+
+ break;
+ case 'skypekit':
+
+ (function() {
+
+ var adapter;
+ try {
+
+ var client = child.spawn(
+ path.join(process.cwd, './support/skypekit/skype')
+ );
+
+ } catch(e) {
+
+ log("Failed to launch client process for skypekit!");
+
+ throw e;
+ }
+
+ watch("Skypekit Client", client);
+
+ client.on(
+ 'exit',
+ function() {
+
+ eventer.emit('dead');
+
+ try {
+ adapter.kill();
+ } catch(e) {}
+ }
+ );
+
+ client.stderr.on(
+ 'data',
+ function() {
+
+ process.nextTick(
+ function() {
+
+ adapter = child.spawn(
+ 'python',
+ [path.join(__dirname, './skypekit.py'), options.account, options.secret, options.port]
+ );
+
+ watch("Skypekit Bridge", adapter);
+
+ adapter.on(
+ 'exit',
+ function() {
+
+ eventer.emit('dead');
+ }
+ );
+ }
+ );
+ }
+ );
+
+ })();
+
+ break;
+ }
+
+ return eventer;
+
+}
+
+
View
0 lib/adapters/skype.py → lib/adapter/skype.py
File renamed without changes.
View
30 lib/adapters/skypekit.py → lib/adapter/skypekit.py
@@ -5,23 +5,33 @@
import sys
import os
+def log(message):
+ sys.stdout.write('[ SKYPEKIT ] ' + message + '\n');
+ sys.stdout.flush();
+
+
sys.path.append(os.path.abspath('./support/skypekit/sdk/ipc/python'))
sys.path.append(os.path.abspath('./support/skypekit/sdk/interfaces/skype/python'))
try:
+ import skypekit
+except Exception as error:
+ log('Error importing the skypekit module: ' + error.__str__())
+ exit()
+
+try:
import SkyLib
-except ImportError:
- raise SystemExit('Program requires SkyLib and skypekit modules')
+except Exception as error:
+ log('Error importing the SkyLib module: ' + error.__str__())
+ exit()
+
+
account = sys.argv[1]
secret = sys.argv[2]
port = sys.argv[3]
-def log(message)
- sys.stdout.write('[ SKYPEKIT ] ' + message + '\n');
- sys.stdout.flush();
-
class SkypekitBridge:
def __init__(self):
@@ -40,8 +50,6 @@ def connect(self):
socket.on_open = self.socketOpen
socket.run_forever()
- def skypeAccountChange(self, propertyName):
-
def socketError(self, socket, error):
log(error)
@@ -60,7 +68,7 @@ def socketOpen(self, socket):
def accountChange(self, propertyName):
if propertyName == 'status':
- if(self.status == 'LOGGED_IN':
+ if self.status == 'LOGGED_IN':
bridge.loggedIn = True
log("Skypekit is logged in to Skype..")
@@ -78,7 +86,7 @@ def receiveSkypeMessage(self, message, changesInboxTimestamp, supersedesHistoryM
if message.author != accountName:
userCount = len(conversation.GetParticipants())
- self.sendBridgeMessage({ "body" : message.body_xml, "date" : message.timestamp, "chat" : { "id" : message.convo_id, "userCount" : userCount, "private" : userCount <= 1 }, "sender" { "id" : message.author, "name" : message.author_displayname }})
+ self.sendBridgeMessage({ "body" : message.body_xml, "date" : message.timestamp, "chat" : { "id" : message.convo_id, "userCount" : userCount, "private" : userCount <= 1 }, "sender" : { "id" : message.author, "name" : message.author_displayname }})
def sendSkypeMessage(self, chatName, message):
log("Sending message via Skypekit bridge to chat with ID " + chatName)
@@ -88,7 +96,7 @@ def receiveBridgeMessage(self, socket, message):
log("Handling message received from bridge.")
- def handleData(message)
+ def handleData(message):
self.sendSkypeMessage(message['chat']['id'], message['text'])
json.loads(message, object_hook=handleData)
View
59 lib/adapters/index.js
@@ -1,59 +0,0 @@
-var events = require('events'),
- child = require('child_process');
-
-exports.createAdapter = function(type, options) {
-
- var eventer = new events.EventEmitter(),
- adapter;
-
- switch(type) {
- case 'skype':
-
- adapter = child.spawn(
- 'python',
- [path.join(__dirname, './skype.py', options.port)]
- );
-
- break;
- case 'skypekit':
-
- adapter = child.spawn(
- 'python',
- [path.join(__dirname, './skypekit.py', options.account, options.secret, options.port)]
- );
-
- break;
- default
- break;
- }
-
- adapter.stdout.on(
- 'data',
- function(data) {
-
- console.log(data.toString());
- }
- );
-
- adapter.stderr.on(
- 'data',
- function(data) {
-
- console.log(data.toString());
- }
- );
-
- adapter.on(
- 'exit',
- function() {
-
- log('Adapter has shut down!');
- eventer.emit('dead');
- }
- );
-
- return eventer;
-
-}
-
-
View
2 lib/bot/index.js
@@ -1,4 +1,4 @@
-var log = require('./log');
+var log = require('../log');
var funny = [
'Chris is infesting something. It might be my brain.',
View
2 lib/bridge.js
@@ -47,7 +47,7 @@ exports.createBridge = function() {
if(argv.bridge) {
- bridge = adapter.createAdapter(argv.bridge, { account: argv.u, secret: argv.p, port: port || 1337 });
+ bridge = adapter.createAdapter(argv.bridge, { account: argv.u, secret: argv.p, port: argv.port || 1337 });
bridge.on('dead', function() { /* TODO: Attempt to restart.. */ });
}
View
1 support/skypekit/ABOUT-SKYPEKIT.md
@@ -0,0 +1 @@
+ lib32asound2 lib32bz2-1.0 lib32gcc1 lib32ncurses5 lib32ncursesw5 lib32stdc++6 lib32v4l-0 lib32z1 libasound2 libc6-i386 libpython2.7 libv4l-0

0 comments on commit f81919a

Please sign in to comment.