-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
import vk_api | ||
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType | ||
|
||
|
||
def main(): | ||
""" Пример использования bots longpoll | ||
https://vk.com/dev/bots_longpoll | ||
""" | ||
|
||
vk_session = vk_api.VkApi(token='your_group_token') | ||
|
||
longpoll = VkBotLongPoll(vk_session, 'your_group_id') | ||
|
||
for event in longpoll.listen(): | ||
|
||
if event.type == VkBotEventType.MESSAGE_NEW: | ||
print('Новое сообщение:') | ||
|
||
print('Для меня от: ', end='') | ||
|
||
print(event.obj.from_id) | ||
|
||
print('Текст:', event.obj.text) | ||
print() | ||
|
||
elif event.type == VkBotEventType.MESSAGE_REPLY: | ||
print('Новое сообщение:') | ||
|
||
print('От меня для: ', end='') | ||
|
||
print(event.obj.peer_id) | ||
|
||
print('Текст:', event.obj.text) | ||
print() | ||
|
||
elif event.type == VkBotEventType.MESSAGE_TYPING_STATE: | ||
print('Печатает ', end='') | ||
|
||
print(event.obj.from_id, end=' ') | ||
|
||
print('для ', end='') | ||
|
||
print(event.obj.to_id) | ||
print() | ||
|
||
elif event.type == VkBotEventType.GROUP_JOIN: | ||
print(event.obj.user_id, end=' ') | ||
|
||
print('Вступил в группу!') | ||
print() | ||
|
||
elif event.type == VkBotEventType.GROUP_LEAVE: | ||
print(event.obj.user_id, end=' ') | ||
|
||
print('Покинул группу!') | ||
print() | ||
|
||
else: | ||
print(event.type) | ||
print() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters