Skip to content

Commit

Permalink
!water now has cooldowns and gives peas to gardener (ducky doing the …
Browse files Browse the repository at this point in the history
…watering)
  • Loading branch information
WhereIsX committed May 4, 2021
1 parent 7e28eef commit bb14440
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
6 changes: 6 additions & 0 deletions sqlstuffs/add_next_water_to_ducky.sql
@@ -0,0 +1,6 @@
-- ALTER TABLE ducky
-- ADD COLUMN next_water TEXT;


UPDATE ducky
SET next_water = "2020-05-04 00:00:00.0 UTC";
36 changes: 30 additions & 6 deletions src/chatty/commands/water.cr
@@ -1,20 +1,44 @@
require "./command.cr"
require "../../models/ducky.cr"

earnings = 10
cd = 1

Command.new(
name: "!water",
description: "attempts to water a named duck; !water <ducky_name>"
description: "attempts to water a named duck (earns #{earnings} peas, cooldown #{cd} min); !water <ducky_name>"
) do |ircm|
# TBD: randomly picks a duck and tags them, asking them to drink
# words: ("!water", "duckyname")
if ircm.words.size != 2

# gardener - ducky doing the watering
# plant - ducky being watered
gardener, args = Command.parse_ircm(ircm)

if gardener.nil?
next "you must have a record with us to water others, try !start_record"
end

# not yet passed cooldown
now = Time.utc
if gardener.next_water && gardener.next_water > now
next "you still have #{(gardener.next_water - now).seconds}s left before you can use this command again"
end

if args.size != 1
next "you wat. it's !water <ducky_name>"
end
duckie = Model::Ducky.find_by(username: ircm.words[1].downcase)
if duckie.nil?

plant = Model::Ducky.find_by(username: ircm.words[1].downcase)
if plant.nil?
next "no such duckie, have they `!start_record` yet?"
elsif duckie.at_me_consent
next "HYDRATE #{duckie.username}! go get your feathers wet :>"
end

if plant.at_me_consent
gardener.next_water = Time.utc + cd.minutes
gardener.points += earnings
gardener.save
next "HYDRATE #{plant.username}! go getyour feathers wet :>"
else
next "they didn't give us consent to water them :<"
end
Expand Down
4 changes: 3 additions & 1 deletion src/models/ducky.cr
Expand Up @@ -7,10 +7,12 @@ module Model

column id : Int32, primary: true # Primary key, defaults to AUTO INCREMENT
column username : String
column created_at : Time = Time.utc

column points : Int64 = 0
column at_me_consent : Bool = true
column super_cow_power : Bool = false
column created_at : Time = Time.utc
column next_water : Time

def self.valid_username?(username : String) : Bool
/^[A-Za-z0-9_]{4,25}$/.matches?(username)
Expand Down
3 changes: 3 additions & 0 deletions todo.md
Expand Up @@ -68,6 +68,9 @@
- whoami? --> all record holders get to see their own record
- commands to be case insensitive
#### TBD COMMANDS
- !water add cooldown, gives peas
- !bribe
- !hack DB.open my-db.db { |db| db.exec "DROP DATABASE;" } => "destroying data... deleting database... D̷̈́̎A̷͛̋T̸̈́̒A̵̓͠ ̷̛͆Ĕ̷̑R̴͐̈́R̸̄̉Õ̵͓Ȑ̸̑"
- !wave -> return the wave emoji
- !ruffle
- !munch
Expand Down

0 comments on commit bb14440

Please sign in to comment.