A Python IRC bot with dynamically loadable modules

Overview

pybot

This is a modular, plugin-based IRC bot written in Python. Plugins can bedynamically loaded and unloaded at runtime. A design goal is the abillity to develop plugins without being able to crash the bot.

Plugins have a simple, easy to pick up API. All events, commands, and triggers use a simple decorator convention.

Clone with: git clone --recursive https://github.com/jkent/pybot.git

Dependencies

Pybot is designed and tested to run under Python 3. Python 2 is no longer supported. Dependencies are listed in requirements.txt.

Configuring

You need to copy config.yaml.example to config.yaml and edit it to your liking.

The below examples in the Plugins section assume directed_triggers is False. Directed triggers start with the bot's name, followed by a colon or comma, and finally the command and any arguments. The other option, classic triggers, take a ! followed by the command and any arguments. The default option is to use directed triggers, so multiple bots can peacefully coexist.

  • config.yaml:

    my_network:
      host: localhost
      port: 6667
      ssl: false
    
      plugins:
        base:
          connect_password: null
          nickname: pybot
          username: pybot
          realname: Python IRC bot - http://git.io/M1XRlw
          nickserv_password: null
          channels:
              - '#dev'
    

Running

Pybot can be run as either a package or using its pybot.py script. It also comes with a shell script, run.sh that will setup a python virtual environment and dependencies for you.

Plugins

anyurl

This plugin will fetch and reply with the og:title or title of a HTML document.

  • Configuration:

    anyurl:
      blacklist:
        - '^https://www.google.com/.*$'
    

base

This plugin handles some of the core behaviors of the bot, such as setting the nick, joining channels, and auto-reconnect. Its required, please don't unload it unless you know what you're doing.

  • Configuration:

    base:
      nickname: pybot
      channels:
        - #dev
        - #UnderGND
    

choose

A fun yet frustrating plugin that gives random responses.

  • Usage:

    should I|<nick> <question>?
    !choose a or b, c.
    

config

This plugin allows configuration reloading. Usage is limited to level 1000.

  • Usage:

    !config reload
    

debug

This plugin prints all IRC traffic and module events while loaded.

  • Usage:

    !raw <message>
    !eval <code>
    

Raw lets you send a raw IRC message, and requires permission level 900 and up. Eval is a dangerous feature that allows arbitrary execution of python code, and usage requires permission level 1000 and up.

github

This plugin will show information about GitHub users and repos when a url is linked within a channel. jrspruitt was the original author, rewritten by jkent.

  • Usage:

    <url>
    

math

The math plugin is a nifty calculator that has support for functions and variables. Its state is saved in a database as workbooks which can be switched out as needed.

  • Usage:

    !math [expr]
    !math var=[expr]
    !math func([var[, ...]])=[expr]
    !math workbook [name]
    !math varlist
    !math funclist
    !math describe <funcname> [description]
    

message

An offline/delayed message facility.

  • Usage:

    !message send <nick> <message> [as dm] [in timespec]
    !message ack
    !message del <num>
    !message list [nick]
    !message block <nick>
    !message unblock <nick>
    !message opt <in | out>
    

perms

Manage bot permissions. Usage is limited to level 1000.

  • Config:

    perms:
      superuser: me!root@localhost
    
  • Usage:

    !perms list
    !perms allow [-]<mask> [<plugin>=<n>]
    !perms deny [-]<mask> [<plugin>=<n>]
    

Where plugin is the name of a plugin and n is the level to set. Plugin can be the special constant ANY.

plugin

Load, unload, reload plugins at runtime. Usage is limited to level 1000.

  • Usage:

    !plugin load <name>
    !plugin reload [!]<name>
    !plugin unload [!]<name>
    !plugin list
    

For reload and unload, the "bang" means force. Use with caution.

song

Choose a random song from a song database.

  • Usage:

    !song
    !song add <artist> - <title>
    !song delete
    !song fix artist <artist>
    !song fix title <title>
    !song last
    !song load <data-file>
    !song search <query>
    !song stats
    !song who
    !song [youtube|yt] <youtube-url>
    !song [youtube|yt] delete
    

topic

Allow users to set the topic with a minimum age.

  • Configuration:

    topic:
      min_age: 24h
      min_level: 100
      bypass_level: 900
    
  • Usage:

    !topic apply
    !topic set <topic>
    

If permissions or min_age not met, apply can be used to override and apply the last proposed topic by anyone with bypass_level or higher.

twitter

Parse URLs, get latest user tweet, and search keywords on Twitter. Configuration requires Twitter account and application setup:

  • Configuration:

    twitter:
    apikey: <api key>
    secret: <api secret>
    auth_token: <auth token>
    auth_secret: <auth secret>
    
  • Usage:

    <url>
    !twitter user <@user_id>
    !twitter search <keyword>
    

For Developers

Plugins

Here's a simple "Hello world" style plugin:

from pybot.plugin import *

class Plugin(BasePlugin):
    @hook
    def hello_trigger(self, msg, args, argstr):
        msg.reply('Hello %s!' % (argstr,))

You would call the trigger on IRC via either:

!hello world

or if directed (conversational) style triggers are enabled:

pybot, hello world

To which the bot would reply:

<pybot> Hello world!

Hooks

There are five types of hooks:

  • event
  • command
  • trigger
  • timestamp
  • url

All except for timestamp hooks can be used via the @hook decorator. @hook is a smart decorator that uses the naming convention of your method to determine the name and type of the hook. Alternatively, it can be called as @hook(names) and @hook(type, names).

Timestamp hooks can be created 3 different ways: one-shot timeouts, one-shot timers, and repeating intervals. They are discussed in more detail with the Bot class.

Bot class

Anything that you may need to access should be accessable from the bot class. Plugins get a reference to the bot instance they are running on (self.bot).

var description
channels A dict with keys being channels, value is a dict with keys 'joined' and 'nicks'
core The core instance the bot is running under
hooks An instance of the HookManager class
nick A string identifying the bot's current nickname
plugins An instance of the PluginManager class
allow_rules Allow rules for the permission system
deny_rules Deny rules for the permission system
method description
set_interval(fn, seconds[, owner]) Install timestamp hook, calls fn every seconds
set_timeout(fn, seconds[, owner]) Install timestamp hook, calls fn after seconds
set_timer(fn, timestamp[, owner]) Install timestamp hook, calls fn at timestamp
join(channels[, keys]) Convenience method for JOIN
notice(target, text) Convenience method for NOTICE
part(channels[, message]) Convenience method for PART
privmsg(target, text) Convenience method for PRIVMSG

Hook class

method description
bind(fn[, owner]) Binds a hook in preparation to install

EventHook class

CommandHook class

TriggerHook class

TimestampHook class

UrlHook class

HookManager class (the hook manager)

method description
install(hook) Install a bound hook
uninstall(hook) Uninstall hook
call(hooks, *args) Call hooks using as many args as possible
find(model) Search for hooks by model hook instance
modify(hook) Context manager for modifying installed hooks
Comments
  • Bump urllib3 from 1.25.3 to 1.25.8

    Bump urllib3 from 1.25.3 to 1.25.8

    Bumps urllib3 from 1.25.3 to 1.25.8.

    Release notes

    Sourced from urllib3's releases.

    1.25.8

    Release: 1.25.8

    1.25.7

    No release notes provided.

    1.25.6

    Release: 1.25.6

    1.25.5

    Release: 1.25.5

    1.25.4

    Release: 1.25.4

    Changelog

    Sourced from urllib3's changelog.

    1.25.8 (2020-01-20)

    • Drop support for EOL Python 3.4 (Pull #1774)

    • Optimize _encode_invalid_chars (Pull #1787)

    1.25.7 (2019-11-11)

    • Preserve chunked parameter on retries (Pull #1715, Pull #1734)

    • Allow unset SERVER_SOFTWARE in App Engine (Pull #1704, Issue #1470)

    • Fix issue where URL fragment was sent within the request target. (Pull #1732)

    • Fix issue where an empty query section in a URL would fail to parse. (Pull #1732)

    • Remove TLS 1.3 support in SecureTransport due to Apple removing support (Pull #1703)

    1.25.6 (2019-09-24)

    • Fix issue where tilde (~) characters were incorrectly percent-encoded in the path. (Pull #1692)

    1.25.5 (2019-09-19)

    • Add mitigation for BPO-37428 affecting Python <3.7.4 and OpenSSL 1.1.1+ which caused certificate verification to be enabled when using cert_reqs=CERT_NONE. (Issue #1682)

    1.25.4 (2019-09-19)

    • Propagate Retry-After header settings to subsequent retries. (Pull #1607)

    • Fix edge case where Retry-After header was still respected even when explicitly opted out of. (Pull #1607)

    • Remove dependency on rfc3986 for URL parsing.

    • Fix issue where URLs containing invalid characters within Url.auth would raise an exception instead of percent-encoding those characters.

    ... (truncated)

    Commits
    • 2a57bc5 Release 1.25.8 (#1788)
    • a2697e7 Optimize _encode_invalid_chars (#1787)
    • d2a5a59 Move IPv6 test skips in server fixtures
    • d44f0e5 Factorize test certificates serialization
    • 84abc7f Generate IPV6 certificates using trustme
    • 6a15b18 Run IPv6 Tornado server from fixture
    • 4903840 Use trustme to generate IP_SAN cert
    • 9971e27 Empty responses should have no lines.
    • 62ef68e Use trustme to generate NO_SAN certs
    • fd2666e Use fixture to configure NO_SAN test certs
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Anyurl requests timeout and user-agent config.ini option.

    Anyurl requests timeout and user-agent config.ini option.

    Set a timeout for requests, so when a web page does not respond the bot does not hang.

    To make setting the user-agent string easier make it a config.ini option for anyurl. If not configured it will fallback to the default value.

    opened by jrspruitt 0
  • messages need to be reassembled before decoding utf-8

    messages need to be reassembled before decoding utf-8

    The current implementation decodes to utf-8 immediately after receiving data from the socket. (see https://github.com/jkent/jkent-pybot/blob/6c4d0da4bb2e6dfd1c5dab3bf9af11b37c9ba3e3/client.py#L102) It would be better to do the utf-8 decoding after spitting the lines up into commands so a fragmented packet won't cause data loss in the try block.

    bug 
    opened by jkent 0
  • Imgurplugin Unicode Decoding Error.

    Imgurplugin Unicode Decoding Error.

    With input of url http://imgur.com/wRdlRtS The bot crashes. The title of that image has a ♫ which seems to be the issue.

    Traceback (most recent call last): File "main.py", line 12, in core.run() File "/srv/pybot/core.py", line 24, in run self.tick() File "/srv/pybot/core.py", line 50, in tick obj.do_write() File "/srv/pybot/client.py", line 35, in do_write n = self._write(self.sendbuf) File "/srv/pybot/client.py", line 81, in _write n = self.sock.send(data) File "/usr/lib64/python2.7/ssl.py", line 198, in send v = self._sslobj.write(data) UnicodeEncodeError: 'ascii' codec can't encode character u'\u266b' in position 23: ordinal not in range(128)

    opened by jrspruitt 0
  • Songs plugin unique database exception.

    Songs plugin unique database exception.

    <class 'hook.TriggerHook'> hook error:
    Traceback (most recent call last):
      File "/srv/pybot/pybot/hook.py", line 28, in __call__
        return self.fn(*args[:self.nargs])
      File "/srv/pybot/plugins/song_plugin.py", line 210, in song_fix_artist_trigger
        self.cur.execute(query, (artist_id, track_id))
    sqlite3.IntegrityError: columns artist_id, name are not unique
    

    Caused when fixing song artist, when the title already exists under the fixed artist.

    opened by jrspruitt 0
Releases(v1.0.2)
Owner
Jeff Kent
Jeff Kent
A free, minimal, lightweight, cross-platform, easily expandable Twitch IRC/API bot.

parky's twitch bot A free, minimal, lightweight, cross-platform, easily expandable Twitch IRC/API bot. Features ?? Connect to Twitch IRC chat! ?? Conn

Andreas Schneider 10 Dec 30, 2022
an OSU! bot sdk based on IRC

osu-bot-sdk an OSU! bot sdk based on IRC Start! The following is an example of event triggering import osu_irc_sdk from osu_irc_sdk import models bot

chinosk 2 Dec 16, 2021
This is the repository for HalpyBOT, the Hull Seals IRC Chatbot Assistant.

HalpyBOT 1.4.2 This is the repository for HalpyBOT, the Hull Seals IRC Chatbot Assistant. Description This repository houses all of the files required

The Hull Seals 3 Nov 3, 2022
To dynamically change the split direction in I3/Sway so as to split new windows automatically based on the width and height of the focused window

To dynamically change the split direction in I3/Sway so as to split new windows automatically based on the width and height of the focused window Insp

Ritin George 6 Mar 11, 2022
ShadowClone allows you to distribute your long running tasks dynamically across thousands of serverless functions and gives you the results within seconds where it would have taken hours to complete

ShadowClone allows you to distribute your long running tasks dynamically across thousands of serverless functions and gives you the results within seconds where it would have taken hours to complete

null 240 Jan 6, 2023
Botto - A discord bot written in python that uses the hikari and lightbulb modules to make this bot

❓ About Botto Hi! This is botto, a discord bot written in python that uses the h

null 3 Sep 13, 2022
❤️ Hi There Im EzilaX ❤️ A next gen powerful telegram group manager bot 😱 for manage your groups and have fun with other cool modules Made By Sadew Jayasekara 🔥

❤️ EzilaX v1 ❤️ Unmaintained. The new repo of @EzilaXBot is Public. (It is no longer based on this source code. The completely rewritten bot available

Sadew Jayasekara 18 Nov 24, 2021
❤️A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules

Natsuki Based on Python Telegram Bot Contributors Video Tutorial: Complete guide on deploying @TheNatsukiBot's clone on Heroku. ☆ Video by Sadew Jayas

Pawan Theekshana 8 Oct 6, 2022
Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Team Amanda 4 Oct 21, 2022
This Is A Python Program To Showcase Two Modules (Gratient And Fade)

Hellooo, It's PndaBoi Here! This Is A Python Program To Showcase Two Modules (Gratient And Fade). I Really Like Both Of These Modules So I Decided To

PndaBoi! 6 May 31, 2022
fhempy is a FHEM binding to write modules in Python language

fhempy (BETA) fhempy allows the usage of Python 3 (NOT 2!) language to write FHEM modules. Python 3.7 or higher is required, therefore I recommend usi

Dominik 27 Dec 14, 2022
Automate TikTok follower bot, like bot, share bot, view bot and more using selenium

Zefoy TikTok Automator Automate TikTok follower bot, like bot, share bot, view bot and more using selenium. Click here to report bugs. Usage Download

null 555 Dec 30, 2022
This repository contains modules that extend / modify parts of Odoo ERP

Odoo Custom Addons This repository contains addons that extend / modify parts of Odoo ERP. Addons list account_cancel_permission Only shows the button

Daniel Luque 3 Dec 28, 2022
Cloudshell-sandbox-reporter - Helper modules and classes for writing to Cloudshell sandbox console

Cloudshell Sandbox Reporter This project provides utility classes for formatting

QualiLab 2 Sep 7, 2022
Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot

- [ MAYBE UPDATE & ADD MORE MODULE ] Bagas Mirror&Leech Bot Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring file

null 4 Nov 23, 2021
A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

Aran 1 Oct 13, 2021
Aqui está disponível GRATUITAMENTE, um bot de discord feito em python, saiba que, terá que criar seu bot como aplicação, e utilizar seu próprio token, e lembrando, é um bot básico, não se utiliza Cogs nem slash commands nele!

BotDiscordPython Aqui está disponível GRATUITAMENTE, um bot de discord feito em python, saiba que, terá que criar seu bot como aplicação, e utilizar s

Matheus Muguet 4 Feb 5, 2022
(@Tablada32BOT is my bot in twitter) This is a simple bot, its main and only function is to reply to tweets where they mention their bot with their @

Remember If you are going to host your twitter bot on a page where they can read your code, I recommend that you create an .env file and put your twit

null 3 Jun 4, 2021