Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bot/commandowner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def __init__(self, bot, helpf, tban, jh, xpf):

@commands.command(name='test', pass_context=True, brief='Testing command for programmer.', description='You need privilege level Owner to use this command. Only the programmer knows what happens here.')
@isBotOwnerCommand()
async def test(self, ctx):
await ctx.send("Geht")
await ctx.message.delete()
async def test(self, ctx, channelID):
channel = self.bot.get_channel(int(channelID))
newName = channel.name[:-1] + str(int(channel.name[-1])+1)
newChannel = await channel.clone(name = newName)
# Move channel
await newChannel.move(after = channel)

@commands.command(name="ping")
@isBotOwnerCommand()
Expand Down
64 changes: 63 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import certifi
import os
import discord
from discord.utils import get
from discord.utils import get, find
from discord.ext import commands
import time
import datetime
Expand Down Expand Up @@ -301,6 +301,68 @@ async def on_error(event, *args, **kwargs):
await helpf.log(message,2)
"""

@bot.event
async def on_voice_state_update(member, before, after):
"""
Clones joined channel if it has a number in the end
"""
# when user joins channel: before = None; after is a voicestate


"""
When a user leaves a channel (before.channel) with a number endingn nobody else is connected und and number is not 1, than the channel will be deleted.
"""
if before.channel and len(before.channel.members) == 0 and before.channel.name[-1].isdigit():
# Member left first channel
if before.channel.name[-1] == "1" and not before.channel.name[-2].isdigit():
# Delete last channel, which has no user in it
serverid = int(jh.getFromConfig("guilde"))
allChannel = helpf.getVoiceChannelsFrom(serverid)

channelWithoutNumber = before.channel.name[:-1]
notFirstVoiceChannel = [channel for channel in allChannel if channelWithoutNumber in channel.name and len(channel.members) == 0 and channel.name != channelWithoutNumber + "1"]
if notFirstVoiceChannel:
lastChannel = max(notFirstVoiceChannel, key = lambda c: int(c.name[len(channelWithoutNumber):]))

await lastChannel.delete()


# User left channel, which is not the first channel. So it will be deleted
else:
await before.channel.delete()


"""
User joins channel after.channel. If channel ends with a number, than a copy will be created with the lowest possible ending number.
"""
if after.channel and len(after.channel.members) <= 1:
# Get channels to get lowest enumeration of channel
afterNumber = None
nameIndex = -1
while after.channel.name[nameIndex:].isdigit():
afterNumber = int(after.channel.name[nameIndex:]) # number on the end of channel name
nameIndex -= 1
nameIndex += 1

serverid = int(jh.getFromConfig("guilde"))
allChannel = helpf.getVoiceChannelsFrom(serverid)
channelWithoutNumber = after.channel.name[:nameIndex]
# When after channel name ends with number and channel number 1 has user in it
if afterNumber and len(find(lambda c: c.name == (channelWithoutNumber + "1"), allChannel).members):
# Get channels with after.channel.name without numbers in it and end with digits
voiceChanelsWithName = [channel for channel in allChannel if after.channel.name[:nameIndex] in channel.name and channel.name[len(channelWithoutNumber):].isdigit()]
# Get all numbers in the end of voiceChannelsWithName
numbersOfChannels = [int(channel.name[len(channelWithoutNumber):]) for channel in voiceChanelsWithName]
lowestFreeID = min([i for i in range(2, max(numbersOfChannels) + 2) if not i in numbersOfChannels])

channelWithNumberBefore = find(lambda c: c.name[-len(str(lowestFreeID - 1)):] == str(lowestFreeID - 1), voiceChanelsWithName)
newChannelName = channelWithoutNumber + str(lowestFreeID)
# Create channel and gets it
newChannel = await channelWithNumberBefore.clone(name = newChannelName)
# Move channel after channelWithNumberBefore
await newChannel.move(after = channelWithNumberBefore)


jh.config["log"] = "False"
jh.saveConfig()
print("Set log to False.")
Expand Down