forked from scrapinghub/slackbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Better py3 support removing imp when possible - Default message personalization - Possibility of creating a custom docs reply - PluginManagerinto it's own file as is used by dispatcher too
- Loading branch information
1 parent
584b499
commit 3a9a055
Showing
9 changed files
with
122 additions
and
66 deletions.
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
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
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,65 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import logging | ||
from glob import glob | ||
from six import PY2 | ||
from importlib import import_module | ||
from slackbot import settings | ||
from slackbot.utils import to_utf8 | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class PluginsManager(object): | ||
def __init__(self): | ||
pass | ||
|
||
commands = { | ||
'respond_to': {}, | ||
'listen_to': {} | ||
} | ||
|
||
def init_plugins(self): | ||
if hasattr(settings, 'PLUGINS'): | ||
plugins = settings.PLUGINS | ||
else: | ||
plugins = 'slackbot.plugins' | ||
|
||
for plugin in plugins: | ||
self._load_plugins(plugin) | ||
|
||
def _load_plugins(self, plugin): | ||
logger.info('loading plugin "%s"', plugin) | ||
path_name = None | ||
|
||
if PY2: | ||
import imp | ||
|
||
for mod in plugin.split('.'): | ||
if path_name is not None: | ||
path_name = [path_name] | ||
_, path_name, _ = imp.find_module(mod, path_name) | ||
else: | ||
from importlib.util import find_spec as importlib_find | ||
|
||
path_name = importlib_find(plugin).submodule_search_locations[0] | ||
|
||
for pyfile in glob('{}/[!_]*.py'.format(path_name)): | ||
module = '.'.join((plugin, os.path.split(pyfile)[-1][:-3])) | ||
try: | ||
import_module(module) | ||
except: | ||
# TODO Better exception handling | ||
logger.exception('Failed to import %s', module) | ||
|
||
def get_plugins(self, category, text): | ||
has_matching_plugin = False | ||
for matcher in self.commands[category]: | ||
m = matcher.search(text) | ||
if m: | ||
has_matching_plugin = True | ||
yield self.commands[category][matcher], to_utf8(m.groups()) | ||
|
||
if not has_matching_plugin: | ||
yield None, None |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
|
||
DEBUG = False | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#coding: UTF-8 | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import print_function, absolute_import | ||
import os | ||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#coding: UTF-8 | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import logging | ||
|