iShotaBot/defs/anti_channel.py

54 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-12-08 09:10:31 +00:00
import pickle
from os import sep, mkdir
2021-12-08 09:10:31 +00:00
from os.path import exists
def init() -> None:
if not exists("data"):
mkdir("data")
2021-12-08 09:10:31 +00:00
if not exists(f"data{sep}anti_channel.pkl"):
2022-07-25 09:35:54 +00:00
data = {}
2021-12-08 09:10:31 +00:00
with open(f"data{sep}anti_channel.pkl", "wb") as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
def add(gid: int, cid: int) -> None:
with open(f"data{sep}anti_channel.pkl", "rb") as f:
data = pickle.load(f)
try:
if cid in data[gid]:
return
data[gid].append(cid)
except KeyError:
data[gid] = [cid]
with open(f"data{sep}anti_channel.pkl", "wb") as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
def clean(gid: int) -> None:
with open(f"data{sep}anti_channel.pkl", "rb") as f:
data = pickle.load(f)
try:
data[gid] = []
except KeyError:
return
with open(f"data{sep}anti_channel.pkl", "wb") as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
def get(gid: int) -> list:
with open(f"data{sep}anti_channel.pkl", "rb") as f:
data = pickle.load(f)
try:
return data[gid]
except KeyError:
return []
def get_status(gid: int) -> bool:
2022-07-25 09:35:54 +00:00
return len(get(gid)) != 0
2021-12-08 09:10:31 +00:00
def check_status(gid: int, cid: int) -> bool:
2022-07-25 09:35:54 +00:00
return cid in get(gid)