Update nemuspeak to V3.3
This commit is contained in:
parent
b251b3d852
commit
cf249d1592
1 changed files with 21 additions and 20 deletions
41
nemuspeak.py
41
nemuspeak.py
|
|
@ -8,6 +8,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import _thread
|
import _thread
|
||||||
|
|
@ -28,7 +29,7 @@ else:
|
||||||
|
|
||||||
import xmlparser as msf
|
import xmlparser as msf
|
||||||
import message
|
import message
|
||||||
import server
|
import IRCServer
|
||||||
|
|
||||||
SMILEY = list()
|
SMILEY = list()
|
||||||
CORRECTIONS = list()
|
CORRECTIONS = list()
|
||||||
|
|
@ -43,10 +44,10 @@ def speak(endstate):
|
||||||
stopSpk = 0
|
stopSpk = 0
|
||||||
|
|
||||||
if lastmsg is None:
|
if lastmsg is None:
|
||||||
lastmsg = message.Message(None, b":Quelqun!someone@p0m.fr PRIVMSG channel nothing", datetime.now())
|
lastmsg = message.Message(b":Quelqun!someone@p0m.fr PRIVMSG channel nothing", datetime.now())
|
||||||
|
|
||||||
while not stopSpk and len(g_queue) > 0:
|
while not stopSpk and len(g_queue) > 0:
|
||||||
msg = g_queue.pop(0)
|
srv, msg = g_queue.pop(0)
|
||||||
lang = "fr"
|
lang = "fr"
|
||||||
sentence = ""
|
sentence = ""
|
||||||
force = 0
|
force = 0
|
||||||
|
|
@ -60,7 +61,7 @@ def speak(endstate):
|
||||||
force = 1
|
force = 1
|
||||||
|
|
||||||
if force or msg.channel != lastmsg.channel:
|
if force or msg.channel != lastmsg.channel:
|
||||||
if msg.channel == msg.srv.owner:
|
if msg.channel == srv.owner:
|
||||||
sentence += "En message priver. " #Just to avoid é :p
|
sentence += "En message priver. " #Just to avoid é :p
|
||||||
else:
|
else:
|
||||||
sentence += "Sur " + msg.channel + ". "
|
sentence += "Sur " + msg.channel + ". "
|
||||||
|
|
@ -112,36 +113,36 @@ def speak(endstate):
|
||||||
talkEC = 1
|
talkEC = 1
|
||||||
|
|
||||||
|
|
||||||
class Server(server.Server):
|
class Server(IRCServer.IRCServer):
|
||||||
def treat_msg(self, line, private = False):
|
def treat_msg(self, line, private = False):
|
||||||
global stopSpk, talkEC, g_queue
|
global stopSpk, talkEC, g_queue
|
||||||
try:
|
try:
|
||||||
msg = message.Message (self, line, datetime.now(), private)
|
msg = message.Message (line, datetime.now(), private)
|
||||||
if msg.cmd == 'PING':
|
if msg.cmd == 'PING':
|
||||||
msg.treat (self.mods)
|
msg.treat (self.mods)
|
||||||
elif msg.cmd == 'PRIVMSG' and msg.authorize():
|
elif msg.cmd == 'PRIVMSG' and self.accepted_channel(msg.channel):
|
||||||
if msg.nick != msg.srv.owner:
|
if msg.nick != self.owner:
|
||||||
g_queue.append(msg)
|
g_queue.append((self, msg))
|
||||||
if talkEC == 0:
|
if talkEC == 0:
|
||||||
_thread.start_new_thread(speak, (0,))
|
_thread.start_new_thread(speak, (0,))
|
||||||
elif msg.content[0] == "`":
|
elif msg.content[0] == "`" and len(msg.content) > 1:
|
||||||
cmd = shlex.split(msg.content[1:])
|
msg.cmds = msg.cmds[1:]
|
||||||
if cmd[0] == "speak":
|
if msg.cmds[0] == "speak":
|
||||||
_thread.start_new_thread(speak, (0,))
|
_thread.start_new_thread(speak, (0,))
|
||||||
elif cmd[0] == "reset":
|
elif msg.cmds[0] == "reset":
|
||||||
while len(g_queue) > 0:
|
while len(g_queue) > 0:
|
||||||
g_queue.pop()
|
g_queue.pop()
|
||||||
elif cmd[0] == "save":
|
elif msg.cmds[0] == "save":
|
||||||
if talkEC == 0:
|
if talkEC == 0:
|
||||||
talkEC = 1
|
talkEC = 1
|
||||||
stopSpk = 1
|
stopSpk = 1
|
||||||
elif cmd[0] == "add":
|
elif msg.cmds[0] == "add":
|
||||||
self.channels.append(cmd[1])
|
self.channels.append(msg.cmds[1])
|
||||||
print (cmd[1] + " added to listened channels")
|
print (cmd[1] + " added to listened channels")
|
||||||
elif cmd[0] == "del":
|
elif msg.cmds[0] == "del":
|
||||||
if self.channels.count(cmd[1]) > 0:
|
if self.channels.count(msg.cmds[1]) > 0:
|
||||||
self.channels.remove(cmd[1])
|
self.channels.remove(msg.cmds[1])
|
||||||
print (cmd[1] + " removed from listened channels")
|
print (msg.cmds[1] + " removed from listened channels")
|
||||||
else:
|
else:
|
||||||
print (cmd[1] + " not in listened channels")
|
print (cmd[1] + " not in listened channels")
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue