BabbageBot - written by NiXijav on 2015-10-15
BabbageBot is a Python bot for Slack. Modular, easy to use and fun.
BabbageBot is a Python made bot for Slack, the communication tool for teams. The bot provides easy to add and easy to modify commands that can greatly expand the experience of chatting.
It was made with the intention of being modular, enabling anyone that wants to modify it to do the changes very easily. The structure of the bot is:
├── LICENSE
├── main.py
├── modules
│ ├── btc.py
│ ├── calc.py
│ ├── help.py
│ ├── __init__.py
│ ├── iss.py
│ ├── list.py
│ ├── ping.py
│ ├── rand.py
│ ├── translate.py
│ ├── weather.py
│ └── wiki.py
└── README.rst
The main.py contains the main methods for connecting to the Slack API through a Websocket. An API key is required. This file also loads the modules/list.py. List.py enumerates all the available modules (aka commands), and main.py uses this list as the message filter. When a string is detected to be in the list, this message gets delivered to the appropriate module. Result is then returned from the specific module and sent back to Slack.
The modules folder, as already said, contains all the modules that can be used by the bot. Each command should have its own file. Not required, but recommended.
For example, calc.py computes any kind of mathematical expression by sending the data to a server and then retrieving the result. Modules like the weather one require an API key. (In this case, from Openweathermap)
Adding a command is pretty simple. Create a .py file with any name in the modules/ folder. Then create the 'execute' function, with an string as a parameter (even if you don't use it). For example, I'll use the file 'wiki.py' (Fetches the Wikipedia). Inside the execute function I have all the necessary code to fetch the relevant Wikipedia article based on the given arguments.
After the code is properly written and working, an entry should be added in modules/list.py. First, importing it (eg, 'import wiki'); and then adding the entry itself in 'commandModules'. In this case I would add ''wiki': wiki'. The first 'wiki' is the keyword the bot will be listening for executing the command specified on the second half, 'wiki'. You could also have ''potato': wiki', and then sending to the bot 'potato Trees' would return the Wikipedia article about trees.
BabbageBot is distributed under the GNU Affero GPL v3 license.
For more information on installing, modifying and redistributing, please visit this GitHub repository: BabbageBot
No comments yet
Leave a comment