PagerMaid-Pyro/pagermaid/utils/_sub.py

36 lines
856 B
Python
Raw Permalink Normal View History

2022-05-25 03:33:32 +00:00
from typing import List
from pagermaid.dependence import sqlite
2022-05-25 03:33:32 +00:00
class Sub:
def __init__(self, name: str):
self.name = name
def get_subs(self) -> List:
return sqlite.get(f"{self.name}.sub", [])
def clear_subs(self) -> None:
sqlite[f"{self.name}.sub"] = []
del sqlite[f"{self.name}.sub"]
def add_id(self, uid: int) -> bool:
data = self.get_subs()
if uid in data:
return False
data.append(uid)
sqlite[f"{self.name}.sub"] = data
return True
def del_id(self, uid: int) -> bool:
data = self.get_subs()
if uid not in data:
return False
data.remove(uid)
sqlite[f"{self.name}.sub"] = data
return True
def check_id(self, uid: int) -> bool:
data = self.get_subs()
return uid in data