Total Complexity | 8 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 61.53% |
Changes | 0 |
1 | #! /usr/bin/env python3 |
||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | """ |
||
5 | Module for the common base class for all Bots |
||
6 | """ |
||
7 | |||
8 | 1 | import logging |
|
9 | 1 | import re |
|
10 | |||
11 | 1 | LOG = logging.getLogger("bot") |
|
12 | |||
13 | 1 | class Bot(): |
|
14 | """Base class for things common between different protocols""" |
||
15 | 1 | def __init__(self): |
|
16 | 1 | self.CONFIG = {} |
|
17 | 1 | self.ACTIONS = [] |
|
18 | 1 | self.GENERAL_ACTIONS = [] |
|
19 | 1 | self.MSG_LOG = logging.getLogger("message") |
|
20 | |||
21 | 1 | def getConfig(self): |
|
22 | """Return the current configuration""" |
||
23 | return self.CONFIG |
||
24 | |||
25 | 1 | def setConfig(self, config): |
|
26 | """Set the current configuration""" |
||
27 | self.CONFIG = config |
||
28 | |||
29 | 1 | def registerActions(self, actions): |
|
30 | """Register actions to use""" |
||
31 | LOG.info("Adding actions") |
||
32 | for action in actions: |
||
33 | LOG.info("Adding action: %s", action.__name__) |
||
34 | self.ACTIONS.extend(actions) |
||
35 | |||
36 | 1 | def registerGeneralActions(self, actions): |
|
37 | """Register general actions to use""" |
||
38 | LOG.info("Adding actions") |
||
39 | for action in actions: |
||
40 | LOG.info("Adding action: %s", action.__name__) |
||
41 | self.GENERAL_ACTIONS.extend(actions) |
||
42 | |||
43 | 1 | @staticmethod |
|
44 | 1 | def tokenize(message): |
|
45 | """Split a message into normalized tokens""" |
||
46 | return re.sub("[,.?:]", " ", message).strip().lower().split() |
||
47 |