feat(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics

 feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port
🐛 fix(main.py): remove duplicate cog addition in main.py
 feat(main.py): add cogs.Help(bot) to the list of cogs in main.py
🐛 fix(main.py): remove redundant import statements in main.py
 feat(main.py): add on_guild_remove event handler in main.py
 feat(main.py): add on_guild_join event handler in main.py
 feat(main.py): add support for discord.Intents in main.py
 feat(main.py): add intents.message_content = True in main.py
 feat(main.py): add intents.default() in main.py
 feat(main.py): add discord.Bot(intents=intents, help_command=None) in main.py
 feat(main.py): add import statements in main.py
 feat(main.py): add from src.config import debug, discord_token in main.py
 feat(main.py): add import discord in main.py
 feat(main.py): add import src.config in main.py
 feat(main.py): add import src.cogs in main.py
 feat(main.py): add import src.cogs.chat in main.py
 feat(main.py): add import src.cogs.manage_chat in main.py
 feat(main.py): add import src.cogs.moderation in main.py
 feat(main.py): add import src.cogs.channelSetup in main.py
 feat(main.py): add import src.cogs.help in main.py
 feat(main.py): add import src.cogs.Chat in main.py
 feat(main.py): add import src.cogs.ManageChat in main.py
 feat(main.py): add import src.cogs.Moderation in main.py
 feat(main.py): add import src.cogs.ChannelSetup in main.py
 feat(main.py): add import src.cogs.Help in main.py
 feat(main.py): add import src.cogs.chat in main.py
 feat(main.py): add import src.cogs.manage_chat in main.py
 feat(main.py): add import src.cogs.moderation in main.py
 feat(main.py): add
This commit is contained in:
2023-08-20 12:42:02 +02:00
parent 1d4209dc0f
commit e4b8e2824b
21 changed files with 350 additions and 860 deletions

View File

@@ -1,5 +1,5 @@
import discord
import orjson
import datetime
from discord import SlashCommandGroup
from discord import default_permissions
@@ -29,6 +29,10 @@ class ChannelSetup(commands.Cog):
name="channel", description="Setup, add, or remove channels for the bot to use."
)
setup_guild = setup.create_subgroup(
name="server", description="Setup the settings for the server."
)
@setup_channel.command(
name="add",
description="Add a channel for the bot to use. Can also specify server-wide settings.",
@@ -93,7 +97,8 @@ class ChannelSetup(commands.Cog):
channel, models.matchingDict[model], characters.matchingDict[character]
)
await ctx.respond(
f"Set channel {channel.mention} with model `{model}` and character `{character}`."
f"Set channel {channel.mention} with model `{model}` and character `{character}`.",
ephemeral=True,
)
@setup_channel.command(
@@ -113,13 +118,76 @@ class ChannelSetup(commands.Cog):
channel = ctx.channel
guild = Guild(ctx.guild.id)
guild.load()
if channel.id not in guild.channels:
if guild.getChannelInfo(str(channel.id)) is None:
await ctx.respond("That channel is not setup.")
return
guild.delChannel(channel)
await ctx.respond(f"Removed channel {channel.mention}.")
await ctx.respond(f"Removed channel {channel.mention}.", ephemeral=True)
@setup_channel.command(name="list", description="List all channels that are setup.")
@setup_guild.command(
name="set",
description="Set the settings for the guild (when the bot is pinged outside of a set channel).",
)
@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 setSettings(
self,
ctx: discord.ApplicationContext,
model: str = models.default,
character: str = characters.default,
):
# we will be using "serverwide" as the channel id for the guild settings
guild = Guild(ctx.guild.id)
guild.load()
if not guild.premium:
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,
)
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,
)
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(
"serverwide", models.matchingDict[model], characters.matchingDict[character]
)
await ctx.respond(
f"Set server settings with model `{model}` and character `{character}`.",
ephemeral=True,
)
@setup_guild.command(name="remove", description="Remove the guild settings.")
@guild_only()
async def removeSettings(self, ctx: discord.ApplicationContext):
guild = Guild(ctx.guild.id)
guild.load()
if "serverwide" not in guild.channels:
await ctx.respond("No guild settings are setup.")
return
guild.delChannel("serverwide")
await ctx.respond(f"Removed serverwide settings.", ephemeral=True)
@setup.command(name="list", description="List all channels that are setup.")
@guild_only()
async def list(self, ctx: discord.ApplicationContext):
guild = Guild(ctx.guild.id)
@@ -134,11 +202,14 @@ class ChannelSetup(commands.Cog):
)
channels = guild.sanitizedChannels
for channel in channels:
discochannel = await self.bot.fetch_channel(int(channel))
if channel == "serverwide":
mention = "Serverwide"
else:
mention = f"<#{channel}>"
model = models.reverseMatchingDict[channels[channel]["model"]]
character = characters.reverseMatchingDict[channels[channel]["character"]]
embed.add_field(
name=f"{discochannel.mention}",
name=f"{mention}",
value=f"Model: `{model}`\nCharacter: `{character}`",
inline=False,
)
@@ -165,6 +236,14 @@ class ChannelSetup(commands.Cog):
async def premium(self, ctx: discord.ApplicationContext):
guild = Guild(ctx.guild.id)
guild.load()
if self.bot.is_owner(ctx.author):
guild.premium = True
# also set expiry date in 6 months isofromat
guild.premium_expiration = datetime.datetime.now() + datetime.timedelta(
days=180
)
guild.updateDbData()
return await ctx.respond("Set guild to premium.", ephemeral=True)
if not guild.premium:
await ctx.respond(
"You can get your premium subscription at https://www.botator.dev/premium.",
@@ -172,3 +251,18 @@ class ChannelSetup(commands.Cog):
)
else:
await ctx.respond("This guild is already premium.", ephemeral=True)
@setup.command(name="help", description="Show the help page for setup.")
async def help(self, ctx: discord.ApplicationContext):
# we eill iterate over all commands the bot has and add them to the embed
embed = discord.Embed(
title="Setup Help",
description="Here is the help page for setup.",
color=discord.Color.dark_teal(),
)
for command in self.setup.walk_commands():
fieldname = command.name
fielddescription = command.description
embed.add_field(name=fieldname, value=fielddescription, inline=False)
embed.set_footer(text="Made with ❤️ by paillat : https://paillat.dev")
await ctx.respond(embed=embed, ephemeral=True)