pmxbot 1122.17.0


pip install pmxbot

  Latest version

Released: Apr 08, 2024

Project Links

Meta
Author: YouGov, Plc.
Maintainer: Jason R. Coombs
Requires Python: >=3.8

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Programming Language
  • Python :: 3
  • Python :: 3 :: Only

Topic
  • Communications :: Chat :: Internet Relay Chat
  • Internet :: WWW/HTTP :: WSGI :: Application
https://img.shields.io/pypi/v/pmxbot.svg https://img.shields.io/pypi/pyversions/pmxbot.svg tests Ruff https://readthedocs.org/projects/pmxbot/badge/?version=latest https://img.shields.io/badge/skeleton-2024-informational https://tidelift.com/badges/package/pypi/pmxbot

pmxbot is bot for IRC and Slack written in Python. Originally built for internal use at YouGov, it’s been sanitized and set free upon the world. You can find out more details on the project website.

Commands

pmxbot listens to commands prefixed by a ‘!’ If it’s a command, it knows it will reply, take an action, etc. It can search the web, store quotes you, track karma, make decisions, and do just about anything else you could want. It stores logs and quotes and karma in either a sqlite or MongoDB database, and there’s a web interface for reviewing the logs and karma.

Contains

pmxbot will respond to things you say if it detects words and phrases it’s been told to recognize. For example, mention sql on rails.

Requirements

pmxbot requires Python 3. It also requires a few python packages as defined in setup.py. Some optional dependencies are installed with extras:

  • mongodb: Enable MongoDB persistence (instead of sqlite).

  • irc: IRC bot client.

  • slack: Slack bot client.

  • viewer: Enable the web viewer application.

Testing

pmxbot includes a test suite that does some functional tests written against the Python IRC server and quite a few unit tests as well. Install tox and run tox to invoke the tests.

Configuration

Configuration is based on very easy YAML files. Check out config.yaml in the source tree for an example.

Usage

Once you’ve setup a config file, you just need to call pmxbot config.yaml and it will join and connect. We recommend running pmxbot under your favorite process supervisor to make it automatically restart if it crashes (or terminates due to a planned restart).

Custom Features

Setuptools Entry Points Plugin

pmxbot provides an extension mechanism for adding commands, and uses this mechanism even for its own built-in commands.

To create a setuptools entry point plugin, package your modules using the setuptools tradition and install it alongside pmxbot. Your package should define an entry point in the group pmxbot_handlers by including something similar to the following in the package’s setup.py:

entry_points = {
    'pmxbot_handlers': [
        'plugin name = pmxbot.mymodule',
    ],
},

During startup, pmxbot will load pmxbot.mymodule. plugin name can be anything, but should be a name suitable to identify the plugin (and it will be displayed during pmxbot startup).

Note that the pmxbot package is a namespace package, and you’re welcome to use that namespace for your plugin (e.g. pmxbot.nsfw).

If your plugin requires any initialization, specify an initialization function (or class method) in the entry point. For example:

'plugin name = pmxbot.mymodule:initialize_func'

On startup, pmxbot will call initialize_func with no parameters.

Within the script you’ll want to import the decorator(s) you need to use with:

from pmxbot.core import command, contains, regexp, execdelay, execat`.

You’ll then decorate each function with the appropriate line so pmxbot registers it.

A command (!g) gets the @command decorator:

@command(aliases=('tt', 'tear', 'cry'))
def tinytear(rest):
  "I cry a tiny tear for you."
  if rest:
    return "/me sheds a single tear for %s" % rest
  else:
    return "/me sits and cries as a single tear slowly trickles down its cheek"

A response (when someone says something) uses the @contains decorator:

@contains("sqlonrails")
def yay_sor():
  karma.Karma.store.change('sql on rails', 1)
  return "Only 76,417 lines..."

Each handler may solicit any of the following parameters:

  • channel (the channel in which the message occurred)

  • nick (the nickname that triggered the command or behavior)

  • rest (any text after the command)

A more complicated response (when you want to extract data from a message) uses the @regexp decorator:

@regexp("jira", r"(?<![a-zA-Z0-9/])(OPS|LIB|SALES|UX|GENERAL|SUPPORT)-\d\d+")
def jira(client, event, channel, nick, match):
    return "https://jira.example.com/browse/%s" % match.group()

For an example of how to implement a setuptools-based plugin, see one of the many examples in the pmxbot project itself or one of the popular third-party projects:

Web Interface

pmxbot includes a web server for allowing users to view the logs, read the help, and check karma. You specify the host, port, base path, logo, title, etc with the same YAML config file. Just run like pmxbotweb config.yaml and it will start up. Like pmxbot, use of a supervisor is recommended to restart the process following termination.

pmxbot as a Slack bot (native)

To use pmxbot as a Slack bot, install with pmxbot[slack], and set slack token in your config to the token from your Bot User. Easy, peasy.

pmxbot as a Slack bot (IRC)

As Slack provides an IRC interface, it’s easy to configure pmxbot for use in Slack. Here’s how:

  1. Install with pmxbot[irc].

  2. Enable the IRC Gateway <https://slack.zendesk.com/hc/en-us/articles/201727913-Connecting-to-Slack-over-IRC-and-XMPP>.

  3. Create an e-mail for the bot.

  4. Create the account for the bot in Slack and activate its account.

  5. Log into Slack using that new account and get the IRC gateway password <https://my.slack.com/account/gateways> for that account.

  6. Configure the pmxbot as you would for an IRC server, but use these settings for the connection:

    message rate limit: 2.5 password: <gateway password> server_host: <team name>.irc.slack.com server_port: 6667

    The rate limit is necessary because Slack will kick the bot if it issues more than 25 messages in 10 seconds, so throttling it to 2.5 messages per second avoids hitting the limit.

  7. Consider leaving ‘log_channels’ and ‘other_channels’ empty, especially if relying on Slack logging. Slack will automatically re-join pmxbot to any channels to which it has been /invited.

For Enterprise

Available as part of the Tidelift Subscription.

This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

Learn more.

1122.17.0 Apr 08, 2024
1122.16.0 Jun 29, 2023
1122.15.0 Jun 25, 2023
1122.14.2 Jan 03, 2023
1122.14.1 Nov 15, 2022
1122.14.0 Nov 11, 2022
1122.13.1 Oct 31, 2022
1122.13.0 Oct 30, 2022
1122.12.0 Aug 12, 2021
1122.11.0 Aug 12, 2021
1122.10.3 Aug 11, 2021
1122.10.2 May 13, 2021
1122.10.1 May 13, 2021
1122.10.0 Nov 14, 2020
1122.9.3 Sep 23, 2020
1122.9.2 Feb 09, 2020
1122.9.0 Apr 16, 2019
1122.8.0 Jan 04, 2019
1122.7.3 Dec 19, 2018
1122.7.2 Nov 15, 2018
1122.7.1 Nov 02, 2018
1122.7 Nov 02, 2018
1122.6 Jun 13, 2018
1122.5 Jun 06, 2018
1122.4 May 24, 2018
1122.3 May 18, 2018
1122.2 May 18, 2018
1122.1 May 11, 2018
1122.0 May 11, 2018
1121.1 Jan 29, 2018
1121.0 Jan 29, 2018
1120.0 Jan 29, 2018
1119.0.3 Jan 11, 2018
1119.0.2 Jan 11, 2018
1119.0.1 Jan 11, 2018
1119.0 Jan 11, 2018
1118.3.2 Jan 11, 2018
1118.3.1 May 24, 2017
1118.3.0 May 24, 2017
1118.2.1 May 22, 2017
1118.2.0 May 22, 2017
1118.1.0 Apr 09, 2017
1118.0.4 Mar 06, 2017
1118.0.3 Mar 01, 2017
1118.0.2 Mar 01, 2017
1118.0.1 Mar 01, 2017
1118.0 Mar 01, 2017
1117.4.3 Mar 01, 2017
1117.4.2 Mar 01, 2017
1117.4.1 Mar 01, 2017
1117.4 Mar 01, 2017
1117.3.9 Mar 01, 2017
1117.3.8 Feb 28, 2017
1117.3.7 Feb 18, 2017
1117.3.6 Feb 18, 2017
1117.3.5 Feb 07, 2017
1117.3.4 Feb 05, 2017
1117.3.2 Nov 18, 2016
1117.3.1 Nov 16, 2016
1117.3 Nov 16, 2016
1117.2.4 Sep 20, 2016
1117.2.3 Sep 20, 2016
1117.2.2 Sep 19, 2016
1117.2.1 Sep 19, 2016
1117.2 Sep 19, 2016
1117.0.2 Sep 13, 2016
1117.0.1 Sep 13, 2016
1117.0 Sep 12, 2016
1116.0 Sep 10, 2016
1115.5 Sep 08, 2016
1115.4.1 Jun 28, 2016
1115.4 Jun 28, 2016
1115.3.2 May 28, 2016
1115.3.1 May 28, 2016
1115.3 May 28, 2016
1115.2.1 May 05, 2016
1115.2 May 05, 2016
1115.1 May 03, 2016
1115.0 Apr 17, 2016
1114.0 Apr 17, 2016
1113.6 Feb 22, 2016
1113.5 Feb 22, 2016
1113.4 Feb 04, 2016
1113.3 Feb 03, 2016
1113.2 Feb 03, 2016
1113.1 Jan 25, 2016
1113.0 Jan 25, 2016
1112.2.2 Jan 25, 2016
1112.2.1 Dec 02, 2015
1112.2 Dec 02, 2015
1112.1 Aug 24, 2015
1112.0 Aug 22, 2015
1111.1 Jul 15, 2015
1111.0.2 Jun 17, 2015
1111.0.1 Jun 10, 2015
1111.0 Jun 10, 2015
1110.7.1 May 05, 2015
1110.7 Mar 12, 2015
1110.6 Dec 18, 2014
1110.5 Dec 18, 2014
1110.4.1 Dec 17, 2014
1110.4 Dec 17, 2014
1110.3.1 Dec 17, 2014
1110.3 Nov 21, 2014
1110.2 Nov 15, 2014
1110.1.1 Nov 13, 2014
1110.1 Nov 13, 2014
1110.0 Sep 30, 2014
1109.3 Sep 24, 2014
1109.2 Aug 14, 2014
1109.0 Aug 08, 2014
1108.4.1 Aug 08, 2014
1108.4 Aug 08, 2014
1108.3.1 Aug 08, 2014
1108.3 Aug 08, 2014
1108.2 Aug 08, 2014
1108.1 Aug 07, 2014
1108.0 Jul 11, 2014
1107.4 May 20, 2014
1107.2 May 12, 2014
1107.1 May 06, 2014
1107.0 May 06, 2014
1106.4.1 May 06, 2014
1106.4 May 06, 2014
1106.3 Apr 24, 2014
1106.2 Mar 28, 2014
1106.1.4 Mar 06, 2014
1106.1.3 Feb 10, 2014
1106.1.2 Dec 28, 2013
1106.1.1 Dec 28, 2013
1106.1 Dec 28, 2013
1106.0 Dec 27, 2013
1105.7 Oct 28, 2013
1105.6 Jun 07, 2013
1105.5 Apr 24, 2013
1105.4.2 Apr 19, 2013
1105.4.1 Jan 22, 2013
1105.4 Jan 18, 2013
1105.3.1 Jan 05, 2013
1105.3 Jan 03, 2013
1105.2.2 Jan 02, 2013
1105.2.1 Jan 02, 2013
1105.1.1 Dec 31, 2012
1105.0.1 Dec 31, 2012
1105.0 Dec 31, 2012
1104.4.3 Dec 25, 2012
1104.4.2 Dec 25, 2012
1104.4.1 Dec 25, 2012
1104.4 Dec 25, 2012
1104.3.1 Dec 15, 2012
1104.3 Dec 15, 2012
1104.2 Nov 17, 2012
1104.1 Nov 17, 2012
1104.0 Nov 16, 2012
1103.7.1.dev0 Nov 16, 2012
1103.7 Nov 08, 2012
1103.6.5 Nov 01, 2012
1103.6.4 Nov 01, 2012
1103.6.3 Nov 01, 2012
1103.6.2 Nov 01, 2012
1103.6.1 Nov 01, 2012
1103.6 Oct 27, 2012
1103.5.1 Oct 18, 2012
1103.4.5 Oct 09, 2012
1103.4.4 Oct 08, 2012
1103.4.3 Oct 08, 2012
1103.4.2 Oct 08, 2012
1103.4.1 Oct 08, 2012
1103.4 Oct 07, 2012
1103.3.2 Oct 03, 2012
1103.3.1 Sep 29, 2012
1103.3 Sep 29, 2012
1103.2 Sep 05, 2012
1103.1.10 Sep 05, 2012
1103.1.9 Sep 03, 2012
1103.1.8 Aug 30, 2012
1103.1.7 Aug 30, 2012
1103.1.6 Aug 30, 2012
1103.1.5 Aug 29, 2012
1103.1.4 Aug 28, 2012
1103.1.3 Aug 28, 2012
1103.1.2 Aug 28, 2012
1103.1.1 Aug 27, 2012
1103.1 Aug 27, 2012
1103.0.4 Aug 27, 2012
1103.0.3 Aug 27, 2012
1103.0.2 Aug 27, 2012
1103.0 Aug 27, 2012
1102.0 Aug 26, 2012
1101.9.2 Aug 24, 2012
1101.9.1 Aug 23, 2012
1101.8.2 Aug 22, 2012
1101.8.1 Aug 18, 2012
1101.8 Jul 30, 2012
1101.7.4 Jun 01, 2012
1101.7.3 May 23, 2012
1101.7.1 May 23, 2012
1101.7 May 23, 2012
1101.6 May 11, 2012
1101.6b1 May 11, 2012
1101.5 Apr 26, 2012
1101.4 Apr 25, 2012
1101.3 Apr 22, 2012
1101.3b1 Apr 21, 2012
1101.2 Apr 03, 2012
1101.1.4 Mar 29, 2012
1101.1.2 Mar 02, 2012
1101.1.1 Dec 08, 2011
1101.1 Dec 07, 2011
1101.0.1 Dec 01, 2011
1101.0 Nov 23, 2011
1100.8.5 Nov 23, 2011
1100.8.1 Nov 21, 2011
1100.6 Nov 21, 2011
1100.5.8 Nov 16, 2011
1100.5.7 Nov 09, 2011
1100.5.6 Nov 09, 2011
1100.5.5 Nov 09, 2011
1100.5.4 Nov 09, 2011
1100.5.3 Nov 09, 2011
1100.5.2 Nov 09, 2011
1100.5.1 Nov 09, 2011
1100.5 Oct 26, 2011
1100.3 Oct 25, 2011
1100.2 Oct 20, 2011
1100.1.1.dev0 Oct 20, 2011
1100.1 Oct 12, 2011
1100.0 Aug 03, 2011
1100b7 Jul 28, 2011
1100b4 Jul 06, 2011
1100b3 Jul 05, 2011
1100b2 Jul 05, 2011
1100b1 Jul 05, 2011
1005 Apr 11, 2011
1005b2 Mar 26, 2011
1005b1 Mar 15, 2011
1004.4 Jan 26, 2011
1004.3 Nov 15, 2010
1004.2 Nov 13, 2010
1004 Aug 24, 2010
1004b16
1004b15
1004b14
1004b13
1004b12
1004b11
1004b10
1004b8
1004b7
1004b6
1004b5
1004b4
1004b3
1004b2
1004b1
1003 Aug 22, 2010
1003b5
1003b4
1003b3
1003b2
1003b1
1002 Aug 22, 2010
1002b3
1002b2
1002b0
1001 May 23, 2010
1000 Apr 03, 2010

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
requests
pyyaml
feedparser
pytz
beautifulsoup4
wordnik-py3
more-itertools
tempora
jaraco.collections (>=3.4)
jaraco.itertools
jaraco.context
jaraco.classes
jaraco.functools
inflect
python-dateutil
jaraco.mongodb (>=7.3.1)
importlib-metadata (>=3.6)
importlib-resources (>=1.3)
dnspython