mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Update usage of utils.iter functions.
This commit is contained in:
parent
4d32d36982
commit
0fde2393e6
@ -27,8 +27,6 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
###
|
###
|
||||||
|
|
||||||
import random
|
|
||||||
|
|
||||||
import babelfish
|
import babelfish
|
||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
@ -152,9 +150,9 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
languages = self.registryValue('languages', msg.args[0])
|
languages = self.registryValue('languages', msg.args[0])
|
||||||
if not languages:
|
if not languages:
|
||||||
irc.error('I can\'t speak any other languages.', Raise=True)
|
irc.error('I can\'t speak any other languages.', Raise=True)
|
||||||
language = random.choice(languages)
|
language = utils.iter.choice(languages)
|
||||||
while not allowEnglish and language == 'English':
|
while not allowEnglish and language == 'English':
|
||||||
language = random.choice(languages)
|
language = utils.iter.choice(languages)
|
||||||
irc.reply(language)
|
irc.reply(language)
|
||||||
randomlanguage = wrap(randomlanguage, [getopts({'allow-english': ''})])
|
randomlanguage = wrap(randomlanguage, [getopts({'allow-english': ''})])
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import supybot.utils as utils
|
|||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
from supybot.commands import *
|
from supybot.commands import *
|
||||||
|
from supybot.utils.iter import all
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
###
|
###
|
||||||
|
|
||||||
import random
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import dictclient
|
import dictclient
|
||||||
@ -64,7 +63,7 @@ class Dict(callbacks.Privmsg):
|
|||||||
server = conf.supybot.plugins.Dict.server()
|
server = conf.supybot.plugins.Dict.server()
|
||||||
conn = dictclient.Connection(server)
|
conn = dictclient.Connection(server)
|
||||||
dbs = conn.getdbdescs().keys()
|
dbs = conn.getdbdescs().keys()
|
||||||
irc.reply(random.choice(dbs))
|
irc.reply(utils.iter.choice(dbs))
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
irc.error(utils.web.strError(e))
|
irc.error(utils.web.strError(e))
|
||||||
random = wrap(random)
|
random = wrap(random)
|
||||||
|
@ -407,7 +407,7 @@ class Filter(callbacks.Privmsg):
|
|||||||
text = text.replace(',', ' ')
|
text = text.replace(',', ' ')
|
||||||
text = text.replace("'", '')
|
text = text.replace("'", '')
|
||||||
text = text.replace('one', '1')
|
text = text.replace('one', '1')
|
||||||
smiley = random.choice(['<3', ':)', ':-)', ':D', ':-D'])
|
smiley = utils.iter.choice(['<3', ':)', ':-)', ':D', ':-D'])
|
||||||
text += smiley*3
|
text += smiley*3
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
aol = wrap(aol, ['text'])
|
aol = wrap(aol, ['text'])
|
||||||
@ -418,7 +418,7 @@ class Filter(callbacks.Privmsg):
|
|||||||
Returns <text> as if JeffK had said it himself.
|
Returns <text> as if JeffK had said it himself.
|
||||||
"""
|
"""
|
||||||
def randomlyPick(L):
|
def randomlyPick(L):
|
||||||
return random.choice(L)
|
return utils.iter.choice(L)
|
||||||
def quoteOrNothing(m):
|
def quoteOrNothing(m):
|
||||||
return randomlyPick(['"', '']).join(m.groups())
|
return randomlyPick(['"', '']).join(m.groups())
|
||||||
def randomlyReplace(s, probability=0.5):
|
def randomlyReplace(s, probability=0.5):
|
||||||
@ -445,22 +445,21 @@ class Filter(callbacks.Privmsg):
|
|||||||
def randomlyLaugh(text, probability=.3):
|
def randomlyLaugh(text, probability=.3):
|
||||||
if random.random() < probability:
|
if random.random() < probability:
|
||||||
if random.random() < .5:
|
if random.random() < .5:
|
||||||
insult = random.choice([' fagot1', ' fagorts', ' jerks',
|
insult = utils.iter.choice([' fagot1', ' fagorts',
|
||||||
'fagot' ' jerk', ' dumbshoes',
|
' jerks', 'fagot' ' jerk',
|
||||||
' dumbshoe'])
|
'dumbshoes', ' dumbshoe'])
|
||||||
else:
|
else:
|
||||||
insult = ''
|
insult = ''
|
||||||
laugh1 = random.choice(['ha', 'hah', 'lol', 'l0l', 'ahh'])
|
laugh1 = utils.iter.choice(['ha', 'hah', 'lol', 'l0l', 'ahh'])
|
||||||
laugh2 = random.choice(['ha', 'hah', 'lol', 'l0l', 'ahh'])
|
laugh2 = utils.iter.choice(['ha', 'hah', 'lol', 'l0l', 'ahh'])
|
||||||
laugh1 = laugh1 * random.randrange(1, 5)
|
laugh1 = laugh1 * random.randrange(1, 5)
|
||||||
laugh2 = laugh2 * random.randrange(1, 5)
|
laugh2 = laugh2 * random.randrange(1, 5)
|
||||||
exclaim = random.choice(['!', '~', '!~', '~!!~~',
|
exclaim = utils.iter.choice(['!', '~', '!~', '~!!~~',
|
||||||
'!!~', '~~~!'])
|
'!!~', '~~~!'])
|
||||||
exclaim += random.choice(['!', '~', '!~', '~!!~~',
|
exclaim += utils.iter.choice(['!', '~', '!~', '~!!~~',
|
||||||
'!!~', '~~~!'])
|
'!!~', '~~~!'])
|
||||||
if random.random() < 0.5:
|
if random.random() < 0.5:
|
||||||
exclaim += random.choice(['!', '~', '!~', '~!!~~',
|
exclaim += utils.iter.choice(['!', '~', '!~', '~!!~~',
|
||||||
|
|
||||||
'!!~', '~~~!'])
|
'!!~', '~~~!'])
|
||||||
laugh = ''.join([' ', laugh1, laugh2, insult, exclaim])
|
laugh = ''.join([' ', laugh1, laugh2, insult, exclaim])
|
||||||
text += laugh
|
text += laugh
|
||||||
|
@ -51,9 +51,9 @@ import pprint
|
|||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
from itertools import imap
|
|
||||||
|
|
||||||
import supybot.ansi as ansi
|
import supybot.ansi as ansi
|
||||||
|
from utils.iter import imap
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
|
@ -48,7 +48,6 @@ import string
|
|||||||
import inspect
|
import inspect
|
||||||
import operator
|
import operator
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from itertools import imap, ifilter
|
|
||||||
|
|
||||||
import supybot.log as log
|
import supybot.log as log
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
@ -59,6 +58,7 @@ import supybot.irclib as irclib
|
|||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
|
from supybot.utils.iter import any, imap, ifilter
|
||||||
|
|
||||||
def _addressed(nick, msg, prefixChars=None, nicks=None,
|
def _addressed(nick, msg, prefixChars=None, nicks=None,
|
||||||
prefixStrings=None, whenAddressedByNick=None,
|
prefixStrings=None, whenAddressedByNick=None,
|
||||||
|
@ -364,7 +364,7 @@ class DB(object):
|
|||||||
|
|
||||||
def random(self):
|
def random(self):
|
||||||
try:
|
try:
|
||||||
return self._newRecord(*random.choice(self.map))
|
return self._newRecord(*utils.iter.choice(self.map))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ from __future__ import division
|
|||||||
import time
|
import time
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
from itertools import imap
|
|
||||||
|
|
||||||
import supybot.log as log
|
import supybot.log as log
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
@ -46,6 +45,7 @@ import supybot.utils as utils
|
|||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
import supybot.drivers as drivers
|
import supybot.drivers as drivers
|
||||||
import supybot.schedule as schedule
|
import supybot.schedule as schedule
|
||||||
|
from supybot.utils.iter import imap
|
||||||
|
|
||||||
# XXX Shouldn't the reconnect wait (at least the last one) be configurable?
|
# XXX Shouldn't the reconnect wait (at least the last one) be configurable?
|
||||||
reconnectWaits = [0, 60, 300]
|
reconnectWaits = [0, 60, 300]
|
||||||
|
@ -74,7 +74,7 @@ class ServersMixin(object):
|
|||||||
super(ServersMixin, self).__init__(irc)
|
super(ServersMixin, self).__init__(irc)
|
||||||
|
|
||||||
def _getServers(self):
|
def _getServers(self):
|
||||||
# We do this, rather than itertools.cycle the servers in __init__,
|
# We do this, rather than utils.iter.cycle the servers in __init__,
|
||||||
# because otherwise registry updates given as setValues or sets
|
# because otherwise registry updates given as setValues or sets
|
||||||
# wouldn't be visible until a restart.
|
# wouldn't be visible until a restart.
|
||||||
return self.networkGroup.servers()[:] # Be sure to copy!
|
return self.networkGroup.servers()[:] # Be sure to copy!
|
||||||
|
@ -856,7 +856,7 @@ class Irc(IrcCommandDispatcher):
|
|||||||
while len(L) <= 3:
|
while len(L) <= 3:
|
||||||
L.append('`')
|
L.append('`')
|
||||||
while ircutils.strEqual(ret, nick):
|
while ircutils.strEqual(ret, nick):
|
||||||
L[random.randrange(len(L))] = random.choice('0123456789')
|
L[random.randrange(len(L))] = utils.iter.choice('0123456789')
|
||||||
ret = ''.join(L)
|
ret = ''.join(L)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -625,7 +625,7 @@ def standardSubstitute(irc, msg, text, env=None):
|
|||||||
if len(L) > 1:
|
if len(L) > 1:
|
||||||
n = msg.nick
|
n = msg.nick
|
||||||
while n == msg.nick:
|
while n == msg.nick:
|
||||||
n = random.choice(L)
|
n = utils.iter.choice(L)
|
||||||
return n
|
return n
|
||||||
else:
|
else:
|
||||||
return msg.nick
|
return msg.nick
|
||||||
|
@ -341,7 +341,7 @@ class TimeoutQueue(object):
|
|||||||
yield elt
|
yield elt
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
# No dependency on utils.
|
# No dependency on utils.iter
|
||||||
# return ilen(self)
|
# return ilen(self)
|
||||||
i = 0
|
i = 0
|
||||||
for _ in self:
|
for _ in self:
|
||||||
|
@ -32,6 +32,7 @@ from supybot.test import *
|
|||||||
import sets
|
import sets
|
||||||
|
|
||||||
import supybot.irclib as irclib
|
import supybot.irclib as irclib
|
||||||
|
from supybot.utils.iter import all
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
|
|
||||||
class holder:
|
class holder:
|
||||||
|
Loading…
Reference in New Issue
Block a user