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