Clone this repo:

Branches

  1. 3343de0 Merge "Parse user@host in wm-bot2 messages" by jenkins-bot · 4 months ago master
  2. 7cd54b3 Parse user@host in wm-bot2 messages by Francesco Negri · 7 months ago
  3. 5c3e0a8 dev: Bump ib3 dependency to 0.3.0 by Bryan Davis · 6 months ago
  4. 2e97848 Remove Twitter support by Bryan Davis · 6 months ago
  5. 0fc09b4 Remove extra deduplication from bot.do_phabecho by Bryan Davis · 7 months ago

Stashbot

An IRC bot designed to store data in an Elasticsearch cluster.

This bot was created to replace Logstash in an application stack that processes IRC messages for:

  • quips
  • SAL
  • (an as yet unwritten IRC history search system)

In addition to its original Elasticsearch storage purpose, the bot has expanded to support:

  • Updating Phabricator tasks mentioned in !log irc massages
  • Providing summary information for Phabricator manifest, differential, and pholio objects mentioned in irc messages
  • Writing !log messages to a MediaWiki wiki
  • Posting !log messages to Mastodon

Install

$ python3 -m venv venv
$ venv/bin/pip3 install -r requirements.txt

Configure

The bot is configured using a yaml file. By default python3 -m stashbot will look for a configuration file named config.yaml. An alternate file can be provided using the --config cli argument. See python3 -m stashbot --help for more information.

Example configuration:

---
irc:
  server: chat.freenode.net
  port: 6697
  nick: mybotnick
  realname: My Real Name
  channels:
    - '##somechan'
    - '##anotherchan'
  ignore:
    - nick1
    - nick2

elasticsearch:
  servers:
    - tools-elastic-01.tools.eqiad.wmflabs
    - tools-elastic-02.tools.eqiad.wmflabs
    - tools-elastic-03.tools.eqiad.wmflabs
  options:
    port: 80
    http_auth:
      - my-es-username
      - my-es-password
    sniff_on_start: false
    sniff_on_connection_fail: false
  index: 'irc-%Y.%m'

ldap:
  uri: ldap://ldap-labs.eqiad.wikimedia.org:389
  base: dc=wikimedia,dc=org

phab:
  url: https://phabricator.wikimedia.org
  user: MyPhabUser
  key: api-xxxxxxxxxxxxxxxxxxxxxxx
  echo: "%(fullName)s - %(uri)s"
  notin:
    - '##somechan'
  delay:
    __default__: 300
    '##somechan': 600

mediawiki:
  wikitech:
    url: https://wikitech.wikimedia.org
    consumer_token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    consumer_secret: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    access_token: cccccccccccccccccccccccccccccccc
    access_secret: dddddddddddddddddddddddddddddddddddddddd
  otherwiki:
    url: https://wiki.example.com
    consumer_token: 11111111111111111111111111111111
    consumer_secret: 2222222222222222222222222222222222222222
    access_token: 33333333333333333333333333333333
    access_secret: 4444444444444444444444444444444444444444

mastodon:
  wikimedia_sal:
    url: https://fosstodon.org
    access_token: cccc

bash:
  view_url: https://tools.wmflabs.org/bash/quip/%s

sal:
  view_url: https://tools.wmflabs.org/sal/log/%s
  # For available placeholders, refer to sal.py
  # and look for Logger._store_in_es() and Logger.log()'s bang object.
  phab: "{nav icon=file, name=Mentioned in SAL (%(project)), href=%(href)s} [%(@timestamp)s] <%(nick)s> %(message)s"
  channels:
    '##somechan':
      project: someproject
      wiki: wikitech
      page: Foo/SAL
      category: SAL
      acl:
        default: deny
        allow:
            - *!*@*.example.net
            - *!*@wikimedia/*
    '##anotherchan':
      project: anotherproject
      wiki: otherwiki
      page: Another project logs
      leader: ===
      acl:
        deny:
            - *!*jerk@*.domain
    '##otherchan':
      use_config: '##somechan'
      mastodon: wikimedia_sal

Operating the bot

# Start the bot
$ ./bin/stashbot.sh start

# Stop the bot
$ ./bin/stashbot.sh stop

# Tail logs
$ ./bin/stashbot.sh tail

License

GPL-3.0-or-later

Some code and much inspiration taken from: