🎨 chore(*): run black to format the code

This commit is contained in:
2023-08-19 14:17:16 +02:00
parent 3a955d4379
commit 775f8758b7
8 changed files with 150 additions and 47 deletions

View File

@@ -14,41 +14,101 @@ sampleDataFormatExample = {
"premium_expiration": 0,
}
class ChannelSetup(commands.Cog):
def __init__(self, bot: discord.Bot):
super().__init__()
self.bot = bot
setup = SlashCommandGroup("setup", description="Setup commands for the bot, inlcuding channels, models, and more.")
setup = SlashCommandGroup(
"setup",
description="Setup commands for the bot, inlcuding channels, models, and more.",
)
setup_channel = setup.create_subgroup(name="channel", description="Setup, add, or remove channels for the bot to use.")
setup_channel = setup.create_subgroup(
name="channel", description="Setup, add, or remove channels for the bot to use."
)
@setup_channel.command(name="add", description="Add a channel for the bot to use. Can also specify server-wide settings.")
@discord.option(name="channel", description="The channel to setup. If not specified, will use the current channel.", type=discord.TextChannel, required=False)
@discord.option(name="model", description="The model to use for this channel.", type=str, required=False, autocomplete=models.autocomplete)
@discord.option(name="character", description="The character to use for this channel.", type=str, required=False, autocomplete=characters.autocomplete)
@setup_channel.command(
name="add",
description="Add a channel for the bot to use. Can also specify server-wide settings.",
)
@discord.option(
name="channel",
description="The channel to setup. If not specified, will use the current channel.",
type=discord.TextChannel,
required=False,
)
@discord.option(
name="model",
description="The model to use for this channel.",
type=str,
required=False,
autocomplete=models.autocomplete,
)
@discord.option(
name="character",
description="The character to use for this channel.",
type=str,
required=False,
autocomplete=characters.autocomplete,
)
@guild_only()
async def channel(self, ctx: discord.ApplicationContext, channel: discord.TextChannel = None, model: str = models.default, character: str = characters.default):
async def channel(
self,
ctx: discord.ApplicationContext,
channel: discord.TextChannel = None,
model: str = models.default,
character: str = characters.default,
):
if channel is None:
channel = ctx.channel
guild = Guild(ctx.guild.id)
guild.load()
if not guild.premium:
if len(guild.channels) >= 1 and guild.channels.get(str(channel.id), None) is None:
await ctx.respond("`Warning: You are not a premium user, and can only have one channel setup. The settings will still be saved, but will not be used.`", ephemeral=True)
if (
len(guild.channels) >= 1
and guild.channels.get(str(channel.id), None) is None
):
await ctx.respond(
"`Warning: You are not a premium user, and can only have one channel setup. The settings will still be saved, but will not be used.`",
ephemeral=True,
)
if model != models.default:
await ctx.respond("`Warning: You are not a premium user, and can only use the default model. The settings will still be saved, but will not be used.`", ephemeral=True)
await ctx.respond(
"`Warning: You are not a premium user, and can only use the default model. The settings will still be saved, but will not be used.`",
ephemeral=True,
)
if character != characters.default:
await ctx.respond("`Warning: You are not a premium user, and can only use the default character. The settings will still be saved, but will not be used.`", ephemeral=True)
await ctx.respond(
"`Warning: You are not a premium user, and can only use the default character. The settings will still be saved, but will not be used.`",
ephemeral=True,
)
if guild.api_keys.get("openai", None) is None:
await ctx.respond("`Error: No openai api key is set. The api key is needed for the openai models, as well as for the content moderation. The openai models will cost you tokens in your openai account. However, if you use one of the llama models, you will not be charged, but the api key is still needed for content moderation, wich is free but requires an api key.`", ephemeral=True)
guild.addChannel(channel, models.matchingDict[model], characters.matchingDict[character])
await ctx.respond(f"Set channel {channel.mention} with model `{model}` and character `{character}`.")
await ctx.respond(
"`Error: No openai api key is set. The api key is needed for the openai models, as well as for the content moderation. The openai models will cost you tokens in your openai account. However, if you use one of the llama models, you will not be charged, but the api key is still needed for content moderation, wich is free but requires an api key.`",
ephemeral=True,
)
guild.addChannel(
channel, models.matchingDict[model], characters.matchingDict[character]
)
await ctx.respond(
f"Set channel {channel.mention} with model `{model}` and character `{character}`."
)
@setup_channel.command(name="remove", description="Remove a channel from the bot's usage.")
@discord.option(name="channel", description="The channel to remove. If not specified, will use the current channel.", type=discord.TextChannel, required=False)
@setup_channel.command(
name="remove", description="Remove a channel from the bot's usage."
)
@discord.option(
name="channel",
description="The channel to remove. If not specified, will use the current channel.",
type=discord.TextChannel,
required=False,
)
@guild_only()
async def remove(self, ctx: discord.ApplicationContext, channel: discord.TextChannel = None):
async def remove(
self, ctx: discord.ApplicationContext, channel: discord.TextChannel = None
):
if channel is None:
channel = ctx.channel
guild = Guild(ctx.guild.id)
@@ -67,17 +127,31 @@ class ChannelSetup(commands.Cog):
if len(guild.channels) == 0:
await ctx.respond("No channels are setup.")
return
embed = discord.Embed(title="Channels", description="All channels that are setup.", color=discord.Color.nitro_pink())
embed = discord.Embed(
title="Channels",
description="All channels that are setup.",
color=discord.Color.nitro_pink(),
)
channels = guild.sanitizedChannels
for channel in channels:
discochannel = await self.bot.fetch_channel(int(channel))
discochannel = await self.bot.fetch_channel(int(channel))
model = models.reverseMatchingDict[channels[channel]["model"]]
character = characters.reverseMatchingDict[channels[channel]["character"]]
embed.add_field(name=f"{discochannel.mention}", value=f"Model: `{model}`\nCharacter: `{character}`", inline=False)
embed.add_field(
name=f"{discochannel.mention}",
value=f"Model: `{model}`\nCharacter: `{character}`",
inline=False,
)
await ctx.respond(embed=embed)
@setup.command(name="api", description="Set an API key for the bot to use.")
@discord.option(name="api", description="The API to set. Currently only OpenAI is supported.", type=str, required=True, autocomplete=apis.autocomplete)
@discord.option(
name="api",
description="The API to set. Currently only OpenAI is supported.",
type=str,
required=True,
autocomplete=apis.autocomplete,
)
@discord.option(name="key", description="The key to set.", type=str, required=True)
@guild_only()
async def api(self, ctx: discord.ApplicationContext, api: str, key: str):
@@ -92,6 +166,9 @@ class ChannelSetup(commands.Cog):
guild = Guild(ctx.guild.id)
guild.load()
if not guild.premium:
await ctx.respond("You can get your premium subscription at https://www.botator.dev/premium.", ephemeral=True)
await ctx.respond(
"You can get your premium subscription at https://www.botator.dev/premium.",
ephemeral=True,
)
else:
await ctx.respond("This guild is already premium.", ephemeral=True)
await ctx.respond("This guild is already premium.", ephemeral=True)