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
gBasic - The easy multiplatform bot

gBasic The easy multiplatform bot gBasic is the module at the core of @GianpiertoldaBot, maintained with 3 for the entire community by the Stockdroid

Stockdroid Fans 5 Nov 03, 2021
Gorrabot is a bot made to automate checks and processes in the development process.

Gorrabot is a Gitlab bot made to automate checks and processes in the Faraday development. Features Check that the CHANGELOG is modified By default, m

Faraday 7 Dec 14, 2022
Python script to replace BTC adresses in the clipboard with similar looking ones, whose private key can be retrieved by a netcat listener or similar.

BTCStealer Python script to replace BTC adresses in the clipboard with similar looking ones, whose private key can be retrieved by a netcat listener o

Some Person 6 Jun 07, 2022
Clubhouse API written in Python. Standalone client included. For reference and education purposes only.

clubhouse-py is originally developed for the sake of interoperability. Standalone client is also created with very basic features, including but not limited to the audio-chat

1.7k Jan 05, 2023
A collection of tools for managing Jira issues for the RHODS project

RHODS-Jira-Tools A collection of tools for managing Jira issues for the RHODS project move_to_qa.py This script handles transitioning a given Jira iss

Alex Corvin 1 Sep 20, 2022
Termux Pkg

PKG Install Termux All Basic Pkg. Installation : pkg update && pkg upgrade && pkg install python && pkg install python2 && pkg install git && git clon

ɴᴏʙɪᴛᴀシ︎ 1 Oct 28, 2021
ChairBot is designed to be reliable, easy to use, and lightweight for every user, and easliy to code add-ons for ChairBot.

ChairBot is designed to be reliable, easy to use, and lightweight for every user, and easliy to code add-ons for ChairBot. Ready to see whats possible with ChairBot?

1 Nov 08, 2021
Python script to Funge NFTs.

Python script to Funge NFTs. It scrapes OpenSea for a given list of NFT collections and downloads a certain number of NFTs from each collection or the entire collections.

3 Apr 28, 2022
PESU Academy Discord Bot built for PESsants and PESts of PES University

PESU Academy Bot PESU Academy Discord Bot built for PESsants and PESts of PES University You can add the bot to your Discord Server using this link. O

Aditeya Baral 0 Nov 16, 2021
Skautský discord bot

Jáchym 🤖 Open-source skautský discord bot postavený na discord.py O čem? • Funkce • TODO • Poděkování ❓ O čem? Jáchym vznikl jako projekt do odborky

10 May 12, 2022
Kali Kush - Account Nuker Tool

Kali Kush - Account Nuker Tool This is a discord tool made by me, and SSL :) antho#1731 How to use? pip3 install -r requirements.txt -py kalikush.py -

ryan 3 Dec 21, 2021
Auto-updater for the Northstar Titanfall 2 client

northstar-updater Auto-updater for the Northstar Titanfall 2 client Usage Put the exe into your Titanfall 2 directory next to Titanfall2.exe Then, whe

7 Nov 25, 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
Deploy your apps on any Cloud provider in just a few seconds

The simplest way to deploy your apps in the Cloud Deploy your apps on any Cloud providers in just a few seconds ⚡ Qovery Engine is an open-source abst

Qovery 1.9k Dec 26, 2022
A fork of discord.py for anime enjoyers

A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using async and await

Senpai Development 4 Nov 05, 2021
Sielzz Music adalah proyek bot musik telegram, memungkinkan Anda memutar musik di telegram grup obrolan suara.

Hi, I am: Requirements 📝 FFmpeg NodeJS nodesource.com Python 3.8 or higher PyTgCalls MongoDB Get STRING_SESSION from below: 🎖 History Features 🔮 Th

1 Nov 29, 2021
High-Resolution Differential Z-Belt Mod for V0 (with optional Kirigami support)

V0-DBM This is a high-resolution differential pulley system belt mod for the Z-axis on Voron 0 with optional Kirigami Bed support. NOTE: Alpha version

Simon Küppers 11 Jan 07, 2023
A simple Telegram bot which handles images in whole different way

zeroimagebot thezeroimagebot 🌟 I Can Edit Dimension Of An image which is required by @stickers 🌟 I Can Extract Text From An Image 🌟 !!! New Updates

RAVEEN KUMAR 4 Jul 01, 2021
Python SDK for IEX Cloud

iexfinance Python SDK for IEX Cloud. Architecture mirrors that of the IEX Cloud API (and its documentation). An easy-to-use toolkit to obtain data for

Addison Lynch 640 Jan 07, 2023
A simple weather information tool.

pwy A simple weather information tool. Table of Contents Features Dependencies Installation Usage Update Changelog Credits License Features ASCII art

Clint 105 Dec 31, 2022