Skip to content

Commit 4048bd0

Browse files
authored
Merge pull request #3 from nm17/afk_func
Afk func
2 parents a9dc2d2 + 1967d8f commit 4048bd0

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

nicevk/plugins/afk_handler.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
from datetime import timedelta
3+
4+
from vkbottle import Message
5+
from nicevk.api import state, save_state, user
6+
7+
8+
@user.middleware.middleware_handler()
9+
async def answer(ans: Message):
10+
print("Asd")
11+
domain = str((await user.api.users.get(fields="domain"))[0].domain)
12+
if (
13+
(len(domain) > 1 and domain in ans.text)
14+
or str(user.user_id) in ans.text
15+
):
16+
if not state["afk"] or not state["afk"]["status"] or str(ans.chat_id) in state["afk"]["mentioned"]:
17+
return True
18+
diff = str(timedelta(seconds=(time.time() - state["afk"]["time"])))
19+
if state["afk"]["reason"]:
20+
await ans("I am afk (for {}): {}".format(diff, state["afk"]["reason"]))
21+
else:
22+
await ans("I am afk (for {}), contact me later".format(diff))
23+
state["afk"]["mentioned"].append(str(ans.chat_id))
24+
save_state()
25+
return True
26+
print(ans.text, str((await user.api.users.get(fields="domain"))[0].domain))
27+
return True

nicevk/plugins/afk_plugin.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from vkbottle import Message
2+
from nicevk.api import user, commands, state, save_state
3+
import time
4+
5+
commands.extend([".afk [reason] - makes you afk", ".unafk - seems like you are here"])
6+
7+
8+
@user.on.message_handler(text=".afk <reason>")
9+
async def afk(ans: Message, reason: str):
10+
if "afk" not in state.keys():
11+
state["afk"] = {}
12+
state["afk"]["status"] = True
13+
if reason is not None:
14+
state["afk"]["reason"] = reason
15+
state["afk"]["time"] = time.time()
16+
state["afk"]["mentioned"] = []
17+
save_state()
18+
await ans.api.messages.edit(ans.peer_id, ans.id, "I will be back")
19+
20+
21+
@user.on.message_handler(text=".unafk")
22+
async def afk(ans: Message):
23+
if "afk" not in state.keys(): # Using unafk without afk
24+
state["afk"] = {}
25+
state["afk"]["status"] = False
26+
try:
27+
del state["afk"]["time"]
28+
del state["afk"]["mentioned"]
29+
except KeyError:
30+
pass
31+
save_state()
32+
await ans.api.messages.edit(ans.peer_id, ans.id, "I am back")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nicevk"
3-
version = "0.5.1"
3+
version = "0.6.0"
44
description = ""
55
authors = ["nm17 <[email protected]>"]
66

0 commit comments

Comments
 (0)