Compare commits

..

No commits in common. "main" and "v0.1.3" have entirely different histories.
main ... v0.1.3

6 changed files with 26 additions and 54 deletions

View File

@ -15,12 +15,12 @@ jobs:
GITHUB: ${{ secrets.GITHUB }} GITHUB: ${{ secrets.GITHUB }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v6 uses: actions/checkout@v4
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v6 uses: actions/setup-python@v5
with: with:
python-version: '3.14' python-version: '3.10'
- name: Install dependencies - name: Install dependencies
run: | run: |
@ -85,7 +85,7 @@ jobs:
# Ergebnisse als Artefakte speichern # Ergebnisse als Artefakte speichern
- name: Upload results as artifacts - name: Upload results as artifacts
uses: actions/upload-artifact@v5 uses: actions/upload-artifact@v3
with: with:
name: quality-reports name: quality-reports
path: /tmp/results path: /tmp/results

View File

@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v6 uses: actions/checkout@v4
- name: Verify Docker installation - name: Verify Docker installation
run: docker --version run: docker --version

20
.github/renovate.json vendored
View File

@ -1,20 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"baseBranches": [
"dev"
],
"packageRules": [
{
"matchUpdateTypes": [
"minor",
"patch",
"pin",
"digest"
],
"automerge": false
}
]
}

View File

@ -1,4 +1,4 @@
FROM python:3.14.2-slim FROM python:3.13.3-slim
WORKDIR /app WORKDIR /app

View File

@ -10,8 +10,8 @@ import sys
import time import time
import zipfile import zipfile
import aiohttp
import discord import discord
import requests
from discord import app_commands from discord import app_commands
from discord.ext import commands from discord.ext import commands
@ -30,7 +30,7 @@ logger = logging.getLogger(__name__)
if not all([NOVELAI_API_TOKEN, BOT_TOKEN, ALLOWED_CHANNEL_ID]): if not all([NOVELAI_API_TOKEN, BOT_TOKEN, ALLOWED_CHANNEL_ID]):
raise ValueError( raise ValueError(
"NOVELAI_API_TOKEN, DISCORD_BOT_TOKEN and DISCORD_CHANNEL_ID have to be set." "NOVELAI_API_TOKEN, DISCORD_BOT_TOKEN und DISCORD_CHANNEL_ID müssen gesetzt sein."
) )
intents = discord.Intents.default() intents = discord.Intents.default()
@ -43,9 +43,9 @@ async def on_ready():
print(f"Bot gestartet als {bot.user}") print(f"Bot gestartet als {bot.user}")
try: try:
synced = await bot.tree.sync() synced = await bot.tree.sync()
logger.info("%d Slash-Commands synchronized.", len(synced)) logger.info("%d Slash-Commands synchronisiert.", len(synced))
except Exception as err: # pylint: disable=W0718 except Exception as err: # pylint: disable=W0718
logger.error("error while syncing the command: %s", err) logger.error("Fehler beim Synchronisieren der Commands: %s", err)
activity = discord.Game(name="generating juicy NovelAI images 🥵") activity = discord.Game(name="generating juicy NovelAI images 🥵")
await bot.change_presence(status=discord.Status.online, activity=activity) await bot.change_presence(status=discord.Status.online, activity=activity)
@ -58,7 +58,7 @@ async def on_ready():
orientation="portrait or landscape (Standard: portrait)", orientation="portrait or landscape (Standard: portrait)",
seed="Optional seed (integer). If empty, a random one will be generated", seed="Optional seed (integer). If empty, a random one will be generated",
) )
# pylint: disable=too-many-locals,too-many-return-statements,too-many-statements # pylint: disable=too-many-locals,too-many-return-statements
async def generate( async def generate(
interaction: discord.Interaction, interaction: discord.Interaction,
prompt: str, prompt: str,
@ -159,25 +159,17 @@ async def generate(
} }
start_time = time.monotonic() start_time = time.monotonic()
try: response = requests.post(
async with aiohttp.ClientSession() as session: "https://image.novelai.net/ai/generate-image",
async with session.post( json=payload,
"https://image.novelai.net/ai/generate-image", headers=headers,
json=payload, timeout=120,
headers=headers, )
timeout=aiohttp.ClientTimeout(total=120),
) as response:
response_bytes = await response.read()
status_code = response.status
except aiohttp.TimeoutError:
await interaction.followup.send("Error: the request timed out.")
except aiohttp.ClientError as e:
await interaction.followup.send(f"Error: {e}")
duration = time.monotonic() - start_time duration = time.monotonic() - start_time
logger.info("Image creation took %.2f seconds", duration) logger.info("Image creation took %.2f seconds", duration)
if status_code == 200: if response.status_code == 200:
response_bytes = response.content
param_text = ( param_text = (
f"```Prompt: {prompt}\n" f"```Prompt: {prompt}\n"
f"Undesired prompt: {negative_prompt}\n" f"Undesired prompt: {negative_prompt}\n"
@ -214,15 +206,15 @@ async def generate(
return return
try: try:
error_data = response_bytes.decode("utf-8") error_data = response.json()
except Exception: # pylint: disable=W0718 except Exception: # pylint: disable=W0718
error_data = "error message unreadable" error_data = {"error": response.text}
error_message = ( error_message = f"Error {response.status_code} at API-request.\n"
f"Error {status_code} at API-request.\n" f"Answer: {error_data}\n" for key, value in error_data.items():
) error_message += f"**{key}**: {value}\n"
await interaction.followup.send(error_message) await interaction.followup.send(error_message)
bot.run(BOT_TOKEN) bot.run(BOT_TOKEN)

View File

@ -1,2 +1,2 @@
discord discord
aiohttp requests