From 78d943d530b75ccc671e73bcc2c4339749ae0bd3 Mon Sep 17 00:00:00 2001 From: Felipe Martin Date: Wed, 4 Nov 2020 16:51:24 +0100 Subject: [PATCH] Channel model --- butterrobot/db.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/butterrobot/db.py b/butterrobot/db.py index 904974e..3dc6033 100644 --- a/butterrobot/db.py +++ b/butterrobot/db.py @@ -51,3 +51,26 @@ class User(Model): fields.update({"username": username}) return cls._table.update(fields, ["username"]) + +class Channel(Model): + _table = db["channels"] + + @classmethod + def create(cls, provider, channel_id, enabled=False, channel_raw={}): + cls._table.insert({"provider": provider, "channel_id": channel_id, "enabled": enabled, "channel_raw": channel_raw}) + + @classmethod + def get(cls, username): + result = cls._table.find_one(username=username) + if not result: + raise cls.UserNotFound + return result + + @classmethod + def delete(cls, username): + return cls._table.delete(username=username) + + @classmethod + def update(cls, username, **fields): + fields.update({"username": username}) + return cls._table.update(fields, ["username"])