Modernized development tooling and added CI pipeline.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# Copyright 2026 Logan Fick
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Crabstero - The simple nonversation Discord bot."""
|
||||
|
||||
try:
|
||||
from ._version import __version__
|
||||
except ImportError:
|
||||
__version__ = "0.0.0+unknown"
|
||||
|
||||
from .bot import Crabstero
|
||||
|
||||
__all__ = [
|
||||
"Crabstero",
|
||||
"__version__",
|
||||
]
|
||||
|
||||
@@ -23,9 +23,9 @@ import asyncio
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from crabstero._version import version as crabstero_version
|
||||
from crabstero import __version__ as crabstero_version
|
||||
from crabstero.bot import Crabstero
|
||||
|
||||
logger = logging.getLogger("crabstero")
|
||||
@@ -47,9 +47,7 @@ def _read_credential(name: str) -> str | None:
|
||||
return None
|
||||
|
||||
try:
|
||||
return (
|
||||
open(os.path.join(credentials_dir, name)).read().strip() # noqa: SIM115
|
||||
)
|
||||
return Path(credentials_dir, name).read_text().strip()
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
|
||||
from crabstero._version import version as crabstero_version
|
||||
from crabstero import __version__ as crabstero_version
|
||||
from crabstero.database import Database
|
||||
from crabstero.tasks.ingestion import ingest_channel
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ Uses aiosqlite for native async access. All methods are async def.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import logging
|
||||
from typing import Self
|
||||
|
||||
@@ -125,10 +126,8 @@ class Database:
|
||||
"""Cancels the flush timer, commits any pending writes, then closes the database connection."""
|
||||
if self._flush_task is not None:
|
||||
self._flush_task.cancel()
|
||||
try:
|
||||
with contextlib.suppress(asyncio.CancelledError):
|
||||
await self._flush_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
self._flush_task = None
|
||||
if self._pending_writes > 0:
|
||||
await self._connection.commit()
|
||||
|
||||
@@ -19,6 +19,7 @@ All of these events share the same outcome: queuing all textable channels for me
|
||||
ingestion when something changes that may grant new read permissions.
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@@ -71,10 +72,8 @@ class ServerEventsCog(commands.Cog):
|
||||
|
||||
app_info = await self.bot.application_info()
|
||||
if app_info.owner:
|
||||
try:
|
||||
with contextlib.suppress(discord.HTTPException):
|
||||
await app_info.owner.send(embed=embed)
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
|
||||
queue_channels_for_ingestion(guild, self.bot)
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ if TYPE_CHECKING:
|
||||
# https://github.com/discordjs/discord-api-types/blob/7fe434114e91c80ed79f0204ae6c73047672d55d/globals.ts#L30
|
||||
MENTION_PATTERN = re.compile(r"<@!?(?P<id>\d{17,20})>")
|
||||
|
||||
_EMBED_CHANCE_THRESHOLD = 95 # Out of 100; sends an embed ~5% of the time.
|
||||
|
||||
|
||||
async def reply_to_message(db: Database, message: discord.Message) -> None:
|
||||
"""
|
||||
@@ -69,7 +71,10 @@ async def reply_to_message(db: Database, message: discord.Message) -> None:
|
||||
embed = None
|
||||
|
||||
# 5% chance to include an embed, if the bot has permission.
|
||||
if secrets.randbelow(100) >= 95 and channel.permissions_for(guild.me).embed_links:
|
||||
if (
|
||||
secrets.randbelow(100) >= _EMBED_CHANCE_THRESHOLD
|
||||
and channel.permissions_for(guild.me).embed_links
|
||||
):
|
||||
embed = discord.Embed(
|
||||
title=await markov.generate(db, channel_id, 200, 300),
|
||||
description=await markov.generate(db, channel_id, 300, 500),
|
||||
|
||||
Reference in New Issue
Block a user