Add support for corrections (remplacement of text)
This commit is contained in:
parent
fa4922d5aa
commit
3a30b482ab
30
nemuspeak.py
30
nemuspeak.py
@ -4,6 +4,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
|
import signal
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -16,7 +17,10 @@ if len(sys.argv) == 1:
|
|||||||
print "This script takes exactly 1 arg: a XML config file"
|
print "This script takes exactly 1 arg: a XML config file"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SMILEY = list()
|
SMILEY = list()
|
||||||
|
CORRECTIONS = list()
|
||||||
g_queue = list()
|
g_queue = list()
|
||||||
talkEC = 0
|
talkEC = 0
|
||||||
stopSpk = 0
|
stopSpk = 0
|
||||||
@ -44,6 +48,11 @@ for smiley in config.getElementsByTagName('smiley'):
|
|||||||
SMILEY.append((smiley.getAttribute("txt"), smiley.getAttribute("mood")))
|
SMILEY.append((smiley.getAttribute("txt"), smiley.getAttribute("mood")))
|
||||||
print ("%d smileys loaded"%len(SMILEY))
|
print ("%d smileys loaded"%len(SMILEY))
|
||||||
|
|
||||||
|
for correct in config.getElementsByTagName('correction'):
|
||||||
|
if correct.hasAttribute("bad") and correct.hasAttribute("good"):
|
||||||
|
CORRECTIONS.append((" " + (correct.getAttribute("bad") + " "), (" " + correct.getAttribute("good") + " ")))
|
||||||
|
print ("%d corrections loaded"%len(CORRECTIONS))
|
||||||
|
|
||||||
def speak(endstate):
|
def speak(endstate):
|
||||||
global lastmsg, g_queue, talkEC, stopSpk
|
global lastmsg, g_queue, talkEC, stopSpk
|
||||||
talkEC = 1
|
talkEC = 1
|
||||||
@ -59,12 +68,12 @@ def speak(endstate):
|
|||||||
force = 0
|
force = 0
|
||||||
|
|
||||||
if force or msg[2] - lastmsg[2] > timedelta(0, 500):
|
if force or msg[2] - lastmsg[2] > timedelta(0, 500):
|
||||||
sentence += "À {0} heure {1} : ".format(msg[2].hour, msg[2].minute)
|
sentence += "A {0} heure {1} : ".format(msg[2].hour, msg[2].minute)
|
||||||
force = 1
|
force = 1
|
||||||
|
|
||||||
if force or msg[0] != lastmsg[0]:
|
if force or msg[0] != lastmsg[0]:
|
||||||
if msg[0] == OWNER:
|
if msg[0] == OWNER:
|
||||||
sentence += "En message privé. "
|
sentence += "En message priver. " #Just to avoid é :p
|
||||||
else:
|
else:
|
||||||
sentence += "Sur " + msg[0] + ". "
|
sentence += "Sur " + msg[0] + ". "
|
||||||
force = 1
|
force = 1
|
||||||
@ -81,6 +90,10 @@ def speak(endstate):
|
|||||||
action = 1
|
action = 1
|
||||||
break
|
break
|
||||||
|
|
||||||
|
for (bad, good) in CORRECTIONS:
|
||||||
|
if msg[3].find(bad) >= 0:
|
||||||
|
msg[3] = (" " + msg[3] + " ").replace(bad, good)
|
||||||
|
|
||||||
if action == 0 and (force or msg[1] != lastmsg[1]):
|
if action == 0 and (force or msg[1] != lastmsg[1]):
|
||||||
sentence += msg[1] + " dit : "
|
sentence += msg[1] + " dit : "
|
||||||
|
|
||||||
@ -212,7 +225,7 @@ class Server:
|
|||||||
line = line.rstrip() #remove trailing 'rn'
|
line = line.rstrip() #remove trailing 'rn'
|
||||||
|
|
||||||
if line.find('PRIVMSG') != -1: #Call a parsing function
|
if line.find('PRIVMSG') != -1: #Call a parsing function
|
||||||
parsemsg(unicode(line, encoding='utf-8'), self.channels)
|
parsemsg(unicode(line, encoding='utf-8', errors='ignore'), self.channels)
|
||||||
|
|
||||||
line = line.split()
|
line = line.split()
|
||||||
|
|
||||||
@ -232,6 +245,17 @@ for server in config.getElementsByTagName('server'):
|
|||||||
srv = Server(server)
|
srv = Server(server)
|
||||||
srv.launch()
|
srv.launch()
|
||||||
|
|
||||||
|
def sighup_h(signum, frame):
|
||||||
|
print "Signal reçu..."
|
||||||
|
if os.path.exists("/tmp/isPresent"):
|
||||||
|
thread.start_new_thread(speak, (0,))
|
||||||
|
else:
|
||||||
|
if talkEC == 0:
|
||||||
|
talkEC = 1
|
||||||
|
stopSpk = 1
|
||||||
|
|
||||||
|
signal.signal(signal.SIGHUP, sighup_h)
|
||||||
|
|
||||||
print ("Nemuspeak ready, waiting for new messages...")
|
print ("Nemuspeak ready, waiting for new messages...")
|
||||||
prompt=""
|
prompt=""
|
||||||
while prompt != "quit":
|
while prompt != "quit":
|
||||||
|
Loading…
Reference in New Issue
Block a user