Skip to main content

Simple framework for creating IRC bots

Project description

Simple IRC bot implementation.

### Example

```python
from pyromancer.objects import Pyromancer

HOST = '1.2.3.4'
PORT = 6667
NICK = 'PyromancerBot'

settings = {'host': HOST, 'port': PORT, 'nick': NICK, 'encoding': 'ISO-8859-1',
'packages': ['.test_examples']}

p = Pyromancer(settings)
p.run()
```

### Custom commands
Writing own commands is fairly simple. Create a folder which will be the package name, with a folder named "commands" in it and a module to hold the commands in there. In your module, you can register functions to be a command with the built-in command decorator. After that you need to register it in your settings, and you can use it.

#### Example

File layout:

```
test/
commands/
__init__.py
test_commands.py
__init__.py
init.py
```

test_commands.py:

```python
from pyromancer.decorators import command

@command(r'bye (.*)')
def bye(match):
match.msg('Bye {m[1]}!')
```

init.py:

```python
settings['packages'] = ['test.test_commands']
```

On IRC:

```
<User> bye everyone
<Bot> Bye everyone!
```

Pyromancer scans the modules in the settings automatically for functions decorated using the commands decorator, so all your commands in `test_commands.py` are used automatically.

#### The `Match.msg` function

The `Match.msg` function applies formatting by default and provides some additional utilities. The most important of those is that when no target has been passed on as an argument, it will use either the channel or the user (in case of a PM) whose input line triggered the command to be executed as the target, effectively replying.

##### Parameters

* `message` - the message to be send to the server. Formatting will be applied when `raw=False` using any additional `args` and `kwargs`, so you can apply the full power of the [Python Format Mini-Language](http://docs.python.org/3.3/library/string.html#format-string-syntax) on the message.

* `target` - the target to send the message to. If not provided, it will attempt to use either the channel or user whose input line triggered the command, which effectively results in repplying.

* `raw` - defaults to `False`. When true, no formatting is applied on `message`.

* `args` and `kwargs` - arguments to be passed on through the formatting which is applied on `message`.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Pyromancer-0.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page