aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBadministrator <badmin@ergaster.selvatic.org>2015-01-21 03:02:39 +0100
committerBadministrator <badmin@ergaster.selvatic.org>2015-01-21 03:02:39 +0100
commit192e4f1d2c987f79c93504ef316864048282f27f (patch)
treedcca5c5747cfe6c76cf78938aa13f81d5b35ece0
parent586b6eca1b61fe413aafe239f4cf7b0464aefcb2 (diff)
downloadreebot-192e4f1d2c987f79c93504ef316864048282f27f.tar.gz
reebot-192e4f1d2c987f79c93504ef316864048282f27f.zip
join channel handler
-rwxr-xr-xrbot.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/rbot.py b/rbot.py
index 677e064..5f853a3 100755
--- a/rbot.py
+++ b/rbot.py
@@ -13,6 +13,7 @@ from config import *
13from messages import messages 13from messages import messages
14from reemongo import reemongo 14from reemongo import reemongo
15 15
16# Set default encoding
16reload(sys) 17reload(sys)
17sys.setdefaultencoding("utf-8") 18sys.setdefaultencoding("utf-8")
18 19
@@ -28,6 +29,7 @@ class rBot:
28 """ IRC objects constructor """ 29 """ IRC objects constructor """
29 # MongoDB connection 30 # MongoDB connection
30 self.db = db 31 self.db = db
32
31 # Create IRC object and connect to the network 33 # Create IRC object and connect to the network
32 self.irc = irclib.IRC() 34 self.irc = irclib.IRC()
33 self.server = self.irc.server() 35 self.server = self.irc.server()
@@ -36,13 +38,13 @@ class rBot:
36 # Join channels and send welcome message 38 # Join channels and send welcome message
37 for channel in channels_list: 39 for channel in channels_list:
38 self.server.join( channel ) 40 self.server.join( channel )
39 self.sendmessage( channel, messages['che'] ) 41 self.sendmessage( channel, messages['che'] )
40 42
41 # Register handlers 43 # Register handlers
42 self.irc.add_global_handler( 'ping', self.ponger, -42 ) 44 self.irc.add_global_handler( 'ping', self.ponger, -42 )
43 self.irc.add_global_handler( 'privmsg', self.handleprivmessage ) 45 self.irc.add_global_handler( 'privmsg', self.handleprivmessage )
44 self.irc.add_global_handler( 'pubmsg', self.handlepubmessage ) 46 self.irc.add_global_handler( 'pubmsg', self.handlepubmessage )
45 self.irc.add_global_handler( 'welcome', self.handlewelcome ) 47 self.irc.add_global_handler( 'join', self.handlejoin )
46 48
47 # Server connection checker 49 # Server connection checker
48 if self.server.is_connected(): 50 if self.server.is_connected():
@@ -86,8 +88,13 @@ class rBot:
86 if argument.find ( 'hola ' + nickname ) == 0: 88 if argument.find ( 'hola ' + nickname ) == 0:
87 self.sendmessage( target, messages['hello'] + source ) 89 self.sendmessage( target, messages['hello'] + source )
88 90
89 def handlewelcome(self, connection, event): 91 def handlejoin(self, connection, event):
90 self.sendmessage( event.target, messages['welcome'] ) 92 """ Handle channel join
93
94 source -- user who joined the channel
95 """
96 source = event.source().split( '!' ) [0]
97 self.sendmessage( source, messages['welcome'] )
91 98
92 def feed_refresh(self): 99 def feed_refresh(self):
93 100