Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harrislapiroff/python-chatbot
A simple, extensible, python-powered IRC bot.
https://github.com/harrislapiroff/python-chatbot
Last synced: 2 months ago
JSON representation
A simple, extensible, python-powered IRC bot.
- Host: GitHub
- URL: https://github.com/harrislapiroff/python-chatbot
- Owner: harrislapiroff
- Created: 2012-08-27T16:31:04.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-04-15T03:57:00.000Z (almost 6 years ago)
- Last Synced: 2024-06-14T01:28:01.573Z (8 months ago)
- Language: Python
- Size: 18.6 KB
- Stars: 19
- Watchers: 3
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Python Chatbot
==============A simple, extensible bot for your IRC channels.
Installation
------------With Pip:
```bash
sudo pip install git+https://github.com/harrislapiroff/python-chatbot.git@master#egg=chatbot
```Usage
-----To run a bot, you must write a short python script. For example `simple_bot.py`:
```python
from chatbot.bots import Bot
from chatbot.contrib import *bot = Bot(
nickname = 'bestbot',
hostname = 'chat.freenode.net',
port = 6665,
server_password = 'my_bots_password',
channels = ('#freenode', '#python'),
features = (
PyPIFeature(),
WikipediaFeature(),
DictionaryFeature(),
DiceFeature(),
ChoiceFeature(),
SlapbackFeature(),
)
)bot.run()
```Then run the script:
```bash
python simple_bot.py
```The Flexible `Match` Feature
----------------------------**Chatbot** comes with a built in `Match` feature, which is both simple and
powerful. You can build an entire bot from `Match` features alone. Here is an
example of a simple bot that will slap people on command.```python
from chatbot.bots import Bot
from chatbot.contrib.simple import Match
from chatbot.chat import ChatResponseSLAP_OPTIONS = (
ChatResponse('slaps \g around a bit with a baseball bat', action=True),
ChatResponse('slaps \g around a bit with a large trout', action=True),
ChatResponse('slaps \g around a bit with a piano', action=True),
ChatResponse('slaps \g around a bit with a french fry', action=True),
)bot = Bot(
nickname = 'bestbot',
hostname = 'chat.freenode.net',
port = 6665,
server_password = 'my_bots_password',
channels = ('#freenode', '#python'),
features = (
Match(r'slap (?P[^\s]+) (?P.+)', ChatResponse('slaps \g around a bit \g', action=True), addressing_required=True, allow_continuation=False),
Match(r'slap (?P.+)', SLAP_OPTIONS, addressing_required=True, allow_continuation=False),
)
)bot.run()
```In this case, the bot handles two possible matches. The first pattern matches sentences such as `bestbot: slap melinath with a frying pan` by responding with an action, `slaps melinath around a bit with a frying pan`. The second pattern matches commands to slap that do not specify the method of slapping (e.g., `slap melinath`), by choosing an option randomly from `SLAP_OPTIONS` (e.g., `slaps melinath around a bit with a french fry`).