Created
March 14, 2013 00:18
-
-
Save automata/5157753 to your computer and use it in GitHub Desktop.
irc2espeak.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> cibeleborg </title> | |
<style> | |
body { | |
background: url("http://24.media.tumblr.com/tumblr_lgjl1fsev41qh644lo1_500.jpg") repeat; | |
} | |
</style> | |
</head> | |
<body> | |
<audio id="foo" src="foo.ogg?123" preload="none"></audio> | |
<script> | |
function carrega() { | |
var audio = document.getElementById("foo"); | |
/****************/ | |
audio.pause(); | |
audio.load(); | |
audio.play(); | |
/****************/ | |
} | |
setInterval("carrega();", 10000); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# installing: | |
# sudo aptitude install python python-setuptools espeak vorbis-tools | |
# sudo easy_install hgtools | |
# sudo easy_install irc | |
# | |
# using: | |
# ./irc2espeak.py & | |
# python -m SimpleHTTPServer | |
# firefox http://localhost:8000/irc2espeak.html | |
import os | |
import irc.bot | |
import irc.strings | |
from irc.client import ip_numstr_to_quad, ip_quad_to_numstr | |
import string | |
server = 'irc.freenode.net' | |
port = 6667 | |
channel = '#labmacambira' | |
nickname = 'blablablablah' | |
class TestBot(irc.bot.SingleServerIRCBot): | |
def __init__(self, channel, nickname, server, port=6667): | |
irc.client.ServerConnection.buffer_class = irc.client.LineBuffer | |
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) | |
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 on_privmsg(self, c, e): | |
msg = e.arguments[0] | |
os.system('espeak -vpt+f3 -s80 "%s" -w foo.wav' % msg) | |
os.system('oggenc -q 6 foo.wav -o foo.ogg') | |
def on_pubmsg(self, c, e): | |
msg = e.arguments[0] | |
nick = e.source.nick | |
so_msg = string.join(msg.split(',')[1:], ',') | |
print '%s falou %s' % (nick, msg) | |
if nick == 'cibeleborg': | |
os.system('espeak -vpt+f3 -s80 "%s" -w foo.wav' % msg) | |
elif e.arguments[0].split(',')[0] == nickname: | |
os.system('espeak -vpt+f3 -s80 "%s" -w foo.wav' % so_msg) | |
os.system('oggenc -q 6 foo.wav -o foo.ogg') | |
return | |
def on_dccmsg(self, c, e): | |
c.privmsg("You said: " + e.arguments[0]) | |
def on_dccchat(self, c, e): | |
if len(e.arguments) != 2: | |
return | |
args = e.arguments[1].split() | |
if len(args) == 4: | |
try: | |
address = ip_numstr_to_quad(args[2]) | |
port = int(args[3]) | |
except ValueError: | |
return | |
self.dcc_connect(address, port) | |
def do_command(self, e, cmd): | |
nick = e.source.nick | |
c = self.connection | |
if cmd == "disconnect": | |
self.disconnect() | |
elif cmd == "die": | |
self.die() | |
elif cmd == "stats": | |
for chname, chobj in self.channels.items(): | |
c.notice(nick, "--- Channel statistics ---") | |
c.notice(nick, "Channel: " + chname) | |
users = chobj.users() | |
users.sort() | |
c.notice(nick, "Users: " + ", ".join(users)) | |
opers = chobj.opers() | |
opers.sort() | |
c.notice(nick, "Opers: " + ", ".join(opers)) | |
voiced = chobj.voiced() | |
voiced.sort() | |
c.notice(nick, "Voiced: " + ", ".join(voiced)) | |
elif cmd == "dcc": | |
dcc = self.dcc_listen() | |
c.ctcp("DCC", nick, "CHAT chat %s %d" % ( | |
ip_quad_to_numstr(dcc.localaddress), | |
dcc.localport)) | |
else: | |
print '%s falou %s' % (nick, cmd) | |
#c.notice(nick, "Not understood: " + cmd) | |
def main(): | |
bot = TestBot(channel, nickname, server, port) | |
bot.start() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment