Test Failed
Pull Request — master (#86)
by Daniel
06:22 queued 03:08
created

irc2phpbb.bot   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 27
dl 0
loc 47
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A Bot.registerGeneralActions() 0 6 2
A Bot.registerActions() 0 6 2
A Bot.setConfig() 0 3 1
A Bot.__init__() 0 5 1
A Bot.tokenize() 0 4 1
A Bot.getConfig() 0 3 1
1
#! /usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
"""
5
Module for the common base class for all Bots
6
"""
7
8
import logging
9
import re
10
11
LOG = logging.getLogger("bot")
12
13
class Bot():
14
    """Base class for things common between different protocols"""
15
    def __init__(self):
16
        self.CONFIG = {}
17
        self.ACTIONS = []
18
        self.GENERAL_ACTIONS = []
19
        self.MSG_LOG = logging.getLogger("message")
20
21
    def getConfig(self):
22
        """Return the current configuration"""
23
        return self.CONFIG
24
25
    def setConfig(self, config):
26
        """Set the current configuration"""
27
        self.CONFIG = config
28
29
    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
    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
    @staticmethod
44
    def tokenize(message):
45
        """Split a message into normalized tokens"""
46
        return re.sub("[,.?:]", " ", message).strip().lower().split()
47