Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active March 9, 2016 13:51
Show Gist options
  • Save blha303/9913570 to your computer and use it in GitHub Desktop.
Save blha303/9913570 to your computer and use it in GitHub Desktop.
Skype<->IRC Bridge. Get ROOM id from https://gist.github.com/blha303/9913693. Getting an error? Remove Transport='x11'. Still getting an error? Join irc.esper.net #blha303 and ask.

Skype<->IRC Bridge

I hate Skype. So much. Words can't even describe. It's slow, it's bloated, people keep telling me to get on Skype, I keep telling them to get on IRC, but I never thought there was a way to bridge the two. But there is. And it's super simple. All you need is a VPS. Windows or Linux, doesn't matter, but I'm using Linux. Python is cross-platform and I tested the bot on Windows, so I can help out if you can't get this working there. irc.esper.net #blha303

  1. Install Python 2.7.*. I use 2.7.3 because it's installed by default in Ubuntu, among other reasons.
  2. Get pip or setuptools and install Skype4Py and irc.
  3. Get the script, the other file in this gist. (If you're not using X11 [for instance, if you're using Windows], remove Transport='x11' from near the bottom of the file. Not the whole line, just those exact characters.)
  4. See the ROOM variable on line 8? Know how to set that? Well, let's go.
    • This script lists all open chats, which includes both P2P and group. Find the one you want by the members in it. Add another member temporarily if you need to narrow it down: https://gist.github.com/blha303/9913693
  5. Well, that was shorter than I thought it'd be. Moving on. Now, I didn't want to have skype running on windows, so I installed X11 on a server, installed MobaXterm locally (for the X server) and installed Skype for Linux on there. You have to get the sound drivers even if you aren't going to use sound, and if you're using a 64bit OS, skype is built on 32bit so you'll need to get ia32-utils from the package repo.
  6. After installing X, you should be able to start the python script in another window, and you should see the IRC bot appear in whatever channel you put at the top of the file, on whatever server, with whatever nickname. If you don't, check the console. If you're seeing an error to do with Transport='x11', remove that bit from the Skype() function. dbus is now default on linux, so I have to have that since I'm using X11.
  7. So now it should work. Let me know on irc.esper.net #blha303 if it doesn't. If it does though, you probably don't want to have a window open all the time just for Skype. Now you need Xvfb. After installing xvfb with your favourite package manager, run these commands from either the directory you extracted Skype to (if you used the Dynamic package) or the directory the script is in: export DISPLAY=:1 Xvfb :1 -screen 0 1024x768x16 & x11vnc -display :1 -bg -nopw -many -listen localhost -xkb & skype & (or ./skype & if in the skype directory) python script.py (if in the script directory, otherwise provide the path to script.py or whatever you called it)
  8. So now you should have skype opening in a dummy X11 server, you can access it through SSH by forwarding local port 5900 to remote port localhost:5900 (ssh -L 5900:localhost:5900 user@hostname from a terminal, or under SSH>Tunnel in Putty) and using UltraVNC's vncviewer to connect to localhost:5900.
  9. If you have any other questions, or I haven't explained something clearly enough here (which is likely, i'm pretty tired at the moment), please join irc.esper.net #blha303 and leave me a message. Please don't get your Skype>IRC bots to join that channel, pick any random empty channel.

If there's any demand I'll add screenshots to this process. Thanks for reading, this has been a really fun day. If you'd like to see the output of the bot for the room I made this script for, ask in the IRC channel I've mentioned a dozen times already and I'll invite you to it. Just FYI

import Skype4Py
from irc.bot import SingleServerIRCBot
SERVER = "irc.esper.net"
PORT = 6667
CHANNEL = "#b3skypetest"
NICKNAME = "b3skypetest"
ROOM = "#stevensmith030/$a5a47aa57ec70504"
OWNER_HANDLE = "stevensmith030"
def munge(inp):
return u"".join([a + u"\u200b" for a in inp])
def skype_handler(msg, event):
if len(msg.Body) == 0:
return
if event == u"RECEIVED" or event == u"SENT" and msg.Sender.Handle != OWNER_HANDLE:
if msg.ChatName == ROOM:
for line in msg.Body.splitlines():
namea = msg.Sender.FullName.split("(")[0]
namea = msg.Sender.Handle if (len(namea) < 1 or len(namea) > 16) else namea
bridge.say(CHANNEL, u"({name}) {msga}".format(name=munge(namea), msga=line))
class SkypeIRCBridge(SingleServerIRCBot):
def __init__(self, skype, server = SERVER):
SingleServerIRCBot.__init__(self, [(SERVER, PORT)], NICKNAME, NICKNAME)
self.skype = skype
self.channel = CHANNEL
def on_nicknameinuse(self, c, e):
c.nick(c.get_nickname() + "_")
def on_welcome(self, c, e):
c.join(self.channel)
def say(self, channel, msg):
self.connection.privmsg(channel, msg)
def do_command(self, c, e):
msg = " ".join(e.arguments)
self.say(self.channel, msg.encode('utf-8'))
def skype_handler(self, c, e):
msg = "(IRC) " + " ".join(e.arguments)
self.skype.Chat(ROOM).SendMessage(msg)
on_pubnotice = do_command
on_privnotice = do_command
on_pubmsg = skype_handler
on_privmsg = do_command
skype = Skype4Py.Skype()
skype.OnMessageStatus = skype_handler
skype.Attach()
chat = [a for a in skype.Chats if a.Name == ROOM][0]
bridge = SkypeIRCBridge(skype)
bridge.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment