strictRfc added, off by default.

This commit is contained in:
Jeremy Fincher 2004-02-11 05:57:34 +00:00
parent 0c605c2163
commit c04d3632cc
3 changed files with 29 additions and 15 deletions

View File

@ -134,6 +134,10 @@ if __name__ == '__main__':
dest='allowEval',
help='Determines whether the bot will '
'allow the evaluation of arbitrary Python code.')
parser.add_option('', '--strict-rfc', action='store_true',
dest='strictRfc',
help='Determines whether the bot will strictly follow '
'RFC guidelines defining nicks and channels.')
(options, args) = parser.parse_args()
@ -291,8 +295,7 @@ if __name__ == '__main__':
except ImportError:
log.warning('Psyco isn\'t installed, cannot -OO.')
if options.allowEval:
conf.allowEval = True
conf.allowEval = options.allowEval
if not os.path.exists(conf.supybot.directories.log()):
os.mkdir(conf.supybot.directories.log())
@ -307,6 +310,9 @@ if __name__ == '__main__':
import callbacks
import Owner
import ircutils
ircutils.strictRfc = options.strictRfc
irc = irclib.Irc(nick, user, ident, password)
callback = Owner.Class()
irc.addCallback(callback)

View File

@ -53,7 +53,6 @@ _pluginsDir = os.path.join(installDir, 'plugins')
###
allowEval = False
supybot = registry.Group()
supybot.setName('supybot')

View File

@ -54,6 +54,12 @@ from cStringIO import StringIO as sio
import utils
###
# strictRfc: Determines whether the bot will very strictly follow the RCE
# or whether it will allow things like @ and . in nicks.
###
strictRfc = False
def isUserHostmask(s):
"""Returns whether or not the string s is a valid User hostmask."""
p1 = s.find('!')
@ -104,29 +110,33 @@ def nickEqual(nick1, nick2):
"""Returns True if nick1 == nick2 according to IRC case rules."""
return toLower(nick1) == toLower(nick2)
_nickchars = r'_[]\`^{}|-'
nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$' % (re.escape(_nickchars),
re.escape(_nickchars)))
def isCtcp(msg):
"""Returns whether or not msg is a CTCP message."""
return msg.command == 'PRIVMSG' and \
msg.args[1].startswith('\x01') and \
msg.args[1].endswith('\x01')
strictNickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$'
% (re.escape(_nickchars), re.escape(_nickchars)))
_nickchars += '@.'
nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$'
% (re.escape(_nickchars), re.escape(_nickchars)))
def isNick(s):
"""Returns True if s is a valid IRC nick."""
if re.match(nickRe, s):
return True
if strictRfc:
return bool(strictNickRe.match(s))
else:
return False
return bool(nickRe.match(s))
def isChannel(s):
"""Returns True if s is a valid IRC channel name."""
return (s and s[0] in '#&+!' and len(s) <= 50 and \
'\x07' not in s and ',' not in s and ' ' not in s)
_match = fnmatch.fnmatchcase
def isCtcp(msg):
"""Returns whether or not msg is a CTCP message."""
return msg.command == 'PRIVMSG' and \
msg.args[1].startswith('\x01') and \
msg.args[1].endswith('\x01')
_match = fnmatch.fnmatchcase
_patternCache = {}
def _hostmaskPatternEqual(pattern, hostmask):
"""Returns True if hostmask matches the hostmask pattern pattern."""
@ -163,7 +173,6 @@ def hostmaskPatternEqual(pattern, hostmask):
_hostmaskPatternEqualCache[(pattern, hostmask)] = b
return b
def banmask(hostmask):
"""Returns a properly generic banning hostmask for a hostmask.