This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlolbot.py
85 lines (59 loc) · 1.94 KB
/
lolbot.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
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
import os
import sys
import time
from vkplus import VkPlus
import settings
def main():
path = 'plugins/'
cmds = {}
plugins = {}
global lastmessid
lastmessid = 0
print('LOLbot by akaluth')
print('Авторизация в вк...')
vk = VkPlus(settings.vk_login, settings.vk_password, settings.vk_app_id)
print('Подгружаем плагины...')
print('---------------------------')
# Подгружаем плагины
sys.path.insert(0, path)
for f in os.listdir(path):
fname, ext = os.path.splitext(f)
if ext == '.py':
mod = __import__(fname)
plugins[fname] = mod.Plugin(vk)
sys.path.pop(0)
print('---------------------------')
# Регистрируем плагины
for plugin in plugins.values():
for key, value in plugin.getkeys().items():
cmds[key] = value
print('Приступаю к приему сообщений')
while True:
values = {
'out': 0,
'offset': 0,
'count': 20,
'time_offset': 50,
'filters': 0,
'preview_length': 0,
'last_message_id': lastmessid
}
response = vk.api.method('messages.get', values)
if response['items']:
lastmessid = response['items'][0]['id']
for item in response['items']:
print('> ' + item['body'])
command(item, cmds)
vk.markasread(item['id']) # Помечаем прочитанным
time.sleep(0.5)
def command(message, cmds):
if message['body'] == u'':
return
words = message['body'].split()
prefixes = ['lolbot', u'лолбот', u'лб', u'чб', u'кб']
if words[0].lower() in prefixes:
if len(words) > 1 and words[1] in cmds:
cmds[words[1].lower()].call(message)
if __name__ == '__main__':
main()