Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge genshinutils cog into main #1

Draft
wants to merge 51 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b398385
Add genshinutils cog
raidensakura Jan 23, 2023
164c5c5
Add verification for profile linking, restructure commands
raidensakura Jan 24, 2023
1953070
Add dictionary
raidensakura Jan 26, 2023
15baef8
More stuff ✨
raidensakura Jan 26, 2023
1df04d2
Too much stuff ✨
raidensakura Jan 28, 2023
46ee2e7
Update README.md
raidensakura Jan 28, 2023
9d5d659
Update README.md
raidensakura Jan 28, 2023
ab53fc0
Update README.md
raidensakura Jan 28, 2023
f5a94f0
Too many stuff again
raidensakura Jan 29, 2023
eeeec87
Cleanup
raidensakura Jan 29, 2023
baf4c96
Add daily command and flake8 cleanup
raidensakura Jan 30, 2023
773dff0
Add workflows
raidensakura Jan 30, 2023
2b6b9d8
More stuff...
raidensakura Jan 30, 2023
96ff5c2
Tweak workflow
raidensakura Jan 30, 2023
dad5b42
Hmm
raidensakura Jan 30, 2023
93dacc3
Test again...
raidensakura Jan 30, 2023
3443cf8
again, blegh
raidensakura Jan 30, 2023
fc4f31f
I hope it work now
raidensakura Jan 30, 2023
be9871f
Cmon pip
raidensakura Jan 30, 2023
fb6498e
🚩
raidensakura Jan 30, 2023
783c626
:(
raidensakura Jan 30, 2023
c1d4093
.
raidensakura Jan 30, 2023
1f0d3d3
TYPO OOF
raidensakura Jan 30, 2023
ef1764a
bruh
raidensakura Jan 30, 2023
e54e577
Remove more stuff
raidensakura Jan 30, 2023
9e27955
Link & format
raidensakura Jan 30, 2023
bc15cb2
Reformat again ugh
raidensakura Jan 30, 2023
543e635
Bump Github Actions ver.
raidensakura Jan 30, 2023
8f74ad2
Update README.md
raidensakura Jan 30, 2023
123a804
Update README.md
raidensakura Jan 30, 2023
f667cd2
Bump pre-commit versions, docs, format json
raidensakura Jan 31, 2023
235d895
Update README.md
raidensakura Jan 31, 2023
b94b122
Update README.md
raidensakura Jan 31, 2023
dd0d1dd
Update README.md
raidensakura Jan 31, 2023
c839aa5
add task
raidensakura Feb 1, 2023
40607b7
Fix cog requirements
raidensakura Feb 2, 2023
d59bbe4
Change checks decorator to commands
raidensakura Feb 2, 2023
45c2c23
Use async in typing
raidensakura Feb 5, 2023
c94c8d3
Add pillow into requirements
raidensakura Feb 5, 2023
0c27fcf
Switch flake8 to ruff
raidensakura Apr 20, 2023
b9e1f22
Include branch in load test
raidensakura Apr 20, 2023
422e57e
Attempt fix loadcheck failing
raidensakura Apr 20, 2023
0a90012
Fix deps installation
raidensakura Apr 20, 2023
0b5b136
Attempt number 2
raidensakura Apr 20, 2023
91c3efc
Update README.md
raidensakura Apr 20, 2023
7075357
Implement ABC class
raidensakura Apr 20, 2023
22e0f74
Shorten long lines
raidensakura Apr 21, 2023
6996b5c
pls flake8
raidensakura Apr 21, 2023
54b8132
Update workflow
raidensakura Jun 28, 2023
15c55be
Update README.md
raidensakura Jul 11, 2023
a16c482
Update README.md
raidensakura Jul 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
# ignore = E302
per-file-ignores = __init__.py:F401, constants.py:E501
max-line-length = 99
exclude = .git, .venv, .tox, __pycache__
10 changes: 10 additions & 0 deletions .github/red_data/cogs/CogManager/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"2938473984732": {
"GLOBAL": {
"paths": [
"C:\\Projects\\raiden-cogs",
"/home/runner/work/raiden-cogs/raiden-cogs"
]
}
}
}
11 changes: 11 additions & 0 deletions .github/red_data/core/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"0": {
"CUSTOM_GROUPS": {},
"GLOBAL": {
"prefix": [
"!"
],
"schema_version": 2
}
}
}
51 changes: 51 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Checks

on:
push:
pull_request:

# thanks red or wherever you got it from
jobs:
tox:
runs-on: ubuntu-latest
strategy:
matrix:
python_version:
- "3.8"
tox_env:
- style-black
- style-ruff
include:
- tox_env: style-black
friendly_name: Style (black)
- tox_env: style-ruff
friendly_name: Style (ruff)

fail-fast: false

name: Tox - ${{ matrix.python_version }} - ${{ matrix.friendly_name }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.ref }}
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}

# caching cuts down time for tox (for example black) from ~40 secs to 4
- name: Cache tox
uses: actions/cache@v3
with:
path: .tox
key: tox-${{ matrix.python_version }}-${{ matrix.tox_env }}-${{ hashFiles('tox.ini') }}

- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: "Run tox: ${{ matrix.friendly_name }}"
env:
TOXENV: ${{ matrix.tox_env }}
run: |
tox
64 changes: 64 additions & 0 deletions .github/workflows/loadcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "Cog load test"

on:
push:

jobs:
loadcheck:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
red-version:
- "git+https://github.com/Cog-Creators/Red-DiscordBot@V3/develop#egg=Red-DiscordBot"
- "Red-DiscordBot"
include:
- red-version: "git+https://github.com/Cog-Creators/Red-DiscordBot@V3/develop#egg=Red-DiscordBot"
friendly-red: "Red (Latest)"
- red-version: "Red-DiscordBot"
friendly-red: "Red (Stable)"
fail-fast: false

name: Cog load test - Python ${{ matrix.python-version }} & ${{ matrix.friendly-red }}
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache venv
id: cache-venv
uses: actions/cache@v3
with:
path: .venv
key: ${{ matrix.red-version }}-${{ matrix.python-version }}-${{ hashFiles('dev-requirements.txt') }}-${{ secrets.CACHE_V }}

- name: Maybe make venv
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install setuptools wheel
pip install ${{ matrix.red-version }}
pip install .
pip install jsonrpc-websocket
- name: Prepare files
run: |
mkdir -p /home/runner/.config/Red-DiscordBot
echo '{"workflow": {"DATA_PATH": "/home/runner/work/raiden-cogs/raiden-cogs/.github/red_data", "COG_PATH_APPEND": "cogs", "CORE_PATH_APPEND": "core", "STORAGE_TYPE": "JSON", "STORAGE_DETAILS": {}}}' > /home/runner/.config/Red-DiscordBot/config.json
- name: Run script loadcheck.py
run: |
source .venv/bin/activate
python .github/workflows/scripts/loadcheck.py
env:
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_TEST_BOT }}

- name: Save Red output as Artifact
if: always() # still run if prev step failed
uses: actions/upload-artifact@v3
with:
name: "Red log - Python ${{ matrix.python-version }} & ${{ matrix.friendly-red }}"
path: red.log
92 changes: 92 additions & 0 deletions .github/workflows/scripts/loadcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# https://github.com/Vexed01/Vex-Cogs/blob/master/.github/workflows/scripts/loadcheck.py
import asyncio
import os
import subprocess
import sys
import time
from typing import Any, Dict, Tuple

from dotenv import load_dotenv
from jsonrpc_websocket import Server
from redbot import __version__ as red_str_ver

load_dotenv(".env")

token = os.environ.get("DISCORD_BOT_TOKEN")

python_version = subprocess.check_output(["python", "-V"]).decode("utf-8")

print("=== Red's logs are available to view as an Artifact on the main matrix page ===\n")

print(f"Starting Red {red_str_ver} with {python_version}")

file = open("red.log", "w")
proc = subprocess.Popen(
f"redbot workflow --no-prompt --token {token} --rpc --debug",
stdout=file,
stderr=subprocess.STDOUT,
shell=True,
)

# let Red boot up
time.sleep(10)

cogs = [
"choose",
"genshinutils",
"longcat",
"throw",
]


async def leswebsockets() -> Tuple[Dict[str, Any], Dict[str, Any]]:
print("Connecting to Red via RPC")

server = Server("ws://localhost:6133")
try:
await server.ws_connect()

print("Loading cogs")
load_results: Dict[str, Any] = await server.CORE__LOAD(cogs)
await asyncio.sleep(1)
print("Unloading cogs")
unload_results: Dict[str, Any] = await server.CORE__UNLOAD(cogs)
finally:
await server.close()

return load_results, unload_results


load, unload = asyncio.run(leswebsockets())

print("Stopping Red")

proc.terminate()

exit_code = 0

fail_load = []
for i in (
"failed_packages",
"invalid_pkg_names",
"notfound_packages",
"alreadyloaded_packages",
"failed_with_reason_packages",
):
fail_load.extend(load[i])

if fail_load:
exit_code = 1
print("\N{CROSS MARK} Failed to load cogs " + ", ".join(fail_load))
print("See the artifact on the main matrix page for more information")
else:
print("\N{HEAVY CHECK MARK} Loaded all cogs successfully")

if unload["notloaded_packages"]:
exit_code = 1
print("\N{CROSS MARK} Failed to unload cogs " + ", ".join(unload["notloaded_packages"]))
print("See the artifact on the main matrix page for more information")
else:
print("\N{HEAVY CHECK MARK} Unloaded all cogs successfully")

sys.exit(exit_code)
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.vscode/
Pipfile
Pipfile.lock

