Skip to content

Commit

Permalink
Fix: v0.1.1
Browse files Browse the repository at this point in the history
This release aims to fix up any bugs, and small fixes to provide a better dev experience and other. For more info, please see the changelog ~ Noelle
  • Loading branch information
No767 authored Sep 4, 2023
2 parents 0ac0131 + 3d244b4 commit 12a7267
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Catherine-Chan

[![Required Python Version](https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11-blue?logo=python&logoColor=white)](https://github.com/No767/Catherine-Chan/blob/main/pyproject.toml) [![CodeQL](https://github.com/No767/Catherine-Chan/actions/workflows/codeql.yml/badge.svg)](https://github.com/No767/Catherine-Chan/actions/workflows/codeql.yml) [![Lint](https://github.com/No767/Catherine-Chan/actions/workflows/lint.yml/badge.svg)](https://github.com/No767/Catherine-Chan/actions/workflows/lint.yml) [![Tests](https://github.com/No767/Catherine-Chan/actions/workflows/tests.yml/badge.svg)](https://github.com/No767/Catherine-Chan/actions/workflows/tests.yml) ![Read the Docs](https://img.shields.io/readthedocs/catherine-chan?label=Docs&logo=readthedocs&logoColor=white) [![codecov](https://codecov.io/gh/No767/Catherine-Chan/graph/badge.svg?token=mAPjhFgiGE)](https://codecov.io/gh/No767/Catherine-Chan) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=No767_Catherine-Chan&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=No767_Catherine-Chan) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=No767_Catherine-Chan&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=No767_Catherine-Chan) ![GitHub release (with filter)](https://img.shields.io/github/v/release/No767/Catherine-Chan?logo=github&label=Release) ![GitHub](https://img.shields.io/github/license/No767/Catherine-Chan?logo=github&logoColor=white&label=License) [![Discord](https://img.shields.io/discord/1145897416160194590?logo=discord&logoColor=white&label=Discord&color=%235865F2)](https://discord.gg/ns3e74frqn) [![Catherine](https://img.shields.io/badge/Catherine-Kano%20(穫野)-pink)]()
[![Required Python Version](https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11-blue?logo=python&logoColor=white)](https://github.com/No767/Catherine-Chan/blob/main/pyproject.toml) [![CodeQL](https://github.com/No767/Catherine-Chan/actions/workflows/codeql.yml/badge.svg)](https://github.com/No767/Catherine-Chan/actions/workflows/codeql.yml) [![Lint](https://github.com/No767/Catherine-Chan/actions/workflows/lint.yml/badge.svg)](https://github.com/No767/Catherine-Chan/actions/workflows/lint.yml) [![Tests](https://github.com/No767/Catherine-Chan/actions/workflows/tests.yml/badge.svg)](https://github.com/No767/Catherine-Chan/actions/workflows/tests.yml) ![Read the Docs](https://img.shields.io/readthedocs/catherine-chan?label=Docs&logo=readthedocs&logoColor=white) [![codecov](https://codecov.io/gh/No767/Catherine-Chan/graph/badge.svg?token=mAPjhFgiGE)](https://codecov.io/gh/No767/Catherine-Chan) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=No767_Catherine-Chan&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=No767_Catherine-Chan) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=No767_Catherine-Chan&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=No767_Catherine-Chan) ![GitHub release (with filter)](https://img.shields.io/github/v/release/No767/Catherine-Chan?label=Release&logo=github&sort=semver) ![GitHub](https://img.shields.io/github/license/No767/Catherine-Chan?logo=github&logoColor=white&label=License) [![Discord](https://img.shields.io/discord/1145897416160194590?logo=discord&logoColor=white&label=Discord&color=%235865F2)](https://discord.gg/ns3e74frqn) [![Catherine](https://img.shields.io/badge/Catherine-Kano%20(穫野)-pink)]()

The modern all-in-one toolkit for LGBTQ+ folks

Expand Down
10 changes: 8 additions & 2 deletions bot/catherinebot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import asyncio
import os
from pathlib import Path

import asyncpg
import discord
from aiohttp import ClientSession
from catherinecore import Catherine
from dotenv import load_dotenv
from libs.utils import CatherineLogger
from libs.utils import CatherineLogger, read_env

# Only used for Windows development
if os.name == "nt":
Expand All @@ -24,6 +25,7 @@
TOKEN = os.environ["TOKEN"]
DEV_MODE = os.getenv("DEV_MODE") in ("True", "TRUE")
POSTGRES_URI = os.environ["POSTGRES_URI"]
ENV_PATH = Path(__file__).parent / ".env"

intents = discord.Intents.default()
intents.message_content = True
Expand All @@ -34,7 +36,11 @@ async def main() -> None:
dsn=POSTGRES_URI, min_size=25, max_size=25, command_timeout=60
) as pool:
async with Catherine(
intents=intents, session=session, pool=pool, dev_mode=DEV_MODE
config=read_env(ENV_PATH),
intents=intents,
session=session,
pool=pool,
dev_mode=DEV_MODE,
) as bot:
await bot.start(TOKEN)

Expand Down
20 changes: 18 additions & 2 deletions bot/catherinecore.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import signal
from typing import Dict, Optional

import asyncpg
import discord
Expand All @@ -21,6 +22,7 @@
class Catherine(commands.Bot):
def __init__(
self,
config: Dict[str, Optional[str]],
intents: discord.Intents,
session: ClientSession,
pool: asyncpg.Pool,
Expand All @@ -32,16 +34,29 @@ def __init__(
activity=discord.Activity(
type=discord.ActivityType.watching, name="for some eggs to hatch!"
),
command_prefix="~",
command_prefix="uwu-oneechan",
help_command=None,
intents=intents,
*args,
**kwargs,
)
self.dev_mode = dev_mode
self.logger: logging.Logger = logging.getLogger("discord")
self._config = config
self._session = session
self._pool = pool

@property
def config(self) -> Dict[str, Optional[str]]:
"""Global configuration dictionary read from .env files
This is used to access API keys, and many others from the bot.
Returns:
Dict[str, str]: A dictionary of configuration values
"""
return self._config

@property
def session(self) -> ClientSession:
"""A global web session used throughout the lifetime of the bot
Expand Down Expand Up @@ -94,7 +109,8 @@ def stop():
await self.load_extension(cog)

if self.dev_mode is True and _fsw is True:
self.logger.info("Dev mode is enabled. Loading FSWatcher")
self.logger.info("Dev mode is enabled. Loading Jishaku and FSWatcher")
await self.load_extension("jishaku")
self.loop.create_task(self.fs_watcher())

async def on_ready(self):
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def __str__(self) -> str:


EXTENSIONS = [module.name for module in iter_modules(__path__, f"{__package__}.")]
VERSION: VersionInfo = VersionInfo(major=0, minor=1, micro=0, releaselevel="final")
VERSION: VersionInfo = VersionInfo(major=0, minor=1, micro=1, releaselevel="final")
7 changes: 7 additions & 0 deletions bot/cogs/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ async def cog_unload(self):
tree = self.bot.tree
tree.on_error = self._old_tree_error

@commands.Cog.listener()
async def on_command_error(
self, ctx: commands.Context, error: commands.CommandError
) -> None:
if isinstance(error, commands.CommandNotFound):
pass

async def on_app_command_error(
self, interaction: discord.Interaction, error: AppCommandError
) -> None:
Expand Down
3 changes: 2 additions & 1 deletion bot/libs/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .embeds import ConfirmEmbed, Embed, ErrorEmbed, SuccessEmbed
from .logger import CatherineLogger
from .time import human_timedelta
from .utils import is_docker
from .utils import is_docker, read_env

__all__ = [
"CatherineLogger",
Expand All @@ -11,4 +11,5 @@
"ErrorEmbed",
"ConfirmEmbed",
"is_docker",
"read_env",
]
10 changes: 10 additions & 0 deletions bot/libs/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import os
from pathlib import Path
from typing import Dict, Optional

from dotenv import dotenv_values


def is_docker() -> bool:
path = "/proc/self/cgroup"
return os.path.exists("/.dockerenv") or (
os.path.isfile(path) and any("docker" in line for line in open(path))
)


def read_env(path: Path, read_from_file: bool = True) -> Dict[str, Optional[str]]:
if is_docker() or read_from_file is False:
return {**os.environ}
return {**dotenv_values(path)}
39 changes: 11 additions & 28 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
# :tada: Catherine-Chan 0.1.0 :tada:
# 🛠️ Catherine-Chan 0.1.1 🛠️

The first stable version of Catherine-Chan. As of now, the codebase is extremely stable, and pretty much replaces Jade's PrideBot. This version rebuilds the whole entire bot using discord.py and all of the internals now use PostgreSQL. There are still features that are planned to be included by as of now, this version pretty much mimics PrideBot.

Since this a full re-implementation, the rest of this section will be the differences included from PrideBot. Again, the changelog doesn't cover every single change I made since there is a ton.
Bugfix version to generally fix up smaller issues and improve dev experience.

## ✨ TD;LR

- Fixes some release stuff.
- Reimplement everything that PrideBot has to offer to PostgreSQL (massive performance boost w/ asyncpg)
- Better interfaces for all of the commands
- The first version that pretty much has everything PrideBot has
- Pronouns tester command now relies on a `re.compile()` and a one-pass Regex implementation instead of 5 `.replace()` methods chained together
- Added the missing feature of being able to to load only the `.env` file or only the current shell's env
- Pretty much disabled prefixed commands

## 🛠️ Changes

- Proper documentation, including a full online docs
- PEP8 standardized code (unlike Jade's version, which is a mess of personal preferences and poor design) enforced by Ruff
- Pronouns tester command now relies on a one-pass regex sub implementation. This essentially removes the need to use `.replace()` a bunch of times. The implementation can be found [here](https://github.com/No767/Catherine-Chan/blob/main/bot/libs/cog_utils/pronouns/__init__.py#L48-L50).
- Now based on PostgreSQL (asyncpg) instead of MongoDB (pymongo)
- Added the missing feature of being able to to load only the `.env` file or only the current shell's env
- Disable the default prefixed help command (we don't need this for slash commands)
- Mute unwanted prefixed command errors
- Make the prefix now something unlikely that you will use.

## ✨ Additions

- Discord support server link and shilling
- Global error handler
- Dockerfile that actually works
- Proper CI/CD pipeline for unit testing, and linting code
- Proper docstrings instead of random strings
- Full unit tests (100% coverage!)
- Pronouns examples approval system
- Tone Tags support
- SonarCloud linting
- Pride Profiles
- Load ENVs based on Dev mode and production.
- Added the missing feature of being able to to load only the `.env` file or only the current shell's env
- Added Jishaku for dev stuff

## ➖ Removals

- MongoDB support
- Random commands that don't work anymore
- Dictionary system (replaced with pronouns.pages support instead)
- And a ton of bad practices that were in PrideBot
- None
Loading

0 comments on commit 12a7267

Please sign in to comment.