Skip to content

Instantly share code, notes, and snippets.

@yuki-yano
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save yuki-yano/3c9b9961b0c676559634 to your computer and use it in GitHub Desktop.

Select an option

Save yuki-yano/3c9b9961b0c676559634 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from ircbot import SingleServerIRCBot
from irclib import nm_to_n
import datetime
import Skype4Py
IRC_SERVER = "localhost"
IRC_PORT = 6668
IRC_NICK = "SkypeBot"
IRC_CHANNELS = {
"#channel": "blob",
}
channels = {}
chats = {}
def handler(msg, event):
raw = msg.Body
msgtype = msg.Type
chat = msg.Chat
senderHandle = msg.FromHandle
if chat in channels:
if event == 'RECEIVED':
print "<skype> " + senderHandle + ": " + raw
bot.say(channels[chat], senderHandle + " : " + raw)
class SkypeMirror(SingleServerIRCBot):
def __init__(self):
SingleServerIRCBot.__init__(self, [(IRC_SERVER, IRC_PORT)], IRC_NICK, IRC_NICK)
def on_welcome(self, connection, e):
print "Connect IRC Server"
for channel in IRC_CHANNELS:
connection.join(channel)
print "join: " + channel
def on_pubmsg(self, connection, event):
nick = nm_to_n(event.source())
msg = event.arguments()[0]
print "<%s> %s: %s " % (event.target(), nick, msg)
chats[event.target()].SendMessage(msg)
def say(self, target, msg):
for line in msg.encode("UTF-8").split("\n"):
print target, line
line += "\r\n"
self.connection.privmsg(target, line)
try:
skype = Skype4Py.Skype(Transport='x11');
except:
print 'Cannot open Skype API'
sys.exit()
if skype.Client.IsRunning:
print 'Skype process found'
elif not skype.Client.IsRunning:
try:
print 'Starting Skype process'
skype.Client.Start()
except:
print 'Failed to start Skype process'
sys.exit()
skype.OnMessageStatus = handler
skype.Attach();
for channel in IRC_CHANNELS:
chat = skype.CreateChatUsingBlob(IRC_CHANNELS[channel])
chats[channel] = chat
channels[chat] = channel
bot = SkypeMirror()
bot.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment