bot   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 47
ccs 16
cts 26
cp 0.6153
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A Bot.registerActions() 0 6 2
A Bot.__init__() 0 5 1
A Bot.getConfig() 0 3 1
A Bot.tokenize() 0 4 1
A Bot.setConfig() 0 3 1
A Bot.registerGeneralActions() 0 6 2
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