Skip to content

Commit 67cc96d

Browse files
authored
Update to Python 3.10 and discord.py 2.0 beta (#46)
* Update to Python 3.10 and discord.py 2.0 beta * Bump alpha version * Update ping * Update status * Update and improve/compact quote * Update kick * Update poster_board * Update jira * Update vote * Update pack * Update and improve `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) * Implement finer-grained permissions for `roles` (fixes #18) * Update `invite` * Update `faq` * Update and improve `automod` - Even data now includes `user` fields. (fixes #43) - Even data now include member date fields by default. - `message` triggers now allow basic matching of message content. (fixes #44) * Update `help_chat` * Update readme * Account for threads in `faq` * Account for threads in `automod` * Update `manifest` * Make commanderbot-ext independent This involves moving the bot core from cb-core to cb-ext, removing the dependency, and restructuring the imports. * Update black and isort * Support `allowed_mentions` in root bot config (fixes #52) * Move root module * Update imports * Update extensions * Update readme * Update changelog * Update codeowners * Update pyproject.toml * Update readme
1 parent 45c86d0 commit 67cc96d

File tree

219 files changed

+2856
-1732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+2856
-1732
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* @arcensoth
22

3-
/commanderbot_ext/ext/pack @vberlier @arcensoth
3+
/commanderbot/ext/pack @vberlier @arcensoth

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.pytest_cache/**
22
**/__pycache__
33
venv/**
4+
.venv/**
45
bot/**
56
dist/**
67
*.egg-info/**
78

89
.vscode/**
10+
911
.python-version

CHANGELOG.md

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@ All notable changes to this project will be documented in this file.
44

55
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).
66

7+
## [Unreleased]
8+
9+
### Changed
10+
11+
- Updated to Python 3.10 (release candidate).
12+
- Updated to the discord.py 2.0 beta.
13+
- Updated all extensions past breaking changes.
14+
- `commanderbot-core` has been merged into `commanderbot-ext`.
15+
- The repository has been renamed to `commanderbot-py`.
16+
- The package has been renamed to `commanderbot` (which used to belong to `commanderbot-core`).
17+
- Exception handling logic has been reworked.
18+
- Fixes #53
19+
- Reconsidered all commands to use a `ctx.reply` wrapper with pings disabled.
20+
- Fixes #42
21+
- `allowed_mentions` field in root bot config is now supported.
22+
- Fixes #52
23+
- `automod`:
24+
- Even data now includes `user` fields.
25+
- Fixes #43
26+
- Even data now includes member date fields by default.
27+
- `message` triggers now allow basic matching of message content.
28+
- Fixes #44
29+
- `roles`:
30+
- Unresolved roles are now deregistered and cleaned-up automatically.
31+
- Fixes #47
32+
- Elevated commands can no longer add/remove unregistered roles to/from users.
33+
- Fixes #48
34+
- Users can now join/leave multiple roles in one command.
35+
- Fixes #49
36+
- Multiple roles can now be added/removed to/from multiple members all in one command.
37+
- Roles can now be targeted using a partial name match.
38+
- Fixes #50
39+
- Roles can now be configured to be able to run elevated commands.
40+
- Fixes #18
41+
742
## [0.15.0] - 2021-08-29
843

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

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

149-
[unreleased]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.15.0...HEAD
150-
[0.15.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.14.0...v0.15.0
151-
[0.14.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.13.0...v0.14.0
152-
[0.13.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.12.0...v0.13.0
153-
[0.12.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.11.0...v0.12.0
154-
[0.11.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.10.0...v0.11.0
155-
[0.10.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.9.0...v0.10.0
156-
[0.9.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.8.0...v0.9.0
157-
[0.8.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.7.0...v0.8.0
158-
[0.7.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.6.0...v0.7.0
159-
[0.6.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.5.0...v0.6.0
160-
[0.5.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.4.0...v0.5.0
161-
[0.4.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.3.0...v0.4.0
162-
[0.3.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.2.0...v0.3.0
163-
[0.2.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/compare/v0.1.0...v0.2.0
164-
[0.1.0]: https://github.com/CommanderBot-Dev/commanderbot-ext/releases/tag/v0.1.0
184+
[unreleased]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.15.0...HEAD
185+
[0.15.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.14.0...v0.15.0
186+
[0.14.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.13.0...v0.14.0
187+
[0.13.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.12.0...v0.13.0
188+
[0.12.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.11.0...v0.12.0
189+
[0.11.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.10.0...v0.11.0
190+
[0.10.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.9.0...v0.10.0
191+
[0.9.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.8.0...v0.9.0
192+
[0.8.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.7.0...v0.8.0
193+
[0.7.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.6.0...v0.7.0
194+
[0.6.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.5.0...v0.6.0
195+
[0.5.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.4.0...v0.5.0
196+
[0.4.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.3.0...v0.4.0
197+
[0.3.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.2.0...v0.3.0
198+
[0.2.0]: https://github.com/CommanderBot-Dev/commanderbot-py/compare/v0.1.0...v0.2.0
199+
[0.1.0]: https://github.com/CommanderBot-Dev/commanderbot-py/releases/tag/v0.1.0

README.md

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,67 @@
1-
# CommanderBot Ext
1+
# commanderbot-py
22

3-
A collection of cogs and extensions for discord.py bots.
3+
A collection of utilities and extensions for discord.py bots.
44

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

8-
[package-badge]: https://img.shields.io/pypi/v/commanderbot-ext.svg
9-
[version-badge]: https://img.shields.io/pypi/pyversions/commanderbot-ext.svg
8+
## Requirements
9+
10+
- Python 3.10+
11+
- discord.py 2.0+
12+
13+
## Running your bot
14+
15+
You can run your own bot without writing any code.
16+
17+
You will need the following:
18+
19+
1. Your own [Discord Application](https://discordapp.com/developers/applications) with a bot token.
20+
2. A [configuration file](#configuring-your-bot) for the bot.
21+
3. A Python 3.10+ environment with the `commanderbot` package installed.
22+
- It is recommended to use a [virtual environment](https://docs.python.org/3/tutorial/venv.html) for this.
23+
- Run `pip install commanderbot` to install the bot core package.
24+
25+
The first thing you should do is check the CLI help menu:
26+
27+
```bash
28+
python -m commanderbot --help
29+
```
30+
31+
There are three ways to provide your bot token:
32+
33+
1. (Recommended) As the `BOT_TOKEN` environment variable: `BOT_TOKEN=put_your_bot_token_here`
34+
2. As a CLI option: `--token put_your_bot_token_here`
35+
3. Manually, when prompted during start-up
36+
37+
Here's an example that provides the bot token as an argument:
38+
39+
```bash
40+
python -m commanderbot bot.json --token put_your_bot_token_here
41+
```
42+
43+
## Configuring your bot
44+
45+
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.
46+
47+
> Note that with this configuration, the `faq` extension will require read-write access to `faq.json` in the working directory.
48+
49+
```json
50+
{
51+
"command_prefix": ">",
52+
"extensions": [
53+
"commanderbot.ext.status",
54+
{
55+
"name": "commanderbot.ext.faq",
56+
"enabled": true,
57+
"options": {
58+
"database": "faq.json",
59+
"prefix": "?"
60+
}
61+
}
62+
]
63+
}
64+
```
65+
66+
[package-badge]: https://img.shields.io/pypi/v/commanderbot.svg
67+
[version-badge]: https://img.shields.io/pypi/pyversions/commanderbot.svg
File renamed without changes.

commanderbot/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from commanderbot.core.cli import run
2+
3+
run()
File renamed without changes.

commanderbot/core/cli.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import argparse
2+
import json
3+
import os
4+
from logging import getLogger
5+
6+
from commanderbot.core.commander_bot import CommanderBot
7+
from commanderbot.lib.logging import setup_logging
8+
9+
__all__ = ("run",)
10+
11+
12+
def run():
13+
arg_parser = argparse.ArgumentParser()
14+
arg_parser.add_argument("config", help="Configuration file")
15+
arg_parser.add_argument(
16+
"--token",
17+
help="Bot token (prefer using the BOT_TOKEN environment variable)",
18+
)
19+
arg_parser.add_argument(
20+
"--tokenfile",
21+
help="Bot token file (prefer using the BOT_TOKEN environment variable)",
22+
)
23+
arg_parser.add_argument("--log", help="Log level", default="WARNING")
24+
parsed_args = arg_parser.parse_args()
25+
26+
setup_logging(parsed_args.log, detailed=True)
27+
28+
log = getLogger(__name__)
29+
30+
log.info("Hello!")
31+
32+
log.info(f"Log level: {parsed_args.log}")
33+
log.info(f"Configuration file: {parsed_args.config}")
34+
35+
log.debug("Parsing configuration file...")
36+
37+
config = json.load(open(parsed_args.config))
38+
39+
log.debug("Successfully parsed configuration file!")
40+
41+
log.info(f"Number of configuration keys: {len(config)}")
42+
43+
bot_token = os.environ.get("BOT_TOKEN", None)
44+
45+
if not bot_token:
46+
log.warning(
47+
"Bot token provided in a form other than the BOT_TOKEN environment variable."
48+
)
49+
50+
if parsed_args.token:
51+
log.info("Using bot token provided as an argument.")
52+
bot_token = parsed_args.token
53+
54+
elif parsed_args.tokenfile:
55+
log.info(f"Reading bot token from file: {parsed_args.tokenfile}")
56+
with open(os.path.abspath(parsed_args.tokenfile)) as fp:
57+
bot_token = fp.read()
58+
59+
else:
60+
bot_token = input("Enter bot token: ")
61+
62+
log.warning("Running bot...")
63+
64+
bot = CommanderBot(**config)
65+
66+
bot.run(bot_token)
67+
68+
log.warning("Bot has shut down.")
69+
70+
log.info("Goodbye!")

0 commit comments

Comments
 (0)