forked from cswimr/SeaCogs
Compare commits
236 commits
aurora-hyb
...
main
Author | SHA1 | Date | |
---|---|---|---|
7af8e02462 | |||
a40f78e88f | |||
216fa74a53 | |||
901c10a458 | |||
1150115171 | |||
8d4d61c017 | |||
23f2aaa2ee | |||
8b6d269e1a | |||
8c323e36a9 | |||
1392a9324a | |||
9cba1767e6 | |||
cbfff6d211 | |||
56d1e14454 | |||
571be4e245 | |||
6b2793e692 | |||
ad0bb7cf00 | |||
1244d5a941 | |||
1c0f12660b | |||
b4a54d214d | |||
260438f397 | |||
5bfb74de47 | |||
b7bde42672 | |||
0f36badbea | |||
f04b452396 | |||
7d4a6b9930 | |||
f6570dd072 | |||
ff68d6ea19 | |||
825a373a9b | |||
d173dd68a5 | |||
24239425c5 | |||
e3e96e5b84 | |||
28f814db56 | |||
7354769962 | |||
2ac1dacd19 | |||
66b933569b | |||
c06db07f08 | |||
46f189a297 | |||
545106d496 | |||
037a26deb0 | |||
f51329524c | |||
5b23f2f0fb | |||
8f492cd937 | |||
dfabac55f5 | |||
4f25e3d0f3 | |||
7207cd3747 | |||
069ea800db | |||
58245c621c | |||
b9f0dbf98a | |||
2d895d16c9 | |||
861a03719b | |||
ac5d4df36b | |||
ae8d0d5db4 | |||
0ea80075f6 | |||
8d3f5c1d5f | |||
42e209b547 | |||
0ed96babdb | |||
29b6a2141a | |||
c4ef2a7d4b | |||
99cd13ccf1 | |||
28246121a6 | |||
a641cae640 | |||
2886d5e80d | |||
50094b85fc | |||
7f46d6accc | |||
cb6ddabb4d | |||
8608e6a34e | |||
fb468ee63e | |||
b27a3ee778 | |||
54491cb9c9 | |||
29bb64b35c | |||
5ffc42480a | |||
7d51814a28 | |||
25fdf7b402 | |||
091f4fe36d | |||
d444242245 | |||
7a2ee0a655 | |||
8b68cb7530 | |||
028cae9e99 | |||
aa7e347a95 | |||
93f358cfad | |||
8867cc627f | |||
e2059eac77 | |||
e9c062afa9 | |||
ee9b62db5b | |||
1405dae49e | |||
7ed836a1cd | |||
d95c9b3255 | |||
c9a47603a7 | |||
d8758cfb1d | |||
3fd91d9776 | |||
d556ee3704 | |||
7019b9ffe5 | |||
5116598788 | |||
2dcbcb0a59 | |||
059badaa9b | |||
84d2728d3a | |||
bb1aca83dd | |||
59848fe857 | |||
516c0feecc | |||
7bd9531b58 | |||
09ab8aa69d | |||
fb34593707 | |||
ebdd3e3525 | |||
e1bfa79cb9 | |||
e59503829f | |||
d126f1e6d3 | |||
66df7664a5 | |||
ce53908938 | |||
8f6afe754d | |||
aa6e0d7590 | |||
d65d04fa7a | |||
bc9bc53967 | |||
2b5a00f512 | |||
4bf3e85df2 | |||
ce595e50da | |||
9ed16a44f2 | |||
59097b676d | |||
537b2edafa | |||
8ebb383a84 | |||
1ed1eb2681 | |||
a02a7ab3d7 | |||
80dcfea95e | |||
7ae8226ca5 | |||
b910d8c614 | |||
d87c37239d | |||
c266997a78 | |||
20c3007306 | |||
8fdf587bde | |||
ea1f7a7f8e | |||
384ce7fc6d | |||
c618f9be72 | |||
99c20c6054 | |||
4370b4ca9a | |||
f4646a1976 | |||
76e9c1ec0d | |||
bd48b43517 | |||
d6f33857a3 | |||
6c56ee6181 | |||
6c859d72a8 | |||
1d1795c262 | |||
af108519f9 | |||
a641b11daa | |||
38b0580228 | |||
cd514d0535 | |||
908fed37bc | |||
7ef13016d9 | |||
877f5e00d3 | |||
bcef643349 | |||
1a74ce9130 | |||
67142c6458 | |||
dc8138bd89 | |||
f9e807957f | |||
8e59b5a4bd | |||
6966ea1613 | |||
752a41855a | |||
0642d5eb42 | |||
ebf739b563 | |||
f6b827c64f | |||
b8a4d247f8 | |||
a7fcbc4dab | |||
1a23a2778a | |||
acb737f0a6 | |||
ce7e39d385 | |||
d0474a3707 | |||
d17a7e645f | |||
aaf9ac1b4e | |||
dbe6fc2390 | |||
b67b692201 | |||
15715dff3c | |||
73b0e73ff0 | |||
d9c123d441 | |||
4f38fc1f7d | |||
602d759e67 | |||
3da2d74a48 | |||
4344d26096 | |||
285257eed5 | |||
2b7f320d2a | |||
df970717c2 | |||
97b54b507b | |||
06e011f670 | |||
0955282325 | |||
19fc6adaad | |||
7ca836759f | |||
833d6954cc | |||
b9e06d6288 | |||
f28a8aad0e | |||
a9c2f18b5d | |||
f0bc915da8 | |||
46b7123fdd | |||
04c3b0e83c | |||
33ce8a147c | |||
01b249fbb3 | |||
f572a0d535 | |||
9f7244cd65 | |||
a4f2d21fa1 | |||
ba25078f3f | |||
3066848853 | |||
0ed7ab6727 | |||
f713780d49 | |||
5adaca755d | |||
09d7f634f2 | |||
069621eee8 | |||
76da85365c | |||
1edb08a127 | |||
43464db6a7 | |||
50d1d7900b | |||
6ec79c9f92 | |||
9f6e960a25 | |||
46b534ebf8 | |||
74f58162de | |||
39808f1766 | |||
014025f547 | |||
9b0a11a7bc | |||
6ab593390c | |||
7c16ec8df8 | |||
cbd9f28f38 | |||
c546fa597b | |||
7b859e07e9 | |||
5f4cb88ea8 | |||
4135cd4f98 | |||
d6bccf20e9 | |||
7a75266b01 | |||
25b26322d2 | |||
|
40b846123f | ||
4c603eea46 | |||
92e8ee2dc2 | |||
99dddf2fa7 | |||
ba7a5f9208 | |||
ddb9f30d6f | |||
3b5932bac9 | |||
f4efcb8ea5 | |||
6035aea5c6 | |||
03c14a0311 | |||
56522e51ad | |||
9eff010b35 | |||
c0195f44f6 |
66 changed files with 9298 additions and 2968 deletions
|
@ -80,9 +80,23 @@ Manage the immunity whitelist.
|
|||
- Usage: `[p]aurora timedelta <duration>`
|
||||
- Aliases: `tdc, td, and timedeltaconvert`
|
||||
|
||||
This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.
|
||||
This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.You cannot convert years or months as they are not fixed units. Use `[p]aurora relativedelta` for that.
|
||||
|
||||
**Example usage**
|
||||
`[p]timedelta 1 day 15hr 82 minutes 52s`
|
||||
`[p]aurora timedelta 1 day 15hr 82 minutes 52s`
|
||||
|
||||
**Output**
|
||||
`1 day, 16:22:52`
|
||||
|
||||
### aurora relativedelta
|
||||
|
||||
- Usage: `[p]aurora relativedelta <duration>`
|
||||
- Aliases: `rdc, rd, and relativedeltaconvert`
|
||||
|
||||
This command converts a duration to a [`relativedelta`](https://dateutil.readthedocs.io/en/stable/relativedelta.html) Python object.
|
||||
|
||||
**Example usage**
|
||||
`[p]aurora relativedelta 3 years 1 day 15hr 82 minutes 52s`
|
||||
|
||||
**Output**
|
||||
`relativedelta(years=+3, days=+1, hours=+15, minutes=+82, seconds=+52)`
|
||||
|
|
|
@ -10,7 +10,7 @@ Aurora is a fully-featured moderation system. It is heavily inspired by Galactic
|
|||
## Installation
|
||||
|
||||
```bash
|
||||
[p]repo add seacogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add seacogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
[p]cog install seacogs aurora
|
||||
[p]cog load aurora
|
||||
```
|
||||
|
|
|
@ -23,19 +23,27 @@ Add a note to a user.
|
|||
|
||||
Warn a user.
|
||||
|
||||
## blacklist
|
||||
## addrole
|
||||
|
||||
/// admonition | This command is unfinished, and doesn't currently work.
|
||||
type: warning
|
||||
///
|
||||
|
||||
- Usage: `/blacklist <target> <role> <reason> [silent]`
|
||||
- `target:` (Required) Who are you blacklisting?
|
||||
- `role:` (Required) What blacklist type are you applying to the target?
|
||||
- `reason:` (Required) Why are you blacklisting this user?
|
||||
- Usage: `/addrole <target> <role> <reason> [duration] [silent]`
|
||||
- `target:` (Required) Who are you adding a role to?
|
||||
- `role:` (Required) What role are you adding to the target?
|
||||
- `reason:` (Required) Why are you adding a role to this user?
|
||||
- `duration:` (Optional) How long are you adding this role for?
|
||||
- `silent:` (Optional) Should the user be messaged?
|
||||
|
||||
Add a blacklist role to a user.
|
||||
Add a role to a user.
|
||||
|
||||
## removerole
|
||||
|
||||
- Usage: `/removerole <target> <role> <reason> [duration] [silent]`
|
||||
- `target:` (Required) Who are you removing a role from?
|
||||
- `role:` (Required) What role are you removing from the target?
|
||||
- `reason:` (Required) Why are you removing a role from this user?
|
||||
- `duration:` (Optional) How long are you removing this role for?
|
||||
- `silent:` (Optional) Should the user be messaged?
|
||||
|
||||
Remove a role from a user.
|
||||
|
||||
## mute
|
||||
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
# Backup
|
||||
|
||||
Backup allows you to export a JSON list of all of your installed repositories and cogs, then reimport them and automatically reinstall/reload the cogs.
|
||||
Backup allows you to export a JSON list of all of your installed repositories and cogs, then reimport them and automatically reinstall the cogs.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
[p]repo add seacogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add seacogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
[p]cog install seacogs backup
|
||||
[p]cog load backup
|
||||
```
|
||||
|
||||
## Version Compatibility
|
||||
|
||||
As of commit [1edb08a](https://www.coastalcommits.com/cswimr/SeaCogs/commit/1edb08a1271f12098ca0bed11a735f7162cedd14), the Backup cog no longer supports Red versions older than 3.5.6. If you want to use the cog on an earlier version (3.5.0 - 3.5.5), install the cog pinned to this commit: `43464db6a7c51bc69282b1ae3dc507a4aae851de`.
|
||||
|
||||
```bash
|
||||
[p]cog installversion sea-cogs 43464db6a7c51bc69282b1ae3dc507a4aae851de backup
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
### backup export
|
||||
|
|
|
@ -6,7 +6,7 @@ This cog does require an api key to work.
|
|||
## Installation
|
||||
|
||||
```bash
|
||||
[p]repo add seacogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add seacogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
[p]cog install seacogs bible
|
||||
[p]cog load bible
|
||||
```
|
||||
|
|
19
.docs/emojiinfo.md
Normal file
19
.docs/emojiinfo.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# EmojiInfo
|
||||
|
||||
EmojiInfo allows you to retrieve information about an emoji.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
[p]repo add seacogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
[p]cog install seacogs emojiinfo
|
||||
[p]cog load emojiinfo
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
### emoji
|
||||
|
||||
- Usage: `[p]emoji <emoji> [ephemeral]`
|
||||
|
||||
Retrieve information about the provided emoji. If `ephemeral` is provided and the command is used as a slash command, the response will be sent as an ephemeral message.
|
|
@ -5,7 +5,7 @@ Nerdify allows you to nerdify other people's text.
|
|||
## Installation
|
||||
|
||||
```bash
|
||||
[p]repo add seacogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add seacogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
[p]cog install seacogs nerdify
|
||||
[p]cog load nerdify
|
||||
```
|
||||
|
|
|
@ -39,7 +39,9 @@ Default value:
|
|||
tellraw @a ["",{"text":".$N ","color":".$C","insertion":"<@.$I>","hoverEvent":{"action":"show_text","contents":"Shift click to mention this user inside Discord"}},{"text":"(DISCORD):","color":"blue","clickEvent":{"action":"open_url","value":".$V"},"hoverEvent":{"action":"show_text","contents":"Click to join the Discord Server"}},{"text":" .$M","color":"white"}]
|
||||
```
|
||||
|
||||
## `consolechannel`
|
||||
## `console`
|
||||
|
||||
### `channel`
|
||||
|
||||
/// admonition | Only give access to the console channel to people you trust!
|
||||
type: danger
|
||||
|
@ -63,6 +65,21 @@ This is to prevent the console channel from flooding and getting backed up by Di
|
|||
|
||||
Default value: `None`
|
||||
|
||||
### `commands`
|
||||
|
||||
/// admonition | This has no effect on the `[p]pterodactyl command` text command, or the matching slash command.
|
||||
type: danger
|
||||
If you want to disable the ability to execute commands on the server through Discord, use the following commands:
|
||||
`[p]pterodactyl config console commands False` - this command
|
||||
`[p]command disable pterodactyl command` - disables the text command that lets you execute commands on the server
|
||||
`[p]slash disable pterodactyl` - due to how slash commands are laid out, this is the only way to disable the ability to execute commands on the server
|
||||
`[p]slash sync` - apply above slash command change
|
||||
///
|
||||
|
||||
This option determines if commands sent to the console channel will be sent to the Pterodactyl console.
|
||||
|
||||
Default value: `False`
|
||||
|
||||
## `invite`
|
||||
|
||||
This option determines what url the chat command will substitute in for the Discord invite placeholder.
|
||||
|
@ -136,6 +153,41 @@ This option determines which server's websocket to connect to. See [Getting Star
|
|||
|
||||
Default value: `None`
|
||||
|
||||
## `topic`
|
||||
|
||||
### `host`
|
||||
|
||||
This option determines the hostname of your server that will be used to retrieve server information.
|
||||
|
||||
### `port`
|
||||
|
||||
This option determines the port of your server that will be used to retrieve server information.
|
||||
|
||||
Default value: `25565`
|
||||
|
||||
### `text`
|
||||
|
||||
This option determines what the channel topic will be set to.
|
||||
|
||||
Available placeholders:
|
||||
|
||||
- `.$H` - replaced with the server's hostname
|
||||
- `.$O` - replaced with the server's port
|
||||
|
||||
Available with a Minecraft server:
|
||||
|
||||
- `.$I` - replaced with the server's ip address
|
||||
- `.$M` - replaced with maximum player count
|
||||
- `.$P` - replaced with current online player count
|
||||
- `.$V` - replaced with the server's current version
|
||||
- `.$D` - replaced with the server's description / message of the day
|
||||
|
||||
Default value:
|
||||
|
||||
```
|
||||
Server IP: .$H\nServer Players: .$P/.$M
|
||||
```
|
||||
|
||||
## `url`
|
||||
|
||||
This option determines what panel the cog will send requests to. See [Getting Started](getting-started.md#getting-server-information) for more information on this.
|
||||
|
|
|
@ -28,7 +28,7 @@ The Downloader cog allows you to add Git repositories to your bot in order to do
|
|||
Now, use Downloader to add my repository to your bot:
|
||||
|
||||
```
|
||||
[p]repo add sea-cogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add sea-cogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
```
|
||||
|
||||
Now, install the Pterodactyl cog:
|
||||
|
|
|
@ -10,7 +10,7 @@ Pterodactyl allows for connecting to a Pterodactyl server through websockets. It
|
|||
## Installation
|
||||
|
||||
```bash
|
||||
[p]repo add seacogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add seacogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
[p]cog install seacogs pterodactyl
|
||||
[p]cog load aurora
|
||||
```
|
||||
|
|
|
@ -10,7 +10,7 @@ There are a few caveats to running an instance of Red on Pterodactyl.
|
|||
|
||||
- You will not receive any support from the Red developers.
|
||||
- The built-in Audio cog will not work.
|
||||
- Depending on your host, you might have to request a [`tmpfs` size increase](https://github.com/ign-gg/Pterodactyl-Eggs/tree/master/bots/discord/redbot#additional-requirements).
|
||||
- Depending on your host, you might have to request a [`tmpfs` size increase](https://github.com/pelican-eggs/eggs/tree/master/bots/discord/redbot#additional-requirements).
|
||||
|
||||
If these are unacceptable to you, you should [install Red normally](https://docs.discord.red/en/stable/install_guides/index.html).
|
||||
///
|
||||
|
@ -64,7 +64,7 @@ Red is quite a large bot, so I'll focus on the specifics of getting the bot work
|
|||
```
|
||||
2. Add my repository to the bot
|
||||
```bash
|
||||
[p]repo add sea-cogs https://www.coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
[p]repo add sea-cogs https://www.coastalcommits.com/cswimr/SeaCogs
|
||||
```
|
||||
3. Install and load the Pterodactyl cog
|
||||
```bash
|
||||
|
|
10
.envrc
Normal file
10
.envrc
Normal file
|
@ -0,0 +1,10 @@
|
|||
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
|
||||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
|
||||
fi
|
||||
|
||||
watch_file flake.nix
|
||||
watch_file flake.lock
|
||||
if ! use flake . --no-pure-eval
|
||||
then
|
||||
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
|
||||
fi
|
|
@ -1,23 +0,0 @@
|
|||
---
|
||||
name: Bug Report
|
||||
about: Got an issue with a cog from SeaCogs? Use this.
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
What caused the error?
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
53
.forgejo/ISSUE_TEMPLATE/bug_report.yaml
Normal file
53
.forgejo/ISSUE_TEMPLATE/bug_report.yaml
Normal file
|
@ -0,0 +1,53 @@
|
|||
name: Bug Report
|
||||
about: File a bug report
|
||||
labels: [bug]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you for taking the time to fill out this bug report!
|
||||
- type: checkboxes
|
||||
id: confirmation
|
||||
attributes:
|
||||
label: Please confirm that;
|
||||
options:
|
||||
- label: I have checked that this bug does not already have an opened/closed [issue](https://www.coastalcommits.com/cswimr/SeaCogs/issues) or [pull request](https://www.coastalcommits.com/cswimr/SeaCogs/pulls) associated with it.
|
||||
required: true
|
||||
- label: I have checked that I am on the latest version of [Red-DiscordBot](https://github.com/CogCreators/Red-DiscordBot), and SeaCogs.
|
||||
required: true
|
||||
- type: input
|
||||
id: hosting
|
||||
attributes:
|
||||
label: Hosting
|
||||
description: How is your bot hosted?
|
||||
placeholder: Local, Docker, etc.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: Also, what did you expect to happen?
|
||||
placeholder: A bug happened!
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: Reproduction steps
|
||||
description: Please provide detailed steps to reproduce the bug.
|
||||
placeholder: |
|
||||
1. Do this
|
||||
2. Do that
|
||||
3. Do this other thing
|
||||
4. Bug happens!
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Relevant traceback or logs
|
||||
description: Please copy and paste any relevant tracebacks or log output. This will be automatically formatted into code, so no need for backticks.
|
||||
render: py
|
||||
validations:
|
||||
required: false
|
5
.forgejo/ISSUE_TEMPLATE/config.yaml
Normal file
5
.forgejo/ISSUE_TEMPLATE/config.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Other Concerns?
|
||||
url: https://discord.gg/eMUMe77Yb8
|
||||
about: Ask in our Discord server!
|
|
@ -1,26 +0,0 @@
|
|||
---
|
||||
name: Suggestion
|
||||
about: Trying to suggest something for SeaCogs? Use this.
|
||||
title: "[SUGGESTION]"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**What cog is your feature request for?**
|
||||
A cog in this repository.
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
53
.forgejo/ISSUE_TEMPLATE/suggestion.yaml
Normal file
53
.forgejo/ISSUE_TEMPLATE/suggestion.yaml
Normal file
|
@ -0,0 +1,53 @@
|
|||
name: Suggestion
|
||||
about: Trying to suggest something for SeaCogs? Use this.
|
||||
labels: [enhancement]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you for taking the time to suggest an enhancement!
|
||||
- type: input
|
||||
id: cog
|
||||
attributes:
|
||||
label: What cog is your feature request for?
|
||||
description: Specify the cog within the repository.
|
||||
placeholder: E.g., Pterodactyl
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: problem-description
|
||||
attributes:
|
||||
label: Is your feature request related to a problem? Please describe.
|
||||
placeholder: A clear and concise description of what the problem is.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: solution-description
|
||||
attributes:
|
||||
label: Describe the solution you'd like
|
||||
placeholder: A clear and concise description of what you want to happen.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
placeholder: A clear and concise description of any alternative solutions or features you've considered.
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: Screenshots
|
||||
description: If applicable, add screenshots to help explain your problem.
|
||||
placeholder: Paste image links here.
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: additional-context
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context about the problem here.
|
||||
placeholder: Any extra information you think might be useful.
|
||||
validations:
|
||||
required: false
|
6
.forgejo/pull_request_template.md
Normal file
6
.forgejo/pull_request_template.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Describe what your pull request does and which issue you're targeting
|
||||
|
||||
<!-- Create a new issue, if it doesn't exist yet -->
|
||||
|
||||
- [ ] By submitting this pull request, I permit cswimr to license my work under
|
||||
the [Mozilla Public License Version 2.0](https://www.coastalcommits.com/cswimr/SeaCogs/src/branch/main/LICENSE).
|
|
@ -17,4 +17,6 @@
|
|||
import-outside-toplevel,
|
||||
import-self,
|
||||
relative-beyond-top-level,
|
||||
too-many-instance-attributes
|
||||
too-many-instance-attributes,
|
||||
duplicate-code,
|
||||
too-many-nested-blocks
|
||||
|
|
|
@ -1,39 +1,46 @@
|
|||
name: Actions
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
Lint Code (Ruff & Pylint):
|
||||
lint:
|
||||
name: Lint Code (Ruff & Pylint)
|
||||
runs-on: docker
|
||||
container: www.coastalcommits.com/seaswimmerthefsh/actionscontainers-seacogs:latest
|
||||
container: www.coastalcommits.com/cswimr/actions:uv
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install python
|
||||
run: uv python install 3.11
|
||||
|
||||
- name: Install dependencies
|
||||
run: poetry install --with dev --no-root
|
||||
run: uv sync
|
||||
|
||||
- name: Analysing code with Ruff
|
||||
run: ruff check $(git ls-files '*.py')
|
||||
run: uv run ruff check $(git ls-files '*.py')
|
||||
continue-on-error: true
|
||||
|
||||
- name: Analysing code with Pylint
|
||||
run: pylint --rcfile=.forgejo/workflows/config/.pylintrc $(git ls-files '*.py')
|
||||
run: uv run pylint --rcfile=.forgejo/workflows/config/.pylintrc $(git ls-files '*.py')
|
||||
|
||||
Build Documentation (MkDocs):
|
||||
docs:
|
||||
name: Build Documentation (MkDocs)
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
runs-on: docker
|
||||
container: www.coastalcommits.com/seaswimmerthefsh/actionscontainers-seacogs:latest
|
||||
container: www.coastalcommits.com/cswimr/actions:docs
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install python
|
||||
run: uv python install 3.11
|
||||
|
||||
- name: Install dependencies
|
||||
run: poetry install --with docs --no-root
|
||||
run: uv sync --no-dev --extra=documentation
|
||||
|
||||
- name: Set environment variables
|
||||
uses: actions/env@v2
|
||||
|
@ -42,7 +49,7 @@ jobs:
|
|||
run: |
|
||||
export SITE_URL="https://$CI_ACTION_REF_NAME_SLUG.seacogs.coastalcommits.com"
|
||||
export EDIT_URI="src/branch/$CI_ACTION_REF_NAME/.docs"
|
||||
mkdocs build -v
|
||||
uv run mkdocs build -v
|
||||
|
||||
- name: Deploy documentation
|
||||
run: |
|
||||
|
@ -58,7 +65,7 @@ jobs:
|
|||
npx -p "@getmeli/cli" meli upload ./site \
|
||||
--url "https://pages.coastalcommits.com" \
|
||||
--site "${{ vars.MELI_SITE_ID }}" \
|
||||
--token "${{ secrets.MELI_SITE_SECRET }}" \
|
||||
--token "${{ secrets.MELI_TOKEN }}" \
|
||||
--release "$CI_ACTION_REF_NAME_SLUG/${{ env.GITHUB_SHA }}" \
|
||||
--branch "$CI_ACTION_REF_NAME_SLUG"
|
||||
|
||||
|
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
|||
.cache
|
||||
.vscode
|
||||
site
|
||||
.venv
|
||||
__pycache__
|
||||
.direnv
|
||||
.devenv
|
||||
|
|
|
@ -11,7 +11,7 @@ My assorted cogs for Red-DiscordBot.
|
|||
To get started with a development environment, first clone this repository.
|
||||
|
||||
```sh
|
||||
git clone https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs.git
|
||||
git clone https://coastalcommits.com/cswimr/SeaCogs.git
|
||||
```
|
||||
|
||||
Then, install Poetry.
|
||||
|
|
5
antipolls/__init__.py
Normal file
5
antipolls/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from .antipolls import AntiPolls
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(AntiPolls(bot))
|
181
antipolls/antipolls.py
Normal file
181
antipolls/antipolls.py
Normal file
|
@ -0,0 +1,181 @@
|
|||
# _____ _
|
||||
# / ____| (_)
|
||||
# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __
|
||||
# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__|
|
||||
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
|
||||
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
||||
|
||||
import discord
|
||||
from red_commons.logging import getLogger
|
||||
from redbot.core import commands
|
||||
from redbot.core.bot import Config, Red
|
||||
from redbot.core.utils.chat_formatting import bold, humanize_list
|
||||
|
||||
|
||||
class AntiPolls(commands.Cog):
|
||||
"""AntiPolls deletes messages that contain polls, with a configurable per-guild role and channel whitelist and support for default Discord permissions (Manage Messages)."""
|
||||
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "1.0.1"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/antipolls/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
super().__init__()
|
||||
self.bot = bot
|
||||
self.logger = getLogger("red.SeaCogs.AntiPolls")
|
||||
self.config = Config.get_conf(self, identifier=23517395243, force_registration=True)
|
||||
self.config.register_guild(
|
||||
role_whitelist=[],
|
||||
channel_whitelist=[],
|
||||
manage_messages=True,
|
||||
)
|
||||
if not self.bot.intents.message_content:
|
||||
self.logger.error("Message Content intent is not enabled, cog will not load.")
|
||||
raise RuntimeError("This cog requires the Message Content intent to function. To prevent potentially destructive behavior, the cog will not load without the intent enabled.")
|
||||
|
||||
def format_help_for_context(self, ctx: commands.Context) -> str:
|
||||
pre_processed = super().format_help_for_context(ctx) or ""
|
||||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
async def red_delete_data_for_user(self, **kwargs): # pylint: disable=unused-argument
|
||||
"""Nothing to delete."""
|
||||
return
|
||||
|
||||
@commands.Cog.listener('on_message')
|
||||
async def polls_listener(self, message: discord.Message) -> None:
|
||||
if message.guild is None:
|
||||
return self.logger.verbose("Message in direct messages ignored")
|
||||
|
||||
if message.author.bot:
|
||||
return self.logger.verbose("Message from bot ignored")
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, message.guild):
|
||||
return self.logger.verbose("Message ignored, cog is disabled in guild %s", message.guild.id)
|
||||
|
||||
guild_config = await self.config.guild(message.guild).all()
|
||||
|
||||
if guild_config['manage_messages'] is True and message.author.guild_permissions.manage_messages:
|
||||
return self.logger.verbose("Message from user with Manage Messages permission ignored")
|
||||
|
||||
if message.channel.id in guild_config['channel_whitelist']:
|
||||
return self.logger.verbose("Message in whitelisted channel %s ignored", message.channel.id)
|
||||
|
||||
if any(role.id in guild_config['role_whitelist'] for role in message.author.roles):
|
||||
return self.logger.verbose("Message from whitelisted role %s ignored", message.author.roles)
|
||||
|
||||
if not message.content and not message.embeds and not message.attachments and not message.stickers:
|
||||
self.logger.trace("Message %s is a poll, attempting to delete", message.id)
|
||||
|
||||
try:
|
||||
await message.delete()
|
||||
except discord.HTTPException as e:
|
||||
return self.logger.error("Failed to delete message: %s", e)
|
||||
|
||||
return self.logger.trace("Deleted poll message %s", message.id)
|
||||
self.logger.verbose("Message %s is not a poll, ignoring", message.id)
|
||||
|
||||
@commands.group(name="antipolls", aliases=["ap"])
|
||||
@commands.guild_only()
|
||||
@commands.admin_or_permissions(manage_guild=True)
|
||||
async def antipolls(self, ctx: commands.Context) -> None:
|
||||
"""Manage AntiPolls settings."""
|
||||
|
||||
@antipolls.group(name="roles")
|
||||
async def antipolls_roles(self, ctx: commands.Context) -> None:
|
||||
"""Manage role whitelist."""
|
||||
|
||||
@antipolls_roles.command(name="add")
|
||||
async def antipolls_roles_add(self, ctx: commands.Context, *roles: discord.Role) -> None:
|
||||
"""Add roles to the whitelist."""
|
||||
async with self.config.guild(ctx.guild).role_whitelist() as role_whitelist:
|
||||
role_whitelist: list
|
||||
failed: list[discord.Role] = []
|
||||
for role in roles:
|
||||
if role.id in role_whitelist:
|
||||
failed.append(role)
|
||||
continue
|
||||
role_whitelist.append(role.id)
|
||||
await ctx.tick()
|
||||
if failed:
|
||||
await ctx.send(f"The following roles were already in the whitelist: {humanize_list([role.mention for role in failed])}", delete_after=10)
|
||||
|
||||
@antipolls_roles.command(name="remove")
|
||||
async def antipolls_roles_remove(self, ctx: commands.Context, *roles: discord.Role) -> None:
|
||||
"""Remove roles from the whitelist."""
|
||||
async with self.config.guild(ctx.guild).role_whitelist() as role_whitelist:
|
||||
role_whitelist: list
|
||||
failed: list[discord.Role] = []
|
||||
for role in roles:
|
||||
if role.id not in role_whitelist:
|
||||
failed.append(role)
|
||||
continue
|
||||
role_whitelist.remove(role.id)
|
||||
await ctx.tick()
|
||||
if failed:
|
||||
await ctx.send(f"The following roles were not in the whitelist: {humanize_list([role.mention for role in failed])}", delete_after=10)
|
||||
|
||||
@antipolls_roles.command(name="list")
|
||||
async def antipolls_roles_list(self, ctx: commands.Context) -> None:
|
||||
"""List roles in the whitelist."""
|
||||
role_whitelist = await self.config.guild(ctx.guild).role_whitelist()
|
||||
if not role_whitelist:
|
||||
return await ctx.send("No roles in the whitelist.")
|
||||
roles = [ctx.guild.get_role(role) for role in role_whitelist]
|
||||
await ctx.send(humanize_list([role.mention for role in roles]))
|
||||
|
||||
@antipolls.group(name="channels")
|
||||
async def antipolls_channels(self, ctx: commands.Context) -> None:
|
||||
"""Manage channel whitelist."""
|
||||
|
||||
@antipolls_channels.command(name="add")
|
||||
async def antipolls_channels_add(self, ctx: commands.Context, *channels: discord.TextChannel) -> None:
|
||||
"""Add channels to the whitelist."""
|
||||
async with self.config.guild(ctx.guild).channel_whitelist() as channel_whitelist:
|
||||
channel_whitelist: list
|
||||
failed: list[discord.TextChannel] = []
|
||||
for channel in channels:
|
||||
if channel.id in channel_whitelist:
|
||||
failed.append(channel)
|
||||
continue
|
||||
channel_whitelist.append(channel.id)
|
||||
await ctx.tick()
|
||||
if failed:
|
||||
await ctx.send(f"The following channels were already in the whitelist: {humanize_list([channel.mention for channel in failed])}", delete_after=10)
|
||||
|
||||
@antipolls_channels.command(name="remove")
|
||||
async def antipolls_channels_remove(self, ctx: commands.Context, *channels: discord.TextChannel) -> None:
|
||||
"""Remove channels from the whitelist."""
|
||||
async with self.config.guild(ctx.guild).channel_whitelist() as channel_whitelist:
|
||||
channel_whitelist: list
|
||||
failed: list[discord.TextChannel] = []
|
||||
for channel in channels:
|
||||
if channel.id not in channel_whitelist:
|
||||
failed.append(channel)
|
||||
continue
|
||||
channel_whitelist.remove(channel.id)
|
||||
await ctx.tick()
|
||||
if failed:
|
||||
await ctx.send(f"The following channels were not in the whitelist: {humanize_list([channel.mention for channel in failed])}", delete_after=10)
|
||||
|
||||
@antipolls_channels.command(name="list")
|
||||
async def antipolls_channels_list(self, ctx: commands.Context) -> None:
|
||||
"""List channels in the whitelist."""
|
||||
channel_whitelist = await self.config.guild(ctx.guild).channel_whitelist()
|
||||
if not channel_whitelist:
|
||||
return await ctx.send("No channels in the whitelist.")
|
||||
channels = [ctx.guild.get_channel(channel) for channel in channel_whitelist]
|
||||
await ctx.send(humanize_list([channel.mention for channel in channels]))
|
||||
|
||||
@antipolls.command(name="managemessages")
|
||||
async def antipolls_managemessages(self, ctx: commands.Context, enabled: bool) -> None:
|
||||
"""Toggle Manage Messages permission check."""
|
||||
await self.config.guild(ctx.guild).manage_messages.set(enabled)
|
||||
await ctx.tick()
|
17
antipolls/info.json
Normal file
17
antipolls/info.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing AntiPolls!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).",
|
||||
"name" : "AntiPolls",
|
||||
"short" : "AntiPolls deletes messages that contain polls.",
|
||||
"description" : "AntiPolls deletes messages that contain polls, with a configurable per-guild role and channel whitelist and support for default Discord permissions (Manage Messages).",
|
||||
"end_user_data_statement" : "This cog does not store any user data.",
|
||||
"hidden": true,
|
||||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
"min_python_version": [3, 10, 0],
|
||||
"tags": [
|
||||
"automod",
|
||||
"automoderation",
|
||||
"polls"
|
||||
]
|
||||
}
|
359
aurora/aurora.py
359
aurora/aurora.py
|
@ -13,14 +13,13 @@ from datetime import datetime, timedelta, timezone
|
|||
from math import ceil
|
||||
|
||||
import discord
|
||||
import humanize
|
||||
from discord import Object
|
||||
from discord.ext import tasks
|
||||
from pytimeparse2 import disable_dateutil, parse
|
||||
from redbot.core import app_commands, commands, data_manager
|
||||
from redbot.core.app_commands import Choice
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import (box, error, humanize_list,
|
||||
warning)
|
||||
from redbot.core.commands.converter import parse_relativedelta, parse_timedelta
|
||||
from redbot.core.utils.chat_formatting import box, error, humanize_list, humanize_timedelta, warning
|
||||
|
||||
from aurora.importers.aurora import ImportAuroraView
|
||||
from aurora.importers.galacticbot import ImportGalacticBotView
|
||||
|
@ -29,17 +28,10 @@ from aurora.menus.guild import Guild
|
|||
from aurora.menus.immune import Immune
|
||||
from aurora.menus.overrides import Overrides
|
||||
from aurora.utilities.config import config, register_config
|
||||
from aurora.utilities.database import (connect, create_guild_table, fetch_case,
|
||||
mysql_log)
|
||||
from aurora.utilities.factory import (addrole_embed, case_factory,
|
||||
changes_factory, evidenceformat_factory,
|
||||
guild_embed, immune_embed,
|
||||
message_factory, overrides_embed)
|
||||
from aurora.utilities.database import connect, create_guild_table, fetch_case, mysql_log
|
||||
from aurora.utilities.factory import addrole_embed, case_factory, changes_factory, evidenceformat_factory, guild_embed, immune_embed, message_factory, overrides_embed
|
||||
from aurora.utilities.logger import logger
|
||||
from aurora.utilities.utils import (check_moddable, check_permissions,
|
||||
convert_timedelta_to_str,
|
||||
fetch_channel_dict, fetch_user_dict,
|
||||
generate_dict, log, send_evidenceformat)
|
||||
from aurora.utilities.utils import check_moddable, check_permissions, convert_timedelta_to_str, fetch_channel_dict, fetch_user_dict, generate_dict, get_footer_image, log, send_evidenceformat, timedelta_from_relativedelta
|
||||
|
||||
|
||||
class Aurora(commands.Cog):
|
||||
|
@ -47,8 +39,9 @@ class Aurora(commands.Cog):
|
|||
It is heavily inspired by GalacticBot, and is designed to be a more user-friendly alternative to Red's core Mod cogs.
|
||||
This cog stores all of its data in an SQLite database."""
|
||||
|
||||
__author__ = ["SeaswimmerTheFsh"]
|
||||
__version__ = "2.0.6"
|
||||
__author__ = ["cswimr"]
|
||||
__version__ = "2.1.3"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/aurora/"
|
||||
|
||||
async def red_delete_data_for_user(self, *, requester, user_id: int):
|
||||
if requester == "discord_deleted_user":
|
||||
|
@ -84,7 +77,6 @@ class Aurora(commands.Cog):
|
|||
super().__init__()
|
||||
self.bot = bot
|
||||
register_config(config)
|
||||
disable_dateutil()
|
||||
self.handle_expiry.start()
|
||||
|
||||
def format_help_for_context(self, ctx: commands.Context) -> str:
|
||||
|
@ -94,6 +86,7 @@ class Aurora(commands.Cog):
|
|||
f"{pre_processed}{n}",
|
||||
f"Cog Version: **{self.__version__}**",
|
||||
f"Author: {humanize_list(self.__author__)}",
|
||||
f"Documentation: {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
@ -121,6 +114,20 @@ class Aurora(commands.Cog):
|
|||
except ConnectionRefusedError:
|
||||
return
|
||||
|
||||
@commands.Cog.listener("on_member_join")
|
||||
async def addrole_on_member_join(self, member: discord.Member):
|
||||
"""This method automatically adds roles to users when they join the server."""
|
||||
if not await self.bot.cog_disabled_in_guild(self, member.guild):
|
||||
query = f"""SELECT moderation_id, role_id, reason FROM moderation_{member.guild.id} WHERE target_id = ? AND moderation_type = 'ADDROLE' AND expired = 0 AND resolved = 0;"""
|
||||
database = connect()
|
||||
cursor = database.cursor()
|
||||
cursor.execute(query, (member.id,))
|
||||
results = cursor.fetchall()
|
||||
for result in results:
|
||||
role = member.guild.get_role(result[1])
|
||||
reason = result[2]
|
||||
await member.add_roles(role, reason=f"Role automatically added on member rejoin for: {reason} (Case #{result[0]:,})")
|
||||
|
||||
@commands.Cog.listener("on_audit_log_entry_create")
|
||||
async def autologger(self, entry: discord.AuditLogEntry):
|
||||
"""This method automatically logs moderations done by users manually ("right clicks")."""
|
||||
|
@ -217,7 +224,7 @@ class Aurora(commands.Cog):
|
|||
moderation_type="note",
|
||||
response=await interaction.original_response(),
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -276,7 +283,7 @@ class Aurora(commands.Cog):
|
|||
moderation_type="warned",
|
||||
response=await interaction.original_response(),
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -332,13 +339,10 @@ class Aurora(commands.Cog):
|
|||
return
|
||||
|
||||
if duration is not None:
|
||||
try:
|
||||
parsed_time = parse(
|
||||
sval=duration, as_timedelta=True, raise_exception=True
|
||||
)
|
||||
except ValueError:
|
||||
parsed_time = parse_timedelta(duration)
|
||||
if parsed_time is None:
|
||||
await interaction.response.send_message(
|
||||
error("Please provide a valid duration!"), ephemeral=True
|
||||
content=error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
else:
|
||||
|
@ -377,16 +381,16 @@ class Aurora(commands.Cog):
|
|||
duration=parsed_time,
|
||||
role=role,
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
await target.add_roles(
|
||||
role,
|
||||
reason=f"Role added by {interaction.user.id}{(' for ' + {humanize.precisedelta(parsed_time)} if parsed_time != 'NULL' else '')} for: {reason}",
|
||||
reason=f"Role added by {interaction.user.id}{' for ' + humanize_timedelta(timedelta=parsed_time) if parsed_time != 'NULL' else ''} for: {reason}",
|
||||
)
|
||||
response: discord.WebhookMessage = await interaction.followup.send(
|
||||
content=f"{target.mention} has been given the {role.mention} role{(' for ' + {humanize.precisedelta(parsed_time)} if parsed_time != 'NULL' else '')}!\n**Reason** - `{reason}`"
|
||||
content=f"{target.mention} has been given the {role.mention} role{' for ' + humanize_timedelta(timedelta=parsed_time) if parsed_time != 'NULL' else ''}!\n**Reason** - `{reason}`"
|
||||
)
|
||||
|
||||
moderation_id = await mysql_log(
|
||||
|
@ -400,7 +404,113 @@ class Aurora(commands.Cog):
|
|||
reason,
|
||||
)
|
||||
await response.edit(
|
||||
content=f"{target.mention} has been given the {role.mention} role{(' for ' + {humanize.precisedelta(parsed_time)} if parsed_time != 'NULL' else '')}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`",
|
||||
content=f"{target.mention} has been given the {role.mention} role{' for ' + humanize_timedelta(timedelta=parsed_time) if parsed_time != 'NULL' else ''}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`",
|
||||
)
|
||||
await log(interaction, moderation_id)
|
||||
|
||||
case = await fetch_case(moderation_id, interaction.guild.id)
|
||||
await send_evidenceformat(interaction, case)
|
||||
|
||||
@app_commands.command(name="removerole")
|
||||
async def removerole(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
target: discord.Member,
|
||||
role: discord.Role,
|
||||
reason: str,
|
||||
duration: str = None,
|
||||
silent: bool = None,
|
||||
):
|
||||
"""Remove a role from a user.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
target: discord.Member
|
||||
Who are you removing a role from?
|
||||
role: discord.Role
|
||||
What role are you removing from the target?
|
||||
reason: str
|
||||
Why are you removing a role from this user?
|
||||
duration: str
|
||||
How long are you removing this role for?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
addrole_whitelist = await config.guild(interaction.guild).addrole_whitelist()
|
||||
|
||||
if not addrole_whitelist:
|
||||
await interaction.response.send_message(
|
||||
content=error("There are no whitelisted roles set for this server!"),
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
|
||||
if duration is not None:
|
||||
parsed_time = parse_timedelta(duration)
|
||||
if parsed_time is None:
|
||||
await interaction.response.send_message(
|
||||
content=error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
else:
|
||||
parsed_time = "NULL"
|
||||
|
||||
if role.id not in addrole_whitelist:
|
||||
await interaction.response.send_message(
|
||||
content=error("That role isn't whitelisted!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
if not await check_moddable(
|
||||
target, interaction, ["moderate_members", "manage_roles"]
|
||||
):
|
||||
return
|
||||
|
||||
if role.id not in [user_role.id for user_role in target.roles]:
|
||||
await interaction.response.send_message(
|
||||
content=error(f"{target.mention} does not have this role!"),
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
|
||||
await interaction.response.defer()
|
||||
if silent is None:
|
||||
silent = not await config.guild(interaction.guild).dm_users()
|
||||
if silent is False:
|
||||
try:
|
||||
embed = await message_factory(
|
||||
await self.bot.get_embed_color(interaction.channel),
|
||||
guild=interaction.guild,
|
||||
moderator=interaction.user,
|
||||
reason=reason,
|
||||
moderation_type="removerole",
|
||||
response=await interaction.original_response(),
|
||||
duration=parsed_time,
|
||||
role=role,
|
||||
)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
await target.remove_roles(
|
||||
role,
|
||||
reason=f"Role removed by {interaction.user.id}{' for ' + humanize_timedelta(timedelta=parsed_time) if parsed_time != 'NULL' else ''} for: {reason}",
|
||||
)
|
||||
response: discord.WebhookMessage = await interaction.followup.send(
|
||||
content=f"{target.mention} has had the {role.mention} role removed{' for ' + humanize_timedelta(timedelta=parsed_time) if parsed_time != 'NULL' else ''}!\n**Reason** - `{reason}`"
|
||||
)
|
||||
|
||||
moderation_id = await mysql_log(
|
||||
interaction.guild.id,
|
||||
interaction.user.id,
|
||||
"REMOVEROLE",
|
||||
"USER",
|
||||
target.id,
|
||||
role.id,
|
||||
parsed_time,
|
||||
reason,
|
||||
)
|
||||
await response.edit(
|
||||
content=f"{target.mention} has had the {role.mention} role removed{' for ' + humanize_timedelta(timedelta=parsed_time) if parsed_time != 'NULL' else ''}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`",
|
||||
)
|
||||
await log(interaction, moderation_id)
|
||||
|
||||
|
@ -440,16 +550,15 @@ class Aurora(commands.Cog):
|
|||
return
|
||||
|
||||
try:
|
||||
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
|
||||
except ValueError:
|
||||
parsed_time = parse_timedelta(duration, maximum=timedelta(days=28))
|
||||
if parsed_time is None:
|
||||
await interaction.response.send_message(
|
||||
error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
except commands.BadArgument:
|
||||
await interaction.response.send_message(
|
||||
error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
if parsed_time.total_seconds() / 1000 > 2419200000:
|
||||
await interaction.response.send_message(
|
||||
error("Please provide a duration that is less than 28 days.")
|
||||
error("Please provide a duration that is less than 28 days."), ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -458,7 +567,7 @@ class Aurora(commands.Cog):
|
|||
)
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`"
|
||||
content=f"{target.mention} has been muted for {humanize_timedelta(timedelta=parsed_time)}!\n**Reason** - `{reason}`"
|
||||
)
|
||||
|
||||
if silent is None:
|
||||
|
@ -474,7 +583,7 @@ class Aurora(commands.Cog):
|
|||
response=await interaction.original_response(),
|
||||
duration=parsed_time,
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -489,7 +598,7 @@ class Aurora(commands.Cog):
|
|||
reason,
|
||||
)
|
||||
await interaction.edit_original_response(
|
||||
content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`"
|
||||
content=f"{target.mention} has been muted for {humanize_timedelta(timedelta=parsed_time)}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`"
|
||||
)
|
||||
await log(interaction, moderation_id)
|
||||
|
||||
|
@ -549,7 +658,7 @@ class Aurora(commands.Cog):
|
|||
moderation_type="unmuted",
|
||||
response=await interaction.original_response(),
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -608,7 +717,7 @@ class Aurora(commands.Cog):
|
|||
moderation_type="kicked",
|
||||
response=await interaction.original_response(),
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -684,18 +793,22 @@ class Aurora(commands.Cog):
|
|||
pass
|
||||
|
||||
if duration:
|
||||
try:
|
||||
parsed_time = parse(
|
||||
sval=duration, as_timedelta=True, raise_exception=True
|
||||
parsed_time = parse_relativedelta(duration)
|
||||
if parsed_time is None:
|
||||
await interaction.response.send_message(
|
||||
content=error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
try:
|
||||
parsed_time = timedelta_from_relativedelta(parsed_time)
|
||||
except ValueError:
|
||||
await interaction.response.send_message(
|
||||
error("Please provide a valid duration!"), ephemeral=True
|
||||
content=error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
content=f"{target.mention} has been banned for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`"
|
||||
content=f"{target.mention} has been banned for {humanize_timedelta(timedelta=parsed_time)}!\n**Reason** - `{reason}`"
|
||||
)
|
||||
|
||||
try:
|
||||
|
@ -708,7 +821,7 @@ class Aurora(commands.Cog):
|
|||
response=await interaction.original_response(),
|
||||
duration=parsed_time,
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -729,7 +842,7 @@ class Aurora(commands.Cog):
|
|||
reason,
|
||||
)
|
||||
await interaction.edit_original_response(
|
||||
content=f"{target.mention} has been banned for {humanize.precisedelta(parsed_time)}! (Case `#{moderation_id}`)\n**Reason** - `{reason}`"
|
||||
content=f"{target.mention} has been banned for {humanize_timedelta(timedelta=parsed_time)}! (Case `#{moderation_id}`)\n**Reason** - `{reason}`"
|
||||
)
|
||||
await log(interaction, moderation_id)
|
||||
|
||||
|
@ -752,7 +865,7 @@ class Aurora(commands.Cog):
|
|||
moderation_type="banned",
|
||||
response=await interaction.original_response(),
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -835,7 +948,7 @@ class Aurora(commands.Cog):
|
|||
moderation_type="unbanned",
|
||||
response=await interaction.original_response(),
|
||||
)
|
||||
await target.send(embed=embed)
|
||||
await target.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -1069,9 +1182,9 @@ class Aurora(commands.Cog):
|
|||
}
|
||||
)
|
||||
duration_embed = (
|
||||
f"{humanize.precisedelta(td)} | <t:{case['end_timestamp']}:R>"
|
||||
f"{humanize_timedelta(timedelta=td)} | <t:{case['end_timestamp']}:R>"
|
||||
if bool(case["expired"]) is False
|
||||
else f"{humanize.precisedelta(td)} | Expired"
|
||||
else f"{humanize_timedelta(timedelta=td)} | Expired"
|
||||
)
|
||||
field_value += f"\n**Duration:** {duration_embed}"
|
||||
|
||||
|
@ -1314,7 +1427,7 @@ class Aurora(commands.Cog):
|
|||
os.remove(filename)
|
||||
return
|
||||
await interaction.response.send_message(
|
||||
content=box({json.dumps(case_dict, indent=2)}),
|
||||
content=box(json.dumps(case_dict, indent=2), 'json'),
|
||||
ephemeral=ephemeral,
|
||||
)
|
||||
return
|
||||
|
@ -1380,11 +1493,8 @@ class Aurora(commands.Cog):
|
|||
case_dict = await fetch_case(case, interaction.guild.id)
|
||||
if case_dict:
|
||||
if duration:
|
||||
try:
|
||||
parsed_time = parse(
|
||||
sval=duration, as_timedelta=True, raise_exception=True
|
||||
)
|
||||
except ValueError:
|
||||
parsed_time = parse_timedelta(duration)
|
||||
if parsed_time is None:
|
||||
await interaction.response.send_message(
|
||||
error("Please provide a valid duration!"), ephemeral=True
|
||||
)
|
||||
|
@ -1497,10 +1607,13 @@ class Aurora(commands.Cog):
|
|||
|
||||
@tasks.loop(minutes=1)
|
||||
async def handle_expiry(self):
|
||||
await self.bot.wait_until_red_ready()
|
||||
current_time = time.time()
|
||||
database = connect()
|
||||
cursor = database.cursor()
|
||||
global_num = 0
|
||||
global_unban_num = 0
|
||||
global_addrole_num = 0
|
||||
global_removerole_num = 0
|
||||
|
||||
guilds: list[discord.Guild] = self.bot.guilds
|
||||
for guild in guilds:
|
||||
|
@ -1518,7 +1631,7 @@ class Aurora(commands.Cog):
|
|||
target_ids = [row[0] for row in result]
|
||||
moderation_ids = [row[1] for row in result]
|
||||
|
||||
num = 0
|
||||
unban_num = 0
|
||||
for target_id, moderation_id in zip(target_ids, moderation_ids):
|
||||
user: discord.User = await self.bot.fetch_user(target_id)
|
||||
name = (
|
||||
|
@ -1539,7 +1652,7 @@ class Aurora(commands.Cog):
|
|||
)
|
||||
|
||||
try:
|
||||
await user.send(embed=embed)
|
||||
await user.send(embed=embed, file=get_footer_image(self))
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
|
||||
|
@ -1550,7 +1663,7 @@ class Aurora(commands.Cog):
|
|||
guild.name,
|
||||
guild.id,
|
||||
)
|
||||
num = num + 1
|
||||
unban_num = unban_num + 1
|
||||
except (
|
||||
discord.errors.NotFound,
|
||||
discord.errors.Forbidden,
|
||||
|
@ -1565,12 +1678,10 @@ class Aurora(commands.Cog):
|
|||
e,
|
||||
)
|
||||
|
||||
expiry_query = f"UPDATE `moderation_{guild.id}` SET expired = 1 WHERE (end_timestamp != 0 AND end_timestamp <= ? AND expired = 0 AND moderation_type != 'BLACKLIST') OR (expired = 0 AND resolved = 1 AND moderation_type != 'BLACKLIST')"
|
||||
cursor.execute(expiry_query, (time.time(),))
|
||||
|
||||
blacklist_query = f"SELECT target_id, moderation_id, role_id FROM moderation_{guild.id} WHERE end_timestamp != 0 AND end_timestamp <= ? AND moderation_type = 'BLACKLIST' AND expired = 0"
|
||||
removerole_num = 0
|
||||
addrole_query = f"SELECT target_id, moderation_id, role_id FROM moderation_{guild.id} WHERE end_timestamp != 0 AND end_timestamp <= ? AND moderation_type = 'ADDROLE' AND expired = 0"
|
||||
try:
|
||||
cursor.execute(blacklist_query, (time.time(),))
|
||||
cursor.execute(addrole_query, (time.time(),))
|
||||
result = cursor.fetchall()
|
||||
except sqlite3.OperationalError:
|
||||
continue
|
||||
|
@ -1582,27 +1693,72 @@ class Aurora(commands.Cog):
|
|||
target_ids, moderation_ids, role_ids
|
||||
):
|
||||
try:
|
||||
# member: discord.Member = await guild.fetch_member(target_id)
|
||||
member = await guild.fetch_member(target_id)
|
||||
|
||||
role: discord.Role = guild.get_role(role_id)
|
||||
if role is None:
|
||||
raise discord.errors.NotFound
|
||||
await member.remove_roles(
|
||||
Object(role_id), reason=f"Automatic role removal from case #{moderation_id}"
|
||||
)
|
||||
|
||||
removerole_num = removerole_num + 1
|
||||
except (
|
||||
discord.errors.NotFound,
|
||||
discord.errors.Forbidden,
|
||||
discord.errors.HTTPException,
|
||||
):
|
||||
) as e:
|
||||
logger.error(
|
||||
"Removing the role %s from user %s failed due to: \n%s",
|
||||
role_id,
|
||||
target_id,
|
||||
e,
|
||||
)
|
||||
continue
|
||||
|
||||
addrole_num = 0
|
||||
removerole_query = f"SELECT target_id, moderation_id, role_id FROM moderation_{guild.id} WHERE end_timestamp != 0 AND end_timestamp <= ? AND moderation_type = 'REMOVEROLE' AND expired = 0"
|
||||
try:
|
||||
cursor.execute(removerole_query, (time.time(),))
|
||||
result = cursor.fetchall()
|
||||
except sqlite3.OperationalError:
|
||||
continue
|
||||
target_ids = [row[0] for row in result]
|
||||
moderation_ids = [row[1] for row in result]
|
||||
role_ids = [row[2] for row in result]
|
||||
|
||||
for target_id, moderation_id, role_id in zip(
|
||||
target_ids, moderation_ids, role_ids
|
||||
):
|
||||
try:
|
||||
member = await guild.fetch_member(target_id)
|
||||
|
||||
await member.add_roles(
|
||||
Object(role_id), reason=f"Automatic role addition from case #{moderation_id}"
|
||||
)
|
||||
|
||||
addrole_num = addrole_num + 1
|
||||
except (
|
||||
discord.errors.NotFound,
|
||||
discord.errors.Forbidden,
|
||||
discord.errors.HTTPException,
|
||||
) as e:
|
||||
logger.error("Adding the role %s to user %s failed due to: \n%s", role_id, target_id, e)
|
||||
continue
|
||||
|
||||
expiry_query = f"UPDATE `moderation_{guild.id}` SET expired = 1 WHERE (end_timestamp != 0 AND end_timestamp <= ? AND expired = 0) OR (expired = 0 AND resolved = 1);"
|
||||
cursor.execute(expiry_query, (time.time(),))
|
||||
|
||||
per_guild_completion_time = (time.time() - time_per_guild) * 1000
|
||||
logger.debug(
|
||||
"Completed expiry loop for %s (%s) in %sms with %s users unbanned",
|
||||
"Completed expiry loop for %s (%s) in %sms with %s users unbanned, %s roles added, and %s roles removed",
|
||||
guild.name,
|
||||
guild.id,
|
||||
f"{per_guild_completion_time:.6f}",
|
||||
num,
|
||||
unban_num,
|
||||
addrole_num,
|
||||
removerole_num,
|
||||
)
|
||||
global_num = global_num + num
|
||||
global_unban_num = global_unban_num + unban_num
|
||||
global_addrole_num = global_addrole_num + addrole_num
|
||||
global_removerole_num = global_removerole_num + removerole_num
|
||||
|
||||
database.commit()
|
||||
cursor.close()
|
||||
|
@ -1610,9 +1766,11 @@ class Aurora(commands.Cog):
|
|||
|
||||
completion_time = (time.time() - current_time) * 1000
|
||||
logger.debug(
|
||||
"Completed expiry loop in %sms with %s users unbanned",
|
||||
"Completed expiry loop in %sms with %s users unbanned, %s roles added, and %s roles removed",
|
||||
f"{completion_time:.6f}",
|
||||
global_num,
|
||||
global_unban_num,
|
||||
global_addrole_num,
|
||||
global_removerole_num,
|
||||
)
|
||||
|
||||
########################################################################################################################
|
||||
|
@ -1630,14 +1788,16 @@ class Aurora(commands.Cog):
|
|||
@aurora_settings.command(name="overrides", aliases=["override", "user"])
|
||||
async def aurora_settings_overrides(self, ctx: commands.Context):
|
||||
"""Manage Aurora's user overriddable settings."""
|
||||
await ctx.send(embed=await overrides_embed(ctx), view=Overrides(ctx))
|
||||
msg = await ctx.send(embed=await overrides_embed(ctx))
|
||||
await msg.edit(view=Overrides(ctx, msg, 60))
|
||||
|
||||
@aurora_settings.command(name="guild", aliases=["server"])
|
||||
@commands.admin_or_permissions(manage_guild=True)
|
||||
@commands.guild_only()
|
||||
async def aurora_settings_guild(self, ctx: commands.Context):
|
||||
"""Manage Aurora's guild settings."""
|
||||
await ctx.send(embed=await guild_embed(ctx), view=Guild(ctx))
|
||||
msg = await ctx.send(embed=await guild_embed(ctx))
|
||||
await msg.edit(view=Guild(ctx, msg, 60))
|
||||
|
||||
@aurora_settings.command(name="addrole", aliases=["removerole"])
|
||||
@commands.admin_or_permissions(manage_guild=True)
|
||||
|
@ -1646,14 +1806,16 @@ class Aurora(commands.Cog):
|
|||
"""Manage the addrole whitelist.
|
||||
|
||||
Roles added to this list are also applied to `/removerole`."""
|
||||
await ctx.send(embed=await addrole_embed(ctx), view=Addrole(ctx))
|
||||
msg = await ctx.send(embed=await addrole_embed(ctx))
|
||||
await msg.edit(view=Addrole(ctx, msg, 60))
|
||||
|
||||
@aurora_settings.command(name="immunity")
|
||||
@commands.admin_or_permissions(manage_guild=True)
|
||||
@commands.guild_only()
|
||||
async def aurora_settings_immunity(self, ctx: commands.Context):
|
||||
"""Manage the immunity whitelist."""
|
||||
await ctx.send(embed=await immune_embed(ctx), view=Immune(ctx))
|
||||
msg = await ctx.send(embed=await immune_embed(ctx))
|
||||
await msg.edit(view=Immune(ctx, msg, 60))
|
||||
|
||||
@aurora.group(autohelp=True, name="import")
|
||||
@commands.admin()
|
||||
|
@ -1700,15 +1862,34 @@ class Aurora(commands.Cog):
|
|||
)
|
||||
|
||||
@aurora.command(aliases=["tdc", "td", "timedeltaconvert"])
|
||||
async def timedelta(self, ctx: commands.Context, *, duration: str):
|
||||
"""This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.
|
||||
async def timedelta(self, ctx: commands.Context, *, duration: str) -> None:
|
||||
"""Convert a string to a timedelta.
|
||||
|
||||
This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.
|
||||
You cannot convert years or months as they are not fixed units. Use `[p]aurora relativedelta` for that.
|
||||
|
||||
**Example usage**
|
||||
`[p]aurora timedelta 1 day 15hr 82 minutes 52s`
|
||||
**Output**
|
||||
`1 day, 16:22:52`"""
|
||||
try:
|
||||
parsed_time = parse(duration, as_timedelta=True, raise_exception=True)
|
||||
await ctx.send(f"`{str(parsed_time)}`")
|
||||
except ValueError:
|
||||
parsed_time = parse_timedelta(duration)
|
||||
if parsed_time is None:
|
||||
await ctx.send(error("Please provide a convertible value!"))
|
||||
return
|
||||
await ctx.send(f"`{parsed_time}`")
|
||||
|
||||
@aurora.command(aliases=["rdc", "rd", "relativedeltaconvert"])
|
||||
async def relativedelta(self, ctx: commands.Context, *, duration: str) -> None:
|
||||
"""Convert a string to a relativedelta.
|
||||
|
||||
This command converts a duration to a [`relativedelta`](https://dateutil.readthedocs.io/en/stable/relativedelta.html) Python object.
|
||||
|
||||
**Example usage**
|
||||
`[p]aurora relativedelta 3 years 1 day 15hr 82 minutes 52s`
|
||||
**Output**
|
||||
`relativedelta(years=+3, days=+1, hours=+15, minutes=+82, seconds=+52)`"""
|
||||
parsed_time = parse_relativedelta(duration)
|
||||
if parsed_time is None:
|
||||
await ctx.send(error("Please provide a convertible value!"))
|
||||
return
|
||||
await ctx.send(f"`{parsed_time}`")
|
||||
|
|
BIN
aurora/data/arrow.png
Normal file
BIN
aurora/data/arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
|
@ -43,7 +43,7 @@ class ImportAuroraView(ui.View):
|
|||
file = await self.ctx.message.attachments[0].read()
|
||||
data: list[dict] = sorted(json.loads(file), key=lambda x: x["moderation_id"])
|
||||
|
||||
user_mod_types = ["NOTE", "WARN", "MUTE", "UNMUTE", "KICK", "BAN", "UNBAN"]
|
||||
user_mod_types = ["NOTE", "WARN", "ADDROLE", "REMOVEROLE", "MUTE", "UNMUTE", "KICK", "TEMPBAN", "BAN", "UNBAN"]
|
||||
|
||||
channel_mod_types = ["SLOWMODE", "LOCKDOWN"]
|
||||
|
||||
|
@ -58,6 +58,8 @@ class ImportAuroraView(ui.View):
|
|||
case["target_type"] = "USER"
|
||||
elif case["moderation_type"] in channel_mod_types:
|
||||
case["target_type"] = "CHANNEL"
|
||||
else:
|
||||
case["target_type"] = "USER"
|
||||
|
||||
if "role_id" not in case or not case["role_id"]:
|
||||
case["role_id"] = 0
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
{
|
||||
"author" : ["SeaswimmerTheFsh (seasw.)"],
|
||||
"install_msg" : "Thank you for installing Aurora!\nMost of this cog's functionality requires enabling slash commands.\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).",
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing Aurora!\nMost of this cog's functionality requires enabling slash commands.\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).",
|
||||
"name" : "Aurora",
|
||||
"short" : "A full replacement for Red's core Mod cogs.",
|
||||
"description" : "Aurora is a fully-featured moderation system. It is heavily inspired by GalacticBot, and is designed to be a more user-friendly alternative to Red's core Mod cogs. This cog stores all of its data in an SQLite database.",
|
||||
"end_user_data_statement" : "This cog stores the following information:\n- User IDs of accounts who moderate users or are moderated\n- Guild IDs of guilds with the cog enabled\n- Timestamps of moderations\n- Other information relating to moderations",
|
||||
"requirements": ["humanize", "pytimeparse2"],
|
||||
"hidden": false,
|
||||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from discord import ButtonStyle, Interaction, ui
|
||||
from discord import ButtonStyle, Interaction, Message, ui
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import error
|
||||
|
||||
|
@ -7,9 +7,14 @@ from aurora.utilities.factory import addrole_embed
|
|||
|
||||
|
||||
class Addrole(ui.View):
|
||||
def __init__(self, ctx: commands.Context):
|
||||
def __init__(self, ctx: commands.Context, message: Message, timeout: int = None):
|
||||
super().__init__()
|
||||
self.ctx = ctx
|
||||
self.message = message
|
||||
self.timeout = timeout
|
||||
|
||||
async def on_timeout(self):
|
||||
await self.message.edit(view=None)
|
||||
|
||||
@ui.select(cls=ui.RoleSelect, placeholder="Select a role", min_values=0, max_values=25)
|
||||
async def addrole_select(self, interaction: Interaction, select: ui.RoleSelect):
|
||||
|
@ -17,12 +22,13 @@ class Addrole(ui.View):
|
|||
await interaction.response.send_message(error("You must have the manage guild permission to add roles to the addrole whitelist."), ephemeral=True)
|
||||
return
|
||||
await interaction.response.defer()
|
||||
addrole_whitelist: list = await config.guild(self.ctx.guild).addrole_whitelist()
|
||||
if select.values[0].id in addrole_whitelist:
|
||||
addrole_whitelist.remove(select.values[0].id)
|
||||
else:
|
||||
addrole_whitelist.append(select.values[0].id)
|
||||
await config.guild(self.ctx.guild).addrole_whitelist.set(addrole_whitelist)
|
||||
async with config.guild(self.ctx.guild).addrole_whitelist() as addrole_whitelist:
|
||||
addrole_whitelist: list # type hint
|
||||
for value in select.values:
|
||||
if value.id in addrole_whitelist:
|
||||
addrole_whitelist.remove(value.id)
|
||||
else:
|
||||
addrole_whitelist.append(value.id)
|
||||
await interaction.message.edit(embed=await addrole_embed(self.ctx))
|
||||
|
||||
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from discord import ButtonStyle, Interaction, ui
|
||||
from discord import ButtonStyle, Interaction, Message, ui
|
||||
from redbot.core import commands
|
||||
|
||||
from aurora.utilities.config import config
|
||||
|
@ -7,9 +7,14 @@ from aurora.utilities.utils import create_pagesize_options
|
|||
|
||||
|
||||
class Guild(ui.View):
|
||||
def __init__(self, ctx: commands.Context):
|
||||
def __init__(self, ctx: commands.Context, message: Message, timeout: int = None):
|
||||
super().__init__()
|
||||
self.ctx = ctx
|
||||
self.message = message
|
||||
self.timeout = timeout
|
||||
|
||||
async def on_timeout(self):
|
||||
await self.message.edit(view=None)
|
||||
|
||||
@ui.button(label="Show Moderator", style=ButtonStyle.green, row=0)
|
||||
async def show_moderator(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||
|
@ -17,7 +22,7 @@ class Guild(ui.View):
|
|||
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||
return
|
||||
await interaction.response.defer()
|
||||
current_setting = await config.guild(interaction.guild).show_moderator
|
||||
current_setting = await config.guild(interaction.guild).show_moderator()
|
||||
await config.guild(interaction.guild).show_moderator.set(not current_setting)
|
||||
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||
|
||||
|
@ -31,6 +36,16 @@ class Guild(ui.View):
|
|||
await config.guild(interaction.guild).use_discord_permissions.set(not current_setting)
|
||||
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||
|
||||
@ui.button(label="Respect Hierarchy", style=ButtonStyle.green, row=0)
|
||||
async def respect_heirarchy(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
||||
return
|
||||
await interaction.response.defer()
|
||||
current_setting = await config.guild(interaction.guild).respect_hierarchy()
|
||||
await config.guild(interaction.guild).respect_hierarchy.set(not current_setting)
|
||||
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
||||
|
||||
@ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0)
|
||||
async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from discord import ButtonStyle, Interaction, ui
|
||||
from discord import ButtonStyle, Interaction, Message, ui
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import error
|
||||
|
||||
|
@ -7,9 +7,14 @@ from aurora.utilities.factory import immune_embed
|
|||
|
||||
|
||||
class Immune(ui.View):
|
||||
def __init__(self, ctx: commands.Context):
|
||||
def __init__(self, ctx: commands.Context, message: Message, timeout: int = None):
|
||||
super().__init__()
|
||||
self.ctx = ctx
|
||||
self.message = message
|
||||
self.timeout = timeout
|
||||
|
||||
async def on_timeout(self):
|
||||
await self.message.edit(view=None)
|
||||
|
||||
@ui.select(cls=ui.RoleSelect, placeholder="Select a role", min_values=0, max_values=25)
|
||||
async def immune_select(self, interaction: Interaction, select: ui.RoleSelect):
|
||||
|
@ -17,13 +22,13 @@ class Immune(ui.View):
|
|||
await interaction.response.send_message(error("You must have the manage guild permission to add immune roles."), ephemeral=True)
|
||||
return
|
||||
await interaction.response.defer()
|
||||
immune_roles: list = await config.guild(self.ctx.guild).immune_roles()
|
||||
for role in select.values:
|
||||
if role.id in immune_roles:
|
||||
immune_roles.remove(role.id)
|
||||
else:
|
||||
immune_roles.append(role.id)
|
||||
await config.guild(self.ctx.guild).immune_roles.set(immune_roles)
|
||||
async with config.guild(self.ctx.guild).immune_roles() as immune_roles:
|
||||
immune_roles: list # type hint
|
||||
for value in select.values:
|
||||
if value.id in immune_roles:
|
||||
immune_roles.remove(value.id)
|
||||
else:
|
||||
immune_roles.append(value.id)
|
||||
await interaction.message.edit(embed=await immune_embed(self.ctx))
|
||||
|
||||
@ui.button(label="Clear", style=ButtonStyle.red, row=1)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from discord import ButtonStyle, Interaction, ui
|
||||
from discord import ButtonStyle, Interaction, Message, ui
|
||||
from redbot.core import commands
|
||||
|
||||
from aurora.utilities.config import config
|
||||
|
@ -7,9 +7,14 @@ from aurora.utilities.utils import create_pagesize_options
|
|||
|
||||
|
||||
class Overrides(ui.View):
|
||||
def __init__(self, ctx: commands.Context):
|
||||
def __init__(self, ctx: commands.Context, message: Message, timeout: int = None):
|
||||
super().__init__()
|
||||
self.ctx = ctx
|
||||
self.message = message
|
||||
self.timeout = timeout
|
||||
|
||||
async def on_timeout(self):
|
||||
await self.message.edit(view=None)
|
||||
|
||||
@ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=0)
|
||||
async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
||||
|
|
|
@ -7,6 +7,7 @@ def register_config(config_obj: Config):
|
|||
config_obj.register_guild(
|
||||
show_moderator=True,
|
||||
use_discord_permissions=True,
|
||||
respect_hierarchy=True,
|
||||
ignore_modlog=True,
|
||||
ignore_other_bots=True,
|
||||
dm_users=True,
|
||||
|
|
|
@ -2,16 +2,12 @@
|
|||
from datetime import datetime, timedelta
|
||||
from typing import Union
|
||||
|
||||
import humanize
|
||||
from discord import (Color, Embed, Guild, Interaction, InteractionMessage,
|
||||
Member, Role, User)
|
||||
from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import bold, box, error, warning
|
||||
from redbot.core.utils.chat_formatting import bold, box, error, humanize_timedelta, warning
|
||||
|
||||
from aurora.utilities.config import config
|
||||
from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict,
|
||||
get_bool_emoji, get_next_case_number,
|
||||
get_pagesize_str)
|
||||
from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str
|
||||
|
||||
|
||||
async def message_factory(
|
||||
|
@ -50,8 +46,10 @@ async def message_factory(
|
|||
else:
|
||||
guild_name = guild.name
|
||||
|
||||
title = moderation_type
|
||||
|
||||
if moderation_type in ["tempbanned", "muted"] and duration:
|
||||
embed_duration = f" for {humanize.precisedelta(duration)}"
|
||||
embed_duration = f" for {humanize_timedelta(timedelta=duration)}"
|
||||
else:
|
||||
embed_duration = ""
|
||||
|
||||
|
@ -59,13 +57,17 @@ async def message_factory(
|
|||
embed_desc = "received a"
|
||||
elif moderation_type == "addrole":
|
||||
embed_desc = f"received the {role.name} role"
|
||||
title = "Role Added"
|
||||
moderation_type = ""
|
||||
elif moderation_type == "removerole":
|
||||
embed_desc = f"lost the {role.name} role"
|
||||
title = "Role Removed"
|
||||
moderation_type = ""
|
||||
else:
|
||||
embed_desc = "been"
|
||||
|
||||
embed = Embed(
|
||||
title=str.title(moderation_type),
|
||||
title=str.title(title),
|
||||
description=f"You have {embed_desc} {moderation_type}{embed_duration} in {guild_name}.",
|
||||
color=color,
|
||||
timestamp=datetime.now(),
|
||||
|
@ -85,7 +87,7 @@ async def message_factory(
|
|||
|
||||
embed.set_footer(
|
||||
text=f"Case #{await get_next_case_number(guild.id):,}",
|
||||
icon_url="https://cdn.discordapp.com/attachments/1070822161389994054/1159469476773904414/arrow-right-circle-icon-512x512-2p1e2aaw.png?ex=65312319&is=651eae19&hm=3cebdd28e805c13a79ec48ef87c32ca532ffa6b9ede2e48d0cf8e5e81f3a6818&",
|
||||
icon_url="attachment://arrow.png",
|
||||
)
|
||||
|
||||
return embed
|
||||
|
@ -141,9 +143,9 @@ async def log_factory(
|
|||
}
|
||||
)
|
||||
duration_embed = (
|
||||
f"{humanize.precisedelta(td)} | <t:{case_dict['end_timestamp']}:R>"
|
||||
f"{humanize_timedelta(timedelta=td)} | <t:{case_dict['end_timestamp']}:R>"
|
||||
if case_dict["expired"] == "0"
|
||||
else str(humanize.precisedelta(td))
|
||||
else str(humanize_timedelta(timedelta=td))
|
||||
)
|
||||
embed.description = (
|
||||
embed.description
|
||||
|
@ -204,7 +206,7 @@ async def log_factory(
|
|||
)
|
||||
embed.description = (
|
||||
embed.description
|
||||
+ f"\n**Duration:** {humanize.precisedelta(td)} | <t:{case_dict['end_timestamp']}:R>"
|
||||
+ f"\n**Duration:** {humanize_timedelta(timedelta=td)} | <t:{case_dict['end_timestamp']}:R>"
|
||||
)
|
||||
|
||||
embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False)
|
||||
|
@ -255,9 +257,9 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
|||
}
|
||||
)
|
||||
duration_embed = (
|
||||
f"{humanize.precisedelta(td)} | <t:{case_dict['end_timestamp']}:R>"
|
||||
f"{humanize_timedelta(timedelta=td)} | <t:{case_dict['end_timestamp']}:R>"
|
||||
if bool(case_dict["expired"]) is False
|
||||
else str(humanize.precisedelta(td))
|
||||
else str(humanize_timedelta(timedelta=td))
|
||||
)
|
||||
embed.description += f"\n**Duration:** {duration_embed}\n**Expired:** {bool(case_dict['expired'])}"
|
||||
|
||||
|
@ -267,6 +269,9 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed:
|
|||
else "\n**Changes:** 0"
|
||||
)
|
||||
|
||||
if case_dict["role_id"]:
|
||||
embed.description += f"\n**Role:** <@&{case_dict['role_id']}>"
|
||||
|
||||
if case_dict["metadata"]:
|
||||
if case_dict["metadata"]["imported_from"]:
|
||||
embed.description += (
|
||||
|
@ -376,10 +381,14 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s
|
|||
|
||||
content = f"Case: {case_dict['moderation_id']:,} ({str.title(case_dict['moderation_type'])})\nTarget: {target_name} ({target_user['id']})\nModerator: {moderator_name} ({moderator_user['id']})"
|
||||
|
||||
if case_dict["role_id"] != "0":
|
||||
role = interaction.guild.get_role(int(case_dict["role_id"]))
|
||||
content += "\nRole: " + (role.name if role is not None else case_dict["role_id"])
|
||||
|
||||
if case_dict["duration"] != "NULL":
|
||||
hours, minutes, seconds = map(int, case_dict["duration"].split(":"))
|
||||
td = timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
||||
content += f"\nDuration: {humanize.precisedelta(td)}"
|
||||
content += f"\nDuration: {humanize_timedelta(timedelta=td)}"
|
||||
|
||||
content += f"\nReason: {case_dict['reason']}"
|
||||
|
||||
|
@ -455,6 +464,7 @@ async def guild_embed(ctx: commands.Context) -> Embed:
|
|||
ctx.guild
|
||||
).history_inline_pagesize(),
|
||||
"auto_evidenceformat": await config.guild(ctx.guild).auto_evidenceformat(),
|
||||
"respect_hierarchy": await config.guild(ctx.guild).respect_hierarchy(),
|
||||
}
|
||||
|
||||
channel = ctx.guild.get_channel(guild_settings["log_channel"])
|
||||
|
@ -471,6 +481,9 @@ async def guild_embed(ctx: commands.Context) -> Embed:
|
|||
+ bold("Use Discord Permissions: ")
|
||||
+ get_bool_emoji(guild_settings["use_discord_permissions"]),
|
||||
"- "
|
||||
+ bold("Respect Hierarchy: ")
|
||||
+ get_bool_emoji(guild_settings["respect_hierarchy"]),
|
||||
"- "
|
||||
+ bold("Ignore Modlog: ")
|
||||
+ get_bool_emoji(guild_settings["ignore_modlog"]),
|
||||
"- "
|
||||
|
@ -510,15 +523,29 @@ async def guild_embed(ctx: commands.Context) -> Embed:
|
|||
async def addrole_embed(ctx: commands.Context) -> Embed:
|
||||
"""Generates a configuration menu field value for a guild's addrole whitelist."""
|
||||
|
||||
whitelist = await config.guild(ctx.guild).addrole_whitelist()
|
||||
if whitelist:
|
||||
whitelist = [
|
||||
ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)")
|
||||
for role in whitelist
|
||||
]
|
||||
whitelist = "\n".join(whitelist)
|
||||
roles = []
|
||||
async with config.guild(ctx.guild).addrole_whitelist() as whitelist:
|
||||
for role in whitelist:
|
||||
evalulated_role = ctx.guild.get_role(role) or error(f"`{role}` (Not Found)")
|
||||
if isinstance(evalulated_role, Role):
|
||||
roles.append({
|
||||
"id": evalulated_role.id,
|
||||
"mention": evalulated_role.mention,
|
||||
"position": evalulated_role.position
|
||||
})
|
||||
else:
|
||||
roles.append({
|
||||
"id": role,
|
||||
"mention": error(f"`{role}` (Not Found)"),
|
||||
"position": 0
|
||||
})
|
||||
|
||||
if roles:
|
||||
roles = sorted(roles, key=lambda x: x["position"], reverse=True)
|
||||
roles = [role["mention"] for role in roles]
|
||||
whitelist_str = "\n".join(roles)
|
||||
else:
|
||||
whitelist = warning("No roles are on the addrole whitelist!")
|
||||
whitelist_str = warning("No roles are on the addrole whitelist!")
|
||||
|
||||
e = await _config(ctx)
|
||||
e.title += ": Addrole Whitelist"
|
||||
|
@ -526,8 +553,8 @@ async def addrole_embed(ctx: commands.Context) -> Embed:
|
|||
"Use the select menu below to manage this guild's addrole whitelist."
|
||||
)
|
||||
|
||||
if len(whitelist) > 4000 and len(whitelist) < 5000:
|
||||
lines = whitelist.split("\n")
|
||||
if len(whitelist_str) > 4000 and len(whitelist_str) < 5000:
|
||||
lines = whitelist_str.split("\n")
|
||||
chunks = []
|
||||
chunk = ""
|
||||
for line in lines:
|
||||
|
@ -541,21 +568,35 @@ async def addrole_embed(ctx: commands.Context) -> Embed:
|
|||
for chunk in chunks:
|
||||
e.add_field(name="", value=chunk)
|
||||
else:
|
||||
e.description += "\n\n" + whitelist
|
||||
e.description += "\n\n" + whitelist_str
|
||||
|
||||
return e
|
||||
|
||||
|
||||
async def immune_embed(ctx: commands.Context) -> Embed:
|
||||
"""Generates a configuration menu field value for a guild's immune roles."""
|
||||
"""Generates a configuration menu embed for a guild's immune roles."""
|
||||
|
||||
immune_roles = await config.guild(ctx.guild).immune_roles()
|
||||
if immune_roles:
|
||||
immune_str = [
|
||||
ctx.guild.get_role(role).mention or error(f"`{role}` (Not Found)")
|
||||
for role in immune_roles
|
||||
]
|
||||
immune_str = "\n".join(immune_str)
|
||||
roles = []
|
||||
async with config.guild(ctx.guild).immune_roles() as immune_roles:
|
||||
for role in immune_roles:
|
||||
evalulated_role = ctx.guild.get_role(role) or error(f"`{role}` (Not Found)")
|
||||
if isinstance(evalulated_role, Role):
|
||||
roles.append({
|
||||
"id": evalulated_role.id,
|
||||
"mention": evalulated_role.mention,
|
||||
"position": evalulated_role.position
|
||||
})
|
||||
else:
|
||||
roles.append({
|
||||
"id": role,
|
||||
"mention": error(f"`{role}` (Not Found)"),
|
||||
"position": 0
|
||||
})
|
||||
|
||||
if roles:
|
||||
roles = sorted(roles, key=lambda x: x["position"], reverse=True)
|
||||
roles = [role["mention"] for role in roles]
|
||||
immune_str = "\n".join(roles)
|
||||
else:
|
||||
immune_str = warning("No roles are set as immune roles!")
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
from red_commons.logging import getLogger
|
||||
|
||||
logger = getLogger("red.seacogs.aurora")
|
||||
logger = getLogger("red.SeaCogs.Aurora")
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# pylint: disable=cyclic-import
|
||||
import json
|
||||
from datetime import datetime
|
||||
from datetime import timedelta as td
|
||||
from typing import Union
|
||||
from typing import Optional, Union
|
||||
|
||||
from discord import Guild, Interaction, Member, SelectOption, User
|
||||
from dateutil.relativedelta import relativedelta as rd
|
||||
from discord import File, Guild, Interaction, Member, SelectOption, User
|
||||
from discord.errors import Forbidden, NotFound
|
||||
from redbot.core import commands
|
||||
from redbot.core import commands, data_manager
|
||||
from redbot.core.utils.chat_formatting import error
|
||||
|
||||
from .config import config
|
||||
|
@ -75,7 +77,7 @@ async def check_moddable(
|
|||
return False
|
||||
|
||||
if isinstance(target, Member):
|
||||
if interaction.user.top_role <= target.top_role:
|
||||
if interaction.user.top_role <= target.top_role and await config.guild(interaction.guild).respect_hierarchy() is True:
|
||||
await interaction.response.send_message(
|
||||
content=error(
|
||||
"You cannot moderate members with a higher role than you!"
|
||||
|
@ -248,7 +250,7 @@ def convert_timedelta_to_str(timedelta: td) -> str:
|
|||
return f"{hours}:{minutes}:{seconds}"
|
||||
|
||||
|
||||
def get_bool_emoji(value: bool) -> str:
|
||||
def get_bool_emoji(value: Optional[bool]) -> str:
|
||||
"""Returns a unicode emoji based on a boolean value."""
|
||||
if value is True:
|
||||
return "\N{WHITE HEAVY CHECK MARK}"
|
||||
|
@ -283,3 +285,14 @@ def create_pagesize_options() -> list[SelectOption]:
|
|||
)
|
||||
)
|
||||
return options
|
||||
|
||||
def timedelta_from_relativedelta(relativedelta: rd) -> td:
|
||||
"""Converts a relativedelta object to a timedelta object."""
|
||||
now = datetime.now()
|
||||
then = now - relativedelta
|
||||
return now - then
|
||||
|
||||
def get_footer_image(coginstance: commands.Cog) -> File:
|
||||
"""Returns the footer image for the embeds."""
|
||||
image_path = data_manager.bundled_data_path(coginstance) / "arrow.png"
|
||||
return File(image_path, filename="arrow.png", description="arrow")
|
||||
|
|
|
@ -14,29 +14,31 @@ from redbot.cogs.downloader import errors
|
|||
from redbot.cogs.downloader.converters import InstalledCog
|
||||
from redbot.core import commands
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import (error, humanize_list,
|
||||
text_to_file)
|
||||
from redbot.core.utils.chat_formatting import bold, error, humanize_list, text_to_file
|
||||
|
||||
|
||||
# pylint: disable=protected-access
|
||||
class Backup(commands.Cog):
|
||||
"""A utility to make reinstalling repositories and cogs after migrating the bot far easier."""
|
||||
|
||||
__author__ = ["SeaswimmerTheFsh"]
|
||||
__version__ = "1.0.1"
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "1.1.1"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/backup/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
super().__init__()
|
||||
self.bot = bot
|
||||
self.logger = getLogger("red.seacogs.backup")
|
||||
self.logger = getLogger("red.SeaCogs.Backup")
|
||||
|
||||
def format_help_for_context(self, ctx: commands.Context) -> str:
|
||||
pre_processed = super().format_help_for_context(ctx) or ""
|
||||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"Cog Version: **{self.__version__}**",
|
||||
f"Author: {humanize_list(self.__author__)}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
@ -99,7 +101,7 @@ class Backup(commands.Cog):
|
|||
except (json.JSONDecodeError, IndexError):
|
||||
try:
|
||||
export = json.loads(await ctx.message.reference.resolved.attachments[0].read())
|
||||
except (json.JSONDecodeError, IndexError):
|
||||
except (json.JSONDecodeError, IndexError, AttributeError):
|
||||
await ctx.send(error("Please provide a valid JSON export file."))
|
||||
return
|
||||
|
||||
|
@ -159,17 +161,15 @@ class Backup(commands.Cog):
|
|||
)
|
||||
self.logger.debug("Repository %s already exists", name)
|
||||
|
||||
# This is commented out because errors.AuthenticationError is not yet implemented in Red 3.5.5's Downloader cog.
|
||||
# Rather, it is only in the development version and will be added in version 3.5.6 (or whatever the next version is).
|
||||
# except errors.AuthenticationError as err:
|
||||
# repo_e.append(f"Authentication error while adding repository {name}. See logs for more information.")
|
||||
# self.logger.exception(
|
||||
# "Something went wrong whilst cloning %s (to revision %s)",
|
||||
# url,
|
||||
# branch,
|
||||
# exc_info=err,
|
||||
# )
|
||||
# continue
|
||||
except errors.AuthenticationError as err:
|
||||
repo_e.append(f"Authentication error while adding repository {name}. See logs for more information.")
|
||||
self.logger.exception(
|
||||
"Something went wrong whilst cloning %s (to revision %s)",
|
||||
url,
|
||||
branch,
|
||||
exc_info=err,
|
||||
)
|
||||
continue
|
||||
|
||||
except errors.CloningError as err:
|
||||
repo_e.append(
|
||||
|
@ -197,7 +197,7 @@ class Backup(commands.Cog):
|
|||
cog_modules = []
|
||||
for cog in cogs:
|
||||
# If you're forking this cog, make sure to change these strings!
|
||||
if cog["name"] == "backup" and "SeaswimmerTheFsh/SeaCogs" in url:
|
||||
if cog["name"] == "backup" and "cswimr/SeaCogs" in url:
|
||||
continue
|
||||
try:
|
||||
cog_module = await InstalledCog.convert(ctx, cog["name"])
|
||||
|
@ -233,7 +233,7 @@ class Backup(commands.Cog):
|
|||
commit = None
|
||||
|
||||
# If you're forking this cog, make sure to change these strings!
|
||||
if cog_name == "backup" and "SeaswimmerTheFsh/SeaCogs" in url:
|
||||
if cog_name == "backup" and "cswimr/SeaCogs" in url:
|
||||
continue
|
||||
|
||||
async with repository.checkout(
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"author" : ["SeaswimmerTheFsh (seasw.)"],
|
||||
"install_msg" : "Thank you for installing Backup!\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).",
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing Backup!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).",
|
||||
"name" : "Backup",
|
||||
"short" : "A utility to make reinstalling repositories and cogs after migrating the bot far easier.",
|
||||
"description" : "A utility to make reinstalling repositories and cogs after migrating the bot far easier.",
|
||||
"end_user_data_statement" : "This cog does not store end user data.",
|
||||
"hidden": false,
|
||||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
"max_bot_version": "3.5.5",
|
||||
"min_bot_version": "3.5.6",
|
||||
"max_bot_version": "3.5.13",
|
||||
"min_python_version": [3, 9, 0],
|
||||
"tags": [
|
||||
"utility",
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
||||
|
||||
import random
|
||||
from io import BytesIO
|
||||
|
||||
import aiohttp
|
||||
from discord import Embed
|
||||
import numpy as np
|
||||
from discord import Colour, Embed, File
|
||||
from PIL import Image
|
||||
from red_commons.logging import getLogger
|
||||
from redbot.core import Config, commands
|
||||
from redbot.core import Config, commands, data_manager
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import error, humanize_list
|
||||
from redbot.core.utils.chat_formatting import bold, error, humanize_list
|
||||
|
||||
import bible.errors
|
||||
from bible.models import Version
|
||||
|
@ -21,8 +24,10 @@ from bible.models import Version
|
|||
class Bible(commands.Cog):
|
||||
"""Retrieve Bible verses from the API.bible API."""
|
||||
|
||||
__author__ = ["SeaswimmerTheFsh"]
|
||||
__version__ = "1.0.1"
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "1.1.1"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/pterodactyl/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
super().__init__()
|
||||
|
@ -31,7 +36,7 @@ class Bible(commands.Cog):
|
|||
self.config = Config.get_conf(
|
||||
self, identifier=481923957134912, force_registration=True
|
||||
)
|
||||
self.logger = getLogger("red.seacogs.bible")
|
||||
self.logger = getLogger("red.SeaCogs.Bible")
|
||||
self.config.register_global(bible="de4e12af7f28f599-02")
|
||||
self.config.register_user(bible=None)
|
||||
|
||||
|
@ -40,11 +45,29 @@ class Bible(commands.Cog):
|
|||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"Cog Version: **{self.__version__}**",
|
||||
f"Author: {humanize_list(self.__author__)}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
||||
def get_icon(self, color: Colour) -> File:
|
||||
"""Get the docs.api.bible favicon with a given color."""
|
||||
image_path = data_manager.bundled_data_path(self) / "api.bible-logo.png"
|
||||
image = Image.open(image_path)
|
||||
image = image.convert("RGBA")
|
||||
data = np.array(image)
|
||||
red, green, blue, alpha = data.T # pylint: disable=unused-variable
|
||||
white_areas = (red == 255) & (blue == 255) & (green == 255)
|
||||
data[..., :-1][white_areas.T] = color.to_rgb()
|
||||
image = Image.fromarray(data)
|
||||
|
||||
with BytesIO() as image_binary:
|
||||
image.save(image_binary, "PNG")
|
||||
image_binary.seek(0)
|
||||
return File(image_binary, filename="icon.png", description="API.Bible Icon")
|
||||
|
||||
async def translate_book_name(self, bible_id: str, book_name: str) -> str:
|
||||
"""Translate a book name to a book ID."""
|
||||
book_name_list = [
|
||||
|
@ -246,15 +269,17 @@ class Bible(commands.Cog):
|
|||
return
|
||||
|
||||
if await ctx.embed_requested():
|
||||
icon = self.get_icon(await ctx.embed_color())
|
||||
embed = Embed(
|
||||
title=f"{passage['reference']}",
|
||||
description=passage["content"].replace("¶ ", ""),
|
||||
color=await self.bot.get_embed_color(ctx.channel),
|
||||
color=await ctx.embed_color(),
|
||||
)
|
||||
embed.set_footer(
|
||||
text=f"{ctx.prefix}bible passage - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})"
|
||||
text=f"{ctx.prefix}bible passage - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})",
|
||||
icon_url="attachment://icon.png"
|
||||
)
|
||||
await ctx.send(embed=embed)
|
||||
await ctx.send(embed=embed, file=icon)
|
||||
else:
|
||||
await ctx.send(f"## {passage['reference']}\n{passage['content']}")
|
||||
|
||||
|
@ -286,14 +311,16 @@ class Bible(commands.Cog):
|
|||
return
|
||||
|
||||
if await ctx.embed_requested():
|
||||
icon = self.get_icon(await ctx.embed_color())
|
||||
embed = Embed(
|
||||
title=f"{passage['reference']}",
|
||||
description=passage["content"].replace("¶ ", ""),
|
||||
color=await self.bot.get_embed_color(ctx.channel),
|
||||
color=await ctx.embed_color(),
|
||||
)
|
||||
embed.set_footer(
|
||||
text=f"{ctx.prefix}bible random - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})"
|
||||
text=f"{ctx.prefix}bible random - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})",
|
||||
icon_url="attachment://icon.png"
|
||||
)
|
||||
await ctx.send(embed=embed)
|
||||
await ctx.send(embed=embed, file=icon)
|
||||
else:
|
||||
await ctx.send(f"## {passage['reference']}\n{passage['content']}")
|
||||
|
|
BIN
bible/data/api.bible-logo.png
Normal file
BIN
bible/data/api.bible-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"author" : ["SeaswimmerTheFsh (seasw.)"],
|
||||
"install_msg" : "Thank you for installing Bible!\nThis cog requires setting an API key for API.Bible. Please read the [documentation](https://seacogs.coastalcommits.com/bible/#setup) for more information.\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).",
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing Bible!\nThis cog requires setting an API key for API.Bible. Please read the [documentation](https://seacogs.coastalcommits.com/bible/#setup) for more information.\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).",
|
||||
"name" : "Bible",
|
||||
"short" : "Retrieve Bible verses from API.Bible.",
|
||||
"description" : "Retrieve Bible verses from the API.Bible API. This cog requires an API.Bible api key.",
|
||||
|
@ -9,6 +9,7 @@
|
|||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
"min_python_version": [3, 10, 0],
|
||||
"requirements": ["numpy", "pillow"],
|
||||
"tags": [
|
||||
"fun",
|
||||
"utility",
|
||||
|
|
5
emojiinfo/__init__.py
Normal file
5
emojiinfo/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from .emojiinfo import EmojiInfo
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(EmojiInfo(bot))
|
5309
emojiinfo/data/emojis.json
Normal file
5309
emojiinfo/data/emojis.json
Normal file
File diff suppressed because it is too large
Load diff
130
emojiinfo/emojiinfo.py
Normal file
130
emojiinfo/emojiinfo.py
Normal file
|
@ -0,0 +1,130 @@
|
|||
import io
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
from colorthief import ColorThief
|
||||
from red_commons.logging import RedTraceLogger, getLogger
|
||||
from redbot.core import app_commands, commands
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import bold, humanize_list
|
||||
|
||||
from .model import PartialEmoji
|
||||
|
||||
|
||||
class EmojiInfo(commands.Cog):
|
||||
"""Retrieve information about emojis."""
|
||||
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "1.0.1"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/emojiinfo/"
|
||||
|
||||
def __init__(self, bot: Red) -> None:
|
||||
super().__init__()
|
||||
self.bot: Red = bot
|
||||
self.logger: RedTraceLogger = getLogger(name="red.SeaCogs.Emoji")
|
||||
|
||||
def format_help_for_context(self, ctx: commands.Context) -> str:
|
||||
pre_processed = super().format_help_for_context(ctx) or ""
|
||||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
||||
async def fetch_twemoji(self, unicode_emoji) -> str:
|
||||
base_url = "https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/72x72/"
|
||||
emoji_codepoint = "-".join([hex(ord(char))[2:] for char in unicode_emoji])
|
||||
segments = emoji_codepoint.split("-")
|
||||
valid_segments = [seg for seg in segments if len(seg) >= 4]
|
||||
emoji_url = f"{base_url}{valid_segments[0]}.png"
|
||||
return emoji_url
|
||||
|
||||
async def fetch_primary_color(self, emoji_url: str) -> discord.Color | None:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(emoji_url) as response:
|
||||
if response.status != 200:
|
||||
return None
|
||||
image = await response.read()
|
||||
dominant_color = ColorThief(io.BytesIO(image)).get_color(quality=1)
|
||||
color = discord.Color.from_rgb(*dominant_color)
|
||||
return color
|
||||
|
||||
async def get_emoji_info(self, emoji: PartialEmoji) -> tuple[str, str]:
|
||||
if emoji.is_unicode_emoji():
|
||||
try:
|
||||
emoji_url = await self.fetch_twemoji(unicode_emoji=emoji.name)
|
||||
except IndexError as e:
|
||||
raise e
|
||||
else:
|
||||
emoji_url = emoji.url
|
||||
|
||||
if emoji.id is not None:
|
||||
emoji_id = f"{bold('ID:')} `{emoji.id}`\n"
|
||||
markdown = f"`<{'a' if emoji.animated else ''}:{emoji.name}:{emoji.id}>`"
|
||||
name = f"{bold('Name:')} {emoji.name}\n"
|
||||
aliases = ""
|
||||
group = ""
|
||||
else:
|
||||
emoji_id = ""
|
||||
markdown = f"`{emoji}`"
|
||||
name = f"{bold('Name:')} {emoji.aliases.pop(0)}\n"
|
||||
aliases = f"{bold('Aliases:')} {', '.join(emoji.aliases)}\n" if emoji.aliases else ""
|
||||
group = f"{bold('Group:')} {emoji.group}\n"
|
||||
|
||||
return (
|
||||
f"{name}"
|
||||
f"{emoji_id}"
|
||||
f"{bold('Native:')} {emoji.is_unicode_emoji()}\n"
|
||||
f"{group}"
|
||||
f"{aliases}"
|
||||
f"{bold('Animated:')} {emoji.animated}\n"
|
||||
f"{bold('Markdown:')} {markdown}\n"
|
||||
f"{bold('URL:')} [Click Here]({emoji_url})"
|
||||
), emoji_url
|
||||
|
||||
@app_commands.command(name="emoji")
|
||||
@app_commands.describe(
|
||||
emoji="What emoji would you like to get information on?",
|
||||
ephemeral="Would you like the response to be hidden?"
|
||||
)
|
||||
async def emoji_slash(self, interaction: discord.Interaction, emoji: str, ephemeral: bool = True) -> None:
|
||||
"""Retrieve information about an emoji."""
|
||||
await interaction.response.defer(ephemeral=ephemeral)
|
||||
|
||||
try:
|
||||
emoji: PartialEmoji = PartialEmoji.from_str(self, value=emoji)
|
||||
string, emoji_url, = await self.get_emoji_info(emoji)
|
||||
self.logger.verbose(f"Emoji:\n{string}")
|
||||
except (IndexError, UnboundLocalError):
|
||||
return await interaction.followup.send("Please provide a valid emoji!")
|
||||
|
||||
if await self.bot.embed_requested(channel=interaction.channel):
|
||||
embed = embed = discord.Embed(title="Emoji Information", description=string, color = await self.fetch_primary_color(emoji_url) or await self.bot.get_embed_color(interaction.channel))
|
||||
embed.set_thumbnail(url=emoji_url)
|
||||
|
||||
await interaction.followup.send(embed=embed)
|
||||
else:
|
||||
await interaction.followup.send(content=string)
|
||||
|
||||
@commands.command(name="emoji")
|
||||
async def emoji(self, ctx: commands.Context, *, emoji: str) -> None:
|
||||
"""Retrieve information about an emoji."""
|
||||
try:
|
||||
emoji: PartialEmoji = PartialEmoji.from_str(self, value=emoji)
|
||||
string, emoji_url, = await self.get_emoji_info(emoji)
|
||||
self.logger.verbose(f"Emoji:\n{string}")
|
||||
except (IndexError, UnboundLocalError):
|
||||
return await ctx.send("Please provide a valid emoji!")
|
||||
|
||||
if await ctx.embed_requested():
|
||||
embed = embed = discord.Embed(title="Emoji Information", description=string, color = await self.fetch_primary_color(emoji_url) or await ctx.embed_color)
|
||||
embed.set_thumbnail(url=emoji_url)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send(content=string)
|
16
emojiinfo/info.json
Normal file
16
emojiinfo/info.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing Emoji!",
|
||||
"name" : "Emoji",
|
||||
"short" : "Retrieve information about emojis.",
|
||||
"description" : "Retrieve information about emojis.",
|
||||
"end_user_data_statement" : "This cog does not store end user data.",
|
||||
"hidden": false,
|
||||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
"min_python_version": [3, 10, 0],
|
||||
"requirements": ["colorthief"],
|
||||
"tags": [
|
||||
"utility"
|
||||
]
|
||||
}
|
91
emojiinfo/model.py
Normal file
91
emojiinfo/model.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
import json
|
||||
|
||||
import discord
|
||||
from redbot.core import commands, data_manager
|
||||
|
||||
|
||||
class PartialEmoji(discord.PartialEmoji):
|
||||
"""Represents a "partial" emoji. Subclasses `discord.PartialEmoji`
|
||||
|
||||
.. container:: operations
|
||||
|
||||
.. describe:: x == y
|
||||
|
||||
Checks if two emoji are the same.
|
||||
|
||||
.. describe:: x != y
|
||||
|
||||
Checks if two emoji are not the same.
|
||||
|
||||
.. describe:: hash(x)
|
||||
|
||||
Return the emoji's hash.
|
||||
|
||||
.. describe:: str(x)
|
||||
|
||||
Returns the emoji rendered for discord.
|
||||
|
||||
Attributes
|
||||
-----------
|
||||
name: Optional[:class:`str`]
|
||||
The custom emoji name, if applicable, or the unicode codepoint
|
||||
of the non-custom emoji. This can be ``None`` if the emoji
|
||||
got deleted (e.g. removing a reaction with a deleted emoji).
|
||||
animated: :class:`bool`
|
||||
Whether the emoji is animated or not.
|
||||
id: Optional[:class:`int`]
|
||||
The ID of the custom emoji, if applicable.
|
||||
group: Optional[:class:`str`]
|
||||
The group name of the emoji if it is a native emoji.
|
||||
"""
|
||||
|
||||
def __init__(self, *, name: str, animated: bool = False, id: int | None = None, group: str | None = None, aliases: list | None = None) -> None: # pylint: disable=redefined-builtin
|
||||
super().__init__(name=name, animated=animated, id=id)
|
||||
self.group = group
|
||||
self.aliases = aliases
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, coginstance: commands.Cog, value: str) -> "PartialEmoji":
|
||||
"""Converts a Discord string representation of an emoji to a :class:`PartialEmoji`.
|
||||
|
||||
The formats accepted are:
|
||||
|
||||
- ``a:name:id``
|
||||
- ``<a:name:id>``
|
||||
- ``name:id``
|
||||
- ``<:name:id>``
|
||||
|
||||
If the format does not match then it is assumed to be a unicode emoji.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
Parameters
|
||||
------------
|
||||
value: :class:`str`
|
||||
The string representation of an emoji.
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`PartialEmoji`
|
||||
The partial emoji from this string.
|
||||
"""
|
||||
match = cls._CUSTOM_EMOJI_RE.match(value)
|
||||
if match is not None:
|
||||
groups = match.groupdict()
|
||||
animated = bool(groups['animated'])
|
||||
emoji_id = int(groups['id'])
|
||||
name = groups['name']
|
||||
return cls(name=name, animated=animated, id=emoji_id)
|
||||
|
||||
path: data_manager.Path = data_manager.bundled_data_path(coginstance) / "emojis.json"
|
||||
with open(path, "r", encoding="UTF-8") as file:
|
||||
emojis: dict = json.load(file)
|
||||
emoji_aliases = []
|
||||
emoji_group = None
|
||||
for dict_name, group in emojis.items():
|
||||
for k, v in group.items():
|
||||
if v == value:
|
||||
emoji_group = dict_name
|
||||
if k not in emoji_aliases:
|
||||
emoji_aliases.append(k)
|
||||
return cls(name=value, animated=False, id=None, group=emoji_group, aliases=emoji_aliases)
|
303
flake.lock
Normal file
303
flake.lock
Normal file
|
@ -0,0 +1,303 @@
|
|||
{
|
||||
"nodes": {
|
||||
"cachix": {
|
||||
"inputs": {
|
||||
"devenv": [
|
||||
"devenv"
|
||||
],
|
||||
"flake-compat": [
|
||||
"devenv"
|
||||
],
|
||||
"git-hooks": [
|
||||
"devenv"
|
||||
],
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1728672398,
|
||||
"narHash": "sha256-KxuGSoVUFnQLB2ZcYODW7AVPAh9JqRlD5BrfsC/Q4qs=",
|
||||
"owner": "cachix",
|
||||
"repo": "cachix",
|
||||
"rev": "aac51f698309fd0f381149214b7eee213c66ef0a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "latest",
|
||||
"repo": "cachix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"devenv": {
|
||||
"inputs": {
|
||||
"cachix": "cachix",
|
||||
"flake-compat": "flake-compat",
|
||||
"git-hooks": "git-hooks",
|
||||
"nix": "nix",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1732121232,
|
||||
"narHash": "sha256-CmJt7aeSCJnJYGtYpyslRI+pC28RPVD43PD/7kkIVuM=",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "6ff1e5f92c0d74bbb12f7454a239ca2f02e05ea1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1696426674,
|
||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat_2": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1696426674,
|
||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": [
|
||||
"devenv",
|
||||
"nix",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1712014858,
|
||||
"narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "9126214d0a59633752a136528f5f3b9aa8565b7d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"git-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"devenv"
|
||||
],
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": [
|
||||
"devenv",
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgs-stable": [
|
||||
"devenv"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730302582,
|
||||
"narHash": "sha256-W1MIJpADXQCgosJZT8qBYLRuZls2KSiKdpnTVdKBuvU=",
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"rev": "af8a16fe5c264f5e9e18bcee2859b40a656876cf",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"devenv",
|
||||
"git-hooks",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"libgit2": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1697646580,
|
||||
"narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=",
|
||||
"owner": "libgit2",
|
||||
"repo": "libgit2",
|
||||
"rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "libgit2",
|
||||
"repo": "libgit2",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"devenv"
|
||||
],
|
||||
"flake-parts": "flake-parts",
|
||||
"libgit2": "libgit2",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"nixpkgs-23-11": [
|
||||
"devenv"
|
||||
],
|
||||
"nixpkgs-regression": [
|
||||
"devenv"
|
||||
],
|
||||
"pre-commit-hooks": [
|
||||
"devenv"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1727438425,
|
||||
"narHash": "sha256-X8ES7I1cfNhR9oKp06F6ir4Np70WGZU5sfCOuNBEwMg=",
|
||||
"owner": "domenkozar",
|
||||
"repo": "nix",
|
||||
"rev": "f6c5ae4c1b2e411e6b1e6a8181cc84363d6a7546",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "domenkozar",
|
||||
"ref": "devenv-2.24",
|
||||
"repo": "nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1730531603,
|
||||
"narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-python": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat_2",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730716553,
|
||||
"narHash": "sha256-n4cibCp/ggDlSacCTnP8dVnywclQKYcHy6PRfe35Hk0=",
|
||||
"owner": "cachix",
|
||||
"repo": "nixpkgs-python",
|
||||
"rev": "8fcdb8ec34a1c2bae3f5326873a41b310e948ccc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "nixpkgs-python",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1717432640,
|
||||
"narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "88269ab3044128b7c2f4c7d68448b2fb50456870",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-24.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1731676054,
|
||||
"narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"nixpkgs": "nixpkgs_3",
|
||||
"nixpkgs-python": "nixpkgs-python",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
46
flake.nix
Normal file
46
flake.nix
Normal file
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
nixpkgs-python.url = "github:cachix/nixpkgs-python";
|
||||
nixpkgs-python.inputs = { nixpkgs.follows = "nixpkgs"; };
|
||||
systems.url = "github:nix-systems/default";
|
||||
devenv.url = "github:cachix/devenv";
|
||||
devenv.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
nixConfig = {
|
||||
extra-trusted-public-keys =
|
||||
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
|
||||
extra-substituters = "https://devenv.cachix.org";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, devenv, systems, ... }@inputs:
|
||||
let forEachSystem = nixpkgs.lib.genAttrs (import systems);
|
||||
in {
|
||||
packages = forEachSystem (system: {
|
||||
devenv-up = self.devShells.${system}.default.config.procfileScript;
|
||||
devenv-test = self.devShells.${system}.default.config.test;
|
||||
});
|
||||
|
||||
devShells = forEachSystem (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
default = devenv.lib.mkShell {
|
||||
inherit inputs pkgs;
|
||||
modules = [{
|
||||
languages.python = {
|
||||
enable = true;
|
||||
version = "3.11";
|
||||
uv = {
|
||||
enable = true;
|
||||
sync = {
|
||||
enable = true;
|
||||
allExtras = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
10
info.json
10
info.json
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"author": [
|
||||
"SeaswimmerTheFsh (seasw.)"
|
||||
"cswimr"
|
||||
],
|
||||
"install_msg": "Thanks for installing my repo!\n\nIf you have any issues with any of the cogs, please create an issue [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs/issues) or join my [Discord Server](https://discord.gg/eMUMe77Yb8 ).",
|
||||
"name": "SeaCogs",
|
||||
"short": "Various cogs for Red, by SeaswimmerTheFsh (seasw.)",
|
||||
"description": "Various cogs for Red, by SeaswimmerTheFsh (seasw.)"
|
||||
"install_msg": "Thanks for installing my repo!\n\nIf you have any issues with any of the cogs, please create an issue [here](https://coastalcommits.com/cswimr/SeaCogs/issues) or join my [Discord Server](https://discord.gg/eMUMe77Yb8 ).",
|
||||
"index_name": "sea-cogs",
|
||||
"short": "Various cogs for Red, by cswimr",
|
||||
"description": "Various cogs for Red, by cswimr"
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
site_name: SeaCogs Documentation
|
||||
site_url: !ENV [SITE_URL, 'https://seacogs.coastalcommits.com']
|
||||
repo_name: CoastalCommits
|
||||
repo_url: https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs
|
||||
repo_url: https://coastalcommits.com/cswimr/SeaCogs
|
||||
edit_uri: !ENV [EDIT_URI, 'src/branch/main/.docs']
|
||||
copyright: Copyright © 2023-2024, SeaswimmerTheFsh
|
||||
copyright: Copyright © 2023-2024, cswimr
|
||||
docs_dir: .docs
|
||||
|
||||
site_author: SeaswimmerTheFsh
|
||||
site_author: cswimr
|
||||
site_description: Documentation for my Red-DiscordBot Cogs.
|
||||
|
||||
nav:
|
||||
|
@ -18,6 +18,7 @@ nav:
|
|||
- Configuration: aurora/configuration.md
|
||||
- Bible: bible.md
|
||||
- Backup: backup.md
|
||||
- EmojiInfo: emojiinfo.md
|
||||
- Nerdify: nerdify.md
|
||||
- Pterodactyl:
|
||||
- pterodactyl/index.md
|
||||
|
@ -112,3 +113,5 @@ watch:
|
|||
- ./bible
|
||||
- ./nerdify
|
||||
- ./pterodactyl
|
||||
- ./emojiinfo
|
||||
- ./antipolls
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"author" : ["SeaswimmerTheFsh (seasw.)"],
|
||||
"install_msg" : "Thank you for installing Nerdify!\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs). Based off of PhasecoreX's [UwU](<https://github.com/PhasecoreX/PCXCogs/tree/master/uwu>) cog.",
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing Nerdify!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs). Based off of PhasecoreX's [UwU](<https://github.com/PhasecoreX/PCXCogs/tree/master/uwu>) cog.",
|
||||
"name" : "Nerdify",
|
||||
"short" : "Nerdify your text!",
|
||||
"description" : "Nerdify your text!",
|
||||
|
|
|
@ -12,13 +12,16 @@ from typing import Any, Optional, Union
|
|||
import discord
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils import chat_formatting, common_filters
|
||||
from redbot.core.utils.chat_formatting import bold, humanize_list
|
||||
|
||||
|
||||
class Nerdify(commands.Cog):
|
||||
"""Nerdify your text."""
|
||||
|
||||
__author__ = ["SeaswimmerTheFsh"]
|
||||
__version__ = "1.3.3"
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "1.3.5"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/nerdify/"
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
@ -28,11 +31,13 @@ class Nerdify(commands.Cog):
|
|||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"Cog Version: **{self.__version__}**",
|
||||
f"Author: {chat_formatting.humanize_list(self.__author__)}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
||||
@commands.command(aliases=["nerd"])
|
||||
async def nerdify(
|
||||
self, ctx: commands.Context, *, text: Optional[str] = None
|
||||
|
|
2539
poetry.lock
generated
2539
poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,7 @@ def register_config(config_obj: Config) -> None:
|
|||
base_url=None,
|
||||
server_id=None,
|
||||
console_channel=None,
|
||||
console_commands_enabled=False,
|
||||
current_status='',
|
||||
chat_regex=r"^\[\d{2}:\d{2}:\d{2}\sINFO\]: (?!\[(?:Server|Rcon)\])(?:<|\[)(\w+)(?:>|\]) (.*)",
|
||||
server_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]:(?: \[Not Secure\])? \[(?:Server|Rcon)\] (.*)",
|
||||
|
@ -14,6 +15,9 @@ def register_config(config_obj: Config) -> None:
|
|||
leave_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: ([^<\n]+) left the game$",
|
||||
achievement_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: (.*) has (made the advancement|completed the challenge) \[(.*)\]$",
|
||||
chat_command='tellraw @a ["",{"text":".$N ","color":".$C","insertion":"<@.$I>","hoverEvent":{"action":"show_text","contents":"Shift click to mention this user inside Discord"}},{"text":"(DISCORD):","color":"blue","clickEvent":{"action":"open_url","value":".$V"},"hoverEvent":{"action":"show_text","contents":"Click to join the Discord Server"}},{"text":" .$M","color":"white"}]', # noqa: E501
|
||||
topic='Server IP: .$H\nServer Players: .$P/.$M',
|
||||
topic_hostname=None,
|
||||
topic_port=25565,
|
||||
api_endpoint="minecraft",
|
||||
chat_channel=None,
|
||||
startup_msg='Server started!',
|
||||
|
|
BIN
pterodactyl/data/unknown.png
Normal file
BIN
pterodactyl/data/unknown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"author" : ["SeaswimmerTheFsh (seasw.)"],
|
||||
"install_msg" : "Thank you for installing Pterodactyl!\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).\nDocumentation can be found [here](https://seacogs.coastalcommits.com/pterodactyl ).",
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing Pterodactyl!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).\nDocumentation can be found [here](https://seacogs.coastalcommits.com/pterodactyl ).",
|
||||
"name" : "Pterodactyl",
|
||||
"short" : "Interface with Pterodactyl through websockets.",
|
||||
"description" : "Interface with Pterodactyl through websockets.",
|
||||
|
@ -9,7 +9,7 @@
|
|||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
"min_python_version": [3, 8, 0],
|
||||
"requirements": ["git+https://github.com/SeaswimmerTheFsh/pydactyl", "websockets"],
|
||||
"requirements": ["git+https://github.com/cswimr/pydactyl", "websockets"],
|
||||
"tags": [
|
||||
"pterodactyl",
|
||||
"minecraft",
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
from red_commons import logging
|
||||
from red_commons.logging import getLogger
|
||||
|
||||
logger = getLogger('red.seacogs.pterodactyl')
|
||||
websocket_logger = getLogger('red.seacogs.pterodactyl.websocket')
|
||||
logger = getLogger('red.SeaCogs.Pterodactyl')
|
||||
websocket_logger = getLogger('red.SeaCogs.Pterodactyl.websocket')
|
||||
if logger.level >= logging.VERBOSE:
|
||||
websocket_logger.setLevel(logging.logging.INFO)
|
||||
elif logger.level < logging.VERBOSE:
|
||||
websocket_logger.setLevel(logging.logging.DEBUG)
|
||||
|
|
10
pterodactyl/mcsrvstatus.py
Normal file
10
pterodactyl/mcsrvstatus.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
import aiohttp
|
||||
|
||||
|
||||
async def get_status(host: str, port: int = 25565) -> tuple[bool, dict]:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(f'https://api.mcsrvstat.us/2/{host}:{port}') as response:
|
||||
response = await response.json()
|
||||
if response['online']:
|
||||
return (True, response)
|
||||
return (False, response)
|
|
@ -1,16 +1,18 @@
|
|||
import asyncio
|
||||
import json
|
||||
from typing import Mapping, Optional, Union
|
||||
from typing import Mapping, Optional, Tuple, Union
|
||||
|
||||
import discord
|
||||
import websockets
|
||||
from discord.ext import tasks
|
||||
from pydactyl import PterodactylClient
|
||||
from redbot.core import app_commands, commands
|
||||
from redbot.core.app_commands import Choice
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import box, error
|
||||
from redbot.core.utils.chat_formatting import bold, box, error, humanize_list
|
||||
from redbot.core.utils.views import ConfirmView
|
||||
|
||||
from pterodactyl import mcsrvstatus
|
||||
from pterodactyl.config import config, register_config
|
||||
from pterodactyl.logger import logger
|
||||
|
||||
|
@ -18,6 +20,11 @@ from pterodactyl.logger import logger
|
|||
class Pterodactyl(commands.Cog):
|
||||
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
|
||||
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "2.0.4"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/pterodactyl/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
self.bot = bot
|
||||
self.client: Optional[PterodactylClient] = None
|
||||
|
@ -25,12 +32,39 @@ class Pterodactyl(commands.Cog):
|
|||
self.websocket: Optional[websockets.WebSocketClientProtocol] = None
|
||||
self.retry_counter: int = 0
|
||||
register_config(config)
|
||||
self.task = self.get_task()
|
||||
self.update_topic.start()
|
||||
|
||||
def format_help_for_context(self, ctx: commands.Context) -> str:
|
||||
pre_processed = super().format_help_for_context(ctx) or ""
|
||||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"{bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{bold('Author:')} {humanize_list(self.__author__)}",
|
||||
f"{bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
async def cog_load(self) -> None:
|
||||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
pterodactyl_keys = await self.bot.get_shared_api_tokens("pterodactyl")
|
||||
api_key = pterodactyl_keys.get("api_key")
|
||||
if api_key is None:
|
||||
self.task.cancel()
|
||||
raise ValueError("Pterodactyl API key not set. Please set it using `[p]set api`.")
|
||||
base_url = await config.base_url()
|
||||
if base_url is None:
|
||||
self.task.cancel()
|
||||
raise ValueError("Pterodactyl base URL not set. Please set it using `[p]pterodactyl config url`.")
|
||||
server_id = await config.server_id()
|
||||
if server_id is None:
|
||||
self.task.cancel()
|
||||
raise ValueError("Pterodactyl server ID not set. Please set it using `[p]pterodactyl config serverid`.")
|
||||
|
||||
self.client = PterodactylClient(base_url, api_key).client
|
||||
|
||||
async def cog_unload(self) -> None:
|
||||
self.update_topic.cancel()
|
||||
self.task.cancel()
|
||||
self.retry_counter = 0
|
||||
await self.client._session.close() # pylint: disable=protected-access
|
||||
|
@ -56,11 +90,26 @@ class Pterodactyl(commands.Cog):
|
|||
else:
|
||||
logger.info("Retry limit reached. Stopping task.")
|
||||
|
||||
@tasks.loop(minutes=6)
|
||||
async def update_topic(self):
|
||||
await self.bot.wait_until_red_ready()
|
||||
topic = await self.get_topic()
|
||||
console = self.bot.get_channel(await config.console_channel())
|
||||
chat = self.bot.get_channel(await config.chat_channel())
|
||||
if console:
|
||||
await console.edit(topic=topic)
|
||||
if chat:
|
||||
await chat.edit(topic=topic)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_without_command(self, message: discord.Message) -> None:
|
||||
if message.channel.id == await config.console_channel() and message.author.bot is False:
|
||||
if await config.console_commands_enabled() is False:
|
||||
await message.channel.send("Console commands are disabled.")
|
||||
logger.debug("Received console command from %s, but console commands are disabled: %s", message.author.id, message.content)
|
||||
return
|
||||
logger.debug("Received console command from %s: %s", message.author.id, message.content)
|
||||
await message.channel.send(f"Received console command from {message.author.id}: {message.content[:1900]}")
|
||||
await message.channel.send(f"Received console command from {message.author.id}: {message.content[:1900]}", allowed_mentions=discord.AllowedMentions.none())
|
||||
try:
|
||||
await self.websocket.send(json.dumps({"event": "send command", "args": [message.content]}))
|
||||
except websockets.exceptions.ConnectionClosed as e:
|
||||
|
@ -72,7 +121,7 @@ class Pterodactyl(commands.Cog):
|
|||
logger.debug("Received chat message from %s: %s", message.author.id, message.content)
|
||||
channel = self.bot.get_channel(await config.console_channel())
|
||||
if channel:
|
||||
await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}")
|
||||
await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}", allowed_mentions=discord.AllowedMentions.none())
|
||||
msg = json.dumps({"event": "send command", "args": [await self.get_chat_command(message)]})
|
||||
logger.debug("Sending chat message to server:\n%s", msg)
|
||||
try:
|
||||
|
@ -83,13 +132,41 @@ class Pterodactyl(commands.Cog):
|
|||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
|
||||
async def get_topic(self) -> str:
|
||||
topic: str = await config.topic()
|
||||
placeholders = {
|
||||
"H": await config.topic_hostname() or "unset",
|
||||
"O": str(await config.topic_port()),
|
||||
}
|
||||
if await config.api_endpoint() == "minecraft":
|
||||
status, response = await mcsrvstatus.get_status(await config.topic_hostname(), await config.topic_port())
|
||||
if status:
|
||||
placeholders.update({
|
||||
"I": response['ip'],
|
||||
"M": str(response['players']['max']),
|
||||
"P": str(response['players']['online']),
|
||||
"V": response['version'],
|
||||
"D": response['motd']['clean'][0] if response['motd']['clean'] else "unset",
|
||||
})
|
||||
else:
|
||||
placeholders.update({
|
||||
"I": response['ip'],
|
||||
"M": "0",
|
||||
"P": "0",
|
||||
"V": "Server Offline",
|
||||
"D": "Server Offline",
|
||||
})
|
||||
for key, value in placeholders.items():
|
||||
topic = topic.replace('.$' + key, value)
|
||||
return topic
|
||||
|
||||
async def get_chat_command(self, message: discord.Message) -> str:
|
||||
command: str = await config.chat_command()
|
||||
placeholders = {
|
||||
"C": str(message.author.color),
|
||||
"D": message.author.discriminator,
|
||||
"I": str(message.author.id),
|
||||
"M": message.content.replace('"',''),
|
||||
"M": message.content.replace('"','').replace("\n", " "),
|
||||
"N": message.author.display_name,
|
||||
"U": message.author.name,
|
||||
"V": await config.invite() or "use [p]pterodactyl config invite to change me",
|
||||
|
@ -98,78 +175,65 @@ class Pterodactyl(commands.Cog):
|
|||
command = command.replace('.$' + key, value)
|
||||
return command
|
||||
|
||||
async def get_player_list(self) -> Optional[Tuple[str, list]]:
|
||||
if await config.api_endpoint() == "minecraft":
|
||||
status, response = await mcsrvstatus.get_status(await config.topic_hostname(), await config.topic_port())
|
||||
if status and 'list' in response['players']:
|
||||
output_str = '\n'.join(response['players']['list'])
|
||||
return output_str, response['players']['list']
|
||||
return None
|
||||
|
||||
async def get_player_list_embed(self, ctx: Union[commands.Context, discord.Interaction]) -> Optional[discord.Embed]:
|
||||
player_list = await self.get_player_list()
|
||||
if player_list:
|
||||
embed = discord.Embed(color=await self.bot.get_embed_color(ctx.channel), title="Players Online")
|
||||
embed.description = player_list[0]
|
||||
return embed
|
||||
return None
|
||||
|
||||
async def power(self, ctx: Union[discord.Interaction, commands.Context], action: str, action_ing: str, warning: str = '') -> None:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
author = ctx.user
|
||||
else:
|
||||
author = ctx.author
|
||||
ctx = await self.bot.get_context(ctx)
|
||||
|
||||
current_status = await config.current_status()
|
||||
|
||||
if current_status == action_ing:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
return await ctx.response.send_message(f"Server is already {action_ing}.", ephemeral=True)
|
||||
return await ctx.send(f"Server is already {action_ing}.")
|
||||
return await ctx.send(f"Server is already {action_ing}.", ephemeral=True)
|
||||
|
||||
if current_status in ["starting", "stopping"]:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
return await ctx.response.send_message("Another power action is already in progress.", ephemeral=True)
|
||||
return await ctx.send("Another power action is already in progress.")
|
||||
if current_status in ["starting", "stopping"] and action != "kill":
|
||||
return await ctx.send("Another power action is already in progress.", ephemeral=True)
|
||||
|
||||
view = ConfirmView(author, disable_buttons=True)
|
||||
view = ConfirmView(ctx.author, disable_buttons=True)
|
||||
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.response.send_message(f"{warning}Are you sure you want to {action} the server?", view=view)
|
||||
else:
|
||||
message = await ctx.send(f"{warning}Are you sure you want to {action} the server?", view=view)
|
||||
message = await ctx.send(f"{warning}Are you sure you want to {action} the server?", view=view)
|
||||
|
||||
await view.wait()
|
||||
|
||||
if view.result is True:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.edit_original_response(content=f"Sending websocket command to {action} server...", view=None)
|
||||
else:
|
||||
await message.edit(content=f"Sending websocket command to {action} server...", view=None)
|
||||
await message.edit(content=f"Sending websocket command to {action} server...", view=None)
|
||||
|
||||
await self.websocket.send(json.dumps({"event": "set state", "args": [action]}))
|
||||
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.edit_original_response(content=f"Server {action_ing}", view=None)
|
||||
else:
|
||||
await message.edit(content=f"Server {action_ing}", view=None)
|
||||
await message.edit(content=f"Server {action_ing}", view=None)
|
||||
|
||||
else:
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
await ctx.edit_original_response(content="Cancelled.", view=None)
|
||||
else:
|
||||
await message.edit(content="Cancelled.", view=None)
|
||||
await message.edit(content="Cancelled.", view=None)
|
||||
|
||||
async def send_command(self, ctx: Union[discord.Interaction, commands.Context], command: str):
|
||||
channel = self.bot.get_channel(await config.console_channel())
|
||||
if isinstance(ctx, discord.Interaction):
|
||||
if channel:
|
||||
await channel.send(f"Received console command from {ctx.user.id}: {command[:1900]}")
|
||||
try:
|
||||
await self.websocket.send(json.dumps({"event": "send command", "args": [command]}))
|
||||
await ctx.response.send_message(f"Command sent to server. {box(command, 'json')}", ephemeral=True)
|
||||
except websockets.exceptions.ConnectionClosed as e:
|
||||
logger.error("WebSocket connection closed: %s", e)
|
||||
await ctx.response.send_message(error("WebSocket connection closed."))
|
||||
self.task.cancel()
|
||||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
else:
|
||||
if channel:
|
||||
await channel.send(f"Received console command from {ctx.author.id}: {command[:1900]}")
|
||||
try:
|
||||
await self.websocket.send(json.dumps({"event": "send command", "args": [command]}))
|
||||
await ctx.send(f"Command sent to server. {box(command, 'json')}")
|
||||
except websockets.exceptions.ConnectionClosed as e:
|
||||
logger.error("WebSocket connection closed: %s", e)
|
||||
await ctx.send(error("WebSocket connection closed."))
|
||||
self.task.cancel()
|
||||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
ctx = await self.bot.get_context(ctx)
|
||||
if channel:
|
||||
await channel.send(f"Received console command from {ctx.author.id}: {command[:1900]}", allowed_mentions=discord.AllowedMentions.none())
|
||||
try:
|
||||
await self.websocket.send(json.dumps({"event": "send command", "args": [command]}))
|
||||
await ctx.send(f"Command sent to server. {box(command, 'json')}")
|
||||
except websockets.exceptions.ConnectionClosed as e:
|
||||
logger.error("WebSocket connection closed: %s", e)
|
||||
await ctx.send(error("WebSocket connection closed."))
|
||||
self.task.cancel()
|
||||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_red_api_tokens_update(self, service_name: str, api_tokens: Mapping[str,str]): # pylint: disable=unused-argument
|
||||
|
@ -191,6 +255,15 @@ class Pterodactyl(commands.Cog):
|
|||
The command to send to the server."""
|
||||
return await self.send_command(interaction, command)
|
||||
|
||||
@slash_pterodactyl.command(name = "players", description = "Retrieve a list of players on the server.")
|
||||
async def slash_pterodactyl_players(self, interaction: discord.Interaction) -> None:
|
||||
"""Retrieve a list of players on the server."""
|
||||
e = await self.get_player_list_embed(interaction)
|
||||
if e:
|
||||
await interaction.response.send_message(embed=e, ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message("No players online.", ephemeral=True)
|
||||
|
||||
@slash_pterodactyl.command(name = "power", description = "Send power actions to the server.")
|
||||
@app_commands.choices(action=[
|
||||
Choice(name="Start", value="start"),
|
||||
|
@ -207,12 +280,23 @@ class Pterodactyl(commands.Cog):
|
|||
The action to perform on the server."""
|
||||
if action.value == "kill":
|
||||
return await self.power(interaction, action.value, "stopping... (forcefully killed)", warning="**⚠️ Forcefully killing the server process can corrupt data in some cases. ⚠️**\n")
|
||||
if action.value == "stop":
|
||||
return await self.power(interaction, action.value, "stopping...")
|
||||
return await self.power(interaction, action.value, f"{action.value}ing...")
|
||||
|
||||
@commands.group(autohelp = True, name = "pterodactyl", aliases = ["ptero"])
|
||||
async def pterodactyl(self, ctx: commands.Context) -> None:
|
||||
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
|
||||
|
||||
@pterodactyl.command(name = "players", aliases=["list", "online", "playerlist", "who"])
|
||||
async def pterodactyl_players(self, ctx: commands.Context) -> None:
|
||||
"""Retrieve a list of players on the server."""
|
||||
e = await self.get_player_list_embed(ctx)
|
||||
if e:
|
||||
await ctx.send(embed=e)
|
||||
else:
|
||||
await ctx.send("No players online.")
|
||||
|
||||
@pterodactyl.command(name = "command", aliases = ["cmd", "execute", "exec"])
|
||||
@commands.admin()
|
||||
async def pterodactyl_command(self, ctx: commands.Context, *, command: str) -> None:
|
||||
|
@ -272,18 +356,60 @@ class Pterodactyl(commands.Cog):
|
|||
self.retry_counter = 0
|
||||
self.task = self.get_task()
|
||||
|
||||
@pterodactyl_config.command(name = "consolechannel")
|
||||
@pterodactyl_config.group(name = "console")
|
||||
async def pterodactyl_config_console(self, ctx: commands.Context):
|
||||
"""Configure console settings."""
|
||||
|
||||
@pterodactyl_config_console.command(name = "channel")
|
||||
async def pterodactyl_config_console_channel(self, ctx: commands.Context, channel: discord.TextChannel) -> None:
|
||||
"""Set the channel to send console output to."""
|
||||
await config.console_channel.set(channel.id)
|
||||
await ctx.send(f"Console channel set to {channel.mention}")
|
||||
|
||||
@pterodactyl_config_console.command(name = "commands")
|
||||
async def pterodactyl_config_console_commands(self, ctx: commands.Context, enabled: bool) -> None:
|
||||
"""Enable or disable console commands."""
|
||||
await config.console_commands_enabled.set(enabled)
|
||||
await ctx.send(f"Console commands set to {enabled}")
|
||||
|
||||
@pterodactyl_config.command(name = "invite")
|
||||
async def pterodactyl_config_invite(self, ctx: commands.Context, invite: str) -> None:
|
||||
"""Set the invite link for your server."""
|
||||
await config.invite.set(invite)
|
||||
await ctx.send(f"Invite link set to {invite}")
|
||||
|
||||
@pterodactyl_config.group(name = "topic")
|
||||
async def pterodactyl_config_topic(self, ctx: commands.Context):
|
||||
"""Set the topic for the console and chat channels."""
|
||||
|
||||
@pterodactyl_config_topic.command(name = "host", aliases = ["hostname", "ip"])
|
||||
async def pterodactyl_config_topic_host(self, ctx: commands.Context, host: str) -> None:
|
||||
"""Set the hostname or IP address of your server."""
|
||||
await config.topic_hostname.set(host)
|
||||
await ctx.send(f"Hostname/IP set to `{host}`")
|
||||
|
||||
@pterodactyl_config_topic.command(name = "port")
|
||||
async def pterodactyl_config_topic_port(self, ctx: commands.Context, port: int) -> None:
|
||||
"""Set the port of your server."""
|
||||
await config.topic_port.set(port)
|
||||
await ctx.send(f"Port set to `{port}`")
|
||||
|
||||
@pterodactyl_config_topic.command(name = "text")
|
||||
async def pterodactyl_config_topic_text(self, ctx: commands.Context, *, text: str) -> None:
|
||||
"""Set the text for the console and chat channels.
|
||||
|
||||
Available placeholders:
|
||||
- `.$H` (hostname)
|
||||
- `.$O` (port)
|
||||
Available for Minecraft servers:
|
||||
- `.$I` (ip)
|
||||
- `.$M` (max players)
|
||||
- `.$P` (players online)
|
||||
- `.$V` (version)
|
||||
- `.$D` (description / Message of the Day)"""
|
||||
await config.topic.set(text)
|
||||
await ctx.send(f"Topic set to:\n{box(text, 'yaml')}")
|
||||
|
||||
@pterodactyl_config.group(name = "chat")
|
||||
async def pterodactyl_config_chat(self, ctx: commands.Context):
|
||||
"""Configure chat settings."""
|
||||
|
@ -408,7 +534,7 @@ class Pterodactyl(commands.Cog):
|
|||
await view.wait()
|
||||
if view.result is True:
|
||||
blacklist.update({name: regex})
|
||||
await msg.edit(f"Updated `{name}` in the regex blacklist.\n{box(regex, 're')}")
|
||||
await msg.edit(content=f"Updated `{name}` in the regex blacklist.\n{box(regex, 're')}")
|
||||
else:
|
||||
await msg.edit(content="Cancelled.")
|
||||
|
||||
|
@ -423,7 +549,7 @@ class Pterodactyl(commands.Cog):
|
|||
await view.wait()
|
||||
if view.result is True:
|
||||
del blacklist[name]
|
||||
await msg.edit(content="Removed `{name}` from the regex blacklist.")
|
||||
await msg.edit(content=f"Removed `{name}` from the regex blacklist.")
|
||||
else:
|
||||
await msg.edit(content="Cancelled.")
|
||||
else:
|
||||
|
@ -435,6 +561,7 @@ class Pterodactyl(commands.Cog):
|
|||
base_url = await config.base_url()
|
||||
server_id = await config.server_id()
|
||||
console_channel = await config.console_channel()
|
||||
console_commands_enabled = await config.console_commands_enabled()
|
||||
chat_channel = await config.chat_channel()
|
||||
chat_command = await config.chat_command()
|
||||
chat_regex = await config.chat_regex()
|
||||
|
@ -450,10 +577,14 @@ class Pterodactyl(commands.Cog):
|
|||
api_endpoint = await config.api_endpoint()
|
||||
invite = await config.invite()
|
||||
regex_blacklist: dict = await config.regex_blacklist()
|
||||
topic_text = await config.topic()
|
||||
topic_hostname = await config.topic_hostname()
|
||||
topic_port = await config.topic_port()
|
||||
embed = discord.Embed(color = await ctx.embed_color(), title="Pterodactyl Configuration")
|
||||
embed.description = f"""**Base URL:** {base_url}
|
||||
**Server ID:** `{server_id}`
|
||||
**Console Channel:** <#{console_channel}>
|
||||
**Console Commands:** {self.get_bool_str(console_commands_enabled)}
|
||||
**Chat Channel:** <#{chat_channel}>
|
||||
**Startup Message:** {startup_msg}
|
||||
**Shutdown Message:** {shutdown_msg}
|
||||
|
@ -463,6 +594,10 @@ class Pterodactyl(commands.Cog):
|
|||
**API Endpoint:** `{api_endpoint}`
|
||||
**Invite:** {invite}
|
||||
|
||||
**Topic Hostname:** `{topic_hostname}`
|
||||
**Topic Port:** `{topic_port}`
|
||||
**Topic Text:** {box(topic_text, 'yaml')}
|
||||
|
||||
**Chat Command:** {box(chat_command, 'json')}
|
||||
**Chat Regex:** {box(chat_regex, 're')}
|
||||
**Server Regex:** {box(server_regex, 're')}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# pylint: disable=cyclic-import
|
||||
import json
|
||||
import re
|
||||
from typing import Optional, Union
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple, Union
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
import websockets
|
||||
from pydactyl import PterodactylClient
|
||||
from redbot.core.data_manager import bundled_data_path
|
||||
from redbot.core.utils.chat_formatting import bold, pagify
|
||||
|
||||
from pterodactyl.config import config
|
||||
|
@ -15,6 +17,7 @@ from pterodactyl.pterodactyl import Pterodactyl
|
|||
|
||||
|
||||
async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
||||
await coginstance.bot.wait_until_red_ready()
|
||||
base_url = await config.base_url()
|
||||
base_url = base_url[:-1] if base_url.endswith('/') else base_url
|
||||
|
||||
|
@ -52,18 +55,18 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
if await config.mask_ip() is True:
|
||||
content = mask_ip(content)
|
||||
|
||||
channel = coginstance.bot.get_channel(await config.console_channel())
|
||||
if channel is not None:
|
||||
console_channel = coginstance.bot.get_channel(await config.console_channel())
|
||||
chat_channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if console_channel is not None:
|
||||
if content.startswith('['):
|
||||
pagified_content = pagify(content, delims=[" ", "\n"])
|
||||
for page in pagified_content:
|
||||
await channel.send(content=page, allowed_mentions=discord.AllowedMentions.none())
|
||||
await console_channel.send(content=page, allowed_mentions=discord.AllowedMentions.none())
|
||||
|
||||
server_message = await check_if_server_message(content)
|
||||
if server_message:
|
||||
channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if channel is not None:
|
||||
await channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
|
||||
if chat_channel is not None:
|
||||
await chat_channel.send(server_message if len(server_message) < 2000 else server_message[:1997] + '...', allowed_mentions=discord.AllowedMentions.none())
|
||||
|
||||
chat_message = await check_if_chat_message(content)
|
||||
if chat_message:
|
||||
|
@ -75,30 +78,37 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
|
||||
join_message = await check_if_join_message(content)
|
||||
if join_message:
|
||||
channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if channel is not None:
|
||||
if coginstance.bot.embed_requested(channel):
|
||||
await channel.send(embed=await generate_join_leave_embed(join_message, True))
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=join_message,join=True)
|
||||
if img:
|
||||
with open(img, 'rb') as file:
|
||||
await chat_channel.send(embed=embed, file=file)
|
||||
else:
|
||||
await chat_channel.send(embed=embed)
|
||||
else:
|
||||
await channel.send(f"{join_message} joined the game", allowed_mentions=discord.AllowedMentions.none())
|
||||
await chat_channel.send(f"{join_message} joined the game", allowed_mentions=discord.AllowedMentions.none())
|
||||
|
||||
leave_message = await check_if_leave_message(content)
|
||||
if leave_message:
|
||||
channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if channel is not None:
|
||||
if coginstance.bot.embed_requested(channel):
|
||||
await channel.send(embed=await generate_join_leave_embed(leave_message, False))
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=leave_message,join=False)
|
||||
if img:
|
||||
with open(img, 'rb') as file:
|
||||
await chat_channel.send(embed=embed, file=file)
|
||||
else:
|
||||
await chat_channel.send(embed=embed)
|
||||
else:
|
||||
await channel.send(f"{leave_message} left the game", allowed_mentions=discord.AllowedMentions.none())
|
||||
await chat_channel.send(f"{leave_message} left the game", allowed_mentions=discord.AllowedMentions.none())
|
||||
|
||||
achievement_message = await check_if_achievement_message(content)
|
||||
if achievement_message:
|
||||
channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if channel is not None:
|
||||
if coginstance.bot.embed_requested(channel):
|
||||
await channel.send(embed=await generate_achievement_embed(achievement_message['username'], achievement_message['achievement'], achievement_message['challenge']))
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
await chat_channel.send(embed=await generate_achievement_embed(coginstance, achievement_message['username'], achievement_message['achievement'], achievement_message['challenge']))
|
||||
else:
|
||||
await channel.send(f"{achievement_message['username']} has {'completed the challenge' if achievement_message['challenge'] else 'made the advancement'} {achievement_message['achievement']}")
|
||||
await chat_channel.send(f"{achievement_message['username']} has {'completed the challenge' if achievement_message['challenge'] else 'made the advancement'} {achievement_message['achievement']}")
|
||||
|
||||
if message['event'] == 'status':
|
||||
old_status = await config.current_status()
|
||||
|
@ -155,7 +165,7 @@ async def check_if_server_message(text: str) -> Union[bool, str]:
|
|||
regex = await config.server_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
logger.debug("Message is a server message")
|
||||
logger.trace("Message is a server message")
|
||||
return match.group(1)
|
||||
return False
|
||||
|
||||
|
@ -164,7 +174,7 @@ async def check_if_chat_message(text: str) -> Union[bool, dict]:
|
|||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
groups = {"username": match.group(1), "message": match.group(2)}
|
||||
logger.debug("Message is a chat message\n%s", json.dumps(groups))
|
||||
logger.trace("Message is a chat message\n%s", json.dumps(groups))
|
||||
return groups
|
||||
return False
|
||||
|
||||
|
@ -172,7 +182,7 @@ async def check_if_join_message(text: str) -> Union[bool, str]:
|
|||
regex = await config.join_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
logger.debug("Message is a join message")
|
||||
logger.trace("Message is a join message")
|
||||
return match.group(1)
|
||||
return False
|
||||
|
||||
|
@ -180,7 +190,7 @@ async def check_if_leave_message(text: str) -> Union[bool, str]:
|
|||
regex = await config.leave_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
logger.debug("Message is a leave message")
|
||||
logger.trace("Message is a leave message")
|
||||
return match.group(1)
|
||||
return False
|
||||
|
||||
|
@ -193,23 +203,23 @@ async def check_if_achievement_message(text: str) -> Union[bool, dict]:
|
|||
groups["challenge"] = True
|
||||
else:
|
||||
groups["challenge"] = False
|
||||
logger.debug("Message is an achievement message")
|
||||
logger.trace("Message is an achievement message")
|
||||
return groups
|
||||
return False
|
||||
|
||||
async def get_info(username: str) -> Optional[dict]:
|
||||
logger.debug("Retrieving player info for %s", username)
|
||||
logger.verbose("Retrieving player info for %s", username)
|
||||
endpoint = await config.api_endpoint()
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(f"https://playerdb.co/api/player/{endpoint}/{username}") as response:
|
||||
if response.status == 200:
|
||||
logger.debug("Player info retrieved for %s", username)
|
||||
logger.verbose("Player info retrieved for %s", username)
|
||||
return await response.json()
|
||||
logger.error("Failed to retrieve player info for %s: %s", username, response.status)
|
||||
logger.warning("Failed to retrieve player info for %s: %s", username, response.status)
|
||||
return None
|
||||
|
||||
async def send_chat_discord(coginstance: Pterodactyl, username: str, message: str, avatar_url: str) -> None:
|
||||
logger.debug("Sending chat message to Discord")
|
||||
logger.trace("Sending chat message to Discord")
|
||||
channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if channel is not None:
|
||||
webhooks = await channel.webhooks()
|
||||
|
@ -217,33 +227,37 @@ async def send_chat_discord(coginstance: Pterodactyl, username: str, message: st
|
|||
if webhook is None:
|
||||
webhook = await channel.create_webhook(name="Pterodactyl Chat")
|
||||
await webhook.send(content=message, username=username, avatar_url=avatar_url, allowed_mentions=discord.AllowedMentions(everyone=False, roles=False, users=True))
|
||||
logger.debug("Chat message sent to Discord")
|
||||
logger.trace("Chat message sent to Discord")
|
||||
else:
|
||||
logger.warning("Chat channel not set. Skipping sending chat message to Discord")
|
||||
|
||||
async def generate_join_leave_embed(username: str, join: bool) -> discord.Embed:
|
||||
async def generate_join_leave_embed(coginstance: Pterodactyl, username: str, join: bool) -> Tuple[discord.Embed, Optional[Union[str, Path]]]:
|
||||
embed = discord.Embed()
|
||||
embed.color = discord.Color.green() if join else discord.Color.red()
|
||||
embed.description = await config.join_msg() if join else await config.leave_msg()
|
||||
info = await get_info(username)
|
||||
if info:
|
||||
img = None
|
||||
embed.set_author(name=username, icon_url=info['data']['player']['avatar'])
|
||||
else:
|
||||
embed.set_author(name=username, icon_url='https://seafsh.cc/u/j3AzqQ.png')
|
||||
img = bundled_data_path(coginstance) / "unknown.png"
|
||||
embed.set_author(name=username, icon_url='attachment://unknown.png')
|
||||
embed.timestamp = discord.utils.utcnow()
|
||||
return embed
|
||||
return embed, img
|
||||
|
||||
async def generate_achievement_embed(username: str, achievement: str, challenge: bool) -> discord.Embed:
|
||||
async def generate_achievement_embed(coginstance: Pterodactyl, username: str, achievement: str, challenge: bool) -> Tuple[discord.Embed, Optional[Union[str, Path]]]:
|
||||
embed = discord.Embed()
|
||||
embed.color = discord.Color.from_str('#a800a7') if challenge else discord.Color.from_str('#54fb54')
|
||||
embed.description = f"{bold(username)} has {'completed the challenge' if challenge else 'made the advancement'} {bold(achievement)}"
|
||||
info = await get_info(username)
|
||||
if info:
|
||||
img = None
|
||||
embed.set_author(name=username, icon_url=info['data']['player']['avatar'])
|
||||
else:
|
||||
embed.set_author(name=username, icon_url='https://seafsh.cc/u/j3AzqQ.png')
|
||||
img = bundled_data_path(coginstance) / "unknown.png"
|
||||
embed.set_author(name=username, icon_url='attachment://unknown.png')
|
||||
embed.timestamp = discord.utils.utcnow()
|
||||
return embed
|
||||
return embed, img
|
||||
|
||||
def mask_ip(string: str) -> str:
|
||||
def check(match: re.Match[str]):
|
||||
|
|
|
@ -1,40 +1,44 @@
|
|||
[tool.poetry]
|
||||
[project]
|
||||
name = "seacogs"
|
||||
version = "0.1.0"
|
||||
description = "My assorted cogs for Red-DiscordBot."
|
||||
authors = ["SeaswimmerTheFsh"]
|
||||
license = "MPL 2"
|
||||
authors = [{name = "cswimr", email = "seaswimmerthefsh@gmail.com"}]
|
||||
license = {file="LICENSE"}
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
"aiosqlite>=0.20.0",
|
||||
"beautifulsoup4>=4.12.3",
|
||||
"colorthief>=0.2.1",
|
||||
"markdownify>=0.13.1",
|
||||
"numpy>=2.1.2",
|
||||
"phx-class-registry>=5.0.0",
|
||||
"pillow>=10.4.0",
|
||||
"py-dactyl",
|
||||
"pydantic>=2.9.2",
|
||||
"red-discordbot>=3.5.13",
|
||||
"websockets>=13.1",
|
||||
]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.11,<3.12"
|
||||
Red-DiscordBot = "^3.5.5"
|
||||
pytimeparse2 = "^1.7.1"
|
||||
humanize = "^4.8.0"
|
||||
py-dactyl = "^2.0.4"
|
||||
websockets = "^12.0"
|
||||
[project.optional-dependencies]
|
||||
documentation = [
|
||||
"mkdocs>=1.6.1",
|
||||
"mkdocs-git-authors-plugin>=0.9.0",
|
||||
"mkdocs-git-revision-date-localized-plugin>=1.2.9",
|
||||
"mkdocs-material[imaging]>=9.5.40",
|
||||
"mkdocstrings[python]>=0.26.1",
|
||||
"mkdocs-redirects>=1.2.1",
|
||||
]
|
||||
|
||||
[tool.poetry.group.dev]
|
||||
optional = true
|
||||
[tool.uv]
|
||||
dev-dependencies = [
|
||||
"pylint>=3.3.1",
|
||||
"ruff>=0.6.9",
|
||||
"sqlite-web>=0.6.4",
|
||||
]
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ruff = "^0.2.1"
|
||||
pylint = "^3.1.0"
|
||||
|
||||
[tool.poetry.group.docs]
|
||||
optional = true
|
||||
|
||||
[tool.poetry.group.docs.dependencies]
|
||||
mkdocs = "1.5.3"
|
||||
mkdocstrings = {extras = ["python"], version = "0.24.0"}
|
||||
mkdocs-git-authors-plugin = "0.7.2"
|
||||
mkdocs-git-revision-date-localized-plugin = "1.2.2"
|
||||
mkdocs-material = {extras = ["imaging"], version = "^9.5.2"}
|
||||
mkdocs-redirects = "^1.2.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
[tool.uv.sources]
|
||||
py-dactyl = { git = "https://github.com/cswimr/pydactyl" }
|
||||
|
||||
[tool.ruff]
|
||||
# Exclude a variety of commonly ignored directories.
|
||||
|
|
5
seautils/__init__.py
Normal file
5
seautils/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from .seautils import SeaUtils
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(SeaUtils(bot))
|
13
seautils/info.json
Normal file
13
seautils/info.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"author" : ["cswimr"],
|
||||
"install_msg" : "Thank you for installing SeaUtils!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).",
|
||||
"name" : "SeaUtils",
|
||||
"short" : "A collection of useful utilities.",
|
||||
"description" : "A collection of useful utilities.",
|
||||
"end_user_data_statement" : "This cog does not store end user data.",
|
||||
"hidden": true,
|
||||
"disabled": false,
|
||||
"min_bot_version": "3.5.0",
|
||||
"min_python_version": [3, 8, 0],
|
||||
"requirements": ["beautifulsoup4", "markdownify"]
|
||||
}
|
254
seautils/seautils.py
Normal file
254
seautils/seautils.py
Normal file
|
@ -0,0 +1,254 @@
|
|||
# _____ _
|
||||
# / ____| (_)
|
||||
# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __
|
||||
# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__|
|
||||
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
|
||||
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
||||
|
||||
import asyncio
|
||||
import inspect
|
||||
import operator
|
||||
import re
|
||||
from asyncio.subprocess import Process
|
||||
from functools import partial, partialmethod
|
||||
from typing import Any
|
||||
|
||||
import aiohttp
|
||||
import yaml
|
||||
from bs4 import BeautifulSoup
|
||||
from discord import Color, Embed, app_commands
|
||||
from discord.utils import CachedSlotProperty, cached_property
|
||||
from markdownify import MarkdownConverter
|
||||
from redbot.core import commands
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.dev_commands import cleanup_code
|
||||
from redbot.core.utils import chat_formatting as cf
|
||||
from redbot.core.utils.views import SimpleMenu
|
||||
|
||||
|
||||
def md(soup: BeautifulSoup, **options) -> Any | str:
|
||||
return MarkdownConverter(**options).convert_soup(soup=soup)
|
||||
|
||||
def format_rfc_text(text: str, number: int) -> str:
|
||||
one: str = re.sub(r"\(\.\/rfc(\d+)", r"(https://www.rfc-editor.org/rfc/rfc\1.html", text)
|
||||
two: str = re.sub(r"\((#(?:section|page)-\d+(?:.\d+)?)\)", f"(https://www.rfc-editor.org/rfc/rfc{number}.html\1)", one)
|
||||
three: str = re.sub(r"\n{3,}", "\n\n", two)
|
||||
return three
|
||||
|
||||
class SeaUtils(commands.Cog):
|
||||
"""A collection of random utilities."""
|
||||
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "1.0.1"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/seautils/"
|
||||
|
||||
def __init__(self, bot: Red) -> None:
|
||||
self.bot = bot
|
||||
|
||||
def format_help_for_context(self, ctx: commands.Context) -> str:
|
||||
pre_processed = super().format_help_for_context(ctx) or ""
|
||||
n = "\n" if "\n\n" not in pre_processed else ""
|
||||
text = [
|
||||
f"{pre_processed}{n}",
|
||||
f"{cf.bold('Cog Version:')} [{self.__version__}]({self.__git__})",
|
||||
f"{cf.bold('Author:')} {cf.humanize_list(self.__author__)}",
|
||||
f"{cf.bold('Documentation:')} {self.__documentation__}",
|
||||
]
|
||||
return "\n".join(text)
|
||||
|
||||
|
||||
def format_src(self, obj: Any) -> str:
|
||||
"""A large portion of this code is repurposed from Zephyrkul's RTFS cog.
|
||||
https://github.com/Zephyrkul/FluffyCogs/blob/master/rtfs/rtfs.py"""
|
||||
obj = inspect.unwrap(func=obj)
|
||||
src: Any = getattr(obj, "__func__", obj)
|
||||
if isinstance(obj, (commands.Command, app_commands.Command)):
|
||||
src = obj.callback
|
||||
elif isinstance(obj, (partial, partialmethod)):
|
||||
src = obj.func
|
||||
elif isinstance(obj, property):
|
||||
src = obj.fget
|
||||
elif isinstance(obj, (cached_property, CachedSlotProperty)):
|
||||
src = obj.function
|
||||
return inspect.getsource(object=src)
|
||||
|
||||
@commands.command(aliases=["source", "src", "code", "showsource"])
|
||||
@commands.is_owner()
|
||||
async def showcode(self, ctx: commands.Context, *, object: str) -> None: # pylint: disable=redefined-builtin
|
||||
"""Show the code for a particular object."""
|
||||
try:
|
||||
if object.startswith("/") and (obj := ctx.bot.tree.get_command(object[1:])):
|
||||
text = self.format_src(obj)
|
||||
elif obj := ctx.bot.get_cog(object):
|
||||
text = self.format_src(type(obj))
|
||||
elif obj := ctx.bot.get_command(object):
|
||||
text = self.format_src(obj)
|
||||
else:
|
||||
raise AttributeError
|
||||
temp_content = cf.pagify(
|
||||
text=cleanup_code(text),
|
||||
escape_mass_mentions=True,
|
||||
page_length = 1977
|
||||
)
|
||||
content = []
|
||||
max_i = operator.length_hint(temp_content)
|
||||
i = 1
|
||||
for page in temp_content:
|
||||
content.append(f"**Page {i}/{max_i}**\n{cf.box(page, lang='py')}")
|
||||
i += 1
|
||||
await SimpleMenu(pages=content, disable_after_timeout=True, timeout=180).start(ctx)
|
||||
except (OSError, AttributeError, UnboundLocalError):
|
||||
if ctx.embed_requested():
|
||||
embed = Embed(title="Object not found!", color=await ctx.embed_color())
|
||||
await ctx.send(embed=embed, reference=ctx.message.to_reference(fail_if_not_exists=False))
|
||||
else:
|
||||
await ctx.send(content="Object not found!", reference=ctx.message.to_reference(fail_if_not_exists=False))
|
||||
|
||||
@commands.command(name='dig', aliases=['dnslookup', 'nslookup'])
|
||||
@commands.is_owner()
|
||||
async def dig(self, ctx: commands.Context, name: str, record_type: str | None = None, server: str | None = None, port: int = 53) -> None:
|
||||
"""Retrieve DNS information for a domain.
|
||||
|
||||
Uses `dig` to perform a DNS query. Will fall back to `nslookup` if `dig` is not installed on the system.
|
||||
`nslookup` does not provide as much information as `dig`, so only the `name` parameter will be used if `nslookup` is used.
|
||||
Will return the A, AAAA, and CNAME records for a domain by default. You can specify a different record type with the `type` parameter."""
|
||||
command_opts: list[str | int] = ['dig']
|
||||
query_types: list[str] = [record_type] if record_type else ['A', 'AAAA', 'CNAME']
|
||||
if server:
|
||||
command_opts.extend(['@', server])
|
||||
for query_type in query_types:
|
||||
command_opts.extend([name, query_type])
|
||||
command_opts.extend(['-p', str(port), '+yaml'])
|
||||
|
||||
try:
|
||||
process: Process = await asyncio.create_subprocess_exec(*command_opts, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||
stdout, stderr = await process.communicate()
|
||||
if stderr:
|
||||
await ctx.maybe_send_embed(message="An error was encountered!\n" + cf.box(text=stderr.decode()))
|
||||
else:
|
||||
data = yaml.safe_load(stdout.decode())
|
||||
message_data: dict = data[0]['message']
|
||||
response_data: dict = message_data['response_message_data']
|
||||
if ctx.embed_requested():
|
||||
embed = Embed(
|
||||
title="DNS Query Result",
|
||||
color=await ctx.embed_color(),
|
||||
timestamp=message_data['response_time']
|
||||
)
|
||||
embed.add_field(name="Response Address", value=message_data['response_address'], inline=True)
|
||||
embed.add_field(name="Response Port", value=message_data['response_port'], inline=True)
|
||||
embed.add_field(name="Query Address", value=message_data['query_address'], inline=True)
|
||||
embed.add_field(name="Query Port", value=message_data['query_port'], inline=True)
|
||||
embed.add_field(name="Status", value=response_data['status'], inline=True)
|
||||
embed.add_field(name="Flags", value=response_data['flags'], inline=True)
|
||||
|
||||
if response_data.get('status') != 'NOERROR':
|
||||
embed.colour = Color.red()
|
||||
embed.description = cf.error("Dig query did not return `NOERROR` status.")
|
||||
|
||||
questions = []
|
||||
answers = []
|
||||
authorities = []
|
||||
for m in data:
|
||||
response = m['message']['response_message_data']
|
||||
if 'QUESTION_SECTION' in response:
|
||||
for question in response['QUESTION_SECTION']:
|
||||
if question not in questions:
|
||||
questions.append(question)
|
||||
|
||||
if 'ANSWER_SECTION' in response:
|
||||
for answer in response['ANSWER_SECTION']:
|
||||
if answer not in answers:
|
||||
answers.append(answer)
|
||||
|
||||
if 'AUTHORITY_SECTION' in response:
|
||||
for authority in response['AUTHORITY_SECTION']:
|
||||
if authority not in authorities:
|
||||
authorities.append(authority)
|
||||
|
||||
if questions:
|
||||
question_section = "\n".join(questions)
|
||||
embed.add_field(name="Question Section", value=f"{cf.box(text=question_section, lang='prolog')}", inline=False)
|
||||
|
||||
if answers:
|
||||
answer_section = "\n".join(answers)
|
||||
if len(answer_section) > 1024:
|
||||
embed.description = cf.warning("Answer section is too long to fit within embed field, falling back to description.") + cf.box(answer_section)
|
||||
else:
|
||||
embed.add_field(name="Answer Section", value=f"{cf.box(text=answer_section, lang='prolog')}", inline=False)
|
||||
|
||||
if authorities:
|
||||
authority_section = "\n".join(authorities)
|
||||
embed.add_field(name="Authority Section", value=f"{cf.box(text=authority_section, lang='prolog')}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send(content=cf.box(text=stdout, lang='yaml'))
|
||||
except (FileNotFoundError):
|
||||
try:
|
||||
ns_process = await asyncio.create_subprocess_exec('nslookup', name, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||
ns_stdout, ns_stderr = await ns_process.communicate()
|
||||
if ns_stderr:
|
||||
await ctx.maybe_send_embed(message="An error was encountered!\n" + cf.box(text=ns_stderr.decode()))
|
||||
else:
|
||||
warning = cf.warning("`dig` is not installed! Defaulting to `nslookup`.\nThis command provides more information when `dig` is installed on the system.\n")
|
||||
if await ctx.embed_requested():
|
||||
embed = Embed(
|
||||
title="DNS Query Result",
|
||||
color=await ctx.embed_color(),
|
||||
timestamp=ctx.message.created_at
|
||||
)
|
||||
embed.description = warning + cf.box(text=ns_stdout.decode())
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send(content = warning + cf.box(text=ns_stdout.decode()))
|
||||
except (FileNotFoundError):
|
||||
await ctx.maybe_send_embed(message=cf.error("Neither `dig` nor `nslookup` are installed on the system. Unable to resolve DNS query."))
|
||||
|
||||
@commands.command()
|
||||
async def rfc(self, ctx: commands.Context, number: int) -> None:
|
||||
"""Retrieve the text of an RFC document.
|
||||
|
||||
This command uses the [RFC Editor website](https://www.rfc-editor.org/) to fetch the text of an RFC document.
|
||||
A [Request for Comments (RFC)](https://en.wikipedia.org/wiki/Request_for_Comments) is a publication in a series from the principal technical development and standards-setting bodies for the [Internet](https://en.wikipedia.org/wiki/Internet), most prominently the [Internet Engineering Task Force](https://en.wikipedia.org/wiki/Internet_Engineering_Task_Force). An RFC is authored by individuals or groups of engineers and [computer scientists](https://en.wikipedia.org/wiki/Computer_scientist) in the form of a [memorandum](https://en.wikipedia.org/wiki/Memorandum) describing methods, behaviors, research, or innovations applicable to the working of the Internet and Internet-connected systems. It is submitted either for [peer review](https://en.wikipedia.org/wiki/Peer_review) or to convey new concepts, information, or, occasionally, engineering humor.""" # noqa: E501
|
||||
url = f"https://www.rfc-editor.org/rfc/rfc{number}.html"
|
||||
datatracker_url = f"https://datatracker.ietf.org/doc/rfc{number}"
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url=url) as response:
|
||||
if response.status == 200:
|
||||
html = await response.text()
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
pre_tags = soup.find_all('pre')
|
||||
content: list[Embed | str] = []
|
||||
for pre_tag in pre_tags:
|
||||
text = format_rfc_text(md(pre_tag), number)
|
||||
if len(text) > 4096:
|
||||
pagified_text = cf.pagify(text, delims=["\n\n"], page_length=4096)
|
||||
for page in pagified_text:
|
||||
if await ctx.embed_requested():
|
||||
embed = Embed(
|
||||
title=f"RFC Document {number}",
|
||||
url=datatracker_url,
|
||||
description=page,
|
||||
color=await ctx.embed_color()
|
||||
)
|
||||
content.append(embed)
|
||||
else:
|
||||
content.append(page)
|
||||
else:
|
||||
if await ctx.embed_requested():
|
||||
embed = Embed(
|
||||
title=f"RFC Document {number}",
|
||||
url=datatracker_url,
|
||||
description=text,
|
||||
color=await ctx.embed_color()
|
||||
)
|
||||
content.append(embed)
|
||||
else:
|
||||
content.append(text)
|
||||
if await ctx.embed_requested():
|
||||
for embed in content:
|
||||
embed.set_footer(text=f"Page {content.index(embed) + 1}/{len(content)}")
|
||||
await SimpleMenu(pages=content, disable_after_timeout=True, timeout=300).start(ctx)
|
||||
else:
|
||||
await ctx.maybe_send_embed(message=cf.error(f"An error occurred while fetching RFC {number}. Status code: {response.status}."))
|
Loading…
Reference in a new issue