-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcrinkle_butt.rb
99 lines (86 loc) · 2.38 KB
/
crinkle_butt.rb
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
97
98
99
#!/usr/bin/env ruby
# A watcher and state class for all you silly babs
class CrinkleButt
attr_reader :watcher, :noticed, :restrained
attr_accessor :diaper
# Creates a CrinkleButt and attaches a watcher thread that will call
# the passed in block at least once an hour
#
# This block will be passed this bab object to do things like
# checks, or interacting with the user attached to it in various
# ways
def initialize(event, bab_id, &block)
@bab_id = bab_id.to_i
@event = event
@diaper = 0
@bladder = 0
@continence = 0
@watcher = make_watcher(&block)
end
# Retreives the user on this server who is attached to this
# CrinkleButt object
def user
@event.channel.users.find do |user|
user.id == @bab_id
end
end
# Messages the user this CrinkleButt object is for
def message(text)
@event.respond text
end
# Returns a string that will ping the attached user
def ping
"<@#{@bab_id}>"
end
# Messages the user this CrinkleButt object is for, except with a
# ping!
def ping_message(text)
@event.respond "#{ping}: #{text}"
end
# Outputs a stream of messages, all with a random delay between them
# according to the range passed in
def delay_message(delay, *messages)
messages.each do |message|
message(message)
sleep(rand delay)
end
end
# Locks this user to a specific role (Default 'Restrained'), yields
# to the passed-in block, and then restores the user to the roles
# from before
def lock(restrained = get_role('Restrained'), normal = get_role('Normal'))
user.remove_role normal
user.add_role restrained
yield self
user.remove_role restrained
user.add_role normal
end
private
# Creates a watcher thread for this CrinkleButt that updates this
# thread at least once an hour, and then calls the passed in block
# with this object
def make_watcher
Thread.new do
loop do
sleep rand(60 * 60)
update
yield self
end
end
end
# What happens as time passes for this CrinkleButt?
def update
if rand(@continence) < @bladder && rand(2).zero?
how_bad = rand(@bladder)
@diaper += how_bad
@bladder -= how_bad
end
@bladder += 1
end
# Fetches a role from this CrinkleButt's server by name
def get_role(name)
@event.server.roles.find do |role|
role.name == name
end
end
end