summaryrefslogtreecommitdiff
path: root/figlet.py
blob: 10120bb7716dc8e80af80c231e9c07f555bc821a (plain)
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
#!/usr/bin/python
import re
import os


class Figlet(object):
    def onRecv(self, IRC, line, data):
        if data is None:
            return
        (origin, ident, host, cmd, target, params, extinfo) = data
        if len(target) and target[0] == "#" and cmd == "PRIVMSG":
            channel = IRC.channel(target)
            matches = re.findall("^!figlet\\s+(.*)$", extinfo)
            if matches:
                gif, fig = os.popen2("figlet")
                gif.write(matches[0])
                gif.close()
                while True:
                    line = fig.readline()
                    if line == "":
                        break
                    if re.match("^\\s+$", line.rstrip()):
                        continue
                    channel.msg(line.rstrip())
                fig.close()