Class: Botbckt::StarJar
- Defined in:
- lib/botbckt/commands/star_jar.rb
Overview
Gives a gold star to a space-separated list of users.
< user> ~star joe
< botbckt> joe: Gold star for you!
But when a user tries to award himself…
< user> ~star user
< botbckt> user: No star for you!
Instance Method Summary collapse
- #call(giver, channel, receiver) ⇒ Object
-
#pop(user, &block) ⇒ Object
Removes a star from the jar for the user.
-
#push(user, &block) ⇒ Object
Adds a star to the jar for the user.
Methods inherited from Command
create!, #get, #increment!, #say, say, #set, trigger
Methods included from Utilities
Instance Method Details
#call(giver, channel, receiver) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/botbckt/commands/star_jar.rb', line 42 def call(giver, channel, receiver) receiver.split(' ').each do |rcv| if rcv != freenode_split(giver).first push(rcv) do |total| say "#{rcv}: Gold star for you! (#{total})", channel end else say "#{rcv}: No star for you!", channel end end end |
#pop(user, &block) ⇒ Object
Removes a star from the jar for the user
Parameters
- user<String>
-
The user being docked a star. Required.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/botbckt/commands/star_jar.rb', line 31 def pop(user, &block) get "starjar-#{user}" do |stars| if stars set "starjar-#{user}", stars - 1, &block else set "starjar-#{user}", 0, &block end end end |
#push(user, &block) ⇒ Object
Adds a star to the jar for the user
Parameters
- user<String>
-
The user receiving a star. Required.
22 23 24 |
# File 'lib/botbckt/commands/star_jar.rb', line 22 def push(user, &block) increment! "starjar-#{user}", &block end |