1 """
2 irc client
3
4 Simple irc implementation, is missing a lot of features
5
6 This is a modification of the testbot.py example of the irclib
7
8 @copyright: (c) 2011 hackmeeting U{http://sindominio.net/hackmeeting}
9 @author: Ruben Pollan
10 @organization: hackmeeting U{http://sindominio.net/hackmeeting}
11 @contact: meskio@sindominio.net
12 @license:
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the Do What The Fuck You Want To
15 Public License, Version 2, as published by Sam Hocevar. See
16 U{http://sam.zoy.org/projects/COPYING.WTFPL} for more details.
17 """
18
19 import re
20 import logging
21 from ircbot import SingleServerIRCBot
22 from irclib import nm_to_n
23
24 from emma.events import Event, subscribe, trigger
25 from message import Message
26
27
29 - def __init__(self, identifier, channels, nickname, server, port=6667):
30 SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
31 self.nick = nickname
32 self.chann = channels
33 self.identifier = identifier
34
36 c.nick(c.get_nickname() + "_")
37
39 for channel in self.chann:
40 c.join(channel)
41
47
49 msg = Message(e)
50 self._trigger_rcv(msg)
51
52
53 cmdexp = re.compile(r"^" + c.get_nickname() + r"[:, ] *(.*)$")
54 m = cmdexp.match(msg["Body"])
55 if m:
56 args = m.groups()[0]
57 self._trigger_cmd(args, msg)
58
62
66
67 - def send(self, to, msg, tpe="privmsg"):
68 c = self.connection
69 msg = msg.encode('UTF-8')
70 if tpe == "ctcp":
71 c.ctcp("ACTION", to, msg)
72 else:
73 c.privmsg(to, msg)
74
76 recv_event = Event(event='receive', interface='irc', \
77 identifier=self.identifier)
78 trigger(recv_event, msg)
79
81 s = args.split(" ", 1)
82 if len(s) == 2:
83 cmd, args = s
84 else:
85 cmd = s[0]
86 args = ""
87
88 logging.info(_("[irc %(identifier)s] command received: %(cmd)s: " \
89 "%(args)s") % {'identifier': self.identifier,
90 'cmd': cmd, 'args': args})
91 cmd_event = Event(event='command', interface='irc', \
92 identifier=self.identifier)
93 trigger(cmd_event, ((cmd, args), msg))
94