summaryrefslogtreecommitdiff
path: root/modules/ships.py
blob: 0a296ca3855cfd88c344e3538234a31530bc9945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from . import tasks
from .database import cursor, conn


class Ship:
    def __init__(self, symbol: str):
        self.symbol = symbol
        self.callsign = "-".split(symbol)[0]

        self.task = None

    def load_task(self):
        cursor.execute("SELECT task, params FROM ships WHERE symbol = ?", (self.symbol,))
        row = cursor.fetchone()
        if row is None:
            cursor.execute("INSERT INTO ships (symbol, task, params) VALUES (?, ?, ?)", (self.symbol, tasks.IDLE, None))
            conn.commit()

            self.task = tasks.IDLE
        else:
            self.task = row[0]

    def set_task(self, task):
        self.task = task
        if task != tasks.ERROR:
            cursor.execute("UPDATE ships SET task = ? WHERE symbol = ?", (task, self.symbol))
            conn.commit()