forked from sopel-irc/sopel-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roulette.py
82 lines (70 loc) · 2.66 KB
/
roulette.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
roulette.py - Willie Roulette Game Module
Copyright 2010, Kenneth Sham
Licensed under the Eiffel Forum License 2.
http://willie.dftba.net
"""
from __future__ import print_function
from willie.module import commands, priority
import random
from datetime import datetime, timedelta
random.seed()
# edit this setting for roulette counter. Larger, the number, the harder the game.
ROULETTE_SETTINGS = {
# the bigger the MAX_RANGE, the harder/longer the game will be
'MAX_RANGE': 5,
# game timeout in minutes (default is 1 minute)
'INACTIVE_TIMEOUT': 1,
}
# edit this setting for text displays
ROULETTE_STRINGS = {
'TICK': '*TICK*',
'KICK_REASON': '*SNIPED! YOU LOSE!*',
'GAME_END': 'Game stopped.',
'GAME_END_FAIL': "%s: Please wait %s seconds to stop Roulette.",
}
## do not edit below this line unless you know what you're doing
ROULETTE_TMP = {
'LAST-PLAYER': None,
'NUMBER': None,
'TIMEOUT': timedelta(minutes=ROULETTE_SETTINGS['INACTIVE_TIMEOUT']),
'LAST-ACTIVITY': None,
}
@commands('roulette')
@priority('low')
def roulette(bot, trigger):
"""Play a game of Russian Roulette"""
global ROULETTE_SETTINGS, ROULETTE_STRINGS, ROULETTE_TMP
if ROULETTE_TMP['NUMBER'] is None:
ROULETTE_TMP['NUMBER'] = random.randint(0, ROULETTE_SETTINGS['MAX_RANGE'])
ROULETTE_TMP['LAST-PLAYER'] = trigger.nick
ROULETTE_TMP['LAST-ACTIVITY'] = datetime.now()
bot.say(ROULETTE_STRINGS['TICK'])
return
if ROULETTE_TMP['LAST-PLAYER'] == trigger.nick:
return
ROULETTE_TMP['LAST-ACTIVITY'] = datetime.now()
ROULETTE_TMP['LAST-PLAYER'] = trigger.nick
if ROULETTE_TMP['NUMBER'] == random.randint(0, ROULETTE_SETTINGS['MAX_RANGE']):
bot.write(['KICK', '%s %s :%s' % (trigger.sender, trigger.nick, ROULETTE_STRINGS['KICK_REASON'])])
ROULETTE_TMP['LAST-PLAYER'] = None
ROULETTE_TMP['NUMBER'] = None
ROULETTE_TMP['LAST-ACTIVITY'] = None
else:
bot.say(ROULETTE_STRINGS['TICK'])
@commands('roulette-stop')
@priority('low')
def rouletteStop(bot, trigger):
"""Reset a game of Russian Roulette"""
global ROULETTE_TMP, ROULETTE_STRINGS
if ROULETTE_TMP['LAST-PLAYER'] is None:
return
if datetime.now() - ROULETTE_TMP['LAST-ACTIVITY'] > ROULETTE_TMP['TIMEOUT']:
bot.say(ROULETTE_STRINGS['GAME_END'])
ROULETTE_TMP['LAST-ACTIVITY'] = None
ROULETTE_TMP['LAST-PLAYER'] = None
ROULETTE_TMP['NUMBER'] = None
else:
bot.say(ROULETTE_STRINGS['GAME_END_FAIL'] % (trigger.nick, ROULETTE_TMP['TIMEOUT'].seconds - (datetime.now() - ROULETTE_TMP['LAST-ACTIVITY']).seconds))
if __name__ == '__main__':
print(__doc__.strip())