Improved handling of incoming messages

Signed-off-by: merspieler <merspieler@users.noreply.github.com>
This commit is contained in:
merspieler 2018-03-15 17:13:51 +01:00
parent 158259dfa0
commit cc9364d2f6

View file

@ -142,49 +142,50 @@ class IRCSkill(MycroftSkill):
except Exception: except Exception:
continue continue
if text != "": for line in text.splitlines():
if line != "":
if self.settings['debug']: if self.settings['debug']:
self.speak(text) self.speak(str(line))
pass
# Prevent Timeout # Prevent Timeout
match = re.search("PING (.*)", text) match = re.search("^PING (.*)$", line, re.M)
if match != None: if match != None:
irc.send('PONG ' + match.group(1) + '\r\n') irc.send('PONG ' + match.group(1) + '\r\n')
match = re.search(":(.*)!.*@.* QUIT", text) match = re.search("^:(.*)!.*@.* QUIT", line, re.M)
if match != None: if match != None:
self.speak(match.group(1) + " has disconnected") self.speak(match.group(1) + " has disconnected")
match = re.search(":(.*)!.*@.* JOIN", text) match = re.search("^:(.*)!.*@.* JOIN", line, re.M)
if match != None: if match != None:
if match.group(1) != self.settings['user']: if match.group(1) != self.settings['user']:
self.speak(match.group(1) + " has joined the channel") self.speak(match.group(1) + " has joined the channel")
match = re.search(":(.*)!.*@.* PART", text) match = re.search("^:(.*)!.*@.* PART", line, re.M)
if match != None: if match != None:
self.speak(match.group(1) + " has left the channel") self.speak(match.group(1) + " has left the channel")
match = re.search(":(.*)!.*@.* QUIT", text) match = re.search("^:(.*)!.*@.* QUIT", line, re.M)
if match != None: if match != None:
self.speak(match.group(1) + " has disconnected") self.speak(match.group(1) + " has disconnected")
match = re.search(":(.*)!.*@.* PRIVMSG #(.*) :(.*)", text) match = re.search("^:(.*)!.*@.* PRIVMSG #(.*) :(.*)", line, re.M)
if match != None: if match != None:
self.speak(match.group(1) + " has written in " + match.group(2) + ": " + match.group(3)) self.speak(match.group(1) + " has written in " + match.group(2) + ": " + match.group(3))
# TODO fix match = re.search("^:(.*)!.*@.* NOTICE #.* :(.*)", line, re.M)
# match = re.search(":(.*)!.*@.* PRIVMSG " + self.settings['user'] + " :(.*)", text)
# if match != None:
# self.speak(match.group(1) + " has written you a private message: " + match.group(2))
match = re.search(":(.*)!.*@.* NOTICE #.* :(.*)", text)
if match != None: if match != None:
self.speak(match.group(1) + " has written a notice to " + match.group(2) + ". The notice is: " + match.group(3)) self.speak(match.group(1) + " has written a notice to " + match.group(2) + ". The notice is: " + match.group(3))
# TODO fix match = re.search("^:(.*)!.*@.* PRIVMSG " + re.escape(self.settings['user']) + " :(.*)$", line, re.M)
# match = re.search(":(.*)!.*@.* NOTICE " + self.settings['user'] + " :(.*)", text) if match != None:
# if match != None: self.speak(line)
# self.speak(match.group(1) + " has written a private notice to you. The notice is: " + match.group(2)) self.speak(match.group(1) + " has written you a private message: " + match.group(2))
match = re.search(":(.*)!.*@.* NOTICE " + re.escape(self.settings['user']) + " :(.*)", line)
if match != None:
self.speak(match.group(1) + " has written a private notice to you. The notice is: " + match.group(2))
cmd = "" cmd = ""
string = "" string = ""