-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathlow_level_lp.py
75 lines (64 loc) · 2.54 KB
/
low_level_lp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from vkwave.bots import LowLevelBot
from vkwave.types.bot_events import BotEventType
bot = LowLevelBot("Token", 12345) # Bot
# bot = LowLevelBot("Token") # User (not recommended, because events will come in strange lists)
async def not_fast_mode():
# You can ignore all lp errors
async for event in bot.listen(ignore_errors=True):
# for User:
# from vkwave.types.user_events import EventId
# event[0] == EventId.MESSAGE_EVENT
if event.type == BotEventType.MESSAGE_NEW:
if event.object.message.text == "/start":
bot.react(
bot.api_context.messages.send(
peer_id=event.object.message.peer_id,
message="i got start",
random_id=0,
)
)
elif event.object.message.text == "/end":
bot.react(
bot.api_context.messages.send(
peer_id=event.object.message.peer_id,
message="i got end",
random_id=0,
)
)
else:
bot.react(
bot.api_context.messages.send(
peer_id=event.object.message.peer_id,
message="don't understand",
random_id=0,
)
)
async def fast_mode():
async for event in bot.listen(fast_mode=True):
if event["type"] == BotEventType.MESSAGE_NEW:
if event["object"]["message"]["text"] == "/start":
bot.react(
bot.api_context.messages.send(
peer_id=event["object"]["message"]["peer_id"],
message="i got start",
random_id=0,
)
)
elif event["object"]["message"]["text"] == "/end":
bot.react(
bot.api_context.messages.send(
peer_id=event["object"]["message"]["peer_id"],
message="i got end",
random_id=0,
)
)
else:
bot.react(
bot.api_context.messages.send(
peer_id=event["object"]["message"]["peer_id"],
message="don't understand",
random_id=0,
)
)
# bot.run(main_loop=fast_mode())
bot.run(main_loop=not_fast_mode())