Expand Down Expand Up @@ -154,3 +153,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.ruff_cache
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-json
- id: pretty-format-json
args: ["--autofix", "--indent", "4"]
- id: end-of-file-fixer
- id: mixed-line-ending
- repo: https://github.com/psf/black
rev: "22.12.0"
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.261'
hooks:
- id: ruff
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"autoDocstring.docstringFormat": "one-line-sphinx",
"autoDocstring.guessTypes": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"python.terminal.activateEnvironment": true
}
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<h1 align="center"><img src="https://files.catbox.moe/92mfqx.png"><img src="https://img.icons8.com/cotton/512/settings.png" style="height: 70px;"></h1>
<a name="readme-top"></a>
<h1 align="center"><img src="https://files.catbox.moe/92mfqx.png"><img src="https://files.catbox.moe/k7viho.png"></h1>
<div align="center">
<a href="https://github.com/raidensakura"><img src="https://img.shields.io/badge/raiden--cogs-by%20Raiden-d11df9"></a>
<a href="https://github.com/Cog-Creators/Red-DiscordBot"><img src="https://img.shields.io/badge/Red%20DiscordBot-V3-red.svg"></a>
<a href="[https://github.com/raidensakura](https://github.com/python/black)"><img src="https://img.shields.io/badge/code%20style-black-1c1c1c.svg"></a>
<a href="https://dsc.gg/transience/"><img src="https://discord.com/api/guilds/616969119685935162/widget.png"></a><br>
<a href="https://ko-fi.com/P5P6D65UW"><img src="https://storage.ko-fi.com/cdn/brandasset/kofi_button_red.png" style="height: 25px;"></a>
<a href="https://ko-fi.com/P5P6D65UW"><img src="https://ko-fi.com/img/githubbutton_sm.svg"></a>
</div>
<br>
<p align="center">A collection of <strike>badly written</strike> cogs I made for fun in the process of learning Python.</p>
<p align="center">A collection of <strike>badly written</strike> homemade cogs I made for fun in the process of learning Python.</p>
<p align="center"><b>Support:</b> Join my <a href="https://dsc.gg/transience">Discord server</a> or mention <code>Raiden#5008</code> in <a href="https://discord.gg/GET4DVk">Red Cog Support server.</a></p>

<h2 align="center">Installation</h2>

Expand All @@ -16,6 +18,7 @@
[p]repo add raiden-cogs https://github.com/raidensakura/raiden-cogs/
[p]cog install raiden-cogs <cog_name>
```
<sup>[p] is your prefix</sup>

<h2 align="center">List of Cogs</h2>

Expand All @@ -42,29 +45,29 @@
<td><a href="https://github.com/raidensakura/raiden-cogs/tree/main/choose">choose</a></td>
<td>A cog to replace Red Bot's <a href="https://docs.discord.red/en/stable/cog_guides/general.html?highlight=general">General</a> cog <code>choose</code> command to something more intuitive.</td>
</tr>

<tr>
<td><a href="https://github.com/raidensakura/raiden-cogs/tree/main/genshinutils">genshinutils</a></td>
<td>Multipurpose Genshin Impact oriented cog. Able to retrieve game profile data, character data and many more.</td>
</tr>

</table>

<h2 align="center">Dev Stuff</h2>

<h3 align="center">Formatting</h3>
<p align="center">To make sure things stay nice and clean.</p>
<p align="center">For manual formatting, this repo uses these:</p>

```py
pip install -U black isort
black . ; isort .
pip install .[dev]
black . ; ruff .
```

<h3 align="center"><code>.vscode/settings.json</code></h3>
<p align="center">To make sure the venv always open when I work on cogs.</p>

```json
{
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"python.defaultInterpreterPath": "C:\\Users\\Raiden\\redenv\\Scripts\\python.exe"
}
<h3 align="center">Pre-commit hooks</h3>
<p align="center">Optional but it keeps manual formatting work away from you.</p>

```py
pre-commit install
```

<h2 align="center">Credits</h2>
Expand All @@ -73,6 +76,9 @@ black . ; isort .
<ul>
<li><a href="https://github.com/o-wo">ow0x</a> for their Roleplay cog</li>
<li><a href="https://github.com/Aioxas">Aioxas</a> for their Longcat cog</li>
<li><a href="https://github.com/Vexed01/Vex-Cogs">Vexed</a> for their workflow steps and pre-commit hooks</li>
<li><a href="https://discord.red">Cog-Creators Community</a> for Red Bot and its documentation</li>
</ul>
</p>

<p align="right">(<a href="#">Back to top</a>)</p>
2 changes: 1 addition & 1 deletion choose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from pathlib import Path

from .choose import setup
from .choose import setup # noqa: F401

with open(Path(__file__).parent / "info.json") as fp:
__red_end_user_data_statement__ = json.load(fp)["end_user_data_statement"]
Loading