mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 13:01:07 -05:00
Namegen: make number of syllables configurable & update gitignore
This commit is contained in:
parent
1009856b1f
commit
50768cfd53
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,6 +5,8 @@ __pycache__/
|
|||||||
**/test-conf/
|
**/test-conf/
|
||||||
**/test-logs/
|
**/test-logs/
|
||||||
backup/
|
backup/
|
||||||
|
web/
|
||||||
|
tmp/
|
||||||
|
|
||||||
# emacs/vi
|
# emacs/vi
|
||||||
*.swo
|
*.swo
|
||||||
|
@ -48,9 +48,9 @@ def configure(advanced):
|
|||||||
|
|
||||||
|
|
||||||
Namegen = conf.registerPlugin('Namegen')
|
Namegen = conf.registerPlugin('Namegen')
|
||||||
# This is where your configuration variables (if any) should go. For example:
|
conf.registerGlobalValue(Namegen, 'syllables',
|
||||||
# conf.registerGlobalValue(Namegen, 'someConfigVariableName',
|
registry.PositiveInteger(2, _("""Specifies the maximum amount of syllables
|
||||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
a name can have.""")))
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
@ -56,26 +56,33 @@ class Namegen(callbacks.Plugin):
|
|||||||
with open(os.path.join(os.path.dirname(__file__), '%s.txt') % fn) as f:
|
with open(os.path.join(os.path.dirname(__file__), '%s.txt') % fn) as f:
|
||||||
self.names[fn] = f.read().splitlines()
|
self.names[fn] = f.read().splitlines()
|
||||||
|
|
||||||
def _namegen(self):
|
def _namegen(self, syl):
|
||||||
"""Generates a random name."""
|
"""Generates a random name."""
|
||||||
numSyl = random.randint(0, 3)
|
numSyl = random.randint(0, syl)
|
||||||
name = "{}{}{}".format(random.choice(self.names['starts']), \
|
name = "{}{}{}".format(random.choice(self.names['starts']), \
|
||||||
''.join(random.sample(self.names['middles'], numSyl)), \
|
''.join(random.sample(self.names['middles'], numSyl)), \
|
||||||
random.choice(self.names['ends']))
|
random.choice(self.names['ends']))
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def namegen(self, irc, msg, args, count):
|
def namegen(self, irc, msg, args, count, syl):
|
||||||
"""[<count>]
|
"""[<count>] [<syllables>]
|
||||||
|
|
||||||
Generates random names. If not specified, [<count>] defaults to 10."""
|
Generates random names. If not specified, [<count>] defaults to 10.
|
||||||
|
[<syllables>] specifies the maximum number of syllables a name can have,
|
||||||
|
and defaults to the value set in 'config plugins.namegen.syllables'."""
|
||||||
|
confsyl = self.registryValue("syllables")
|
||||||
|
maxsyl = max(confsyl, 10)
|
||||||
if not count:
|
if not count:
|
||||||
count = 10
|
count = 10
|
||||||
elif count > 100:
|
elif count > 100:
|
||||||
irc.error("Too many names to count!", Raise=True)
|
irc.error("Too many names to count!", Raise=True)
|
||||||
|
elif syl and syl > maxsyl:
|
||||||
|
irc.error("Too many syllables specified.", Raise=True)
|
||||||
|
syl = syl or confsyl
|
||||||
r = range if version_info[0] >= 3 else xrange
|
r = range if version_info[0] >= 3 else xrange
|
||||||
s = ', '.join([self._namegen() for _ in r(count)])
|
s = ', '.join([self._namegen(syl) for _ in r(count)])
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
namegen = wrap(namegen, [optional('int')])
|
namegen = wrap(namegen, [optional('positiveInt'), optional('positiveInt')])
|
||||||
|
|
||||||
|
|
||||||
Class = Namegen
|
Class = Namegen
|
||||||
|
Loading…
x
Reference in New Issue
Block a user