コード例 #1
0
ファイル: allfor.py プロジェクト: dosisod/SHIMON
def allfor(self: "Shimon", user: str, redirect: bool) -> HttpResponse:
    raw = api_allfor(self, user)

    if raw == False:
        return error_400()

    return error_200(raw)
コード例 #2
0
    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)")
コード例 #3
0
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")
コード例 #4
0
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()
コード例 #5
0
ファイル: status.py プロジェクト: dosisod/SHIMON
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,
    )
コード例 #6
0
ファイル: send_msg.py プロジェクト: dosisod/SHIMON
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()
コード例 #7
0
ファイル: test_error.py プロジェクト: dosisod/SHIMON
 def test_custom_error_wrapper_is_same_when_called_directly(self) -> None:
     assert error_200("test")[0].json == error(200, "test", False)[0].json
コード例 #8
0
def recent(self: "Shimon", _: None, redirect: bool) -> HttpResponse:
    return error_200(api_recent(self))
コード例 #9
0
def friends(self: "Shimon", _: None, redirect: bool) -> HttpResponse:
    return error_200(api_friends(self))
コード例 #10
0
def devmode(self: "Shimon", enable: bool, redirect: bool) -> HttpResponse:
    self.cache.mapper["developer"] = enable

    return error_200()
コード例 #11
0
def ping(self: "Shimon", _: None, redirect: bool) -> HttpResponse:
    return error_200("pong", redirect)