Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
a32c8d9
1
Parent(s): b009b86
fully / command
Browse files- pydvpl_bot.py +50 -76
pydvpl_bot.py
CHANGED
|
@@ -82,7 +82,7 @@ async def list_feedback(ctx, folder_path, title):
|
|
| 82 |
await ctx.send(embed=feedback_embed)
|
| 83 |
else:
|
| 84 |
await ctx.send("No feedback found.")
|
| 85 |
-
|
| 86 |
|
| 87 |
|
| 88 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
@@ -99,7 +99,7 @@ async def clean_directory(ctx, directory):
|
|
| 99 |
await ctx.send(f"All files cleaned successfully in {directory}. Total files cleaned: {file_count}.")
|
| 100 |
except Exception as e:
|
| 101 |
await ctx.send(f"An error occurred while cleaning files: {e}")
|
| 102 |
-
|
| 103 |
|
| 104 |
|
| 105 |
# HELPER ------------------------------------------------------ END
|
|
@@ -172,7 +172,7 @@ async def on_command(ctx):
|
|
| 172 |
async def on_command_error(ctx, error):
|
| 173 |
if isinstance(error, commands.CommandNotFound):
|
| 174 |
await ctx.send("Sorry, I couldn't find that command. Use `>>help` to see the list of available commands.")
|
| 175 |
-
|
| 176 |
else:
|
| 177 |
print(f'An error occurred: {error}')
|
| 178 |
|
|
@@ -289,7 +289,7 @@ async def compress(ctx):
|
|
| 289 |
if not attachments:
|
| 290 |
await ctx.send("No file attached.")
|
| 291 |
await ctx.send(f"The command `compress` was executed by - {ctx.author.mention}")
|
| 292 |
-
|
| 293 |
return
|
| 294 |
|
| 295 |
for attachment in attachments:
|
|
@@ -311,7 +311,7 @@ async def compress(ctx):
|
|
| 311 |
await ctx.send("Failed to `compress` the file.")
|
| 312 |
|
| 313 |
await ctx.send(f"The command `compress` was executed by - {ctx.author.mention}")
|
| 314 |
-
|
| 315 |
|
| 316 |
|
| 317 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
@@ -324,7 +324,7 @@ async def decompress(ctx):
|
|
| 324 |
if not attachments:
|
| 325 |
await ctx.send("No file attached.")
|
| 326 |
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 327 |
-
|
| 328 |
return
|
| 329 |
|
| 330 |
for attachment in attachments:
|
|
@@ -345,7 +345,7 @@ async def decompress(ctx):
|
|
| 345 |
await ctx.send("Failed to decompress the file.")
|
| 346 |
|
| 347 |
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 348 |
-
|
| 349 |
|
| 350 |
|
| 351 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
@@ -356,7 +356,7 @@ async def ping(ctx):
|
|
| 356 |
latency = round(bot.latency * 1000) # latency in milliseconds
|
| 357 |
await ctx.send(f"Pong! Bot latency is {latency}ms.")
|
| 358 |
await ctx.send(f"The command `ping` was executed by - {ctx.author.mention}")
|
| 359 |
-
|
| 360 |
|
| 361 |
|
| 362 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
@@ -384,7 +384,7 @@ async def invite(ctx):
|
|
| 384 |
await ctx.send(f"Sent the invite link to your DM. {ctx.author.mention}")
|
| 385 |
except discord.Forbidden:
|
| 386 |
await ctx.send(f"Failed to send the invite link to your DM. {ctx.author.mention} Please make sure your DMs are open.")
|
| 387 |
-
|
| 388 |
|
| 389 |
|
| 390 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
@@ -419,20 +419,20 @@ async def feedback(ctx, category: str, *, message: str):
|
|
| 419 |
json.dump(data, f, indent=4)
|
| 420 |
|
| 421 |
await ctx.send(f"Thank you for your {category.lower()}. It has been recorded.")
|
| 422 |
-
|
| 423 |
|
| 424 |
|
| 425 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 426 |
|
| 427 |
|
| 428 |
-
@bot.
|
| 429 |
async def uptime(ctx):
|
| 430 |
global activity_start_time
|
| 431 |
|
| 432 |
if activity_start_time == 0:
|
| 433 |
bot_mention = ctx.me.mention
|
| 434 |
await ctx.send("{bot_mention}'s activity hasn't been set yet.")
|
| 435 |
-
|
| 436 |
return
|
| 437 |
|
| 438 |
current_time = time.time()
|
|
@@ -443,7 +443,7 @@ async def uptime(ctx):
|
|
| 443 |
bot_mention = ctx.me.mention
|
| 444 |
uptime_message = f"{bot_mention} has been playing for - {hours} hours, {minutes} minutes, {seconds} seconds."
|
| 445 |
await ctx.send(uptime_message)
|
| 446 |
-
|
| 447 |
|
| 448 |
|
| 449 |
# UTILITY USER_CMD ------------------------------------------------------ END
|
|
@@ -452,11 +452,11 @@ async def uptime(ctx):
|
|
| 452 |
# UTILITY ADMIN_CMD ------------------------------------------------------ START
|
| 453 |
|
| 454 |
|
| 455 |
-
@bot.
|
| 456 |
async def clean(ctx, clean_mode):
|
| 457 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 458 |
await ctx.send("You are not authorized to use this command.")
|
| 459 |
-
|
| 460 |
return
|
| 461 |
|
| 462 |
if clean_mode.lower() == 'compress':
|
|
@@ -474,53 +474,53 @@ async def clean(ctx, clean_mode):
|
|
| 474 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 475 |
|
| 476 |
|
| 477 |
-
@bot.
|
| 478 |
async def online(ctx):
|
| 479 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 480 |
await ctx.send("You are not authorized to use this command.")
|
| 481 |
-
|
| 482 |
return
|
| 483 |
await bot.change_presence(activity=discord.Game(name=playing_time_activity))
|
| 484 |
await ctx.send("Bot's presence set to online.")
|
| 485 |
-
|
| 486 |
|
| 487 |
|
| 488 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 489 |
|
| 490 |
|
| 491 |
-
@bot.
|
| 492 |
async def dnd(ctx):
|
| 493 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 494 |
await ctx.send("You are not authorized to use this command.")
|
| 495 |
-
|
| 496 |
return
|
| 497 |
await bot.change_presence(status=discord.Status.dnd)
|
| 498 |
await ctx.send("Bot's presence set to Do Not Disturb.")
|
| 499 |
-
|
| 500 |
|
| 501 |
|
| 502 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 503 |
|
| 504 |
|
| 505 |
-
@bot.
|
| 506 |
async def offline(ctx):
|
| 507 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 508 |
await ctx.send("You are not authorized to use this command.")
|
| 509 |
-
|
| 510 |
return
|
| 511 |
await bot.change_presence(status=discord.Status.offline)
|
| 512 |
await ctx.send("Bot's presence set to offline.")
|
| 513 |
-
|
| 514 |
|
| 515 |
|
| 516 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 517 |
|
| 518 |
|
| 519 |
-
@bot.
|
| 520 |
async def activity(ctx, activity_type, *, activity_text=None):
|
| 521 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 522 |
await ctx.send("You are not authorized to use this command.")
|
| 523 |
-
|
| 524 |
return
|
| 525 |
|
| 526 |
if activity_type.lower() == 'listening':
|
|
@@ -531,129 +531,103 @@ async def activity(ctx, activity_type, *, activity_text=None):
|
|
| 531 |
activity = discord.Activity(type=discord.ActivityType.playing, name=activity_text)
|
| 532 |
else:
|
| 533 |
await ctx.send('Invalid activity type. Please choose either "listening", "playing" or "watching".')
|
| 534 |
-
|
| 535 |
return
|
| 536 |
|
| 537 |
if not activity_text:
|
| 538 |
await ctx.send('Please provide an activity text.')
|
| 539 |
-
|
| 540 |
return
|
| 541 |
|
| 542 |
await bot.change_presence(activity=activity)
|
| 543 |
await ctx.send(f'Activity set to {activity_type} {activity_text}')
|
| 544 |
-
|
| 545 |
|
| 546 |
|
| 547 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 548 |
|
| 549 |
|
| 550 |
-
@bot.
|
| 551 |
-
async def say(ctx, destination_type, *
|
|
|
|
| 552 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 553 |
await ctx.send("You are not authorized to use this command.")
|
| 554 |
-
await ctx.message.delete()
|
| 555 |
return
|
| 556 |
|
| 557 |
if destination_type.lower() == 'channel':
|
| 558 |
-
if len(args) < 2:
|
| 559 |
-
await ctx.send("Usage: >>say channel <channel_id> <message>")
|
| 560 |
-
await ctx.message.delete()
|
| 561 |
-
return
|
| 562 |
try:
|
| 563 |
-
channel_id = int(
|
| 564 |
except ValueError:
|
| 565 |
await ctx.send("Channel ID must be a valid integer.")
|
| 566 |
-
await ctx.message.delete()
|
| 567 |
return
|
| 568 |
-
message = ' '.join(args[1:])
|
| 569 |
channel = bot.get_channel(channel_id)
|
| 570 |
if channel:
|
| 571 |
await channel.send(message)
|
| 572 |
await ctx.send(f"Message `{message}` sent to channel `{channel.name}`.")
|
| 573 |
-
await ctx.message.delete()
|
| 574 |
else:
|
| 575 |
await ctx.send("Channel not found.")
|
| 576 |
-
|
| 577 |
elif destination_type.lower() == 'server':
|
| 578 |
-
if len(args) < 2:
|
| 579 |
-
await ctx.send("Usage: >>say server <server_id> <message>")
|
| 580 |
-
await ctx.message.delete()
|
| 581 |
-
return
|
| 582 |
try:
|
| 583 |
-
server_id = int(
|
| 584 |
except ValueError:
|
| 585 |
await ctx.send("Server ID must be a valid integer.")
|
| 586 |
-
await ctx.message.delete()
|
| 587 |
return
|
| 588 |
-
message = ' '.join(args[1:])
|
| 589 |
server = bot.get_guild(server_id)
|
| 590 |
if server:
|
| 591 |
announcement_channel = discord.utils.get(server.channels, name="important-announcements")
|
| 592 |
if announcement_channel:
|
| 593 |
await announcement_channel.send(message)
|
| 594 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in `important-announcements` channel.")
|
| 595 |
-
await ctx.message.delete()
|
| 596 |
else:
|
| 597 |
announcements_channel = discord.utils.get(server.channels, name="announcements")
|
| 598 |
if announcements_channel:
|
| 599 |
await announcements_channel.send(message)
|
| 600 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in `announcements` channel.")
|
| 601 |
-
await ctx.message.delete()
|
| 602 |
else:
|
| 603 |
public_updates_channel = server.public_updates_channel
|
| 604 |
if public_updates_channel:
|
| 605 |
await public_updates_channel.send(message)
|
| 606 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in `public updates` channel.")
|
| 607 |
-
await ctx.message.delete()
|
| 608 |
else:
|
| 609 |
default_channel = server.system_channel or server.text_channels[0] # Default to the first text channel
|
| 610 |
if default_channel:
|
| 611 |
await default_channel.send(message)
|
| 612 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in the default channel.")
|
| 613 |
-
await ctx.message.delete()
|
| 614 |
else:
|
| 615 |
await ctx.send("No announcement channels found in the server. Also, no default `public updates` neither `default` channels found.")
|
| 616 |
-
await ctx.message.delete()
|
| 617 |
else:
|
| 618 |
await ctx.send("Server not found.")
|
| 619 |
-
|
| 620 |
-
elif destination_type.lower()
|
| 621 |
-
if len(args) < 2:
|
| 622 |
-
await ctx.send("Usage: >>say user <user_id> <message>")
|
| 623 |
-
await ctx.message.delete()
|
| 624 |
-
return
|
| 625 |
try:
|
| 626 |
-
user_id = int(
|
| 627 |
except ValueError:
|
| 628 |
await ctx.send("User ID must be a valid integer.")
|
| 629 |
-
await ctx.message.delete()
|
| 630 |
return
|
| 631 |
-
message = ' '.join(args[1:])
|
| 632 |
user = bot.get_user(user_id)
|
| 633 |
if user:
|
| 634 |
try:
|
| 635 |
await user.send(message)
|
| 636 |
await ctx.send(f"Message `{message}` sent to user '{user.display_name}'.")
|
| 637 |
-
await ctx.message.delete()
|
| 638 |
except discord.Forbidden:
|
| 639 |
await ctx.send(f"Couldn't send message to `{user.display_name}`. Their DMs are closed.")
|
| 640 |
-
await ctx.message.delete()
|
| 641 |
else:
|
| 642 |
await ctx.send("User not found.")
|
| 643 |
-
|
| 644 |
else:
|
| 645 |
await ctx.send("Invalid destination type. Use either 'channel', 'server', or 'user'.")
|
| 646 |
-
|
| 647 |
|
| 648 |
|
| 649 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 650 |
|
| 651 |
|
| 652 |
-
@bot.
|
| 653 |
async def announce(ctx, *, message):
|
| 654 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 655 |
await ctx.send("You are not authorized to use this command.")
|
| 656 |
-
|
| 657 |
return
|
| 658 |
|
| 659 |
embed = discord.Embed(title="Announcement", description=message, color=discord.Color.blurple())
|
|
@@ -685,18 +659,18 @@ async def announce(ctx, *, message):
|
|
| 685 |
await ctx.send(f"No suitable announcement channel found in server `{server.name}`.")
|
| 686 |
|
| 687 |
# Delete the original command message
|
| 688 |
-
|
| 689 |
|
| 690 |
|
| 691 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 692 |
|
| 693 |
|
| 694 |
-
@bot.
|
| 695 |
async def stats(ctx):
|
| 696 |
|
| 697 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 698 |
await ctx.send("You are not authorized to use this command.")
|
| 699 |
-
|
| 700 |
return
|
| 701 |
|
| 702 |
guild_count = len(bot.guilds)
|
|
@@ -726,20 +700,20 @@ async def stats(ctx):
|
|
| 726 |
f"Memory Usage: {memory_usage}%"
|
| 727 |
)
|
| 728 |
await ctx.send(stats_message)
|
| 729 |
-
|
| 730 |
|
| 731 |
|
| 732 |
-
@bot.
|
| 733 |
-
async def list(ctx, list_type
|
| 734 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 735 |
await ctx.send("You are not authorized to use this command.")
|
| 736 |
-
|
| 737 |
return
|
| 738 |
|
| 739 |
if list_type.lower() == 'servers':
|
| 740 |
servers_info = "\n".join([f"{server.name} - ID: {server.id}" for server in bot.guilds])
|
| 741 |
await ctx.send(f"List of servers the bot is on:\n```{servers_info}```")
|
| 742 |
-
|
| 743 |
elif list_type.lower() == 'issues':
|
| 744 |
await list_feedback(ctx, ISSUES_FOLDER, "List of issues:")
|
| 745 |
elif list_type.lower() == 'requests':
|
|
|
|
| 82 |
await ctx.send(embed=feedback_embed)
|
| 83 |
else:
|
| 84 |
await ctx.send("No feedback found.")
|
| 85 |
+
|
| 86 |
|
| 87 |
|
| 88 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
|
|
| 99 |
await ctx.send(f"All files cleaned successfully in {directory}. Total files cleaned: {file_count}.")
|
| 100 |
except Exception as e:
|
| 101 |
await ctx.send(f"An error occurred while cleaning files: {e}")
|
| 102 |
+
|
| 103 |
|
| 104 |
|
| 105 |
# HELPER ------------------------------------------------------ END
|
|
|
|
| 172 |
async def on_command_error(ctx, error):
|
| 173 |
if isinstance(error, commands.CommandNotFound):
|
| 174 |
await ctx.send("Sorry, I couldn't find that command. Use `>>help` to see the list of available commands.")
|
| 175 |
+
|
| 176 |
else:
|
| 177 |
print(f'An error occurred: {error}')
|
| 178 |
|
|
|
|
| 289 |
if not attachments:
|
| 290 |
await ctx.send("No file attached.")
|
| 291 |
await ctx.send(f"The command `compress` was executed by - {ctx.author.mention}")
|
| 292 |
+
|
| 293 |
return
|
| 294 |
|
| 295 |
for attachment in attachments:
|
|
|
|
| 311 |
await ctx.send("Failed to `compress` the file.")
|
| 312 |
|
| 313 |
await ctx.send(f"The command `compress` was executed by - {ctx.author.mention}")
|
| 314 |
+
|
| 315 |
|
| 316 |
|
| 317 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
|
|
| 324 |
if not attachments:
|
| 325 |
await ctx.send("No file attached.")
|
| 326 |
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 327 |
+
|
| 328 |
return
|
| 329 |
|
| 330 |
for attachment in attachments:
|
|
|
|
| 345 |
await ctx.send("Failed to decompress the file.")
|
| 346 |
|
| 347 |
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 348 |
+
|
| 349 |
|
| 350 |
|
| 351 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
|
|
| 356 |
latency = round(bot.latency * 1000) # latency in milliseconds
|
| 357 |
await ctx.send(f"Pong! Bot latency is {latency}ms.")
|
| 358 |
await ctx.send(f"The command `ping` was executed by - {ctx.author.mention}")
|
| 359 |
+
|
| 360 |
|
| 361 |
|
| 362 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
|
|
| 384 |
await ctx.send(f"Sent the invite link to your DM. {ctx.author.mention}")
|
| 385 |
except discord.Forbidden:
|
| 386 |
await ctx.send(f"Failed to send the invite link to your DM. {ctx.author.mention} Please make sure your DMs are open.")
|
| 387 |
+
|
| 388 |
|
| 389 |
|
| 390 |
# FUNCTION ------------------------------------------------------ SPLIT
|
|
|
|
| 419 |
json.dump(data, f, indent=4)
|
| 420 |
|
| 421 |
await ctx.send(f"Thank you for your {category.lower()}. It has been recorded.")
|
| 422 |
+
|
| 423 |
|
| 424 |
|
| 425 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 426 |
|
| 427 |
|
| 428 |
+
@bot.hybrid_command(help="Show how long the bot has been playing the current game.")
|
| 429 |
async def uptime(ctx):
|
| 430 |
global activity_start_time
|
| 431 |
|
| 432 |
if activity_start_time == 0:
|
| 433 |
bot_mention = ctx.me.mention
|
| 434 |
await ctx.send("{bot_mention}'s activity hasn't been set yet.")
|
| 435 |
+
|
| 436 |
return
|
| 437 |
|
| 438 |
current_time = time.time()
|
|
|
|
| 443 |
bot_mention = ctx.me.mention
|
| 444 |
uptime_message = f"{bot_mention} has been playing for - {hours} hours, {minutes} minutes, {seconds} seconds."
|
| 445 |
await ctx.send(uptime_message)
|
| 446 |
+
|
| 447 |
|
| 448 |
|
| 449 |
# UTILITY USER_CMD ------------------------------------------------------ END
|
|
|
|
| 452 |
# UTILITY ADMIN_CMD ------------------------------------------------------ START
|
| 453 |
|
| 454 |
|
| 455 |
+
@bot.hybrid_command(help="Cleans files in specific directories")
|
| 456 |
async def clean(ctx, clean_mode):
|
| 457 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 458 |
await ctx.send("You are not authorized to use this command.")
|
| 459 |
+
|
| 460 |
return
|
| 461 |
|
| 462 |
if clean_mode.lower() == 'compress':
|
|
|
|
| 474 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 475 |
|
| 476 |
|
| 477 |
+
@bot.hybrid_command(help="Set bot's presence to online")
|
| 478 |
async def online(ctx):
|
| 479 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 480 |
await ctx.send("You are not authorized to use this command.")
|
| 481 |
+
|
| 482 |
return
|
| 483 |
await bot.change_presence(activity=discord.Game(name=playing_time_activity))
|
| 484 |
await ctx.send("Bot's presence set to online.")
|
| 485 |
+
|
| 486 |
|
| 487 |
|
| 488 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 489 |
|
| 490 |
|
| 491 |
+
@bot.hybrid_command(help="Set bot's presence to Do Not Disturb")
|
| 492 |
async def dnd(ctx):
|
| 493 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 494 |
await ctx.send("You are not authorized to use this command.")
|
| 495 |
+
|
| 496 |
return
|
| 497 |
await bot.change_presence(status=discord.Status.dnd)
|
| 498 |
await ctx.send("Bot's presence set to Do Not Disturb.")
|
| 499 |
+
|
| 500 |
|
| 501 |
|
| 502 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 503 |
|
| 504 |
|
| 505 |
+
@bot.hybrid_command(help="Set bot's presence to offline")
|
| 506 |
async def offline(ctx):
|
| 507 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 508 |
await ctx.send("You are not authorized to use this command.")
|
| 509 |
+
|
| 510 |
return
|
| 511 |
await bot.change_presence(status=discord.Status.offline)
|
| 512 |
await ctx.send("Bot's presence set to offline.")
|
| 513 |
+
|
| 514 |
|
| 515 |
|
| 516 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 517 |
|
| 518 |
|
| 519 |
+
@bot.hybrid_command(help="Set bot's activity")
|
| 520 |
async def activity(ctx, activity_type, *, activity_text=None):
|
| 521 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 522 |
await ctx.send("You are not authorized to use this command.")
|
| 523 |
+
|
| 524 |
return
|
| 525 |
|
| 526 |
if activity_type.lower() == 'listening':
|
|
|
|
| 531 |
activity = discord.Activity(type=discord.ActivityType.playing, name=activity_text)
|
| 532 |
else:
|
| 533 |
await ctx.send('Invalid activity type. Please choose either "listening", "playing" or "watching".')
|
| 534 |
+
|
| 535 |
return
|
| 536 |
|
| 537 |
if not activity_text:
|
| 538 |
await ctx.send('Please provide an activity text.')
|
| 539 |
+
|
| 540 |
return
|
| 541 |
|
| 542 |
await bot.change_presence(activity=activity)
|
| 543 |
await ctx.send(f'Activity set to {activity_type} {activity_text}')
|
| 544 |
+
|
| 545 |
|
| 546 |
|
| 547 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 548 |
|
| 549 |
|
| 550 |
+
@bot.hybrid_command(help="Send messages to specific channels or users")
|
| 551 |
+
async def say(ctx, destination_type, *, id, message):
|
| 552 |
+
|
| 553 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 554 |
await ctx.send("You are not authorized to use this command.")
|
|
|
|
| 555 |
return
|
| 556 |
|
| 557 |
if destination_type.lower() == 'channel':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
try:
|
| 559 |
+
channel_id = int(id)
|
| 560 |
except ValueError:
|
| 561 |
await ctx.send("Channel ID must be a valid integer.")
|
|
|
|
| 562 |
return
|
|
|
|
| 563 |
channel = bot.get_channel(channel_id)
|
| 564 |
if channel:
|
| 565 |
await channel.send(message)
|
| 566 |
await ctx.send(f"Message `{message}` sent to channel `{channel.name}`.")
|
|
|
|
| 567 |
else:
|
| 568 |
await ctx.send("Channel not found.")
|
| 569 |
+
|
| 570 |
elif destination_type.lower() == 'server':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
try:
|
| 572 |
+
server_id = int(id)
|
| 573 |
except ValueError:
|
| 574 |
await ctx.send("Server ID must be a valid integer.")
|
|
|
|
| 575 |
return
|
|
|
|
| 576 |
server = bot.get_guild(server_id)
|
| 577 |
if server:
|
| 578 |
announcement_channel = discord.utils.get(server.channels, name="important-announcements")
|
| 579 |
if announcement_channel:
|
| 580 |
await announcement_channel.send(message)
|
| 581 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in `important-announcements` channel.")
|
|
|
|
| 582 |
else:
|
| 583 |
announcements_channel = discord.utils.get(server.channels, name="announcements")
|
| 584 |
if announcements_channel:
|
| 585 |
await announcements_channel.send(message)
|
| 586 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in `announcements` channel.")
|
|
|
|
| 587 |
else:
|
| 588 |
public_updates_channel = server.public_updates_channel
|
| 589 |
if public_updates_channel:
|
| 590 |
await public_updates_channel.send(message)
|
| 591 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in `public updates` channel.")
|
|
|
|
| 592 |
else:
|
| 593 |
default_channel = server.system_channel or server.text_channels[0] # Default to the first text channel
|
| 594 |
if default_channel:
|
| 595 |
await default_channel.send(message)
|
| 596 |
await ctx.send(f"Message `{message}` sent to server `{server.name}` in the default channel.")
|
|
|
|
| 597 |
else:
|
| 598 |
await ctx.send("No announcement channels found in the server. Also, no default `public updates` neither `default` channels found.")
|
|
|
|
| 599 |
else:
|
| 600 |
await ctx.send("Server not found.")
|
| 601 |
+
|
| 602 |
+
elif destination_type.lower() == 'user':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
try:
|
| 604 |
+
user_id = int(id)
|
| 605 |
except ValueError:
|
| 606 |
await ctx.send("User ID must be a valid integer.")
|
|
|
|
| 607 |
return
|
|
|
|
| 608 |
user = bot.get_user(user_id)
|
| 609 |
if user:
|
| 610 |
try:
|
| 611 |
await user.send(message)
|
| 612 |
await ctx.send(f"Message `{message}` sent to user '{user.display_name}'.")
|
|
|
|
| 613 |
except discord.Forbidden:
|
| 614 |
await ctx.send(f"Couldn't send message to `{user.display_name}`. Their DMs are closed.")
|
|
|
|
| 615 |
else:
|
| 616 |
await ctx.send("User not found.")
|
| 617 |
+
|
| 618 |
else:
|
| 619 |
await ctx.send("Invalid destination type. Use either 'channel', 'server', or 'user'.")
|
| 620 |
+
|
| 621 |
|
| 622 |
|
| 623 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 624 |
|
| 625 |
|
| 626 |
+
@bot.hybrid_command(help="Send announcements to all servers")
|
| 627 |
async def announce(ctx, *, message):
|
| 628 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 629 |
await ctx.send("You are not authorized to use this command.")
|
| 630 |
+
|
| 631 |
return
|
| 632 |
|
| 633 |
embed = discord.Embed(title="Announcement", description=message, color=discord.Color.blurple())
|
|
|
|
| 659 |
await ctx.send(f"No suitable announcement channel found in server `{server.name}`.")
|
| 660 |
|
| 661 |
# Delete the original command message
|
| 662 |
+
|
| 663 |
|
| 664 |
|
| 665 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 666 |
|
| 667 |
|
| 668 |
+
@bot.hybrid_command(help="Show statistics about bot's health and connection.")
|
| 669 |
async def stats(ctx):
|
| 670 |
|
| 671 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 672 |
await ctx.send("You are not authorized to use this command.")
|
| 673 |
+
|
| 674 |
return
|
| 675 |
|
| 676 |
guild_count = len(bot.guilds)
|
|
|
|
| 700 |
f"Memory Usage: {memory_usage}%"
|
| 701 |
)
|
| 702 |
await ctx.send(stats_message)
|
| 703 |
+
|
| 704 |
|
| 705 |
|
| 706 |
+
@bot.hybrid_command(help="List issues, requests, or servers")
|
| 707 |
+
async def list(ctx, list_type):
|
| 708 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 709 |
await ctx.send("You are not authorized to use this command.")
|
| 710 |
+
|
| 711 |
return
|
| 712 |
|
| 713 |
if list_type.lower() == 'servers':
|
| 714 |
servers_info = "\n".join([f"{server.name} - ID: {server.id}" for server in bot.guilds])
|
| 715 |
await ctx.send(f"List of servers the bot is on:\n```{servers_info}```")
|
| 716 |
+
|
| 717 |
elif list_type.lower() == 'issues':
|
| 718 |
await list_feedback(ctx, ISSUES_FOLDER, "List of issues:")
|
| 719 |
elif list_type.lower() == 'requests':
|