Changed from 's.find(x) != -1' to 'x in s'

This commit is contained in:
Jeremy Fincher 2003-08-11 17:16:03 +00:00
parent feda60aff2
commit 39cce9c3af
13 changed files with 26 additions and 20 deletions

View File

@ -70,7 +70,7 @@ def findBiggestDollar(alias):
def makeNewAlias(name, alias): def makeNewAlias(name, alias):
if findAliasCommand(name, alias): if findAliasCommand(name, alias):
raise RecursiveAlias raise RecursiveAlias
doChannel = alias.find('$channel') != -1 doChannel = '$channel' in alias
biggestDollar = findBiggestDollar(alias) biggestDollar = findBiggestDollar(alias)
doDollars = bool(biggestDollar) doDollars = bool(biggestDollar)
if biggestDollar is not None: if biggestDollar is not None:

View File

@ -39,12 +39,12 @@ import callbacks
class Friendly(callbacks.PrivmsgRegexp): class Friendly(callbacks.PrivmsgRegexp):
def greet(self, irc, msg, match): def greet(self, irc, msg, match):
"(?:heya?|(?:w(?:hat'?s\b|as)s?up)|howdy|hi|hello)" "(?:heya?|(?:w(?:hat'?s\b|as)s?up)|howdy|hi|hello)"
if msg.args[1].find(irc.nick) != -1: if irc.nick in msg.args[1]:
irc.queueMsg(ircmsgs.privmsg(msg.args[0], 'howdy :)')) irc.queueMsg(ircmsgs.privmsg(msg.args[0], 'howdy :)'))
def goodbye(self, irc, msg, match): def goodbye(self, irc, msg, match):
"(?:good)?bye|adios|vale|ciao|au revoir|seeya|night" "(?:good)?bye|adios|vale|ciao|au revoir|seeya|night"
if msg.args[1].find(irc.nick) != -1: if irc.nick in msg.args[1]:
irc.queueMsg(ircmsgs.privmsg(msg.args[0], 'seeya, d00d!')) irc.queueMsg(ircmsgs.privmsg(msg.args[0], 'seeya, d00d!'))
def exclaim(self, irc, msg, match): def exclaim(self, irc, msg, match):

View File

@ -344,7 +344,7 @@ class FunDB(callbacks.Privmsg):
be "addlart chops $who in half with an AOL cd." be "addlart chops $who in half with an AOL cd."
""" """
lart = privmsgs.getArgs(args) lart = privmsgs.getArgs(args)
if lart.find('$who') == -1: if '$who' in lart:
irc.error(msg, 'There must be an $who in the lart somewhere.') irc.error(msg, 'There must be an $who in the lart somewhere.')
return return
cursor = self.db.cursor() cursor = self.db.cursor()
@ -431,7 +431,7 @@ if __name__ == '__main__':
cursor.execute("""PRAGMA cache_size = 50000""") cursor.execute("""PRAGMA cache_size = 50000""")
addWord(db, line) addWord(db, line)
elif category == 'larts': elif category == 'larts':
if line.find('$who') != -1: if '$who' in line:
cursor.execute("""INSERT INTO larts VALUES (NULL, %s)""", line) cursor.execute("""INSERT INTO larts VALUES (NULL, %s)""", line)
else: else:
print 'Invalid lart: %s' % line print 'Invalid lart: %s' % line

View File

