Skip to content

Instantly share code, notes, and snippets.

@mvanorder
Created February 13, 2019 14:13
Show Gist options
  • Save mvanorder/342d5bc30d40822234d56f9ce862da56 to your computer and use it in GitHub Desktop.
Save mvanorder/342d5bc30d40822234d56f9ce862da56 to your computer and use it in GitHub Desktop.
Listen to IRC channels
import os
import re
import time
import sys
from google_speech import Speech
sox_effects = ("speed", "1.4", "pitch", "-600")
mode = 'irssi'
regexs = {
'hexchat': {
'exclude': r'^\w+ [0-9 ][0-9] ([0-9]{2}:){2}[0-9]{2} \*',
'replace': (
r'^\w+ [0-9 ][0-9] ([0-9]{2}:){2}[0-9]{2} <(\w+)>\t',
r'\2 said:'),
},
'irssi': {
'exclude': r'^([0-9]{2}:[0-9]{2}[ \t]+){1,2}(join|quit) \|',
'replace': (
r'^([0-9]{2}:[0-9]{2}[ \t]+){1,2}(\b.+\b)\W+\|',
r'\2 said:'),
},
'global': [],
}.get(mode)
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = os.path.join(os.path.expanduser('~'), '.config', 'hexchat', 'logs', 'freenode', '#python.log')
f = open(filename, 'r')
f.read()
last_line = None
while True:
line = f.readline()
if line == last_line:
line = f.readline()
if not line:
time.sleep(0.5)
continue
if not re.match(regexs['exclude'], line):
message = re.sub(regexs['replace'][0], regexs['replace'][1], line)
speech = Speech(message, 'en')
speech.play(sox_effects)
last_line = line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment