From 3bebee82c56d1605d8ed7a51f3159502154283ca Mon Sep 17 00:00:00 2001 From: Schlumpfi <103204803+devschlumpfi@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:59:38 +0200 Subject: [PATCH] =?UTF-8?q?Made=20with=20=E2=9D=A4=EF=B8=8F=20and=20everyt?= =?UTF-8?q?hing=20in=20English?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Discord Codes/python/Auto Delete (time).py | 11 + Discord Codes/python/Clear Chat.py | 31 ++ Discord Codes/python/Command Handler Cogs.py | 45 +++ Discord Codes/python/Counting Game.py | 119 ++++++ Discord Codes/python/Radio.py | 48 +++ Discord Codes/python/Server Info Command.py | 171 +++++++++ Discord Codes/python/Tempchannels.py | 366 +++++++++++++++++++ Discord Codes/python/Unban.py | 32 ++ Discord Codes/python/Vanity Check.py | 55 +++ Discord Codes/python/Youtube Notify.py | 86 +++++ Discord Codes/python/api.py | 46 +++ 11 files changed, 1010 insertions(+) create mode 100644 Discord Codes/python/Auto Delete (time).py create mode 100644 Discord Codes/python/Clear Chat.py create mode 100644 Discord Codes/python/Command Handler Cogs.py create mode 100644 Discord Codes/python/Counting Game.py create mode 100644 Discord Codes/python/Radio.py create mode 100644 Discord Codes/python/Server Info Command.py create mode 100644 Discord Codes/python/Tempchannels.py create mode 100644 Discord Codes/python/Unban.py create mode 100644 Discord Codes/python/Vanity Check.py create mode 100644 Discord Codes/python/Youtube Notify.py create mode 100644 Discord Codes/python/api.py diff --git a/Discord Codes/python/Auto Delete (time).py b/Discord Codes/python/Auto Delete (time).py new file mode 100644 index 0000000..6fafadc --- /dev/null +++ b/Discord Codes/python/Auto Delete (time).py @@ -0,0 +1,11 @@ + @tasks.loop(seconds=10) + async def cdeletecommandclear(self): + channel = self.bot.get_channel('CHANNEL_ID') + messages = await channel.history(limit=200).flatten() + for message in messages: + if message.pinned: + pass + + + else: + await message.delete() \ No newline at end of file diff --git a/Discord Codes/python/Clear Chat.py b/Discord Codes/python/Clear Chat.py new file mode 100644 index 0000000..e760bca --- /dev/null +++ b/Discord Codes/python/Clear Chat.py @@ -0,0 +1,31 @@ +import discord +from discord.ext import commands +from discord.commands import slash_command, Option + +class Clear(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print(" ✅ - Der Clear Command wurde geladen.") + async def on_application_command_error(self, ctx, error): + if isinstance(error, commands.CheckFailure): + await ctx.respond(f"› Du hast keine Berechtigungen um diesen Befehl auszuführen.", ephemeral=True) + return + + await ctx.respond(f"Es ist ein Fehler aufgetreten: {error}", ephemeral=True) + raise error + + + + @slash_command(description='› Lösche eine bestimmte Anzahl an Nachrichten.') + @commands.has_permissions(manage_messages=True) + @discord.guild_only() + async def clear(self, ctx, + amount: Option(int, "› Die Anzahl der Nachrichten, die du löschen möchtest:", required=True)): + await ctx.channel.purge(limit=amount) + await ctx.respond(f"› Es wurden erfolgreich **{amount}** Nachrichten gelöscht.", delete_after=3) + +def setup(bot): + bot.add_cog(Clear(bot)) \ No newline at end of file diff --git a/Discord Codes/python/Command Handler Cogs.py b/Discord Codes/python/Command Handler Cogs.py new file mode 100644 index 0000000..487c922 --- /dev/null +++ b/Discord Codes/python/Command Handler Cogs.py @@ -0,0 +1,45 @@ +import asyncio +import os +import discord +from discord.ext import commands +from dotenv import load_dotenv +from discord import app_commands +intents = discord.Intents.default() +intents.message_content = True +intents.members = True + +status = discord.Status.online +activity = discord.Activity(type=discord.ActivityType.playing, name=":O") + + +client = commands.Bot( + intents=intents, + status=status, + activity=activity, + command_prefix="-", +) + + + + +@client.event +async def on_ready(): + print(f"{client.user} Online") + await client.tree.sync() + +async def funktion(): + for filename in os.listdir('./cogs'): + if filename.endswith('.py'): + await client.load_extension(f'cogs.{filename[:-3]}') + +asyncio.run(funktion()) + + + + + + +load_dotenv() +client.run(os.getenv("TOKEN")) + +#from lucky \ No newline at end of file diff --git a/Discord Codes/python/Counting Game.py b/Discord Codes/python/Counting Game.py new file mode 100644 index 0000000..c28fe6a --- /dev/null +++ b/Discord Codes/python/Counting Game.py @@ -0,0 +1,119 @@ +import discord +import asyncio +# nur nötig wenn connect hier in der selben datei ist +# import contextlib + +from discord import InputTextStyle +from discord.ext.commands import MissingPermissions +from discord.ext import commands, tasks +from discord.ui import Button, View, Modal, InputText +from discord.commands import Option, slash_command, SlashCommandGroup + +# from utils.funcs import get_config +# from utils.funcs import connect +# from utils.funcs import get_database_tables + +### {list(get_database_tables())[5]} das ist "counting" +# connect ist: +# @contextlib.asynccontextmanager +# async def connect(): +# conn = await aiomysql.connect( +# host=get_config("mysql")["host"], +# user=get_config("mysql")["user"], +# password=get_config("mysql")["password"], +# db=get_config("mysql")["database"], +# autocommit=True +# ) +# async with conn.cursor() as cur: +# yield conn, cur +# conn.close() +# +# Datenbank structure +# "guild_id": "BIGINT", +# "counting_channel_id": "BIGINT", +# "score": "BIGINT", +# "highscore": "BIGINT", +# "last_user": "BIGINT", +# "fail_role": "BIGINT", +# "only_numbers": "BOOLEAN" + + +class counting(commands.Cog): + def __init__(self, bot): + self.bot = bot + + + counting_cmd = SlashCommandGroup(name="counting", description="All counting commands", guild_only=True) + + @counting_cmd.command() + async def setchannel(self, ctx, channel: Option(discord.abc.GuildChannel, "Choose a Welcome Channel")): + async with connect() as (conn, cur): + await cur.execute(f"SELECT counting_channel_id FROM {list(get_database_tables())[5]} WHERE guild_id = {ctx.guild.id}") + result_channel = await cur.fetchone() + if not result_channel: + await cur.execute(f"INSERT INTO `counting`(`guild_id`, `counting_channel_id`, `score`, `highscore`, `last_user`, `only_numbers`) VALUES ('{ctx.guild.id}','{channel.id}','1','0','0','0')") + else: + await cur.execute(f"UPDATE `counting` SET `counting_channel_id`='{channel.id}' WHERE guild_id = {ctx.guild.id}") + return await ctx.respond(f"Der Counting-Channel wurde auf {channel.mention} Gesetzt", ephemeral=True) + + @counting_cmd.command() + async def next(self, ctx): + async with connect() as (conn, cur): + await cur.execute(f"SELECT counting_channel_id FROM {list(get_database_tables())[5]} WHERE guild_id = {ctx.guild.id}") + result_channel = await cur.fetchone() + if not result_channel: + return await ctx.respond(f"Nutze vorher /counting setchannel", ephemeral=True) + await cur.execute(f"SELECT score FROM {list(get_database_tables())[5]} WHERE guild_id = {ctx.guild.id}") + next_int = await cur.fetchone() + await cur.execute(f"SELECT last_user FROM {list(get_database_tables())[5]} WHERE guild_id = {ctx.guild.id}") + next_user = await cur.fetchone() + if next_user[0] == 0: + return await ctx.respond(f"Die nächste Zahl ist {next_int[0]}!", ephemeral=True) + else: + return await ctx.respond(f"Die nächste Zahl ist {next_int[0]} und der User <@{next_user[0]}> darf nicht als nächstes Zählen!", ephemeral=True) + + @commands.Cog.listener() + async def on_message(self, message): + async with connect() as (conn, cur): + if message.author.bot: + return + await cur.execute(f"SELECT counting_channel_id FROM {list(get_database_tables())[5]} WHERE guild_id = {message.guild.id}") + result_channel = await cur.fetchone() + if not result_channel: + return + if message.channel.id == result_channel[0]: + if message.author.bot: + return + await cur.execute(f"SELECT only_numbers FROM {list(get_database_tables())[5]} WHERE guild_id = {message.guild.id}") + num = await cur.fetchone() + if num: + if not message.content.isnumeric(): + await asyncio.sleep(2) + return await message.delete() + if not message.content.isnumeric(): + return + await cur.execute(f"SELECT last_user FROM {list(get_database_tables())[5]} WHERE guild_id = {message.guild.id}") + last_user = await cur.fetchone() + if message.author.id == int(last_user[0]): + await cur.execute(f"UPDATE {list(get_database_tables())[5]} SET score = %s, last_user = %s WHERE guild_id = %s", ("1", "0", message.guild.id)) + await message.add_reaction("❌") + channel = self.bot.get_channel(result_channel[0]) + if channel: + return await message.channel.send(F"{message.author.mention} hat die Reihe unterbrochen, da er versucht hat 2 mal hinter einander zu Zählen") + else: + await cur.execute(f"SELECT score FROM {list(get_database_tables())[5]} WHERE guild_id = {message.guild.id}") + score_result = await cur.fetchone() + if message.content == str(score_result[0]): + count = score_result[0] + 1 + await cur.execute(f"UPDATE {list(get_database_tables())[5]} SET score = %s, last_user = %s WHERE guild_id = %s", (count, message.author.id, message.guild.id)) + if score_result[0] < count: + await cur.execute(f"UPDATE {list(get_database_tables())[5]} SET highscore = %s WHERE guild_id = %s", (message.content, message.guild.id)) + return await message.add_reaction("✅") + else: + await cur.execute(f"UPDATE {list(get_database_tables())[5]} SET score = %s, last_user = %s WHERE guild_id = %s", ("1", "0", message.guild.id)) + return await message.add_reaction("❌") + else: + return + +def setup(bot): + bot.add_cog(counting(bot)) \ No newline at end of file diff --git a/Discord Codes/python/Radio.py b/Discord Codes/python/Radio.py new file mode 100644 index 0000000..e86a75e --- /dev/null +++ b/Discord Codes/python/Radio.py @@ -0,0 +1,48 @@ +############################################ +# Discord Radio Bot +# Author: @InvalidJoker +# Version: 1.0 +# Diese Nachricht darf nicht entfernt werden! +############################################ +from discord.ext import tasks +import discord +import asyncio + +CHANNEL = 1052660703267393567 + +bot = discord.Bot(intents=discord.Intents.all()) + +@bot.event +async def on_ready(): + channel = bot.get_channel(CHANNEL) + + await channel.connect() + channel.guild.voice_client.play(discord.FFmpegPCMAudio("https://streams.ilovemusic.de/iloveradio16.mp3")) + check_music.start() + auto_restart.start() + print("The Radio is online!") + +@tasks.loop(seconds=60) +async def check_music(): + channel = bot.get_channel(CHANNEL) + + if channel.guild.voice_client is None: + await channel.connect() + channel.guild.voice_client.play(discord.FFmpegPCMAudio("https://streams.ilovemusic.de/iloveradio16.mp3")) + + if channel.guild.voice_client.is_playing() == False: + channel.guild.voice_client.play(discord.FFmpegPCMAudio("https://streams.ilovemusic.de/iloveradio16.mp3")) + +@tasks.loop(hours=24) +async def auto_restart(): + channel = bot.get_channel(CHANNEL) + + if channel.guild.voice_client: + check_music.stop() + await channel.guild.voice_client.disconnect() + asyncio.sleep(5) + await channel.connect() + channel.guild.voice_client.play(discord.FFmpegPCMAudio("https://streams.ilovemusic.de/iloveradio16.mp3")) + check_music.start() + +bot.run("TOKEN") \ No newline at end of file diff --git a/Discord Codes/python/Server Info Command.py b/Discord Codes/python/Server Info Command.py new file mode 100644 index 0000000..b1b6024 --- /dev/null +++ b/Discord Codes/python/Server Info Command.py @@ -0,0 +1,171 @@ +import discord +from discord.ext import commands +from discord import app_commands + + +class serverinfo(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @app_commands.command(description="Zeigt Infos über den Server.") + async def serverinfo(self, ctx: discord.Interaction): + name = str(ctx.guild.name) + description = str(ctx.guild.description) + guild = ctx.guild + id = str(ctx.guild.id) + memberCount = str(ctx.guild.member_count) + text_channels = len(ctx.guild.text_channels) + voice_channels = len(ctx.guild.voice_channels) + categories = len(ctx.guild.categories) + channels = text_channels + voice_channels + role_count = len(ctx.guild.roles) + emoji_count = len(ctx.guild.emojis) + + statuses = [len(list(filter(lambda m: str(m.status) == "online", ctx.guild.members))), + len(list(filter(lambda m: str(m.status) == "idle", ctx.guild.members))), + len(list(filter(lambda m: str(m.status) == "dnd", ctx.guild.members))), + len(list(filter(lambda m: str(m.status) == "offline", ctx.guild.members)))] + + embed = discord.Embed( + title=f"{name} Server Information", + description=f'**Beschreibung vom Servers**\n {description}', + color=discord.Color.blue() + ) + embed.add_field(name='Owner', value=f'{ctx.guild.owner.mention}\n**ID:**({ctx.guild.owner_id})') + embed.add_field(name="🆔 Server ID", value=id, inline=True) + embed.add_field(name="👥 Mitglieder", value=memberCount, inline=True) + embed.add_field(name='🤖 Bots', value=f'{sum(member.bot for member in ctx.guild.members)}') + embed.add_field(name='👥 User', value=f'{sum(not member.bot for member in ctx.guild.members)}') + embed.add_field(name="💬 Channel", value=f"{channels}", inline=True) + embed.add_field(name='📆 Servererstellung', value=f'', inline=False) + embed.add_field(name='🗂 Kategorien', value=f"{categories}", inline=True) + embed.add_field(name='Rollen', value=str(role_count), inline=False) + embed.add_field(name='✅ Verifizierungslevel', value=str(ctx.guild.verification_level), inline=False) + embed.add_field(name='✨ Boosts', value=f'{str(ctx.guild.premium_subscription_count)}') + embed.add_field(name='🥇 Boostlevel', value=f'{ctx.guild.premium_tier}') + embed.add_field(name="```Status```", value=f"**🟢Online:** {statuses[0]}\n**🟠Abwesend:** {statuses[1]}" + f"\n**🔴Bitte nicht stören:** {statuses[2]}\n**⚪Offline:** " + f"{statuses[3]}", inline=True) + embed.add_field(name='Emojis', value=str(emoji_count), inline=True) + embed.add_field(name='Regelnkanal', + value=ctx.guild.rules_channel.mention if ctx.guild.rules_channel else '~~nicht gegeben~~') + embed.add_field(name="Community Update Kanal", + value=ctx.guild.public_updates_channel if ctx.guild.public_updates_channel else "~~nicht gegeben~~") + embed.add_field(name='AFK CHANNEL', + value=str(ctx.guild.afk_channel.mention if ctx.guild.afk_channel else '~~nicht gegeben~~'), + inline=True) + embed.add_field(name='AFK Timeout in sek.', value=str(ctx.guild.afk_timeout), inline=True) + embed.add_field(name="Threads", value=f"{len(guild.threads) if guild.threads else 0}") + await ctx.response.send_message(embed=embed, view=serverinfob(ctx)) + + +async def setup(bot): + await bot.add_cog(serverinfo(bot)) + + +class serverinfob(discord.ui.View): + def __init__(self, ctx): + self.ctx = ctx + super().__init__(timeout=None) + + @discord.ui.button(label="🏠 Home", style=discord.ButtonStyle.red) + async def serverinfo2(self, ctx, button:discord.ui.Button): + name = str(ctx.guild.name) + description = str(ctx.guild.description) + guild = ctx.guild + id = str(ctx.guild.id) + memberCount = str(ctx.guild.member_count) + text_channels = len(ctx.guild.text_channels) + voice_channels = len(ctx.guild.voice_channels) + categories = len(ctx.guild.categories) + channels = text_channels + voice_channels + role_count = len(ctx.guild.roles) + emoji_count = len(ctx.guild.emojis) + total_member_count = 0 + # Iterate over the voice channels + for voice_channel in ctx.guild.voice_channels: + # Sum the number of members connected in each voice channel + total_member_count += len(voice_channel.members) + statuses = [len(list(filter(lambda m: str(m.status) == "online", ctx.guild.members))), + len(list(filter(lambda m: str(m.status) == "idle", ctx.guild.members))), + len(list(filter(lambda m: str(m.status) == "dnd", ctx.guild.members))), + len(list(filter(lambda m: str(m.status) == "offline", ctx.guild.members)))] + + embed = discord.Embed( + title=name + " Server Information", + description=f'**Beschreibung vom Servers**\n {description if description else" "}', + color=discord.Color.blue() + ) + if guild.banner: + embed.set_image(url=guild.banner.url) + embed.add_field(name='Owner', value=f'{ctx.guild.owner.mention}\n**ID:**({ctx.guild.owner_id})') + embed.add_field(name="🆔 Server ID", value=id, inline=True) + embed.add_field(name='Shard ID', value=ctx.guild.shard_id if ctx.guild.shard_id else "~~nicht gegeben~~") + embed.add_field(name="👥 Mitglieder", value=memberCount, inline=True) + embed.add_field(name='🤖 Bots', value=f'{sum(member.bot for member in ctx.guild.members)}') + embed.add_field(name='👥 User', value=f'{sum(not member.bot for member in ctx.guild.members)}') + embed.add_field(name='😢Inaktive User', value=await ctx.guild.estimate_pruned_members(days=7)) + embed.add_field(name="💬 Channel", value=channels, inline=True) + embed.add_field(name="Forums",value=len(guild.forums) if guild.forums else "0") + embed.add_field(name="Stage Channel", value=guild.stage_channels if guild.stage_channels else "0") + embed.add_field(name='📆 Servererstellung', value=f'', inline=False) + embed.add_field(name='🗂 Kategorien', value=categories, inline=True) + embed.add_field(name='Rollen', value=str(role_count), inline=False) + embed.add_field(name='✅ Verifizierungslevel', value=str(ctx.guild.verification_level), inline=False) + embed.add_field(name='✨ Boosts', value=f'{str(ctx.guild.premium_subscription_count)}') + embed.add_field(name='🥇 Boostlevel', value=f'{ctx.guild.premium_tier}') + embed.add_field(name="```Status```", value=f"**🟢Online:** {statuses[0]}\n**🟠Abwesend:** {statuses[1]}" + f"\n**🔴Bitte nicht stören:** {statuses[2]}\n**⚪Offline:** " + f"{statuses[3]}", inline=True) + embed.add_field(name='Emojis', value=str(emoji_count), inline=True) + embed.add_field(name='Regelnkanal', + value=ctx.guild.rules_channel.mention if ctx.guild.rules_channel else '~~nicht gegeben~~') + embed.add_field(name="Community Update Kanal", value=ctx.guild.public_updates_channel if ctx.guild.public_updates_channel else "~~nicht gegeben~~") + embed.add_field(name="System-Kanal",value=guild.system_channel.mention) + embed.add_field(name='AFK CHANNEL', + value=str(ctx.guild.afk_channel.mention if ctx.guild.afk_channel else '~~nicht gegeben~~'), + inline=True) + embed.add_field(name="User im Sprachkanal",value=f'**Aktive Sprachkanäle**\nMomentan sind {total_member_count} Mitglieder in Sprachkanälen.') + embed.add_field(name='AFK Timeout in sek.', value=str(ctx.guild.afk_timeout), inline=True) + embed.add_field(name='Bitrate', value=(ctx.guild.bitrate_limit if ctx.guild.bitrate_limit else 'keines'), + inline=True) + embed.add_field(name="Vanity URL", value=ctx.guild.vanity_url_code if ctx.guild.vanity_url_code else "~~nicht gegeben~~") + embed.add_field(name="Threads",value=guild.threads if guild.threads else 0) + if guild.features: + embed.add_field(name="Server features",value="✅"+"\n✅".join(guild.features) or "Nothing") + embed.set_footer(text=f'Angefragt von {ctx.user.name} • {ctx.user.id}') + await ctx.response.edit_message(embed=embed) + + @discord.ui.button(label="Serverprofil", style=discord.ButtonStyle.green) + async def icon(self, ctx, button:discord.ui.Button): + embed = discord.Embed(title=f"Das ist das Servericon von {ctx.guild}") + embed.set_image(url=ctx.guild.icon) + await ctx.response.edit_message(embed=embed) + + @discord.ui.button(label="Server emojis", style=discord.ButtonStyle.blurple) + async def serveremoji(self, ctx, button:discord.ui.Button): + embed = discord.Embed() + embed = discord.Embed(title=f"{ctx.guild}`s Serveremojis", + description=(",".join([str(emojis) for emojis in ctx.guild.emojis])), + color=discord.Color.blue()) + await ctx.response.edit_message(embed=embed) + + @discord.ui.button(label="Server rollen", style=discord.ButtonStyle.blurple) + async def serverrollen(self, ctx, button:discord.ui.Button): + embed = discord.Embed(title=f"{ctx.guild}`s Serverrollen", + description=("".join([str(r.mention) for r in ctx.guild.roles]))) + color=discord.Color.blue() + await ctx.response.edit_message(embed=embed) + + @discord.ui.button(label="Serverbanner", style=discord.ButtonStyle.green) + async def serverbanner(self, ctx, button:discord.ui.Button): + if ctx.guild.banner is None: + embed = discord.Embed(title=f"{ctx.guild}`s Banner", description="Der Server besitzt kein Serverbanner") + await ctx.response.edit_message(embed=embed) + else: + embed = discord.Embed(title=f"{ctx.guild}`s Banner") + embed.set_image(url=ctx.guild.banner) + await ctx.response.edit_message(embed=embed) + + +##From Lucky \ No newline at end of file diff --git a/Discord Codes/python/Tempchannels.py b/Discord Codes/python/Tempchannels.py new file mode 100644 index 0000000..2b97190 --- /dev/null +++ b/Discord Codes/python/Tempchannels.py @@ -0,0 +1,366 @@ +import discord +from discord.ext import commands +import aiosqlite +import asyncio +import os + +class JoinToCreate(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.init_db() + self.temp_channels = {} + + def init_db(self): + async def create_voice_channels_table(): + async with aiosqlite.connect("voice_channels.db") as db: + await db.execute(""" + CREATE TABLE IF NOT EXISTS voice_channels ( + user_id INTEGER PRIMARY KEY, + channel_id INTEGER NOT NULL + ) + """) + await db.commit() + + self.bot.loop.create_task(create_voice_channels_table()) + + + + + @commands.Cog.listener() + async def on_voice_state_update(self, member, before, after): + if after.channel and not before.channel and after.channel.id == 1141202340498645062: #HIER DIE CHANNEL ID VOM VOICE + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE user_id = ?", (member.id,)) + channel_info = await cursor.fetchone() + if not channel_info: + guild = member.guild + channel_name = f"{member.name}'s Channel" + category = guild.get_channel(1102689340557103215) # HIER DIE CATEGORIE ID + + if not category: + return print("Channel wurde nicht gefunden") + + voice_channel = await guild.create_voice_channel(channel_name, category=category) + await member.move_to(voice_channel) + + await db.execute("INSERT INTO voice_channels (user_id, channel_id) VALUES (?, ?)", (member.id, voice_channel.id)) + await db.commit() + if before.channel and len(before.channel.members) == 0: + await before.channel.delete() + + self.temp_channels[member.id] = voice_channel.id + + view = discord.ui.View() + limit_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Limitieren", emoji="👥") + rename_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Rename", emoji="✏") + sperren_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Sperren", emoji="🔒") + entsperren_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Entsperren", emoji="🔓") + ban_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Bannen", emoji="🔨") + kick_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Kicken", emoji="⛔") + rechtevergeben_button = discord.ui.Button(style=discord.ButtonStyle.gray, label="Eigentum-Übertragen", emoji="👑") + delete_button = discord.ui.Button(style=discord.ButtonStyle.grey, label=f"{voice_channel.name} Löschen.", emoji="🧨") + # radio_button = discord.ui.Button(style=discord.ButtonStyle.grey, label=f"Beginne das Radio", emoji="🎶") + # stopradio_button = discord.ui.Button(style=discord.ButtonStyle.grey, label=f"Stoppe das Radio", emoji="💤") + + + async def call1(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + else: + def check(message): + return message.author == interaction.user and message.channel == interaction.channel + + await interaction.response.send_message("Bitte gib die gewünschte Benutzerlimitierung für deinen Kanal ein:", ephemeral=True) + try: + response = await interaction.client.wait_for('message', check=check, timeout=30) + limit = int(response.content) + if 0 < limit <= 99: + voice_channel = interaction.message.channel + await voice_channel.edit(user_limit=limit) + await interaction.followup.send(f"Benutzerlimit des Kanals auf {limit} gesetzt.", ephemeral=True) + await asyncio.sleep(1) + await response.delete() + else: + await interaction.followup.send("Ungültige Eingabe. Bitte gib eine Zahl zwischen 1 und 99 ein.", ephemeral=True) + except asyncio.TimeoutError: + await interaction.followup.send("Zeitlimit überschritten. Bitte versuche es erneut.", ephemeral=True) + except ValueError: + await interaction.followup.send("Ungültige Eingabe. Bitte gib eine Zahl zwischen 1 und 99 ein.", ephemeral=True) + + + async def call2(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + else: + def check(message): + return message.author == interaction.user and message.channel == interaction.channel + + await interaction.response.send_message("Bitte gib den neuen Namen für deinen Kanal ein:", ephemeral=True) + try: + response = await interaction.client.wait_for('message', check=check, timeout=30) + new_name = response.content + voice_channel = interaction.message.channel + await voice_channel.edit(name=new_name) + await interaction.followup.send(f"Kanal erfolgreich in `{new_name}` umbenannt.", ephemeral=True) + await asyncio.sleep(1) + await response.delete() + except asyncio.TimeoutError: + await interaction.followup.send("Zeitlimit überschritten. Bitte versuche es erneut.", ephemeral=True) + + + async def call3(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + else: + voice_channel = interaction.message.channel + await voice_channel.set_permissions(interaction.guild.default_role, view_channel=True, connect=False) + await interaction.response.send_message("Der Kanal wurde gesperrt.", ephemeral=True) + + + async def call4(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + else: + voice_channel = interaction.message.channel + await voice_channel.set_permissions(interaction.guild.default_role, connect=True) + await interaction.response.send_message("Der Kanal wurde entsperrt.", ephemeral=True) + + + async def call5(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + else: + await interaction.response.send_message("Bitte gib die ID des Benutzers an, den du bannen möchtest:", ephemeral=True) + try: + response = await self.bot.wait_for('message', timeout=30) + user_id = int(response.content) + voice_channel = interaction.message.channel + member = voice_channel.guild.get_member(user_id) + if member: + await member.move_to(None) + await voice_channel.set_permissions(member, connect=False) + await interaction.followup.send(f"{member.mention} wurde aus dem Kanal gebannt und gesperrt.", ephemeral=True) + await asyncio.sleep(1) + await response.delete() + else: + await interaction.followup.send("Benutzer nicht gefunden.", ephemeral=True) + except asyncio.TimeoutError: + await interaction.followup.send("Zeitlimit überschritten. Bitte versuche es erneut.", ephemeral=True) + + + + async def call6(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + else: + await interaction.response.send_message("Bitte gib die ID des Benutzers an, den du aus dem Kanal kicken möchtest:", ephemeral=True) + try: + response = await self.bot.wait_for('message', timeout=30) + user_id = int(response.content) + voice_channel = interaction.message.channel + member = voice_channel.guild.get_member(user_id) + if member: + await member.move_to(None) + await interaction.followup.send(f"{member.mention} wurde aus dem Kanal gekickt.", ephemeral=True) + await asyncio.sleep(3) + await response.delete() + else: + await interaction.followup.send("Benutzer nicht gefunden.", ephemeral=True) + except asyncio.TimeoutError: + await interaction.followup.send("Zeitlimit überschritten. Bitte versuche es erneut.", ephemeral=True) + + + async def call7(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + if not channel_info: + await interaction.response.send_message("Der Voice Channel existiert nicht in der Datenbank.", ephemeral=True) + return + + current_owner = interaction.guild.get_member(channel_info[0]) + if current_owner is None: + await interaction.response.send_message("Der aktuelle Besitzer ist nicht mehr auf dem Server.", ephemeral=True) + return + + if interaction.user.id == current_owner.id: + if current_owner.voice is None or current_owner.voice.channel != interaction.channel: + await interaction.response.send_message("Du musst im gleichen Voice Channel wie der aktuelle Besitzer sein, um das Eigentum zu übertragen.", ephemeral=True) + return + + await interaction.response.send_message("Bitte gib die ID des Benutzers an, dem du das Eigentum übertragen möchtest:", ephemeral=True) + try: + response = await self.bot.wait_for('message', timeout=30) + new_owner_id = int(response.content) + new_owner = interaction.guild.get_member(new_owner_id) + if new_owner: + await db.execute("UPDATE voice_channels SET user_id = ? WHERE channel_id = ?", (new_owner.id, channel_id)) + await db.commit() + await interaction.followup.send(f"{new_owner.mention} ist jetzt der neue Besitzer des Kanals.", ephemeral=True) + await asyncio.sleep(1) + await response.delete() + else: + await interaction.followup.send("Benutzer nicht gefunden.", ephemeral=True) + except asyncio.TimeoutError: + await interaction.followup.send("Zeitlimit überschritten. Bitte versuche es erneut.", ephemeral=True) + except ValueError: + await interaction.followup.send("Ungültige Benutzer-ID. Bitte gib eine korrekte Benutzer-ID an.", ephemeral=True) + else: + if current_owner.voice is not None: + await interaction.response.send_message("Der aktuelle Besitzer ist online im Voice Channel. Nur er kann das Eigentum übertragen.", ephemeral=True) + return + + await db.execute("UPDATE voice_channels SET user_id = ? WHERE channel_id = ?", (interaction.user.id, channel_id)) + await db.commit() + await interaction.response.send_message(f"{interaction.user.mention} ist jetzt der neue Besitzer des Kanals.", ephemeral=True) + + + + + async def call8(interaction): + channel_id = interaction.message.channel.id + async with aiosqlite.connect("voice_channels.db") as db: + cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + channel_info = await cursor.fetchone() + + + if not channel_info or interaction.user.id != channel_info[0]: + await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + return + + voice_channel = interaction.message.channel + await db.execute("DELETE FROM voice_channels WHERE channel_id = ?", (voice_channel.id,)) + await db.commit() + await voice_channel.delete() + await asyncio.sleep(2) + await member.send("Dein Voice-Kanal wurde per Button gelöscht!") + + + # async def call9(interaction): + # channel_id = interaction.message.channel.id + # async with aiosqlite.connect("voice_channels.db") as db: + # cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + # channel_info = await cursor.fetchone() + + # if not channel_info or interaction.user.id != channel_info[0]: + # await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + # return + + # user_voice_state = interaction.guild.get_member(interaction.user.id).voice + # if user_voice_state is None or user_voice_state.channel is None: + # await interaction.response.send_message("Du musst einem Voice Channel beitreten!", ephemeral=True) + # return + + # voice_channel = user_voice_state.channel + + # if not voice_channel.permissions_for(interaction.guild.me).connect: + # await interaction.response.send_message("Ich habe keine Berechtigung deinem Channel beizutreten!", ephemeral=True) + # return + + # if self.bot.voice_clients: + # # Disconnect from any existing voice channel + # for voice_client in self.bot.voice_clients: + # await voice_client.disconnect() + + # # Join the user's voice channel + # voice_client = await voice_channel.connect() + + # # Play the radio stream + # voice_client.play(discord.FFmpegPCMAudio("https://streams.ilovemusic.de/iloveradio1.mp3")) + + # await interaction.response.send_message("Das Radio wurde gestartet") + + # async def call10(interaction): + # channel_id = interaction.message.channel.id + # async with aiosqlite.connect("voice_channels.db") as db: + # cursor = await db.execute("SELECT * FROM voice_channels WHERE channel_id = ?", (channel_id,)) + # channel_info = await cursor.fetchone() + + # if not channel_info or interaction.user.id != channel_info[0]: + # await interaction.response.send_message("Du bist nicht der Besitzer des Channels.", ephemeral=True) + # return + + # for voice_client in self.bot.voice_clients: + # await voice_client.disconnect() + + # await interaction.response.send_message("Tschauu!!") + + + rename_button.callback = call2 + limit_button.callback = call1 + sperren_button.callback = call3 + entsperren_button.callback = call4 + ban_button.callback = call5 + kick_button.callback = call6 + rechtevergeben_button.callback = call7 + delete_button.callback = call8 + # radio_button.callback = call9 + # stopradio_button.callback = call10 + view.add_item(rename_button) + view.add_item(limit_button) + view.add_item(sperren_button) + view.add_item(entsperren_button) + view.add_item(ban_button) + view.add_item(kick_button) + view.add_item(rechtevergeben_button) + view.add_item(delete_button) + # view.add_item(radio_button) + # view.add_item(stopradio_button) + embed = discord.Embed(title="Neuer Voice Channel", + description=f"Willkommen in deinem eigenen Voice Channel, {member.mention}!", + color=discord.Color.purple()) + embed.set_thumbnail(url=member.guild.icon) + embed.set_footer(text="Made by Bobbyontop. ©") + await voice_channel.send(content=f"{member.mention}", embed=embed, view=view) + + + if before.channel and before.channel.id in self.temp_channels.values(): + if len(before.channel.members) == 0: + await before.channel.delete() + async with aiosqlite.connect("voice_channels.db") as db: + await db.execute("DELETE FROM voice_channels WHERE channel_id = ?", (before.channel.id,)) + await db.commit() + + +def setup(bot): + bot.add_cog(JoinToCreate(bot)) + +##From Bobby \ No newline at end of file diff --git a/Discord Codes/python/Unban.py b/Discord Codes/python/Unban.py new file mode 100644 index 0000000..59462ce --- /dev/null +++ b/Discord Codes/python/Unban.py @@ -0,0 +1,32 @@ +import discord +from discord.utils import basic_autocomplete +from discord.commands import slash_command, Option +from discord.ext import commands + + +async def unban_autocomplete(ctx: discord.AutocompleteContext): + x = await ctx.interaction.guild.bans().flatten() + x = [f'{y.user}' for y in x] + return x + +class UnbanCommand(commands.Cog): + + def __init__(self, bot: discord.Bot): + self.bot = bot + + @slash_command(name="unban", description="") + @discord.default_permissions(ban_members=True) + async def _unban(self, ctx: discord.ApplicationContext, member: Option(str, autocomplete=basic_autocomplete(unban_autocomplete))): + async for ban in ctx.guild.bans(): + if f'{ban.user}' == f'{member}': + await ctx.guild.unban(ban.user) + return await ctx.respond(f"Unbanned {ban.user}") + + else: + continue + + return await ctx.respond("User cant be found") + + +def setup(bot: discord.Bot): + bot.add_cog(UnbanCommand(bot)) \ No newline at end of file diff --git a/Discord Codes/python/Vanity Check.py b/Discord Codes/python/Vanity Check.py new file mode 100644 index 0000000..b8aab86 --- /dev/null +++ b/Discord Codes/python/Vanity Check.py @@ -0,0 +1,55 @@ +#from Marcel + +GUILD = 1234 # Server, auf dem der Bot die Rolle vergeben soll +STATUS_ROLE = 1234 # Rolle die vergeben werden soll, wenn der User den entsprechenden Status hat +STATUS_TEXT = "TEXT" # Status, den der User haben muss +LOG_CHANNEL = 1234 # In dem channel wird geloggt + +@bot.event +async def on_ready(): + print(f"{bot.user} is ready") + vanity_task.start() + +async def has_vanity(member: discord.Member): + if not len(member.activities) == 0: + for i in member.activities: + if isinstance(i, discord.CustomActivity): + if STATUS_TEXT in i.name or STATUS_TEXT == i.name: + return True + + else: + return False + + +@tasks.loop(minutes=1) +async def vanity_task(): + await bot.wait_until_ready() + + guild: discord.Guild = bot.get_guild(GUILD) + role = guild.get_role(STATUS_ROLE) + log = bot.get_channel(LOG_CHANNEL) + + if guild.members: + for member in guild.members: + if member.bot: + continue + vanity = await has_vanity(member) + if vanity: + if not role in member.roles: + await member.add_roles(role, atomic=True) + embed = discord.Embed( + title="Vanity-Rolle hinzugefügt!", + description=f"{member.mention} hat die Vanity-Rolle {role.mention} erhalten.", + color=discord.Color.green() + ) + await log.send(embed=embed) + + else: + if role in member.roles: + await member.remove_roles(role, atomic=True) + embed = discord.Embed( + title="Vanity-Rolle entfernt!", + description=f"{member.mention} hat die Vanity-Rolle {role.mention} entfernt bekommen.", + color=discord.Color.red() + ) + await log.send(embed=embed) \ No newline at end of file diff --git a/Discord Codes/python/Youtube Notify.py b/Discord Codes/python/Youtube Notify.py new file mode 100644 index 0000000..0e05188 --- /dev/null +++ b/Discord Codes/python/Youtube Notify.py @@ -0,0 +1,86 @@ +import json +import discord +from colorama import * +from discord.commands import slash_command, Option +from discord.ext import commands, tasks +from pytube import Channel + + +class YoutubeNotify(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + self.checkforvideos.start() + + # Prüft alle 60 Sekunden die Videos + @tasks.loop(seconds=60) + async def checkforvideos(self): + with open("youtubedata.json", "r") as f: + data = json.load(f) + + print(Fore.RED + "---------------Prüfe YouTube-Daten!---------------") + + # Prüft die Daten in "youtubedata.json" und holt sich die Kanal-URL sowie die html der /videos Seite + for youtube_channel in data: + print(Fore.BLUE + f"----------Prüfe YouTube-Daten von {data[youtube_channel]['channel_name']}----------") + channel = f"https://www.youtube.com/channel/{youtube_channel}" + + c = Channel(channel) + try: + latest_video_url = c.video_urls[0] + except: + continue + + # Prüft ob die url in "youtubedata.json" nicht die selbe ist wie die letzte Video url und ersetzt diese ggf. + if not str(data[youtube_channel]["latest_video_url"]) == latest_video_url: + data[str(youtube_channel)]['latest_video_url'] = latest_video_url + + # dumping der Daten + with open("youtubedata.json", "w") as f: + json.dump(data, f) + + # Nimmt die Channel ID und sendet die Daten + discord_channel_id = data[str(youtube_channel)]['notifying_discord_channel'] + discord_channel = self.bot.get_channel(int(discord_channel_id)) + msg = f"{data[str(youtube_channel)]['channel_name']} hat gerade ein Video hochgeladen: " \ + f"{latest_video_url} " + await discord_channel.send(msg) + + # SlashCommand erstellen um mehr YouTube Accounts hinzuzufügen + @slash_command(description="Füge einen YouTuber zu den Benachrichtigungen hinzu!") + @discord.default_permissions(administrator=True) + @discord.guild_only() + async def add_yt_notify(self, ctx, channel_id: str, *, channel_name: str, discord_channel_id: str): + with open("youtubedata.json", "r") as f: + data = json.load(f) + + data[str(channel_id)] = {} + data[str(channel_id)]["channel_name"] = channel_name + data[str(channel_id)]["latest_video_url"] = "none" + data[str(channel_id)]["notifying_discord_channel"] = discord_channel_id + + with open("youtubedata.json", "w") as f: + json.dump(data, f) + + await ctx.respond("Daten hinzugefügt!", ephemeral=True) + + # SlashCommand um Benachrichtigungen umzustellen + @slash_command(description="Aktiviere oder Deaktiviere Benachrichtigungen") + @discord.default_permissions(administrator=True) + @discord.guild_only() + async def yt_notify( + self, ctx, + status: Option(str, choices=["aktivieren", "deaktivieren"]) + ): + if status == "aktivieren": + self.checkforvideos.start() + else: + self.checkforvideos.stop() + + await ctx.respond("Status wurde geändert!", ephemeral=True) + + +def setup(bot): + bot.add_cog(YoutubeNotify(bot)) \ No newline at end of file diff --git a/Discord Codes/python/api.py b/Discord Codes/python/api.py new file mode 100644 index 0000000..814d670 --- /dev/null +++ b/Discord Codes/python/api.py @@ -0,0 +1,46 @@ +import discord +from discord.ext import commands +from discord.commands import slash_command + +import requests +import random +import os + +from pprint import pprint + + +class API(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @slash_command() + async def keks(self, ctx): + key = os.getenv("API_KEY") + + params = { + "q": "keks", + "key": key, + "limit": "10", + "client_key": "discord_bot", + "media_filter": "gif" + } + result = requests.get("https://tenor.googleapis.com/v2/search", params=params) + data = result.json() + # pprint(data) + + number = random.randint(0, 9) + url = data['results'][number]['media_formats']['gif']['url'] + + embed = discord.Embed( + title="Keks", + color=discord.Color.yellow() + ) + embed.set_image(url=url) + embed.set_footer(text="Via Tenor") + await ctx.respond(embed=embed) + + +def setup(bot): + bot.add_cog(API(bot)) + +#from tibue99 \ No newline at end of file