@ -79,7 +79,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
games = self._gkgames.search(profile).group(1) games = self._gkgames.search(profile).group(1)
(w, l, d) = self._gkrecord.search(profile).groups() (w, l, d) = self._gkrecord.search(profile).groups()
seen = self._gkseen.search(utils.htmlToText(profile)) seen = self._gkseen.search(utils.htmlToText(profile))
if seen.group(0).find("is hiding") != -1: if 'is hiding' in seen.group(0):
seen = '%s is hiding his/her online status.' % name seen = '%s is hiding his/her online status.' % name
elif seen.group(2).startswith('0'): elif seen.group(2).startswith('0'):
seen = '%s is on gameknot right now.' % name seen = '%s is on gameknot right now.' % name
@ -90,7 +90,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
games = '1 active game' games = '1 active game'
else: else:
games = '%s active games' % games games = '%s active games' % games
if profile.find('Team:') >= 0: if 'Team:' in profile:
team = self._gkteam.search(profile).group('name') team = self._gkteam.search(profile).group('name')
irc.reply(msg, '%s (team: %s) is rated %s and has %s ' \ irc.reply(msg, '%s (team: %s) is rated %s and has %s ' \
'and a record of W-%s, L-%s, D-%s. %s' % \ 'and a record of W-%s, L-%s, D-%s. %s' % \
@ -100,7 +100,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp):
'and a record of W-%s, L-%s, D-%s. %s' % \ 'and a record of W-%s, L-%s, D-%s. %s' % \
(name, rating, games, w, l, d, seen)) (name, rating, games, w, l, d, seen))
except AttributeError: except AttributeError:
if profile.find('User %s not found!' % name) != -1: if ('User %s not found!' % name) in profile:
irc.error(msg, 'No user %s exists.' % name) irc.error(msg, 'No user %s exists.' % name)
else: else:
irc.error(msg, 'The format of the page was odd.') irc.error(msg, 'The format of the page was odd.')

View File

@ -305,7 +305,7 @@ class Http(callbacks.Privmsg):
html = m.group(1) html = m.group(1)
s = utils.htmlToText(html, tagReplace='').strip('\xa0 ') s = utils.htmlToText(html, tagReplace='').strip('\xa0 ')
irc.reply(msg, s[9:]) # Snip off "the site" irc.reply(msg, s[9:]) # Snip off "the site"
elif html.find('We could not get any results') != -1: elif 'We could not get any results' in html:
irc.reply(msg, 'No results found for %s.' % hostname) irc.reply(msg, 'No results found for %s.' % hostname)
else: else:
irc.error(msg, 'The format of the was odd.') irc.error(msg, 'The format of the was odd.')

View File

@ -81,7 +81,7 @@ class NickServ(privmsgs.CapabilityCheckingPrivmsg):
# NickServ told us the nick is registered. # NickServ told us the nick is registered.
identify = 'IDENTIFY %s' % self.password identify = 'IDENTIFY %s' % self.password
irc.queueMsg(ircmsgs.privmsg(self.nickserv, identify)) irc.queueMsg(ircmsgs.privmsg(self.nickserv, identify))
elif msg.args[1].find('recognized') != -1: elif 'recognized' in msg.args[1]:
self.sentGhost = False self.sentGhost = False
elif self._ghosted.search(msg.args[1]): elif self._ghosted.search(msg.args[1]):
# NickServ told us the nick has been ghost-killed. # NickServ told us the nick has been ghost-killed.

View File

@ -62,7 +62,7 @@ class OSU(callbacks.Privmsg):
emails = [] emails = []
for line in data.splitlines(): for line in data.splitlines():
line.strip() line.strip()
if line.find('Published address') != -1: if 'Published address' in line:
emails.append(line.split()[-1]) emails.append(line.split()[-1])
if emails: if emails:
irc.reply(msg, 'Possible matches: %s' % ', '.join(emails)) irc.reply(msg, 'Possible matches: %s' % ', '.join(emails))

View File

