Esempio n. 1
0
async def afk(ans: Message, reason: str):
    if "afk" not in state.keys():
        state["afk"] = {}
    state["afk"]["status"] = True
    if reason is not None:
        state["afk"]["reason"] = reason
    state["afk"]["time"] = time.time()
    state["afk"]["mentioned"] = []
    save_state()
    await ans.api.messages.edit(ans.peer_id, ans.id, "I will be back")
Esempio n. 2
0
async def get_notes(ans: Message, name: str):
    if "notes" not in state.keys():
        state["notes"] = {}
        save_state()
    if name in state["notes"].keys():
        await edit(ans.peer_id, ans.id,
                   f"Note '{name}'\n\n{state['notes'][name]}")
    else:
        await ans.api.messages.edit(ans.peer_id, ans.id,
                                    f"Note '{name}' is not found")
Esempio n. 3
0
async def afk(ans: Message):
    if "afk" not in state.keys():  # Using unafk without afk
        state["afk"] = {}
    state["afk"]["status"] = False
    try:
        del state["afk"]["time"]
        del state["afk"]["mentioned"]
    except KeyError:
        pass
    save_state()
    await ans.api.messages.edit(ans.peer_id, ans.id, "I am back")
Esempio n. 4
0
async def help_(ans: Message, username: str):
    if state.get("ignore", None) is None:
        state["ignore"] = []

    state["ignore"] = [
        *state["ignore"],
        (await ans.api.utils.resolve_screen_name(screen_name=username.strip()
                                                 )).object_id,
    ]
    save_state()
    await edit(ans.peer_id, ans.id, "User ignored")
Esempio n. 5
0
async def on_start():
    if (
        state.get("restart", None) is not None
        and state["restart"]["last_message"] is not None
    ):
        try:
            await user.api.messages.edit(
                *state["restart"]["last_message"], "Successfully restarted nicevk"
            )
        except VKError:
            pass
        state["restart"]["last_message"] = None
        save_state()
Esempio n. 6
0
async def help_(ans: Message, username: str):
    if state.get("ignore", None) is None:
        state["ignore"] = []

    try:
        del state["ignore"][state["ignore"].index(
            (await
             ans.api.utils.resolve_screen_name(screen_name=username.strip()
                                               )).object_id)]
    except ValueError:
        await edit(ans.peer_id, ans.id, "That user is not muted")
    else:
        await edit(ans.peer_id, ans.id, "User removed from ignore")
    finally:
        save_state()
Esempio n. 7
0
async def answer(ans: Message):
    print("Asd")
    domain = str((await user.api.users.get(fields="domain"))[0].domain)
    if ((len(domain) > 1 and domain in ans.text)
            or str(user.user_id) in ans.text):
        if not state["afk"] or not state["afk"]["status"] or str(
                ans.chat_id) in state["afk"]["mentioned"]:
            return True
        diff = str(timedelta(seconds=(time.time() - state["afk"]["time"])))
        if state["afk"]["reason"]:
            await ans("I am afk (for {}): {}".format(diff,
                                                     state["afk"]["reason"]))
        else:
            await ans("I am afk (for {}), contact me later".format(diff))
        state["afk"]["mentioned"].append(str(ans.chat_id))
        save_state()
        return True
    print(ans.text, str((await user.api.users.get(fields="domain"))[0].domain))
    return True
Esempio n. 8
0
async def save_notes(ans: Message, name: str, text: str):
    if "notes" not in state.keys():
        state["notes"] = {}
    state["notes"][name] = text
    await edit(ans.peer_id, ans.id, f"Note '{name}' saved!")
    save_state()
Esempio n. 9
0
async def help_(ans: Message):
    state["restart"] = {}
    state["restart"]["last_message"] = (ans.peer_id, ans.id)
    save_state()
    subprocess.Popen(["nicevk"])