-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpluginsManager.py
More file actions
39 lines (33 loc) · 1.4 KB
/
pluginsManager.py
File metadata and controls
39 lines (33 loc) · 1.4 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from security import getAccess
from threading import Thread
import logging
def getInstanseClass(typeObject,bot):
return typeObject(bot)
def loadBotPlugins(bot):
"""загружаем плагины бота из папочки с плагинами"""
import os
plugins=dict()
for fileName in os.listdir('plugins/'):
if fileName.endswith('.py'):#выбираем только файлы с расширением py
pluginName = fileName[:-3]#убираем расширение файла
if pluginName != '__init__':# игнорируем файл __init__.py
pluginModules=__import__('plugins.'+pluginName)
plugin = getattr(pluginModules,pluginName)
pluginType=getattr(plugin,pluginName)
objectPlugin=getInstanseClass(pluginType,bot)
plugins.update([(pluginName,objectPlugin),])
return plugins# возвращаем загруженные плагины
def runPlugin(command,bot,user,message):
"""запускаем комманду из плагинов"""
if getAccess(command,bot,user,message)==True:
logging.debug(u"looking for plug-in"+command)
plugin = bot.plugins[command]
logging.debug(u"get plugin")
thread = Thread(target=plugin.run,args=(bot,user,message))
thread.start()
logging.debug(u"start plugin")
else:
bot.sendMessage(user,"ололо не для тебя эта комманда писалась")