Subversion Repositories navi

Compare Revisions

Ignore whitespace Rev 238 → Rev 246

/ircbot/ircbot.py
24,13 → 24,11
write simpler bots.
"""
 
from UserDict import UserDict
from irclib import ServerConnectionError, SimpleIRCClient, nm_to_n, irc_lower, \
parse_channel_modes, is_channel
import sys
from UserDict import UserDict
 
from irclib import SimpleIRCClient
from irclib import nm_to_n, irc_lower, all_events
from irclib import parse_channel_modes, is_channel
from irclib import ServerConnectionError
 
class SingleServerIRCBot(SimpleIRCClient):
"""A single-server IRC bot class.
66,7 → 64,7
self.channels = IRCDict()
self.server_list = server_list
if not reconnection_interval or reconnection_interval < 0:
reconnection_interval = 2**31
reconnection_interval = 2 ** 31
self.reconnection_interval = reconnection_interval
 
self._nickname = nickname
75,7 → 73,7
"namreply", "nick", "part", "quit"]:
self.connection.add_global_handler(i,
getattr(self, "_on_" + i),
-10)
- 10)
def _connected_checker(self):
"""[Internal]"""
if not self.connection.is_connected():
256,18 → 254,18
Otherwise, it should behave exactly as a normal dictionary.
"""
 
def __init__(self, dict=None):
def __init__(self, dictt=None):
self.data = {}
self.canon_keys = {} # Canonical keys
if dict is not None:
self.update(dict)
if dictt is not None:
self.update(dictt)
def __repr__(self):
return repr(self.data)
def __cmp__(self, dict):
if isinstance(dict, IRCDict):
return cmp(self.data, dict.data)
def __cmp__(self, dictt):
if isinstance(dictt, IRCDict):
return cmp(self.data, dictt.data)
else:
return cmp(self.data, dict)
return cmp(self.data, dictt)
def __len__(self):
return len(self.data)
def __getitem__(self, key):
301,8 → 299,8
return self.data.values()
def has_key(self, key):
return irc_lower(key) in self.canon_keys
def update(self, dict):
for k, v in dict.items():
def update(self, dictt):
for k, v in dictt.items():
self.data[k] = v
def get(self, key, failobj=None):
return self.data.get(key, failobj)
424,7 → 422,7
 
def limit(self):
if self.has_limit():
return self.modes[l]
return self.modes["l"]
else:
return None
 
/ircbot/bot.py
12,7 → 12,7
are given by prefixing the text by the bot name followed by a colon."""
 
from ircbot import SingleServerIRCBot
from irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr
from irclib import nm_to_n
from tsimapiak import translate
 
class Bot(SingleServerIRCBot):
28,12 → 28,12
c.privmsg("NiceBot", "asztallab")
 
def on_privmsg(self, c, e):
self.do_command(e, e.arguments()[0],True)
self.do_command(e, e.arguments()[0], True)
 
def on_pubmsg(self, c, e):
a = e.arguments()[0]
if a[0] == "!":
self.do_command(e, a[1:].strip(),False)
self.do_command(e, a[1:].strip(), False)
return
 
def do_command(self, e, cmd, priv):
/ircbot/irclib.py
17,6 → 17,13
# keltus <keltus@users.sourceforge.net>
#
# $Id: irclib.py,v 1.47 2008/09/25 22:00:59 keltus Exp $
import bisect
import re
import select
import socket
import string
import time
import types
 
"""irclib -- Internet Relay Chat (IRC) protocol client library.
 
61,14 → 68,6
.. [IRC specifications] http://www.irchelp.org/irchelp/rfc/
"""
 
import bisect
import re
import select
import socket
import string
import sys
import time
import types
 
VERSION = 0, 4, 8
DEBUG = 0
287,7 → 286,7
 
arguments -- Arguments to give the function.
"""
self.execute_delayed(at-time.time(), function, arguments)
self.execute_delayed(at - time.time(), function, arguments)
 
def execute_delayed(self, delay, function, arguments=()):
"""Execute a function after a specified time.
300,7 → 299,7
 
