From d3ee249bc99d0987bc79c05b61711e63ea0d08d4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 11 Apr 2019 18:56:01 +0200 Subject: [PATCH] Create Discord users table --- royalnet/database/tables/__init__.py | 3 ++- royalnet/database/tables/discord.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 royalnet/database/tables/discord.py diff --git a/royalnet/database/tables/__init__.py b/royalnet/database/tables/__init__.py index 0e5b8dd6..dcc50e62 100644 --- a/royalnet/database/tables/__init__.py +++ b/royalnet/database/tables/__init__.py @@ -5,5 +5,6 @@ from .aliases import Alias from .activekvgroup import ActiveKvGroup from .keyvalue import Keyvalue from .keygroup import Keygroup +from .discord import Discord -__all__ = ["Royal", "Telegram", "Diario", "Alias", "ActiveKvGroup", "Keyvalue", "Keygroup"] +__all__ = ["Royal", "Telegram", "Diario", "Alias", "ActiveKvGroup", "Keyvalue", "Keygroup", "Discord"] diff --git a/royalnet/database/tables/discord.py b/royalnet/database/tables/discord.py new file mode 100644 index 00000000..c0e9be9d --- /dev/null +++ b/royalnet/database/tables/discord.py @@ -0,0 +1,28 @@ +from sqlalchemy import Column, \ + Integer, \ + String, \ + BigInteger, \ + ForeignKey +from sqlalchemy.orm import relationship +from .royals import Royal + + +class Discord: + __tablename__ = "discord" + + royal_id = Column(Integer, ForeignKey("royals.uid")) + discord_id = Column(BigInteger, primary_key=True) + username = Column(String) + discriminator = Column(String) + avatar_hash = Column(String) + + royal = relationship("Royal", backref="telegram") + + def __repr__(self): + return f"" + + def __str__(self): + return f"[c]discord:{self.full_username()}[/c]" + + def full_username(self): + return f"{self.username}#{self.discriminator}"