Upgrade of Fun's eightball command ported from Tellbot, previously

ported from Mozbot's MagicEightBall.bm module.
This commit is contained in:
Grant Bowman 2004-08-23 06:51:18 +00:00
parent 181f9899b4
commit 992cbb91ee
2 changed files with 48 additions and 23 deletions

View File

@ -33,7 +33,9 @@
Provides a multitude of fun, useless commands. Provides a multitude of fun, useless commands.
""" """
__author__ = "jemfinch"
__revision__ = "$Id$" __revision__ = "$Id$"
__contributors__ = ["Grant Bowman <grantbow@grantbow.com>"]
import supybot.plugins as plugins import supybot.plugins as plugins
@ -42,6 +44,8 @@ import re
import sys import sys
import md5 import md5
import sha import sha
import time
import string
import random import random
import urllib import urllib
import inspect import inspect
@ -329,33 +333,48 @@ class Fun(callbacks.Privmsg):
length = 4 length = 4
irc.reply(utils.soundex(s, length)) irc.reply(utils.soundex(s, length))
_eightballs = (
'outlook not so good.',
'my reply is no.', #
'don\'t count on it.', # The list of words and algorithm are pulled straight the mozbot
'you may rely on it.', # MagicEightBall.bm module.
'ask again later.', #
'most likely.', _responses = {'positive': ['It is possible.', 'Yes!', 'Of course.',
'cannot predict now.', 'Naturally.', 'Obviously.', 'It shall be.',
'yes.', 'The outlook is good.', 'It is so.',
'yes, most definitely.', 'One would be wise to think so.',
'better not tell you now.', 'The answer is certainly yes.'],
'it is certain.', 'negative': ['In your dreams.', 'I doubt it very much.',
'very doubtful.', 'No chance.', 'The outlook is poor.',
'it is decidedly so.', 'Unlikely.', 'About as likely as pigs flying.',
'concentrate and ask again.', 'You\'re kidding, right?', 'NO!', 'NO.', 'No.',
'signs point to yes.', 'The answer is a resounding no.', ],
'my sources say no.', 'unknown' : ['Maybe...', 'No clue.', '_I_ don\'t know.',
'without a doubt.', 'The outlook is hazy, please ask again later.',
'reply hazy, try again.', 'What are you asking me for?', 'Come again?',
'as I see it, yes.', 'You know the answer better than I.',
) 'The answer is def-- oooh! shiny thing!'],
}
def _checkTheBall(self, questionLength):
if questionLength % 3 == 0:
category = 'positive'
elif questionLength % 3 == 1:
category = 'negative'
else:
category = 'unknown'
response = self._responses[category][ int(time.time()) % len(self._responses[category]) ]
return response
def eightball(self, irc, msg, args): def eightball(self, irc, msg, args):
"""[<question>] """[<question>]
Asks the magic eightball a question. Ask a question and the answer shall be provided.
""" """
irc.reply(random.choice(self._eightballs)) if len(args) == 0:
irc.reply(self._checkTheBall(2) )
else:
irc.reply(self._checkTheBall(len(string.join(args,' '))) )
_rouletteChamber = random.randrange(0, 6) _rouletteChamber = random.randrange(0, 6)
_rouletteBullet = random.randrange(0, 6) _rouletteBullet = random.randrange(0, 6)

View File

@ -58,6 +58,12 @@ class FunTest(ChannelPluginTestCase, PluginDocumentation):
def testPing(self): def testPing(self):
self.assertResponse('ping', 'pong') self.assertResponse('ping', 'pong')
def testEightball(self):
self.assertNotError('eightball')
self.assertNotError('eightball a')
self.assertNotError('eightball ab')
self.assertNotError('eightball abc')
def testNoErrors(self): def testNoErrors(self):
self.assertNotError('objects') self.assertNotError('objects')
self.assertNotError('levenshtein Python Perl') self.assertNotError('levenshtein Python Perl')