arguments -- Arguments to give the function.
"""
bisect.insort(self.delayed_commands, (delay+time.time(), function, arguments))
bisect.insort(self.delayed_commands, (delay + time.time(), function, arguments))
if self.fn_to_add_timeout:
self.fn_to_add_timeout(delay)
 
341,7 → 340,7
def __init__(self, irclibobj):
self.irclibobj = irclibobj
 
def _get_socket():
def _get_socket(self):
raise IRCError, "Not overridden"
 
##############################
488,9 → 487,9
 
try:
if self.ssl:
new_data = self.ssl.read(2**14)
new_data = self.ssl.read(2 ** 14)
else:
new_data = self.socket.recv(2**14)
new_data = self.socket.recv(2 ** 14)
except socket.error, x:
# The server hung up.
self.disconnect("Connection reset by peer")
845,10 → 844,10
"""Send a WHOIS command."""
self.send_raw("WHOIS " + ",".join(targets))
 
def whowas(self, nick, max="", server=""):
def whowas(self, nick, maxx="", server=""):
"""Send a WHOWAS command."""
self.send_raw("WHOWAS %s%s%s" % (nick,
max and (" " + max),
maxx and (" " + maxx),
server and (" " + server)))
 
class DCCConnectionError(IRCError):
955,7 → 954,7
return
 
try:
new_data = self.socket.recv(2**14)
new_data = self.socket.recv(2 ** 14)
except socket.error, x:
# The server hung up.
self.disconnect("Connection reset by peer")
972,7 → 971,7
 
# Save the last, unfinished line.
self.previous_buffer = chunks[-1]
if len(self.previous_buffer) > 2**14:
if len(self.previous_buffer) > 2 ** 14:
# Bad peer! Naughty peer!
self.disconnect()
return
1228,14 → 1227,14
 
messages = []
i = 0
while i < len(chunks)-1:
while i < len(chunks) - 1:
# Add message if it's non-empty.
if len(chunks[i]) > 0:
messages.append(chunks[i])
 
if i < len(chunks)-2:
if i < len(chunks) - 2:
# Aye! CTCP tagged data ahead!
messages.append(tuple(chunks[i+1].split(" ", 1)))
messages.append(tuple(chunks[i + 1].split(" ", 1)))
 
i = i + 2
 
1352,8 → 1351,6
for ch in mode_part:
if ch in "+-":
sign = ch
elif ch == " ":
collecting_arguments = 1
elif ch in unary_modes:
if len(args) >= arg_count + 1:
modes.append([sign, ch, args[arg_count]])
1374,7 → 1371,7
"002": "yourhost",
"003": "created",
"004": "myinfo",
"005": "featurelist", # XXX
"005": "featurelist", # XXX
"200": "tracelink",
"201": "traceconnecting",
"202": "tracehandshake",
1467,7 → 1464,7
"374": "endofinfo",
"375": "motdstart",
"376": "endofmotd",
"377": "motd2", # 1997-10-16 -- tkil
"377": "motd2", # 1997-10-16 -- tkil
"381": "youreoper",
"382": "rehashing",
"384": "myportis",
1496,7 → 1493,7
"432": "erroneusnickname", # Thiss iz how its speld in thee RFC.
"433": "nicknameinuse",
"436": "nickcollision",
"437": "unavailresource", # "Nick temporally unavailable"
"437": "unavailresource", # "Nick temporally unavailable"
"441": "usernotinchannel",
"442": "notonchannel",
"443": "useronchannel",
1517,12 → 1514,12
"474": "bannedfromchan",
"475": "badchannelkey",
"476": "badchanmask",
"477": "nochanmodes", # "Channel doesn't support modes"
"477": "nochanmodes", # "Channel doesn't support modes"
"478": "banlistfull",
"481": "noprivileges",
"482": "chanoprivsneeded",
"483": "cantkillserver",
"484": "restricted", # Connection is restricted
"484": "restricted", # Connection is restricted
"485": "uniqopprivsneeded",
"491": "nooperhost",
"492": "noservicehost",