lnbits-legend/lnbits/extensions/streamalerts/models.py

45 lines
1.5 KiB
Python
Raw Normal View History

2021-06-22 13:18:50 +02:00
from sqlite3 import Row
from typing import NamedTuple, Optional
2021-06-20 06:34:01 +02:00
2021-06-22 16:42:50 +02:00
class Donation(NamedTuple):
2021-07-03 18:01:04 +02:00
"""A Donation simply contains all the necessary information about a
user's donation to a streamer
"""
2021-07-07 10:19:16 +01:00
2021-07-03 18:01:04 +02:00
id: str # This ID always corresponds to a satspay charge ID
2021-06-28 17:18:35 +02:00
wallet: str
2021-07-03 18:01:04 +02:00
name: str # Name of the donor
message: str # Donation message
cur_code: str # Three letter currency code accepted by Streamlabs
2021-06-22 13:18:50 +02:00
sats: int
2021-07-03 18:01:04 +02:00
amount: float # The donation amount after fiat conversion
service: int # The ID of the corresponding Service
posted: bool # Whether the donation has already been posted to a Service
2021-06-22 13:18:50 +02:00
@classmethod
2021-06-22 16:42:50 +02:00
def from_row(cls, row: Row) -> "Donation":
2021-06-22 13:18:50 +02:00
return cls(**dict(row))
2021-06-22 16:42:50 +02:00
class Service(NamedTuple):
2021-07-03 18:01:04 +02:00
"""A Service represents an integration with a third-party API
Currently, Streamlabs is the only supported Service.
"""
2021-07-07 10:19:16 +01:00
2021-06-22 13:18:50 +02:00
id: int
2021-07-03 18:01:04 +02:00
state: str # A random hash used during authentication
twitchuser: str # The Twitch streamer's username
client_id: str # Third party service Client ID
client_secret: str # Secret corresponding to the Client ID
2021-06-22 13:18:50 +02:00
wallet: str
onchain: str
2021-07-03 18:01:04 +02:00
servicename: str # Currently, this will just always be "Streamlabs"
authenticated: bool # Whether a token (see below) has been acquired yet
token: Optional[int] # The token with which to authenticate requests
2021-06-22 13:18:50 +02:00
@classmethod
2021-06-22 16:42:50 +02:00
def from_row(cls, row: Row) -> "Service":
2021-06-22 13:18:50 +02:00
return cls(**dict(row))