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: [email protected]
    
  • 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 simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.

telegram-stats-bot Telegram-stats-bot is a simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statist

22 Dec 26, 2022
Project glow is an open source bot worked on by many people to create a good and safe moderation bot for all

Project Glow Greetings, I see you have stumbled upon project glow. Project glow is an open source bot worked on by many people to create a good and sa

Glowstikk 24 Sep 29, 2022
Using GNU Radio and HackRF One to Receive, Analyze and Send ASK/OOK signals

play_with_ask NIS-8016 Lab A code: Recv.grc/py: Receive signals and match with ASK button using HackRF and GNU radio. I use AM demod block(can also in

Chen Anxue 1 Jul 04, 2022
:cloud: Python API for ThePirateBay.

Unofficial Python API for ThePirateBay. Build Status Test Coverage Version Downloads (30 days) Installation $ pip install ThePirateBay Note that ThePi

Karan Goel 334 Oct 21, 2022
Token Manager written in Python

Discord-API-Token-Entrance Description This is a Token Manager that allows your token to enter your discord server, written in python. Packages Requir

Tootle 1 Apr 15, 2022
Video Stream: an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music

SHU KURENAI TEAM 4 Nov 05, 2022
It is automated instagram follower bot.

Instagram-Follower-Bot It is automated instagram follower bot. In This project I've used Selenium and Python. Work-Flow When I run my code. It's gonna

Falak Shair 3 Sep 28, 2022
Irenedao-nft-generator - Original scripts used to generate IreneDAO NFTs

IreneDAO NFT Generator Scripts to generate IreneDAO NFT. Make sure you have Pill

libevm 60 Oct 27, 2022
RedFish API Toolkit

RedFish API Toolkit RedFish API Toolkit Build Status GitHub Actions Travis CI Requirements requirements.txt requirements-dev.txt Dependencies Document

Larry Smith Jr. 1 Nov 20, 2021
Scanner and Checker for Binance Scam Contracts

Money Printer by Warranty Voider well this isnt exactly a printer, but it helps you find and check new token startups. In the end its a nice scam cont

12 Nov 24, 2022
A Discord Bot that tracks and displays cryptocurrencies using the CoinMarketCap API

PyBo - A Crypto Inspired Discord Bot Pybo (paɪ boʊ) is a Discord bot that utilizes the discord.py API wrapper to run the bot. Pybo also integrates the

0 Nov 17, 2022
Send notification to your telegram group/channel/private whenever a new video is uploaded on a youtube channel!

YouTube Feeds Bot. Send notification to your telegram group/channel/private whenever a new video is uploaded on a youtube channel! Variables BOT_TOKEN

Aditya 30 Dec 07, 2022
We propose the adversarial blur attack (ABA) against visual object tracking.

ABA We propose the adversarial blur attack (ABA) against visual object tracking. The ICCV link: https://arxiv.org/abs/2107.12085 and, https://openacce

Qing Guo 13 Dec 01, 2022
Louis Manager Bot With Python

✨ Natsuki ✨ Are You Okay Baby I'm Natsuki Unmaintained. The new repo of @TheNatsukiBot is public. ⚡ (It is no longer based on this source code. The co

Team MasterXBots 1 Nov 07, 2021
Proxy-Bot - Python proxy bot for telegram

Proxy-Bot 🤖 Proxy bot between the main chat and a newcomer, allows all particip

Anton Shumakov 3 Apr 01, 2022
A demo without 🚀 science, just simple UTXO spending logic.

Stuck TX Demo Docker container that runs 4 dogecoind to demonstrate "the stuck tx problem". Scenario A wallet sends out 3 transactions to a recipient

Patrick Lodder 2 Nov 16, 2021
A script that writes automatic instagram comments under a post

Send automatic messages under a post on instagram Instagram will rate limit you after some time. From there on you can only post 1 comment every 40 se

Maximilian Freitag 3 Apr 28, 2022
A Telegram Video Watermark Adder Bot

Watermark-Bot A Telegram Video Watermark Adder Bot by @VideosWaterMarkRobot Features: Save Custom Watermark Image. Auto Resize Watermark According to

5 Jun 17, 2022
A link shortner telegram bot version 2 with advanced features

URL-Shortner-Bot-V2 A link shortner telegram bot version 2 with advanced features Made with Python3 (C) @FayasNoushad Copyright permission under MIT L

Fayas Noushad 18 Dec 29, 2022
A mass account list editor for python

Account-List-Editor This is an mass account list editor Usage Run the editor.py file with python (python3 ./editor.py) Press a button (1/2) and drag &

ExtremeDev 1 Dec 20, 2021