From fed5cf01ec90a92951d54871377f3732ee75e074 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 2 Apr 2020 23:07:08 +0100 Subject: [PATCH] Survey handler module --- houdini.sql | 21 +++++++++++++++++++++ houdini/data/penguin.py | 9 +++++++++ houdini/data/room.py | 3 ++- houdini/handlers/play/survey.py | 17 +++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 houdini/handlers/play/survey.py diff --git a/houdini.sql b/houdini.sql index 91bf600..69385d2 100644 --- a/houdini.sql +++ b/houdini.sql @@ -932,6 +932,7 @@ CREATE TABLE penguin_igloo_room ( music SMALLINT NOT NULL DEFAULT 0, location INT NOT NULL, locked BOOLEAN NOT NULL DEFAULT TRUE, + competition BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (id), CONSTRAINT igloo_room_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin (id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT igloo_room_ibfk_2 FOREIGN KEY (type) REFERENCES igloo (id) ON DELETE CASCADE ON UPDATE CASCADE, @@ -949,6 +950,7 @@ COMMENT ON COLUMN penguin_igloo_room.type IS 'Igloo type ID'; COMMENT ON COLUMN penguin_igloo_room.flooring IS 'Igloo flooring ID'; COMMENT ON COLUMN penguin_igloo_room.music IS 'Igloo music ID'; COMMENT ON COLUMN penguin_igloo_room.locked IS 'Is igloo locked?'; +COMMENT ON COLUMN penguin_igloo_room.competition IS 'Is entered in competition?'; DROP TABLE IF EXISTS igloo_like; CREATE TABLE igloo_like ( @@ -1121,6 +1123,25 @@ COMMENT ON COLUMN login.date IS 'Login date'; COMMENT ON COLUMN login.ip_hash IS 'Connection IP address'; COMMENT ON COLUMN login.minutes_played IS 'Minutes played for session'; +DROP TABLE IF EXISTS cfc_donation; +CREATE TABLE cfc_donation ( + penguin_id INT NOT NULL, + coins INT NOT NULL, + charity SMALLINT NOT NULL, + date TIMESTAMP NOT NULL, + PRIMARY KEY (penguin_id, charity, date), + CONSTRAINT cfc_donation_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +ALTER TABLE cfc_donation ALTER COLUMN date SET DEFAULT now(); + +COMMENT ON TABLE cfc_donation IS 'CFC charity donations'; + +COMMENT ON COLUMN cfc_donation.penguin_id IS 'Donator penguin ID'; +COMMENT ON COLUMN cfc_donation.coins IS 'Donation coin amount'; +COMMENT ON COLUMN cfc_donation.charity IS 'Donation charity or cause'; +COMMENT ON COLUMN cfc_donation.date IS 'Date of donation'; + DROP TABLE IF EXISTS penguin_postcard; CREATE TABLE penguin_postcard ( id SERIAL, diff --git a/houdini/data/penguin.py b/houdini/data/penguin.py index aed0cbd..4a8a472 100644 --- a/houdini/data/penguin.py +++ b/houdini/data/penguin.py @@ -165,3 +165,12 @@ class EpfComMessage(db.Model): message = db.Column(db.Text, nullable=False) character_id = db.Column(db.ForeignKey('character.id', ondelete='RESTRICT', onupdate='CASCADE'), nullable=False) date = db.Column(db.DateTime, nullable=False, server_default=db.text("now()")) + + +class CfcDonation(db.Model): + __tablename__ = 'cfc_donation' + + penguin_id = db.Column(db.ForeignKey('penguin.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False) + coins = db.Column(db.Integer, nullable=False) + charity = db.Column(db.Integer, nullable=False) + date = db.Column(db.DateTime, nullable=False, server_default=db.text("now()")) diff --git a/houdini/data/room.py b/houdini/data/room.py index 4d88b35..b9a0273 100644 --- a/houdini/data/room.py +++ b/houdini/data/room.py @@ -150,7 +150,8 @@ class PenguinIglooRoom(db.Model, RoomMixin): flooring = db.Column(db.ForeignKey('flooring.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False) music = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) location = db.Column(db.ForeignKey('location.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False) - locked = db.Column(db.Boolean, nullable=False, server_default=db.text("false")) + locked = db.Column(db.Boolean, nullable=False, server_default=db.text("true")) + competition = db.Column(db.Boolean, nullable=False, server_default=db.text("false")) internal_id = 2000 name = 'Igloo' diff --git a/houdini/handlers/play/survey.py b/houdini/handlers/play/survey.py new file mode 100644 index 0000000..76662f4 --- /dev/null +++ b/houdini/handlers/play/survey.py @@ -0,0 +1,17 @@ +from houdini import handlers +from houdini.handlers import XTPacket +from houdini.data.penguin import CfcDonation + + +@handlers.handler(XTPacket('e', 'dc')) +async def handle_donate_to_charity(p, charity: int, coins: int): + if p.coins >= coins and 0 <= charity <= 4: + await p.update(coins=p.coins-coins).apply() + await CfcDonation.create(penguin_id=p.id, coins=coins, charity=charity) + await p.send_xt('dc', p.coins) + + +@handlers.handler(XTPacket('e', 'sig')) +async def handle_igloo_contest_entry(p): + if p.room.igloo and p.room.penguin_id == p.id and not p.room.competition: + await p.room.update(competition=True).apply()