-
Notifications
You must be signed in to change notification settings - Fork 0
/
cozmo_irctospeech
67 lines (51 loc) · 1.42 KB
/
cozmo_irctospeech
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import socket
import re
import cozmo
shouldRun = True
script = ""
def quiter():
global shouldRun
shouldRun = False
cmds = {
"quit": (lambda: quiter())
}
def cozmo_program(robot: cozmo.robot.Robot):
robot.say_text(script, use_cozmo_voice=False, duration_scalar=0.5).wait_for_completed()
def joinchan(chan):
ircsock.send(bytes("JOIN "+ chan +"\n", "UTF-8"))
ircmsg = ""
while ircmsg.find("End of /NAMES list.") == -1:
ircmsg = ircsock.recv(2048).decode("UTF-8")
ircmsg = ircmsg.strip('\n\r')
if len(ircmsg) == 0:
break
print("INFO: " + ircmsg)
def ping():
ircsock.send(bytes("PONG :pingis\n", "UTF-8"))
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = "chat.freenode.net"
channel = "##cozmo-test"
botnick = "HI0IM0COZMO"
exitcode = "bye " + botnick
ircsock.connect((server, 6667))
ircsock.send(bytes("USER " + botnick + " " + botnick + " " + botnick + " " + botnick + "\n", "UTF-8"))
ircsock.send(bytes("NICK " + botnick + "\n", "UTF-8"))
#
joinchan(channel)
pattern = re.compile('[^:]+$')
pcmd = re.compile("^\*(\w+)")
while (shouldRun):
ircmsg = ircsock.recv(2048).decode("UTF-8")
ircmsg = ircmsg.strip('\n\r')
if ircmsg.find("PING :") != -1:
ping()
if len(ircmsg) == 0:
continue
m = pattern.search(ircmsg)
script = m.group()
c = pcmd.search(script)
if c :
cmds[c.group()[1:]]()
else:
print("MSG: " + script)
cozmo.run_program(cozmo_program)