@ -382,9 +382,9 @@ class Relay(callbacks.Privmsg):
rAction = re.compile(r'\* [^/]+@(?:%s) ' % '|'.join(abbreviations)) rAction = re.compile(r'\* [^/]+@(?:%s) ' % '|'.join(abbreviations))
if not (rPrivmsg.match(msg.args[1]) or \ if not (rPrivmsg.match(msg.args[1]) or \
rAction.match(msg.args[1]) or \ rAction.match(msg.args[1]) or \
msg.args[1].find('has left on ') != -1 or \ 'has left on ' in msg.args[1] or \
msg.args[1].find('has joined on ') != -1 or \ 'has joined on ' in msg.args[1] or \
msg.args[1].find('has quit') != -1 or \ 'has quit' in msg.args[1] or \
msg.args[1].startswith('mode change') or \ msg.args[1].startswith('mode change') or \
msg.args[1].startswith('nick change')): msg.args[1].startswith('nick change')):
channel = msg.args[0] channel = msg.args[0]

View File

@ -71,9 +71,9 @@ class ThreadedFunCommands(callbacks.Privmsg):
text = conn.read_all() text = conn.read_all()
for line in text.splitlines(): for line in text.splitlines():
(name, version) = line.split(':') (name, version) = line.split(':')
if name.find('latest stable') != -1: if 'latest stable' in name:
stable = version.strip() stable = version.strip()
elif name.find('latest beta') != -1: elif 'latest beta' in name:
beta = version.strip() beta = version.strip()
irc.reply(msg, 'The latest stable kernel is %s; ' \ irc.reply(msg, 'The latest stable kernel is %s; ' \
'the latest beta kernel is %s.' % (stable, beta)) 'the latest beta kernel is %s.' % (stable, beta))

View File

@ -65,7 +65,7 @@ class Topic(callbacks.Privmsg):
capability = ircdb.makeChannelCapability(channel, 'topic') capability = ircdb.makeChannelCapability(channel, 'topic')
topic = privmsgs.getArgs(args) topic = privmsgs.getArgs(args)
if ircdb.checkCapability(msg.prefix, capability): if ircdb.checkCapability(msg.prefix, capability):
if topic.find(self.topicSeparator) != -1: if self.topicSeparator in topic:
s = 'You can\'t have %s in your topic' % self.topicSeparator s = 'You can\'t have %s in your topic' % self.topicSeparator
irc.error(msg, s) irc.error(msg, s)
return return

View File

@ -104,7 +104,7 @@ def processConfigFile(filename):
nick = d['nick'] nick = d['nick']
server = d['server'] server = d['server']
password = d['password'] password = d['password']
if server.find(':') != -1: if ':' in server:
(server, port) = server.split(':', 1) (server, port) = server.split(':', 1)
try: try:
server = (server, int(port)) server = (server, int(port))

View File

@ -100,7 +100,7 @@ class IrcMsg(object):
self.prefix, s = s[1:].split(None, 1) self.prefix, s = s[1:].split(None, 1)
else: else:
self.prefix = '' self.prefix = ''
if s.find(' :') != -1: if ' :' in s:
s, last = s.split(' :', 1) s, last = s.split(' :', 1)
self.args = s.split() self.args = s.split()
self.args.append(last.rstrip('\r\n')) self.args.append(last.rstrip('\r\n'))
@ -186,6 +186,12 @@ class IrcMsg(object):
def __setstate__(self, s): def __setstate__(self, s):
self.__init__(s) self.__init__(s)
try:
import _ircmsg
IrcMsg = _ircmsg.IrcMsg
except:
pass
def isAction(msg): def isAction(msg):
"""A predicate returning true if the PRIVMSG in question is an ACTION""" """A predicate returning true if the PRIVMSG in question is an ACTION"""

View File

@ -54,7 +54,7 @@ def isUserHostmask(s):
def isServerHostmask(s): def isServerHostmask(s):
"""Returns True if s is a valid server hostmask.""" """Returns True if s is a valid server hostmask."""
return (not isUserHostmask(s) and s.find('!') == -1 and s.find('@') == -1) return not isUserHostmask(s)
def nickFromHostmask(hostmask): def nickFromHostmask(hostmask):
"""Returns the nick from a user hostmask.""" """Returns the nick from a user hostmask."""