Development documentation

The Bot

class sid.sid.MUCBot(jid, password, room, nick, log_level=20)[source]

Bases: ClientXMPP

Parameters:
  • jid (str) – jid to log with

  • password (str) – jid password

  • room (str) – conference room to join

  • nick (str) – Nickname to use in the room

disconn(event)[source]

disconnected handler

foreach_plugin(method, *args, **kwds)[source]
help(message, args)[source]

Returns a help string listing available options.

Automatically assigned to the “help” command.

message(msg)[source]

Messages handler

Parses message received to detect prefix

muc_presences

Keep track of MUC presences: {‘nick’: presence}

prefix = '!'

Class attribute to define bot’s command prefix

Defaults to “!”

register_bot_plugin(plugin_cls)[source]

Registers plugin, takes a class, the method instanciates the plugin

Parameters:

plugin_cls (sid.plugin.Plugin) – A sid.plugin.Plugin class

shutdown_plugins()[source]
async start(event)[source]

Process the session_start event.

Typical actions for the session_start event are requesting the roster and broadcasting an initial presence stanza.

Parameters:

event (dict) – An empty dictionary. The session_start event does not provide any additional data.

unregister_bot_plugin(plugin)[source]
@sid.sid.botcmd(hidden, name)[source]

Decorator for bot command functions

Parameters:
  • hidden (bool) – is the command hidden in global help

  • name (str) – command name, default to decorated function name

Plugin base

The plugin class to derive from.

class sid.plugin.Plugin(bot)[source]

Simple Plugin object to derive from:

  • Exposes the bot object and its logger

  • Provides send helpers

Parameters:

bot (sid.sid.MUCBot) – bot the plugin is load from

add_handlers()[source]

Add handlers declared in self.hanlders

async ban(jid, reason)[source]

Coroutine to ban a jid from the room

Parameters:
  • jid (str) – JID to ban

  • reason (str) – Reason

handlers

list : List of tuples (event, handler)

log_level = None

Overriding bot log level for the plugin

reply(rcv, msg)[source]

Smart reply to message received.

Replies msg in private or on the muc depending on rcv

Parameters:
rm_handlers()[source]

Remove handlers declared in self.hanlders

send(dest, msg, mtype='chat')[source]

Send msg to dest

Parameters:
  • dest (str) – Message recipient

  • msg (dict,str) – Message to send (use dict for xhtml-im)

Note

if msg is a dict to provide xhmlt-im massages:

msg = {
    mbody: 'text',
    mhtml: '<b>text</b>,  # optional'
}
shutdown()[source]

Empty method to override. Called on bot shutdown

Available plugins

Generic plugins

class sid.echo.Echo(bot)[source]

Bases: Plugin

Drops a message to be sent when someone gets online.

log_presence(pres)[source]

Handler method registering MUC participants presence

tell(message, args)[source]

Drops a message to be sent when someone gets online.

  • !tell queue : messages in queue

  • !tell <nick> <msg>: append <msg> to <nick> in queue

class sid.feeds.Feeds(bot)[source]

Bases: Plugin

Note

Feeds plugin depends on external module: feedparser

FEEDS = ['https://www.debian.org/security/dsa', 'https://www.debian.org/News/news', 'https://tracker.debian.org/pkg/prosody/rss', 'https://tracker.debian.org/pkg/ejabberd/rss', 'https://planet.debian.org/atom.xml']

Default feeds to monitor

TEMPO = 60

Time between feeds check

feeds(rcv, args)[source]

Monitors debian project related feeds.

  • !feeds : registred feeds list

  • !feeds last : last check time

shutdown()[source]

Empty method to override. Called on bot shutdown

class sid.log.Log(bot)[source]

Bases: Plugin

Logs group chat participant presence.

The account running the bot need at least room moderation right to log participants JIDs (fallback to nickname).

dump(message, args)[source]

!dump : Dumps log as MUC message

write(message, args)[source]

Dump/save room presences log

!write : Writes log to file (use mktemp and return file location as MUC message)

class sid.rtbl.RTBL(bot)[source]

Bases: Plugin

Spam guard plugin for MUC.

async got_online(pres)[source]

Handler method for new MUC participants

got_presence(pres)[source]

Does bot have required permissions

node = 'muc_bans_sha256'

Pubsub server node to subscribe to

pubsub_server = 'example.org'

Pubsub server

async rtbl_ban(jid: JID)[source]

Ban jid in RTBL

rtbl_info(rcv, _)[source]

Show RTBL info

Debian plugins

Fetch packages info from the archive

>>> from sid.archive import Archive
class sid.archive.Archive(bot)[source]

Bases: Plugin

Fetches package info from the archive

archive(rcv, args)[source]

Fetches package info from the archive

!archive pkg-name : Returns package versions (by suite)

re_pkg = re.compile('(?P<package>[0-9a-z.+-]+)$')

Pakage name regexp

stable_codename = 'buster'

Current stable Suite

Intercepts bugs numbers in MUC messages and send info about it

>>> from sid.bts import Bugs
class sid.bts.Bugs(bot)[source]

Bases: Plugin

Gets bugs info from the BTS

Note

This plugin depends on external module: python-debianbts

bugs(rcv, args)[source]

Gets bugs info from the BTS

!bugs pkg-name : Returns latest bug reports if any

muc_message(msg)[source]

Handler method dealing with MUC incoming messages.

Intercepts bugs number in MUC messages (as #629234), replies a bug summary.

re_bugs = re.compile('(?:(?<=#)|(?<=bugreport\\.cgi\\?bug=)|(?<=bugs\\.debian\\.org/))(\\d{6,7})')

Bug id regexp, intercepts bug id in strings : “#629234”, “bugs.debian.org/629234” and “bugreport.cgi?bug=629234”

re_pkg = re.compile('(?P<package>[0-9a-z.+-]+)$')

Package name regexp