A bot framework for Reddit to manage threads, wiki pages, widgets, menus and more.

Overview

Sub Manager

PyPI Python version Framework Tests Pytest Pre-Commit Code style wemake Code style Black

License Maintainer PyPI status GitHub version PyPI version PyPI wheel Subreddit subscribers

Tests status Lint status Mega-Linter Semgrep scan CodeQL analysis Checked with MyPy Awesome badges

Sub Manager is a bot framework for Reddit to automate a variety of tasks on one or more subreddits, and can be configured and run without writing any code. Its initial application was to automatically generate, create, pin and update threads, as well as related tasks. Additionally, it can be used to automatically sync and reformat content between wiki pages, widgets and threads, as well as marked sections of the same (including the sub's sidebar and other content). It includes support for automatically installing a Systemd service unit for real-time operation on modern Linux distributions, which is used in production for the r/SpaceX subreddit, and it can also be run by any other means you choose on your system.

Legal Disclaimer: For the avoidance of doubt, Sub Manager and the r/SpaceX Github org and subreddit are unofficial fan creations, and have no affiliation with nor endorsement by Reddit or SpaceX, which are trademarks of their respective companies.

Installation

Note: You may need to substitute python3 for python in the commands below on some Linux distros where python isn't mapped to python3 (yet).

Create and activate fresh virtual environment

While Sub Manager can be installed in your system Python, we highly recommend you create and activate a virtual environment to avoid any conflicts with other packages on your system or causing any other issues. Using the standard tool venv, you can create an environment as follows:

python -m venv your-env-name

You can then activate it with the following on Linux and macOS,

source your-env-name/bin/activate

or on Windows (cmd),

.\your-env-name\Scripts\activate.bat

Of course, you're free to use any environment management tool of your choice (conda, virtualenvwrapper, pyenv, etc); these steps are just an example.

Download and install

To download and install the package from the Python Package Index (PyPI), simply activate your environment and run

python -m pip install submanager

Alternatively, if you want to use the exact pinned dependencies we do, you can clone this repo and install from the requirements.txt file:

git clone https://github.com/r-spacex/submanager.git
cd submanager
python -m pip install -r requirements.txt
python -m pip install .

Usage

To use Sub Manager, you'll need to activate the appropriate environment you created previously, and then execute its main entrypoint. For example, with venv under bash,

source your-env-name/bin/activate
submanager <command>

To see the various commands and options available, pass it the --help flag.

Contributing

For information on how to contribute to Sub Manager, including reporting issues, setting up a development environment and contributing code, see the Contributing Guide.

Configuration

First, you'll want to generate the primary Sub Manager user config file, in order to tell it what you want it to do. To do so, simply run submanager generate-config to generate it at the default path, and a stock config file with some starting examples will be output (formatted as TOML for humans). The static config file, which stores user configuration as human-friendly TOML, is located in the submanager subdirectory OS-appropriate user config directory, and the dynamic config file, which stores persistent internal state (e.g. current threads being managed) as machine-friendly JSON, is located in submanager subdirectory OS-appropriate user state directory. To view the full paths to and status of these files on your system, simply run submanager get-config-info. You can specify an alternate config file for one or both with the respective --config-path and --dynamic-config-path options, allowing you to run multiple instances of the bot simultaneously on the same machine (for example, to avoid cramming everything into one big configuration file, or use multiple cores).

To improve robustness and enforce safe maintenance practices, Sub Manager must now be stopped and restarted to read-in updated config. Individual modules, such as sync_manager and thread_manager, can be enabled and disabled via their corresponding enabled options, and can be further configured as described below. To perform a variety of checks that your configuration is valid and will result in a successful run, without actually executing any state-changing Reddit actions, run submanager validate-config; if an error occurs, informative output will explain the problem and, often, how to fix it.

Configuring credentials

Starting with Sub Manager v0.5.0 and later, the Reddit account to use for a given action can be specified per module (sync_manager, thread_manager), per task (sync item, thread) and even per source and target, as well as globally. You'll need to configure and register the account(s) involved for Reddit app access with the Reddit API. We recommend you configure your credentials in praw.ini and simply refer to them via the PRAW site_name argument in the config subtable of the respective account listed under the accounts table, which will avoid any secrets leaking if you accidentally or deliberately store your config.toml somewhere public. However, if you prefer, the various arguments that praw.Reddit() can accept, e.g. username, password, client id, client secret, refresh token etc) can be also all be included as subkeys under the config subtable of the named account in the accounts table. Sub Manager v0.5.0 supported the new token manager refresh token handling Reddit announced in early 2021, while v0.6.0 dropped that support along with PRAW due to Reddit reverting that change. While this occurred before to the first wide public release of Sub Manager (v0.6.0), this change is nevertheless transparent to users, as Sub Manager handles this for you.

Posting intervals

If posting new threads is enabled for a configured thread item, it can be set to either post daily, monthly, yearly etc. as soon as the period ticks over (e.g. first of the month), or at an interval of every N periods after the previous thread was posted.

new_thread_interval is specified as a string, either in the form "UNIT" (e.g. "daily", "month", etc) to trigger the first behavior, or "N UNIT" (e.g. "10 weeks", "1 year", etc) to invoke the second, where N is a positive integer and UNIT is a supported period unit. Supported period units for both include years, months, days, hours, minutes and seconds; weeks are currently supported for the latter, but not the former (since there is no unambiguously agreed-upon, locale-independent start of a week, and they don't divide evenly into months or years). For either form, the units can be given with or without s or ly as suffices.

There's currently a minor limitation with this as currently implemented: getting it to create a new thread "on-demand" rather than on a schedule (or not at all) is not completely obvious. There is a relatively simple workaround, however—just set the new_thread_interval to false, and then whenever you want a new thread, set it to e.g. 1 day, wait repeat_interval_s seconds for it to create the new thread (or manually restart it, if you're impatient), and then set it back to false.

We will soon add a proper feature for this, likely in the form of a new CLI command, e.g. submanager create-thread <thread_name>, to programmatically tell the running Sub Manager instance to create a new post on-demand.

Syncing sections

The patterns of text specified in source and targets are searched for in pseudo-Markdown "comments", i.e. empty links that don't appear in the rendered text, like so:

[](#/ <PATTERN><PATTERN_START>)

Example section content

[](#/ <PATTERN><PATTERN_END>)

This allows easily syncing just specific sections between sources and targets.

If any variable (e.g. pattern) is not specified for a target, the value is recursively inherited from the respective defaults table in the sync pair, and then sync config section, including the context sub-table in each as well as the default_context in the config. Conversely, any replace_patterns for a specific target are applied after (and in addition) to those specified in source for all targets; note the source section is not actually modified unless it is specified as a target.

Running as a service

To install a Systemd user service that will run Sub Manager automatically, activate your Sub Manager environment and simply run the submanager install-service command. By default, this will install a user-level service named submanager.service which will run Sub Manager with the primary configuration. If you'd like to install another service with a different config, specify the config file path as usual with --config-path, and (if you don't want the service to overwrite the default one, so you can run as many as you want at once), a custom suffix; the resulting service will be named submanager-<suffix>.service.

The installed service can be enabled and started in the typical way,

systemctl --user daemon-reload
systemctl --user enable submanager
systemctl --user start submanager

and you can check its status and log, respectively, with the usual

systemctl --user status submanager
journalctl --user -xe -u submanager

Note that there are a few considerations to keep in mind when running as a user instance of Systemd, most notably to get it to autostart on boot rather than login and persist after the user is logged out (e.g. on a server, VPS or other unattended box).

Comments
  • Complete final pre-release prep

    Complete final pre-release prep

    • [x] Update Readme badges and add PyPI
    • [x] Resolve issues running online workflows from forks
    • [ ] Update release instructions
    • [ ] Run pre-commit autoupdate
    • [ ] Pip compile dependencies into requirements.txt
    opened by CAM-Gerlach 2
  • Release Sub Manager version 0.6.0

    Release Sub Manager version 0.6.0

    • [x] Complete preliminaries
    • [x] Update pinned deps
    • [x] Update pre-commit hooks
    • [x] Build and test on RPi
    • [x] Transition new version to production on RPi
    • [x] Update documentation and finish release PR
    • [x] Rebuild and upload to PyPI on RPi
    • [x] Re-install production release on Pi
    • [x] Finalize release
    • [x] Cleanup on the RPi
    • [x] Cleanup locally
    • [x] Announce on Slack, etc.
    opened by CAM-Gerlach 1
  • Fix unimport linter repo URL.

    Fix unimport linter repo URL.

    Thank you for using Unimport, there was a slight change in the URL, the old URL works because it is redirected to the new one, but I changed it to the new one just in case.

    opened by hakancelikdev 0
  • Execute pre-release cleanup and preparation for CIs and ancillaries

    Execute pre-release cleanup and preparation for CIs and ancillaries

    A number of pre-release tasks:

    • [x] Split CI into lint and test workflows
    • [x] Add security policy
    • [x] Adopt Keep a Changelog format
    • [x] Add README badges
    opened by CAM-Gerlach 0
  • Add semgrep workflow to CI pipeline, for real this time

    Add semgrep workflow to CI pipeline, for real this time

    Semgrep didn't actually run over the whole repo in the previous are, so the outstanding issues went unreported, per returntocorp/semgrep-action#352 . This PR is a redo of #3 to commit both adding semgrep and fixing its issues in one clean, passing-build, atomic commit.

    opened by CAM-Gerlach 0
  • Update CIs following v0.6.0 release and test changes in new Mega-Linter preview release

    Update CIs following v0.6.0 release and test changes in new Mega-Linter preview release

    • [x] Remove link check disables for PyPI links that didn't work yet
    • [x] Re-enable Bandit and Black on Mega-Linter following fixing blocking Mega-Linter issues with those linters
    • [ ] Bump pre-commit and dep versions
    • [ ] Port improvements from spyder-docs
    • [ ] Add support for Python 3.10 to matrix and setup.cfg
    • [ ] Consider re-basing to 0.6.x?
    • [ ] (Fixup to switch back to production Mega-Linter once CIs pass and the new build is live)

    Mega linter blocking issues reference: Bandit nvuillam/mega-linter#679 and Black nvuillam/mega-linter#681 , both in nvuillam/mega-linter#682

    Task 
    opened by CAM-Gerlach 2
Releases(v0.6.0)
  • v0.6.0(Aug 25, 2021)

    Major release of Sub Manager, with a complete rewrite and numerous new features, enhancements and fixes.

    Added

    • Full command-based CLI with many more options, including separate start and run commands
    • Command get-config-info to print information about the config and list endpoints
    • Command install-service to automatically install a systemd service to run the bot
    • Command generate-config to generate a user config file with example defaults
    • Command validate-config to validate the current config file, offline or online
    • Command cycle-threads to post new versions of the indicated threads
    • --debug flag, to control whether user-friendly error messages or full tracebacks are printed
    • Config option approve_new to control if new posted threads are automatically approved (default)
    • "auto" option for pin_mode (default) will unpin the old thread and pin the new if currently pinned
    • truncate_lines option for source and target endpoints, to truncate to a specified number of lines
    • More fillable/replaceable variables in thread titles
    • Comprehensive offline and online functional tests exercising the options of every supported command
    • Exhaustive suite of pre-commit checks to validate correctness, best-practices, conventions and style
    • Tests, linting and analysis all run across a matrix of platforms/versions in CIs via Github Actions

    Changed

    • Reorganize much of user and dynamic config for consistency and future extensibility
    • Use Platformdirs to install config and state files into platform-appropriate locations
    • Validate config and resync all sources for the first run, to handle any config changes
    • Use Pydantic for config, allowing robust access and user-friendly validation
    • Vastly improved error handing of almost all areas, with much more helpful, user friendly messages
    • Safety run multiple instances via locking, to enable new commands and avoid strange bugs
    • Enable thread redirect in OP and sticky by default (configurable)
    • Inject start and end comments into thread targets, to allow easily adding extra content
    • Formally rename everything to Sub Manager, with consistent naming everywhere
    • Refactor from a monolithic script into a modular package, greatly improving organization
    • Make a Python package for installing from Github or from PyPI and add lint and test extras
    • Package is now fully statically typed, improving correctness, robustness and documentation
    • Add/greatly improve docs including Readme, Contributing Guide, security policy and more
    • Auto-generate pinned requirements files for reproducible dev and production installation

    Fixed

    • Issues with hierarchical config defaults not getting inherited correctly
    • Not syncing new targets until a change is made in the source
    • Not injecting appropriate line breaks in targets for some sources, causing formatting issues
    • Many other edge-case bugs and issues

    Removed

    • Config file no longer generated automatically if its not present, use generate-config instead
    • Drop previous support for token managers, in line with Reddit and PRAW changes
    Source code(tar.gz)
    Source code(zip)
Owner
r/SpaceX
A central location for information and collaboration on all of the awesome projects coming out of r/SpaceX
r/SpaceX
Easy to use reaction role Discord bot written in Python.

Reaction Light - Discord Role Bot Light yet powerful reaction role bot coded in Python. Key Features Create multiple custom embedded messages with cus

eibex 109 Dec 20, 2022
This bot can mention members upto 10,000 in groups and can mention members upto 200 in channels !

Mention All Bot This bot can mention members upto 10,000 in groups and can mention members upto 200 in channels ! 🏷 Infomation Language: Python. Tele

Anjana Madu 52 Dec 29, 2022
Save data from Instagram takeout to a SQLite database

instagram-to-sqlite Save data from a Instagram takeout to a SQLite database. Mise En Place git clone https://github.com/gavindsouza/instagram-to-sqlit

gavin 8 Dec 13, 2022
Alcarin Tengwar - a Tengwar typeface designed to pair well with the Brill typeface

Alcarin Tengwar Alcarin Tengwar is a Tengwar typeface designed to pair well with

Toshi Omagari 23 Nov 02, 2022
Scrapes an instagram user's photos and videos

Instagram Scraper instagram-scraper is a command-line application written in Python that scrapes and downloads an instagram user's photos and videos.

7.3k Nov 18, 2022
A discord bot that moderates your server!

Staff Bot para Discord O que é? É um bot que modera o seu servidor no Discord, apagando mensagens indesejadas que os usuários mandem! Como usar Primei

Isac Gonçalves Cunha 3 Oct 07, 2021
The Bot provide Hadith API and fetch content via api.hadith.sutanlab.id

Bot Hadith-API on Telegram The Bot provide Hadith API and fetch content via api.hadith.sutanlab.id Built With Python Asynchronous HTTP protocol client

xMan 12 Feb 19, 2022
Video Stream is a telegram bot project that's allow you to play video on telegram group video chat

Video Stream is a telegram bot project that's allow you to play video on telegram group video chat 🚀 Get SESSION_NAME from below: Pyrogram ## ✨ Featu

1 Nov 10, 2021
Easy Discord Webhook Token Grabber!

Easy Discord Webhook Token Grabber!

†† 27 Jun 01, 2022
Event-driven-model-serving - Unified API of Apache Kafka and Google PubSub

event-driven-model-serving Unified API of Apache Kafka and Google PubSub 1. Proj

Danny Toeun Kim 4 Sep 23, 2022
Join & Leave spam for aminoapps using aminoboi

JLspam.py Join & Leave spam for https://aminoapps.com using aminoboi Instalação apt-get update -y apt-get upgrade -y apt-get install git pkg install

Moleey 1 Dec 21, 2021
A simple message content sniping Discord bot which you can run yourself! Sniping API pulled from isobot and Arch bot

Discord Snipe Bot This is a bot made with the same message content sniping API from isobot and Arch bot. It's default prefix is -, however you can als

notsniped 5 Aug 11, 2022
Seems Like Everyone Is Posting This, Thought I Should Too, Tokens Get Locked Upon Creation And Im Not Going To Fix For Several Reasons

Member-Booster Seems Like Everyone Is Posting This, Thought I Should Too, Tokens Get Locked Upon Creation And Im Not Going To Fix For Several Reasons

Mintyz 1 Dec 28, 2021
Python bindings for ArrayFire: A general purpose GPU library.

ArrayFire Python Bindings ArrayFire is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific

ArrayFire 402 Dec 20, 2022
A simple python discord bot which give you a yogurt brand name, basing on a large database often updated.

YaourtBot A discord simple bot by Lopinosaurus Before using this code : ・Move env file to .env ・Change the channel ID on line 38 of bot.py to your #pi

The only one bunny who can dev. 0 May 09, 2022
A web app via which users can buy and sell stocks using virtual money

finance Virtual Stock Trader. A web app via which users can buy and sell stocks using virtual money. All stock prices are real and provided by IEX. Fe

Kiron Deb 0 Jan 15, 2022
AirDrive lets you store unlimited files to cloud for free. Upload & download files from your personal drive at any time using its super-fast API.

AirDrive lets you store unlimited files to cloud for free. Upload & download files from your personal drive at any time using its super-fast API.

Sougata 4 Jul 12, 2022
Discord Bot that leverages the idea of nested containers using podman, runs untrusted user input, executes Quantum Circuits, allows users to refer to the Qiskit Documentation, and provides the ability to search questions on the Quantum Computing StackExchange.

Discord Bot that leverages the idea of nested containers using podman, runs untrusted user input, executes Quantum Circuits, allows users to refer to the Qiskit Documentation, and provides the abilit

Mehul 23 Oct 18, 2022
An alternative to OpenFaaS nats-queue-worker for long-running functions

OpenFaas Job Worker OpenFaas Job Worker is a fork of project : OSCAR Worker - https://github.com/grycap/oscar-worker Thanks to Sebástian Risco @srisco

Sebastien Aucouturier 1 Jan 07, 2022
Cryptocurrency Trading Bot - A trading bot to automate cryptocurrency trading strategies using Python, equipped with a basic GUI

Cryptocurrency Trading Bot - A trading bot to automate cryptocurrency trading strategies using Python, equipped with a basic GUI. Used REST and WebSocket API to connect to two of the most popular cry

Francis 8 Sep 15, 2022