Compare commits

...

3 Commits

Author SHA1 Message Date
trueold89 c9fc740708
Update /create command
- Deleting and creating a group is now separated into two different functions
- The bot now reports its actions to the chat room
2024-06-07 18:50:04 +03:00
trueold89 d5f378492f
Now before creating a new group, the bot deletes previously created channels 2024-06-07 18:38:24 +03:00
trueold89 a9ce6a60b9
The "/create" commnad is now available in the bot menu 2024-06-07 18:34:11 +03:00
1 changed files with 38 additions and 9 deletions

View File

@ -2,7 +2,7 @@
from hellmbot.env import ENV from hellmbot.env import ENV
from hellmbot.db import ServersDB from hellmbot.db import ServersDB
from discord import Intents, Member, VoiceState, Permissions from discord import Intents, Member, VoiceState, Permissions, errors
from discord.utils import oauth_url from discord.utils import oauth_url
from discord.ext import commands from discord.ext import commands
@ -39,6 +39,7 @@ async def on_ready() -> None:
""" """
Displays a link to add a bot to the server Displays a link to add a bot to the server
""" """
await bot.tree.sync()
client_id = ENV.CLIENT_ID.fget(None) client_id = ENV.CLIENT_ID.fget(None)
invite = oauth_url(client_id, permissions=Permissions( invite = oauth_url(client_id, permissions=Permissions(
manage_channels=True, manage_channels=True,
@ -47,7 +48,34 @@ async def on_ready() -> None:
print(f"Your bot invite link: {invite}") print(f"Your bot invite link: {invite}")
@bot.command() async def clear_channels(db: ServersDB) -> None:
"""
Clear previously created channels
:param db: Database
"""
channels = db.channels
for channel in channels:
channel = bot.get_channel(channel)
await channel.delete()
db.clear_channels()
async def create_group(server: commands.Context.guild, db: ServersDB) -> None:
"""
Creates a group of voice channels to move the user and adds their id to the database
:param server: Discord server
:param db: Database
"""
circles_count = ENV.CIRCLES_COUNT.fget(None)
group = await server.create_category(f"{circles_count} Circles of Hell")
for circle in range(circles_count):
vc = await server.create_voice_channel(f"{circle + 1} Circle", category=group)
db.add_channel(vc.id, circle + 1)
@bot.hybrid_command(name="create", description="Creates a group of vc to move users")
async def create(ctx: commands.Context) -> None: async def create(ctx: commands.Context) -> None:
""" """
Creates a group of voice channels to move the user and adds their id to the database Creates a group of voice channels to move the user and adds their id to the database
@ -56,13 +84,14 @@ async def create(ctx: commands.Context) -> None:
""" """
server = ctx.guild server = ctx.guild
db = ServersDB(server.id) db = ServersDB(server.id)
circles_count = ENV.CIRCLES_COUNT.fget(None) await ctx.send("Creating group...", ephemeral=True)
group = await server.create_category(f"{circles_count} Circles of Hell") try:
if db: if db:
db.clear_channels() await clear_channels(db)
for circle in range(circles_count): await create_group(server, db)
vc = await server.create_voice_channel(f"{circle + 1} Circle", category=group) await ctx.send("Group was created! HF!", ephemeral=True)
db.add_channel(vc.id, circle + 1) except errors.Any:
await ctx.send("An error occurred!", ephemeral=True)
user_before_channels = {} user_before_channels = {}