summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-13 13:17:32 (GMT)
committer sand <daniel@spatof.org>2013-05-13 13:17:32 (GMT)
commit8cd9f5a51f210728963ee49e5cac0e4fb6889726 (patch)
treebc47637591917f950c224ba4bb79b70360fb75a4
parentd769ca5373b9b0c6c339dc152ad5391910ead8be (diff)
Supporto nickserv, dipendenze python aggiornate
-rw-r--r--pinolo/bot.py1
-rw-r--r--pinolo/irc.py74
-rw-r--r--pinolo/main.py3
-rw-r--r--setup.py6
4 files changed, 66 insertions, 18 deletions
diff --git a/pinolo/bot.py b/pinolo/bot.py
index 0c707fa..81beaa3 100644
--- a/pinolo/bot.py
+++ b/pinolo/bot.py
@@ -184,7 +184,6 @@ class Bot(SignalDispatcher):
now = time.time()
if (now - self._last_crontab) >= CRONTAB_INTERVAL:
- logging.info("CRONTAB!")
self._last_crontab = now
def quit(self):
diff --git a/pinolo/irc.py b/pinolo/irc.py
index c7f8d3e..11d232b 100644
--- a/pinolo/irc.py
+++ b/pinolo/irc.py
@@ -133,6 +133,9 @@ class IRCConnection(object):
# la queue per i thread
self.coda = self.bot.coda
+ def __repr__(self):
+ return "<IRCConnection(%s)>" % self.name
+
def connect(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setblocking(0)
@@ -253,6 +256,8 @@ class IRCConnection(object):
self.dispatch_event(event)
def dispatch_event(self, event):
+ log.debug("Dispatching %r" % event)
+
for handler in [self] + self.bot.plugins:
if hasattr(handler, event.name):
fn = getattr(handler, event.name)
@@ -287,9 +292,14 @@ class IRCConnection(object):
else:
self.parse_line(line)
+ def after_nickserv(self):
+ self.join_all()
+
# IRC COMMANDS
def nick(self, nickname=None):
+ """Send a NICK command"""
+
if nickname is None:
nickname = self.nicknames[self.nicknames_id]
self.send(u"NICK {0}".format(nickname))
@@ -358,10 +368,14 @@ class IRCConnection(object):
# IRC EVENTS
def on_001(self, event):
+ """Server "welcome".
+
+ If we have to login to NickServ we delay the join of all channels.
+ """
if 'nickserv' in self.config:
self.nickserv_login()
-
- self.join_all()
+ else:
+ self.join_all()
def on_433(self, event):
"""Nickname is already in use"""
@@ -381,23 +395,55 @@ class IRCConnection(object):
def on_KICK(self, event):
channel = event.args[0]
- self.join(channel)
+ target = event.args[1]
+
+ if target == self.current_nickname:
+ self.join(channel)
+
+ def on_NOTICE(self, event):
+ """This will handle a bunch of stuff.
+
+ 14:42:54 [Azzurra] -NickServ(service@azzurra.org)- Password accepted for sand. You are now identified.
+
+ <<< :pinolo MODE pinolo :+r
+ <<< :NickServ!service@azzurra.org NOTICE pinolo :Password accepted for pinolo. You are now identified.
+ """
+ # Skip message from ourself
+ if event.user.nickname == self.current_nickname:
+ return
+
+ if event.user.nickname == "NickServ":
+ if u"You are now identified" in event.text:
+ self.after_nickserv()
- def on_cmd_saluta(self, event):
- event.reply(u"ciao")
+# def on_cmd_saluta(self, event):
+# event.reply(u"ciao")
- def on_cmd_getta(self, event):
- task = TestTask(self.name, self.coda)
- task.start()
+# def on_cmd_getta(self, event):
+# task = TestTask(self.name, self.coda)
+# task.start()
def on_cmd_quitta(self, event):
if event.user.nickname == u"sand":
- self.quit()
+ # self.quit()
+ self.bot.quit()
else:
self.msg(event.user.nickname, u"a piĆ  nder culo!")
+
+ def on_cmd_joina(self, event):
+ self.join_all()
+
+ def on_MODE(self, event):
+ """Qui segnala il MODE +r; "+r" e' in event.text
+
+ <<< :pinolo MODE pinolo :+r
+ """
+ target = event.args[0]
+ if target == self.current_nickname:
+ pass
- def on_cmd_cowsay(self, event):
- log.debug("Launching command cowsay")
- righe = cowsay("ciao amico")
- for line in righe:
- event.reply(line)
+# def on_cmd_cowsay(self, event):
+# log.debug("Launching command cowsay")
+# righe = cowsay("ciao amico")
+# for line in righe:
+# event.reply(line)
diff --git a/pinolo/main.py b/pinolo/main.py
index 9c60b47..3950279 100644
--- a/pinolo/main.py
+++ b/pinolo/main.py
@@ -2,6 +2,7 @@
import logging
import getopt
import sys
+import os
from pinolo.bot import Bot
from pinolo.config import read_config_file
@@ -43,7 +44,7 @@ def main():
for name, value in opts:
if name in ('-h', '--help'):
- print usage.format(sys.argv[0])
+ print usage.format(os.path.basename(sys.argv[0]))
sys.exit(0)
elif name in ('-c', '--config'):
options['config_file'] = value
diff --git a/setup.py b/setup.py
index b8de071..03545fe 100644
--- a/setup.py
+++ b/setup.py
@@ -12,8 +12,10 @@ setup(
# xapian!
install_requires=[
"SQLAlchemy==0.7.10",
- "requests==0.14.0",
- "beautifulsoup4==4.1.3"
+ "PyStemmer==1.3.0",
+ "Whoosh==2.3.2",
+ # "requests==0.14.0",
+ # "beautifulsoup4==4.1.3"
],
setup_requires=[],
zip_safe=False,