2005-02-02 03:50:22 +01:00
|
|
|
###
|
|
|
|
# Copyright (c) 2003-2005, Jeremiah Fincher
|
2012-09-01 16:16:48 +02:00
|
|
|
# Copyright (c) 2010, James McCoy
|
2005-02-02 03:50:22 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
import re
|
|
|
|
import random
|
2014-01-21 10:50:55 +01:00
|
|
|
|
2005-02-02 03:50:22 +01:00
|
|
|
|
|
|
|
import supybot.utils as utils
|
|
|
|
from supybot.commands import *
|
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.callbacks as callbacks
|
2010-10-17 14:50:31 +02:00
|
|
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
|
|
|
_ = PluginInternationalization('Games')
|
2005-02-02 03:50:22 +01:00
|
|
|
|
|
|
|
|
2005-02-09 08:04:04 +01:00
|
|
|
class Games(callbacks.Plugin):
|
2014-11-30 21:07:41 +01:00
|
|
|
"""This plugin provides some small games like (Russian) roulette,
|
|
|
|
eightball, monologue, coin and dice."""
|
2010-10-17 14:50:31 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-02 03:50:22 +01:00
|
|
|
def coin(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Flips a coin and returns the result.
|
|
|
|
"""
|
|
|
|
if random.randrange(0, 2):
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(_('heads'))
|
2005-02-02 03:50:22 +01:00
|
|
|
else:
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(_('tails'))
|
2005-02-02 03:50:22 +01:00
|
|
|
coin = wrap(coin)
|
|
|
|
|
2010-10-17 14:50:31 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-02 03:50:22 +01:00
|
|
|
def dice(self, irc, msg, args, m):
|
|
|
|
"""<dice>d<sides>
|
|
|
|
|
|
|
|
Rolls a die with <sides> number of sides <dice> times.
|
|
|
|
For example, 2d6 will roll 2 six-sided dice; 10d10 will roll 10
|
|
|
|
ten-sided dice.
|
|
|
|
"""
|
2014-01-21 10:57:38 +01:00
|
|
|
(dice, sides) = list(map(int, m.groups()))
|
2010-09-09 06:00:47 +02:00
|
|
|
if dice > 1000:
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.error(_('You can\'t roll more than 1000 dice.'))
|
2010-09-09 06:00:47 +02:00
|
|
|
elif sides > 100:
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.error(_('Dice can\'t have more than 100 sides.'))
|
2010-09-09 06:00:47 +02:00
|
|
|
elif sides < 3:
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.error(_('Dice can\'t have fewer than 3 sides.'))
|
2005-02-02 03:50:22 +01:00
|
|
|
else:
|
|
|
|
L = [0] * dice
|
2015-08-10 19:36:07 +02:00
|
|
|
for i in range(dice):
|
2005-02-02 03:50:22 +01:00
|
|
|
L[i] = random.randrange(1, sides+1)
|
|
|
|
irc.reply(format('%L', [str(x) for x in L]))
|
|
|
|
_dicere = re.compile(r'^(\d+)d(\d+)$')
|
|
|
|
dice = wrap(dice, [('matches', _dicere,
|
2010-10-17 14:50:31 +02:00
|
|
|
_('Dice must be of the form <dice>d<sides>'))])
|
2005-02-02 03:50:22 +01:00
|
|
|
|
|
|
|
# The list of words and algorithm are pulled straight the mozbot
|
|
|
|
# MagicEightBall.bm module: http://tinyurl.com/7ytg7
|
2010-10-17 14:50:31 +02:00
|
|
|
_positive = _('It is possible.|Yes!|Of course.|Naturally.|Obviously.|'
|
|
|
|
'It shall be.|The outlook is good.|It is so.|'
|
|
|
|
'One would be wise to think so.|'
|
|
|
|
'The answer is certainly yes.')
|
|
|
|
_negative = _('In your dreams.|I doubt it very much.|No chance.|'
|
|
|
|
'The outlook is poor.|Unlikely.|'
|
|
|
|
'About as likely as pigs flying.|You\'re kidding, right?|'
|
|
|
|
'NO!|NO.|No.|The answer is a resounding no.')
|
|
|
|
_unknown = _('Maybe...|No clue.|_I_ don\'t know.|'
|
|
|
|
'The outlook is hazy, please ask again later.|'
|
|
|
|
'What are you asking me for?|Come again?|'
|
|
|
|
'You know the answer better than I.|'
|
|
|
|
'The answer is def-- oooh! shiny thing!')
|
2005-02-02 03:50:22 +01:00
|
|
|
|
|
|
|
def _checkTheBall(self, questionLength):
|
|
|
|
if questionLength % 3 == 0:
|
2010-10-17 14:50:31 +02:00
|
|
|
catalog = self._positive
|
2005-02-02 03:50:22 +01:00
|
|
|
elif questionLength % 3 == 1:
|
2010-10-17 14:50:31 +02:00
|
|
|
catalog = self._negative
|
2005-02-02 03:50:22 +01:00
|
|
|
else:
|
2010-10-17 14:50:31 +02:00
|
|
|
catalog = self._unknown
|
|
|
|
return utils.iter.choice(catalog.split('|'))
|
2005-02-02 03:50:22 +01:00
|
|
|
|
2010-10-17 14:50:31 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-02 03:50:22 +01:00
|
|
|
def eightball(self, irc, msg, args, text):
|
|
|
|
"""[<question>]
|
|
|
|
|
|
|
|
Ask a question and the answer shall be provided.
|
|
|
|
"""
|
|
|
|
if text:
|
|
|
|
irc.reply(self._checkTheBall(len(text)))
|
|
|
|
else:
|
|
|
|
irc.reply(self._checkTheBall(random.randint(0, 2)))
|
|
|
|
eightball = wrap(eightball, [additional('text')])
|
|
|
|
|
|
|
|
_rouletteChamber = random.randrange(0, 6)
|
|
|
|
_rouletteBullet = random.randrange(0, 6)
|
2010-10-17 14:50:31 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-02 03:50:22 +01:00
|
|
|
def roulette(self, irc, msg, args, spin):
|
|
|
|
"""[spin]
|
|
|
|
|
|
|
|
Fires the revolver. If the bullet was in the chamber, you're dead.
|
|
|
|
Tell me to spin the chambers and I will.
|
|
|
|
"""
|
|
|
|
if spin:
|
|
|
|
self._rouletteBullet = random.randrange(0, 6)
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(_('*SPIN* Are you feeling lucky?'), prefixNick=False)
|
2005-02-02 03:50:22 +01:00
|
|
|
return
|
2019-08-24 17:50:05 +02:00
|
|
|
channel = msg.channel
|
2005-02-02 03:50:22 +01:00
|
|
|
if self._rouletteChamber == self._rouletteBullet:
|
|
|
|
self._rouletteBullet = random.randrange(0, 6)
|
|
|
|
self._rouletteChamber = random.randrange(0, 6)
|
2012-07-13 16:08:55 +02:00
|
|
|
if irc.nick in irc.state.channels[channel].ops or \
|
|
|
|
irc.nick in irc.state.channels[channel].halfops:
|
2005-02-02 03:50:22 +01:00
|
|
|
irc.queueMsg(ircmsgs.kick(channel, msg.nick, 'BANG!'))
|
|
|
|
else:
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(_('*BANG* Hey, who put a blank in here?!'),
|
2005-06-01 23:08:30 +02:00
|
|
|
prefixNick=False)
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(_('reloads and spins the chambers.'), action=True)
|
2005-02-02 03:50:22 +01:00
|
|
|
else:
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(_('*click*'))
|
2005-02-02 03:50:22 +01:00
|
|
|
self._rouletteChamber += 1
|
|
|
|
self._rouletteChamber %= 6
|
|
|
|
roulette = wrap(roulette, ['public', additional(('literal', 'spin'))])
|
|
|
|
|
2010-10-17 14:50:31 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-02 03:50:22 +01:00
|
|
|
def monologue(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Returns the number of consecutive lines you've sent in <channel>
|
|
|
|
without being interrupted by someone else (i.e. how long your current
|
|
|
|
'monologue' is). <channel> is only necessary if the message isn't sent
|
|
|
|
in the channel itself.
|
|
|
|
"""
|
|
|
|
i = 0
|
|
|
|
for m in reversed(irc.state.history):
|
|
|
|
if m.command != 'PRIVMSG':
|
|
|
|
continue
|
|
|
|
if not m.prefix:
|
|
|
|
continue
|
|
|
|
if not ircutils.strEqual(m.args[0], channel):
|
|
|
|
continue
|
|
|
|
if msg.prefix == m.prefix:
|
|
|
|
i += 1
|
|
|
|
else:
|
|
|
|
break
|
2010-10-17 14:50:31 +02:00
|
|
|
irc.reply(format(_('Your current monologue is at least %n long.'),
|
|
|
|
(i, _('line'))))
|
2005-02-02 03:50:22 +01:00
|
|
|
monologue = wrap(monologue, ['channel'])
|
|
|
|
|
|
|
|
Class = Games
|
|
|
|
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|