bot

Module for the common base class for all Bots

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

Base class for things common between different protocols

CONFIG
ACTIONS
GENERAL_ACTIONS
MSG_LOG
def getConfig(self):
22    def getConfig(self):
23        """Return the current configuration"""
24        return self.CONFIG

Return the current configuration

def setConfig(self, config):
26    def setConfig(self, config):
27        """Set the current configuration"""
28        self.CONFIG = config

Set the current configuration

def registerActions(self, actions):
30    def registerActions(self, actions):
31        """Register actions to use"""
32        LOG.info("Adding actions")
33        for action in actions:
34            LOG.info("Adding action: %s", action.__name__)
35        self.ACTIONS.extend(actions)

Register actions to use

def registerGeneralActions(self, actions):
37    def registerGeneralActions(self, actions):
38        """Register general actions to use"""
39        LOG.info("Adding actions")
40        for action in actions:
41            LOG.info("Adding action: %s", action.__name__)
42        self.GENERAL_ACTIONS.extend(actions)

Register general actions to use

@staticmethod
def tokenize(message):
44    @staticmethod
45    def tokenize(message):
46        """Split a message into normalized tokens"""
47        return re.sub("[,.?:]", " ", message).strip().lower().split()

Split a message into normalized tokens