Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
82ecc88
Update to Python 3.10 and discord.py 2.0 beta
Arcensoth Aug 26, 2021
1cf990f
Merge branch 'main' of github.com:CommanderBot-Dev/commanderbot-ext i…
Arcensoth Aug 26, 2021
e33bd79
Bump alpha version
Arcensoth Aug 26, 2021
06f3864
Update ping
Arcensoth Aug 26, 2021
7bff0eb
Update status
Arcensoth Aug 26, 2021
a31ec6b
Update and improve/compact quote
Arcensoth Aug 26, 2021
23a08a1
Update kick
Arcensoth Aug 26, 2021
56da979
Update poster_board
Arcensoth Aug 26, 2021
fd90256
Update jira
Arcensoth Aug 26, 2021
7405da1
Update vote
Arcensoth Aug 26, 2021
e3d8a07
Update pack
Arcensoth Aug 26, 2021
05b74f8
Update and improve `roles`
Arcensoth Aug 27, 2021
636f85c
Implement finer-grained permissions for `roles` (fixes #18)
Arcensoth Aug 28, 2021
f59ac5f
Update `invite`
Arcensoth Aug 28, 2021
f16ef51
Update `faq`
Arcensoth Aug 28, 2021
2ba5b35
Update and improve `automod`
Arcensoth Aug 28, 2021
3777ca0
Update `help_chat`
Arcensoth Aug 28, 2021
2a8af16
Update readme
Arcensoth Aug 28, 2021
2960822
Account for threads in `faq`
Arcensoth Aug 28, 2021
8607d91
Account for threads in `automod`
Arcensoth Aug 28, 2021
54fa708
Merge remote-tracking branch 'origin/main' into dpy2
Arcensoth Aug 29, 2021
3dc6cf8
Update `manifest`
Arcensoth Aug 29, 2021
6093251
Merge branch 'main' into dpy2
Arcensoth Aug 29, 2021
59b95e5
Make commanderbot-ext independent
Arcensoth Aug 29, 2021
83b76d1
Update black and isort
Arcensoth Aug 29, 2021
3a3bf05
Support `allowed_mentions` in root bot config (fixes #52)
Arcensoth Aug 29, 2021
1a56f4a
Move root module
Arcensoth Aug 30, 2021
606774d
Update imports
Arcensoth Aug 30, 2021
23bad3b
Update extensions
Arcensoth Aug 30, 2021
154009a
Update readme
Arcensoth Aug 30, 2021
3692db4
Update changelog
Arcensoth Aug 30, 2021
ec9d976
Update codeowners
Arcensoth Aug 30, 2021
8fd8565
Update pyproject.toml
Arcensoth Aug 30, 2021
470bc58
Update readme
Arcensoth Aug 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* @arcensoth

/commanderbot_ext/ext/pack @vberlier @arcensoth
/commanderbot/ext/pack @vberlier @arcensoth
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.pytest_cache/**
**/__pycache__
venv/**
.venv/**
bot/**
dist/**
*.egg-info/**

.vscode/**

.python-version
67 changes: 51 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Updated to Python 3.10 (release candidate).
- Updated to the discord.py 2.0 beta.
- Updated all extensions past breaking changes.
- `commanderbot-core` has been merged into `commanderbot-ext`.
- The repository has been renamed to `commanderbot-py`.
- The package has been renamed to `commanderbot` (which used to belong to `commanderbot-core`).
- Exception handling logic has been reworked.
- Fixes #53
- Reconsidered all commands to use a `ctx.reply` wrapper with pings disabled.
- Fixes #42
- `allowed_mentions` field in root bot config is now supported.
- Fixes #52
- `automod`:
- Even data now includes `user` fields.
- Fixes #43
- Even data now includes member date fields by default.
- `message` triggers now allow basic matching of message content.
- Fixes #44
- `roles`:
- Unresolved roles are now deregistered and cleaned-up automatically.
- Fixes #47
- Elevated commands can no longer add/remove unregistered roles to/from users.
- Fixes #48
- Users can now join/leave multiple roles in one command.
- Fixes #49
- Multiple roles can now be added/removed to/from multiple members all in one command.
- Roles can now be targeted using a partial name match.
- Fixes #50
- Roles can now be configured to be able to run elevated commands.
- Fixes #18

## [0.15.0] - 2021-08-29

### Added
Expand Down Expand Up @@ -146,19 +181,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Implemented `status` and `faq` extensions as an exercise for developing `commanderbot-lib`

[unreleased]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.15.0...HEAD
[0.15.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.13.0...v0.14.0
[0.13.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.12.0...v0.13.0
[0.12.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.11.0...v0.12.0
[0.11.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.10.0...v0.11.0
[0.10.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.9.0...v0.10.0
[0.9.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/releases/tag/v0.1.0
[unreleased]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.15.0...HEAD
[0.15.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.13.0...v0.14.0
[0.13.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.12.0...v0.13.0
[0.12.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.11.0...v0.12.0
[0.11.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.10.0...v0.11.0
[0.10.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.9.0...v0.10.0
[0.9.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/CommanderBot-Dev/commanderbot-py/releases/tag/v0.1.0
70 changes: 64 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
# CommanderBot Ext
# commanderbot-py

A collection of cogs and extensions for discord.py bots.
A collection of utilities and extensions for discord.py bots.

[![package-badge]](https://pypi.python.org/pypi/commanderbot-ext/)
[![version-badge]](https://pypi.python.org/pypi/commanderbot-ext/)
[![package-badge]](https://pypi.python.org/pypi/commanderbot/)
[![version-badge]](https://pypi.python.org/pypi/commanderbot/)

[package-badge]: https://img.shields.io/pypi/v/commanderbot-ext.svg
[version-badge]: https://img.shields.io/pypi/pyversions/commanderbot-ext.svg
## Requirements

- Python 3.10+
- discord.py 2.0+

## Running your bot

You can run your own bot without writing any code.

You will need the following:

1. Your own [Discord Application](https://discordapp.com/developers/applications) with a bot token.
2. A [configuration file](#configuring-your-bot) for the bot.
3. A Python 3.10+ environment with the `commanderbot` package installed.
- It is recommended to use a [virtual environment](https://docs.python.org/3/tutorial/venv.html) for this.
- Run `pip install commanderbot` to install the bot core package.

The first thing you should do is check the CLI help menu:

```bash
python -m commanderbot --help
```

There are three ways to provide your bot token:

1. (Recommended) As the `BOT_TOKEN` environment variable: `BOT_TOKEN=put_your_bot_token_here`
2. As a CLI option: `--token put_your_bot_token_here`
3. Manually, when prompted during start-up

Here's an example that provides the bot token as an argument:

```bash
python -m commanderbot bot.json --token put_your_bot_token_here
```

## Configuring your bot

The current set of configuration options is limited. Following is an example configuration that sets the command prefix and loads the `status` and `faq` extensions.

> Note that with this configuration, the `faq` extension will require read-write access to `faq.json` in the working directory.

```json
{
"command_prefix": ">",
"extensions": [
"commanderbot.ext.status",
{
"name": "commanderbot.ext.faq",
"enabled": true,
"options": {
"database": "faq.json",
"prefix": "?"
}
}
]
}
```

[package-badge]: https://img.shields.io/pypi/v/commanderbot.svg
[version-badge]: https://img.shields.io/pypi/pyversions/commanderbot.svg
File renamed without changes.
3 changes: 3 additions & 0 deletions commanderbot/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from commanderbot.core.cli import run

run()
File renamed without changes.
70 changes: 70 additions & 0 deletions commanderbot/core/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import argparse
import json
import os
from logging import getLogger

from commanderbot.core.commander_bot import CommanderBot
from commanderbot.lib.logging import setup_logging

__all__ = ("run",)


def run():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("config", help="Configuration file")
arg_parser.add_argument(
"--token",
help="Bot token (prefer using the BOT_TOKEN environment variable)",
)
arg_parser.add_argument(
"--tokenfile",
help="Bot token file (prefer using the BOT_TOKEN environment variable)",
)
arg_parser.add_argument("--log", help="Log level", default="WARNING")
parsed_args = arg_parser.parse_args()

setup_logging(parsed_args.log, detailed=True)

log = getLogger(__name__)

log.info("Hello!")

log.info(f"Log level: {parsed_args.log}")
log.info(f"Configuration file: {parsed_args.config}")

log.debug("Parsing configuration file...")

config = json.load(open(parsed_args.config))

log.debug("Successfully parsed configuration file!")

log.info(f"Number of configuration keys: {len(config)}")

bot_token = os.environ.get("BOT_TOKEN", None)

if not bot_token:
log.warning(
"Bot token provided in a form other than the BOT_TOKEN environment variable."
)

if parsed_args.token:
log.info("Using bot token provided as an argument.")
bot_token = parsed_args.token

elif parsed_args.tokenfile:
log.info(f"Reading bot token from file: {parsed_args.tokenfile}")
with open(os.path.abspath(parsed_args.tokenfile)) as fp:
bot_token = fp.read()

else:
bot_token = input("Enter bot token: ")

log.warning("Running bot...")

bot = CommanderBot(**config)

bot.run(bot_token)

log.warning("Bot has shut down.")

log.info("Goodbye!")
Loading