-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
354 lines (303 loc) · 11.6 KB
/
main.py
File metadata and controls
354 lines (303 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import discord
from discord.ext import commands, tasks
import os
import requests
import json
import asyncio
import random
from datetime import datetime
from server import Live
from Hello import random_language
from Hallo import random_greeting, random_greeting_evening, random_greeting_morning, random_greeting_night
from names import names
from youtubeapi import youtubeapi, youtubeapilong, youtubeapimemeslong, youtubeapisearch, youtubeapimemes, youtubeshortapi, youtubeshortsapimemes, ytapi, randomyoutubeapi
# Definiere Konstanten aus den Umgebungsvariablen
DAILY_CLEARING_CHANNEL_ID = os.getenv('DAILY_CLEARING_CHANNEL_ID') # Kanal-ID für tägliches Löschen
YOUR_SERVER_ID = os.getenv('YOUR_SERVER_ID') # Server-ID
YOUR_CHANNEL_ID = os.getenv('YOUR_CHANNEL_ID') # Kanal-ID
YOUR_DISCORD_BOT_TOKEN = os.getenv('YOUR_DISCORD_BOT_TOKEN') # Discord-Bot-Token
# Erstelle Intents für den Bot, um bestimmte Ereignisse zu behandeln
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(command_prefix='', intents=intents)
# Initialisiere die Startzeit und einige globale Variablen
start_time = datetime.now()
daily_video_online = {}
happycrismas = {}
@tasks.loop(minutes=5)
async def update_time():
# Lösche die Konsole
os.system('clear' if os.name == 'posix' else 'cls')
# Berechne die verstrichene Zeit und aktualisiere den Bot-Status
elapsed_time = datetime.now() - start_time
elapsed_minutes = int(elapsed_time.total_seconds() / 60)
activity = discord.Game(name=f"seit {round(elapsed_minutes/60)}h", type=3)
await bot.change_presence(status=discord.Status.idle, activity=activity)
# Aktuelle Uhrzeit und Datum
current_hour = datetime.now().hour + 1
current_minute = datetime.now().minute
current_second = datetime.now().second
current_day = datetime.now().day
current_month = datetime.now().month
current_year = datetime.now().year
# Guild-ID für tägliches Video-Update
guild_id = YOUR_SERVER_ID
if guild_id not in daily_video_online:
daily_video_online[guild_id] = False
# Bedingte Aufgaben basierend auf der Uhrzeit
if current_hour == 18:
if not daily_video_online[guild_id]:
await send_daily_video(guild_id, 'daily')
elif current_hour == 20:
if not daily_video_online[guild_id]:
await send_daily_meme(guild_id)
elif current_month == 12 and current_day == 24 and current_hour == 12:
if not daily_video_online[guild_id]:
await send_christmas_greeting(guild_id)
elif current_month == 12 and current_day == 31 and current_hour == 23 and 55 >= current_minute >= 50:
if not daily_video_online[guild_id]:
bot.loop.create_task(countdown())
daily_video_online[guild_id] = True
else:
daily_video_online[guild_id] = False
print(f"Aktualisierte Zeit: {elapsed_minutes}min ( {current_day}.{current_month}.{current_year} )( {current_hour}:{current_minute}:{current_second} ) ( Daily Video {daily_video_online[guild_id]} ) Nächste Aktualisierung in 5 min ")
@bot.event
async def on_ready():
# Logge, dass der Bot bereit ist und starte die Zeitaktualisierung
log_event("Bot is ready!")
update_time.start()
@bot.event
async def on_member_join(member):
# Begrüße neue Mitglieder
guild_id = YOUR_SERVER_ID
if guild_id:
await send_welcome_message(member, guild_id)
@bot.command()
async def countdownxyz(ctx):
# Starte den Countdown
bot.loop.create_task(countdown())
async def countdown():
# Countdown-Prozess bis zum Jahreswechsel
current_year = datetime.utcnow().year
guild_id = YOUR_SERVER_ID
channel_id = YOUR_CHANNEL_ID
guild = bot.get_guild(guild_id)
if guild:
channel = guild.get_channel(channel_id)
if channel and isinstance(channel, discord.TextChannel):
await channel.send(f"Nicht mehr lang bis {current_year + 1}")
await countdown_process(channel, current_year)
@bot.command()
async def displaylog(ctx):
# Zeige den Inhalt der Logdatei
await display_file_content(ctx, "log.txt")
@bot.command()
async def displaymemberlog(ctx):
# Zeige den Inhalt der Mitglieder-Logdatei
await display_file_content(ctx, "memberlog.txt")
# YouTube-Befehle
@bot.command()
async def youtube(ctx):
await handle_youtube_command(ctx, youtubeapi)
@bot.command()
async def randomyoutube(ctx):
await handle_youtube_command(ctx, randomyoutubeapi)
@bot.command()
async def yt(ctx):
await handle_youtube_command(ctx, ytapi)
@bot.command()
async def longyoutube(ctx):
await handle_youtube_command(ctx, youtubeapilong)
@bot.command()
async def shortyoutube(ctx):
await handle_youtube_command(ctx, youtubeshortapi)
@bot.command()
async def youtubememe(ctx):
await handle_youtube_command(ctx, youtubeapimemes, 1)
@bot.command()
async def longyoutubememe(ctx):
await handle_youtube_command(ctx, youtubeapimemeslong, 1)
@bot.command()
async def shortyoutubememe(ctx):
await handle_youtube_command(ctx, youtubeshortsapimemes, 1)
@bot.command()
async def youtubememes(ctx, number=None):
await handle_youtube_command(ctx, youtubeapimemes, number, True)
@bot.command()
async def longyoutubememes(ctx, number=None):
await handle_youtube_command(ctx, youtubeapimemeslong, number, True)
@bot.command()
async def shortyoutubememes(ctx, number=None):
await handle_youtube_command(ctx, youtubeshortsapimemes, number, True)
@bot.command()
async def search(ctx, text):
await handle_youtube_command(ctx, youtubeapisearch, text)
# Spaß- und Begrüßungsbefehle
@bot.command()
async def toilette(ctx):
await ctx.send("https://youtu.be/3DpjtBWYifg?si=2NnvHDZky2meF5dH")
@bot.command()
async def meme(ctx):
response = requests.get("https://meme-api.com/gimme")
json_data = json.loads(response.text)
await ctx.send(json_data.get("url"))
# Begrüßungsbefehle
@bot.command()
async def hallo(ctx):
await send_greeting(ctx)
@bot.command()
async def hey(ctx):
await send_greeting(ctx)
@bot.command()
async def na(ctx):
await send_greeting(ctx, night=True)
@bot.command()
async def moin(ctx):
await send_greeting(ctx)
@bot.command()
async def hi(ctx):
await send_greeting(ctx)
@bot.command()
async def write(ctx, text):
await ctx.send(text)
# Begrüßung in verschiedenen Sprachen
@bot.command()
async def hello(ctx):
await ctx.send(random_language())
@bot.command()
async def sus(ctx):
await ctx.send("https://youtu.be/keyRM3h_7tk?si=eIIx3UGRqVKThGsi")
@bot.command()
async def imposter(ctx):
await ctx.send("https://youtu.be/RMyFf73Stoc?si=P_H3VNaiENCyBmUL")
async def clear_channel(ctx, limit=5):
channel = ctx.message.channel
if not channel:
print("Invalid channel ID provided.")
else:
while True:
await clear_messages(channel, limit)
channel = ctx.message.channel
if not channel.last_message:
break
await asyncio.sleep(10)
print(f"All cleared in channel {channel.name}")
async def clear_messages(channel, limit):
try:
async for message in channel.history(limit=limit):
await message.delete()
print(f"Channel ({channel}) got a little bit cleared.")
except discord.Forbidden:
print("Bot does not have the necessary permissions to delete messages.")
except discord.HTTPException as e:
if e.status == 429:
retry_after = e.retry_after
print(f"Rate limited. Retrying in {retry_after} seconds.")
await asyncio.sleep(retry_after)
await clear_messages(channel, limit)
else:
print(f"An error occurred while deleting messages: {e}")
# Hilfsfunktionen
def log_event(message):
file_path = "log.txt"
try:
with open(file_path, 'a') as file:
timestamp = datetime.now().strftime("%H:%M:%S %d.%m.%Y")
print(message)
file.write(f"{message} ({timestamp})\n")
except Exception as e:
print(f"Failed to write to log: {e}")
async def display_file_content(ctx, file_path):
try:
with open(file_path, 'r') as file:
content = file.read()
await ctx.send(f"```{content}```")
except FileNotFoundError:
await ctx.send(f"Datei {file_path} nicht gefunden.")
except Exception as e:
await ctx.send(f"Fehler beim Lesen der Datei: {e}")
async def handle_youtube_command(ctx, api_function, number=None, multiple=False):
if multiple:
try:
if number is None:
await ctx.send("Bitte gib eine Zahl als Parameter an.")
return
number = int(number)
if number > 10:
await ctx.send("Maximal 10 Memes auf einmal erlaubt.")
return
video_urls = api_function(number)
for video_url in video_urls:
await ctx.send(video_url)
except ValueError:
await ctx.send("Bitte gib eine gültige Zahl ein.")
except Exception as e:
await ctx.send(f"Fehler beim Abrufen der YouTube-Videos: {e}")
else:
try:
video_url = api_function() if not number else api_function(number)
await ctx.send(video_url)
except Exception as e:
await ctx.send(f"Fehler beim Abrufen des YouTube-Videos: {e}")
async def send_daily_video(guild_id, video_type):
guild = bot.get_guild(guild_id)
if guild:
channel = guild.get_channel(DAILY_CLEARING_CHANNEL_ID)
if channel and isinstance(channel, discord.TextChannel):
video_url = youtubeapi() if video_type == 'daily' else youtubeapimemes()
await channel.send(video_url)
async def send_daily_meme(guild_id):
guild = bot.get_guild(guild_id)
if guild:
channel = guild.get_channel(DAILY_CLEARING_CHANNEL_ID)
if channel and isinstance(channel, discord.TextChannel):
meme_url = youtubeapimemes()
await channel.send(meme_url)
async def send_christmas_greeting(guild_id):
guild = bot.get_guild(guild_id)
if guild:
channel = guild.get_channel(DAILY_CLEARING_CHANNEL_ID)
if channel and isinstance(channel, discord.TextChannel):
greeting = random.choice([
"Frohe Weihnachten!",
"Merry Christmas!",
"Joyeux Noël!",
"Feliz Navidad!"
])
await channel.send(greeting)
async def send_welcome_message(member, guild_id):
guild = bot.get_guild(guild_id)
if guild:
channel = guild.get_channel(YOUR_CHANNEL_ID)
if channel and isinstance(channel, discord.TextChannel):
greeting = f"Willkommen auf dem Server, {member.name}!"
await channel.send(greeting)
async def countdown_process(channel, current_year):
await asyncio.sleep(30)
await channel.send("Nicht mehr lang!")
await asyncio.sleep(20)
await channel.send("Nur noch 10 Sekunden!")
await asyncio.sleep(5)
for i in range(5, 0, -1):
await channel.send(f"{i}")
await asyncio.sleep(1)
await channel.send(f"Frohes Neues Jahr {current_year + 1}!")
await asyncio.sleep(1)
await channel.send(f"https://youtu.be/2Mf-53_Y-6E")
async def send_greeting(ctx, night=False):
if night:
greeting = random_greeting_night()
else:
current_hour = datetime.now().hour + 1
if 4 <= current_hour <= 11:
greeting = random_greeting_morning()
elif 12 <= current_hour <= 17:
greeting = random_greeting()
else:
greeting = random_greeting_evening()
await ctx.send(greeting)
# Initialisiere den Live-Server (falls benötigt)
live = Live()
# Starte den Bot
bot.run(YOUR_DISCORD_BOT_TOKEN)