
class DiscordData:
    def __init__(self, db, client):
        self.db = db
        self.client = client

    def set_discord_invite(self, char_id, invite):
        return self.db.exec("UPDATE account SET discord_invite = ? WHERE main = ?", [invite, char_id])

    def set_discord_joined(self, char_id, handle, discord_id):
        return self.db.exec("UPDATE account SET discord_joined = 1, discord_handle = ?, discord_id = ? WHERE main = ?",
                            [handle, discord_id, char_id])

    def set_discord_left(self, char_id):
        return self.db.exec("UPDATE account SET discord_joined = 0 WHERE main = ?", [char_id])

    def set_discord_handle(self, discord_id, handle):
        return self.db.exec("UPDATE account SET discord_handle = ? WHERE discord_id = ?", [handle, discord_id])

    def get_discord_invite(self, invite):
        return self.db.query_single("SELECT * FROM account WHERE discord_invite = ?", [invite])

    def get_account_discord_id(self, discord_id):
        return self.db.query_single(
            "SELECT * FROM account a left join player p on a.char_id=p.char_id WHERE discord_id = ?", [discord_id])