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

irc2phpbb.bot.Bot.setConfig()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 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
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