Sync with main #4
19
src/main.py
19
src/main.py
@ -2,6 +2,7 @@ import io
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import logging
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@ -17,14 +18,26 @@ if not all([NOVELAI_API_TOKEN, BOT_TOKEN, ALLOWED_CHANNEL_ID]):
|
|||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
bot = commands.Bot(command_prefix=commands.when_mentioned, intents=intents)
|
bot = commands.Bot(command_prefix=commands.when_mentioned, intents=intents)
|
||||||
|
|
||||||
|
async def get_available_antlas(api_token):
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {api_token}"
|
||||||
|
}
|
||||||
|
response = requests.get("https://api.novelai.net/user/info", headers=headers)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
return data.get("imageAnlas", 0)
|
||||||
|
else:
|
||||||
|
logging.error(f"Fehler beim Abrufen der Antlas: {response.status_code}")
|
||||||
|
return None
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f"Bot started as {bot.user}")
|
print(f"Bot started as {bot.user}")
|
||||||
try:
|
try:
|
||||||
synced = await bot.tree.sync()
|
synced = await bot.tree.sync()
|
||||||
print(f"{len(synced)} Slash-Commands synchronized.")
|
logging.info(f"{len(synced)} Slash-Commands synchronized.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
logging.error(e)
|
||||||
|
|
||||||
@bot.tree.command(name="generate", description="Generate image with NovelAI v4 Full")
|
@bot.tree.command(name="generate", description="Generate image with NovelAI v4 Full")
|
||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
@ -138,6 +151,8 @@ async def generate(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
antlas = get_available_antlas(NOVELAI_API_TOKEN)
|
||||||
|
logging.info("Generated image, current antlas: {antlas}")
|
||||||
response_bytes = response.content
|
response_bytes = response.content
|
||||||
|
|
||||||
param_text = f"""```Prompt: {prompt}
|
param_text = f"""```Prompt: {prompt}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user