-
Notifications
You must be signed in to change notification settings - Fork 4
/
bomb.py
96 lines (83 loc) · 3.62 KB
/
bomb.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# coding=utf-8
"""
bomb.py - Simple Sopel bomb prank game
Copyright 2012, Edward Powell http://embolalia.net
Licensed under the Eiffel Forum License 2.
http://sopel.dfbta.net
"""
from __future__ import unicode_literals
from sopel.module import commands, unblockable, HALFOP
from random import choice, randint
from re import search
import sched
import time
colors = ['Red', 'Yellow', 'Blue', 'White', 'Black']
sch = sched.scheduler(time.time, time.sleep)
fuse = 60 # seconds
bombs = dict()
@commands('bomb')
def start(bot, trigger):
"""
Put a bomb in the specified user's pants. They will be kicked if they
don't guess the right wire fast enough.
"""
if not trigger.group(2):
return
if trigger.sender.is_nick():
return
if bot.privileges[trigger.sender][trigger.nick] < HALFOP:
bot.say('Sorry, you need to be at least a halfop to request my saboteur services.')
return
if bot.privileges[trigger.sender][bot.nick] < HALFOP:
bot.say('Well this is awkward... I seem to have left my bombs at home.')
return
if trigger.group(2).strip() == bot.nick:
bot.say('I\'m not gonna put a bomb in my own pants!')
return
global bombs
global sch
target = trigger.group(2).split(' ')[0]
if target in bombs:
bot.say('I can\'t fit another bomb in ' + target + '\'s pants!')
return
message = 'Hey, ' + target + '! Don\'t look but, I think there\'s a bomb in your pants. 60 second timer, 5 wires: Red, Yellow, Blue, White and Black. Which wire should I cut? Don\'t worry, I know what I\'m doing! (respond with .cutwire color)'
bot.say(message)
color = choice(colors)
bot.msg(trigger.nick, 'Hey, don\'t tell %s, but the %s wire? Yeah, that\'s the one. But shh! Don\'t say anything!' % (target, color))
code = sch.enter(fuse, 1, explode, (bot, trigger))
bombs[target.lower()] = (color, code)
sch.run()
@commands('cutwire')
@unblockable
def cutwire(bot, trigger):
"""
Tells sopel to cut a wire when you've been bombed.
"""
global bombs, colors
target = trigger.nick
if target.lower() != bot.nick.lower() and target.lower() not in bombs:
return
color, code = bombs.pop(target.lower()) # remove target from bomb list
wirecut = trigger.group(2).rstrip(' ')
if wirecut.lower() in ('all', 'all!'):
sch.cancel(code) # defuse timer, execute premature detonation
kmsg = 'Cutting ALL the wires! *boom*'
bot.write(['KICK', trigger.sender, target], kmsg)
elif wirecut.capitalize() not in colors:
bot.say('I can\'t seem to find that wire, ' + target + '! You sure you\'re picking the right one? It\'s not here!')
bombs[target.lower()] = (color, code) # Add the target back onto the bomb list,
elif wirecut.capitalize() == color:
bot.say('You did it, ' + target + '! I\'ll be honest, I thought you were dead. But nope, you did it. You picked the right one. Well done.')
sch.cancel(code) # defuse bomb
else:
sch.cancel(code) # defuse timer, execute premature detonation
kmsg = 'No! No, that\'s the wrong one. Aww, you\'ve gone and killed yourself. Oh, that\'s... that\'s not good. No good at all, really. Wow. Sorry.'
bot.write(['KICK', trigger.sender, target], kmsg)
def explode(bot, trigger):
target = trigger.group(2)
kmsg = 'Oh, come on, ' + target + '! You could\'ve at least picked one! Now you\'re dead. Guts, all over the place. You see that? This is gonna take forever to clean up...'
bot.write(['KICK', trigger.sender, target], kmsg)
try:
bombs.pop(target.lower())
except:
pass