def allfor(self: "Shimon", user: str, redirect: bool) -> HttpResponse: raw = api_allfor(self, user) if raw == False: return error_400() return error_200(raw)
def entry(self, shimon: "Shimon", enable: bool, _: bool) -> HttpResponse: if Path(self.path).is_file(): shimon.cache.mapper[self.name] = enable return error_200() shimon.cache.mapper[self.name] = False return error_400("Missing required file(s)")
def delete_msg(self: "Shimon", data: Dict, redirect: bool) -> HttpResponse: pwd = data.get("pwd", "") if pwd and self.msg_policy == 1: if not self.security.correct_pwd(pwd): return error_401() index = data.get("index") if isinstance(index, str): try: index = int(index) except ValueError: return error_400("Index is not a valid integer") elif not isinstance(index, int): return error_400("Index is not a valid integer") if index < 0: return error_400("Index is out of bounds") hist_id = history_id(self, data.get("id", "")) if hist_id < 0: return error_400() msgs = self.cache["history"][hist_id]["msgs"] if index >= len(msgs): return error_400("Index is not a valid integer") msgs.pop(index) self.redraw = True return error_200("Message deleted")
def save(self: "Shimon", pwd: str, redirect: bool) -> HttpResponse: storage_error = self.storage.save(pwd) if storage_error: return storage_error self.cache.mapper.update(["msg policy", "expiration", "developer"]) return error_200()
def status(self: "Shimon", _: None, redirect: bool) -> HttpResponse: unlocked = not self.cache.is_empty() return error_200( { "version": self.VERSION, "unlocked": unlocked, "developer": self.developer, "msg policy": self.msg_policy if unlocked else None, }, redirect, )
def send_msg(self: "Shimon", sending: Dict, redirect: bool) -> HttpResponse: msg = sending.get("msg") uname = sending.get("uname") if not msg or not uname or msg.isspace(): return error_400() index = history_id(self, uname) if index < 0: return error_400() self.cache["history"][index]["msgs"].append({"sending": True, "msg": msg}) self.redraw = True return error_200()
def test_custom_error_wrapper_is_same_when_called_directly(self) -> None: assert error_200("test")[0].json == error(200, "test", False)[0].json
def recent(self: "Shimon", _: None, redirect: bool) -> HttpResponse: return error_200(api_recent(self))
def friends(self: "Shimon", _: None, redirect: bool) -> HttpResponse: return error_200(api_friends(self))
def devmode(self: "Shimon", enable: bool, redirect: bool) -> HttpResponse: self.cache.mapper["developer"] = enable return error_200()
def ping(self: "Shimon", _: None, redirect: bool) -> HttpResponse: return error_200("pong", redirect)