Skip to main content

a pluggable irc bot framework in python

Project description

a pluggable irc bot framework in python

Tutorial

Installation

$ pip install git+git://github.com/archangelic/pinhook.git

Creating the Bot

To create the bot, just create a python file with the following:

import pinhook.bot

bot = pinhook.bot.Bot(
    channels=['#foo', '#bar'],
    nickname='ph-bot',
    server='irc.freenode.net'
)
bot.start()

This will start a basic bot and look for plugins in the ‘plugins’ directory to add functionality.

Optional arguments are:

  • port: choose a custom port to connect to the server (default: 6667)

  • ops: list of operators who can do things like make the bot join other channels or quit (default: empty list)

  • plugin_dir: directory where the bot should look for plugins (default: “plugins”)

Creating plugins

In your chosen plugins directory (“plugins” by default) make a python file with a function. You can use the @pinhook.plugin.register decorator to tell the bot the command to activate the function.

The function will need to be structured as such:

import pinhook.plugin

@pinhook.plugin.register('!test')
def test_plugin(msg):
    message = '{}: this is a test!'.format(msg.nick)
    return pinhook.plugin.message(message)

The function will need to accept a single argument in order to accept a Message object from the bot.

The Message object has the following attributes:

  • cmd: the command that triggered the function

  • nick: the user who triggered the command

  • arg: all the trailing text after the command. This is what you will use to get optional information for the command

  • channel: the channel where the command was initiated

  • ops: the list of bot operators

  • botnick: the nickname of the bot

The plugin function must return one of the following in order to give a response to the command:

  • pinhook.plugin.message: basic message in channel where command was triggered

  • pinhook.plugin.action: CTCP action in the channel where command was triggered (basically like using /me does a thing)

Examples

There are some basic examples in the examples directory in this repository.

For a live and maintained bot running the current version of pinhook see pinhook-tilde.

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

pinhook-1.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pinhook-1.0.2-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pinhook-1.0.2.tar.gz.

File metadata

  • Download URL: pinhook-1.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pinhook-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1a2e1b859c178ebbf08c1383d315d16d5e078b7c465f76194711d451abb81979
MD5 28bea4ad4bb2b8333e0df79ca09350fd
BLAKE2b-256 e53eb2e8601a6de1ccab43e22ff0eb58f6b4c63565e9c56334ae48589c32d232

See more details on using hashes here.

File details

Details for the file pinhook-1.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pinhook-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bfa1e8d15e04771ab1907f0a7ea1d48d924f641931a049ffca741752288c7e25
MD5 8a5bf02a873426f9f5f0148be210d38c
BLAKE2b-256 f6f08514a221e7ac254b69680e9b871b621e1ed1e56a3f96766a50b8e3048247

See more details on using hashes here.

Supported by

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