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
This commit is contained in:
parent
d5f378492f
commit
9e9e508c30
|
@ -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
|
||||||
|
|
||||||
|
@ -48,6 +48,33 @@ async def on_ready() -> None:
|
||||||
print(f"Your bot invite link: {invite}")
|
print(f"Your bot invite link: {invite}")
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
@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:
|
||||||
"""
|
"""
|
||||||
|
@ -57,18 +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:
|
||||||
await ctx.send("Creating vc's...", ephemeral=True)
|
if db:
|
||||||
if db:
|
await clear_channels(db)
|
||||||
channels = db.channels
|
await create_group(server, db)
|
||||||
for channel in channels:
|
await ctx.send("Group was created! HF!", ephemeral=True)
|
||||||
channel = bot.get_channel(channel)
|
except errors.Any:
|
||||||
await channel.delete()
|
await ctx.send("An error occurred!", ephemeral=True)
|
||||||
db.clear_channels()
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
user_before_channels = {}
|
user_before_channels = {}
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -3,7 +3,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="HellMBot",
|
name="HellMBot",
|
||||||
version="0.1",
|
version="0.2",
|
||||||
url="https://git.orudo.ru/trueold89/HellMBot",
|
url="https://git.orudo.ru/trueold89/HellMBot",
|
||||||
author="trueold89",
|
author="trueold89",
|
||||||
author_email="trueold89@orudo.ru",
|
author_email="trueold89@orudo.ru",
|
||||||
|
|
Loading…
Reference in New Issue