bot.Bot.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 5
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 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