Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
3da1194
1
Parent(s): cad8499
update 2
Browse files- pydvpl_bot.py +30 -3
pydvpl_bot.py
CHANGED
|
@@ -3,6 +3,7 @@ import discord
|
|
| 3 |
from discord.ext import commands
|
| 4 |
from pydvpl.dvpl import compress_dvpl, decompress_dvpl
|
| 5 |
from discord.ext.commands import DefaultHelpCommand
|
|
|
|
| 6 |
|
| 7 |
# Define the authorized user ID
|
| 8 |
AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
|
|
@@ -10,6 +11,8 @@ AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
|
|
| 10 |
# Define your Discord bot token here
|
| 11 |
TOKEN = os.getenv('DISCORD_TOKEN')
|
| 12 |
|
|
|
|
|
|
|
| 13 |
|
| 14 |
class PyDVPLHelpCommand(DefaultHelpCommand):
|
| 15 |
def get_command_signature(self, command):
|
|
@@ -31,6 +34,7 @@ class PyDVPLHelpCommand(DefaultHelpCommand):
|
|
| 31 |
# Set up bot command prefix
|
| 32 |
bot_intents = discord.Intents.all()
|
| 33 |
|
|
|
|
| 34 |
# Initialize the bot with intents
|
| 35 |
bot = commands.Bot(command_prefix=">>", intents=bot_intents, help_command=PyDVPLHelpCommand())
|
| 36 |
|
|
@@ -45,7 +49,9 @@ def ensure_folders():
|
|
| 45 |
|
| 46 |
@bot.event
|
| 47 |
async def on_ready():
|
|
|
|
| 48 |
await bot.change_presence(activity=discord.Game(name=">>help for commands"))
|
|
|
|
| 49 |
print(f'{bot.user} has connected to Discord!')
|
| 50 |
ensure_folders()
|
| 51 |
|
|
@@ -308,9 +314,9 @@ async def say(ctx, destination_type, *args):
|
|
| 308 |
else:
|
| 309 |
await ctx.send("Server not found.")
|
| 310 |
await ctx.message.delete()
|
| 311 |
-
elif destination_type.lower() in ['user'
|
| 312 |
if len(args) < 2:
|
| 313 |
-
await ctx.send("Usage: >>say
|
| 314 |
await ctx.message.delete()
|
| 315 |
return
|
| 316 |
try:
|
|
@@ -333,8 +339,29 @@ async def say(ctx, destination_type, *args):
|
|
| 333 |
await ctx.send("User not found.")
|
| 334 |
await ctx.message.delete()
|
| 335 |
else:
|
| 336 |
-
await ctx.send("Invalid destination type. Use either 'channel', 'server', or '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
await ctx.message.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
|
| 339 |
|
| 340 |
@bot.event
|
|
|
|
| 3 |
from discord.ext import commands
|
| 4 |
from pydvpl.dvpl import compress_dvpl, decompress_dvpl
|
| 5 |
from discord.ext.commands import DefaultHelpCommand
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
# Define the authorized user ID
|
| 9 |
AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
|
|
|
|
| 11 |
# Define your Discord bot token here
|
| 12 |
TOKEN = os.getenv('DISCORD_TOKEN')
|
| 13 |
|
| 14 |
+
activity_start_time = 0
|
| 15 |
+
|
| 16 |
|
| 17 |
class PyDVPLHelpCommand(DefaultHelpCommand):
|
| 18 |
def get_command_signature(self, command):
|
|
|
|
| 34 |
# Set up bot command prefix
|
| 35 |
bot_intents = discord.Intents.all()
|
| 36 |
|
| 37 |
+
|
| 38 |
# Initialize the bot with intents
|
| 39 |
bot = commands.Bot(command_prefix=">>", intents=bot_intents, help_command=PyDVPLHelpCommand())
|
| 40 |
|
|
|
|
| 49 |
|
| 50 |
@bot.event
|
| 51 |
async def on_ready():
|
| 52 |
+
global activity_start_time
|
| 53 |
await bot.change_presence(activity=discord.Game(name=">>help for commands"))
|
| 54 |
+
activity_start_time = time.time()
|
| 55 |
print(f'{bot.user} has connected to Discord!')
|
| 56 |
ensure_folders()
|
| 57 |
|
|
|
|
| 314 |
else:
|
| 315 |
await ctx.send("Server not found.")
|
| 316 |
await ctx.message.delete()
|
| 317 |
+
elif destination_type.lower() in ['user']:
|
| 318 |
if len(args) < 2:
|
| 319 |
+
await ctx.send("Usage: >>say user <user_id> <message>")
|
| 320 |
await ctx.message.delete()
|
| 321 |
return
|
| 322 |
try:
|
|
|
|
| 339 |
await ctx.send("User not found.")
|
| 340 |
await ctx.message.delete()
|
| 341 |
else:
|
| 342 |
+
await ctx.send("Invalid destination type. Use either 'channel', 'server', or 'user'.")
|
| 343 |
+
await ctx.message.delete()
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
@bot.command(help="Show how long the bot has been playing the current game.")
|
| 347 |
+
async def uptime(ctx):
|
| 348 |
+
global activity_start_time
|
| 349 |
+
|
| 350 |
+
if activity_start_time == 0:
|
| 351 |
+
bot_mention = ctx.me.mention
|
| 352 |
+
await ctx.send("{bot_mention}'s activity hasn't been set yet.")
|
| 353 |
await ctx.message.delete()
|
| 354 |
+
return
|
| 355 |
+
|
| 356 |
+
current_time = time.time()
|
| 357 |
+
uptime_seconds = int(current_time - activity_start_time)
|
| 358 |
+
minutes, seconds = divmod(uptime_seconds, 60)
|
| 359 |
+
hours, minutes = divmod(minutes, 60)
|
| 360 |
+
|
| 361 |
+
bot_mention = ctx.me.mention
|
| 362 |
+
uptime_message = f"{bot_mention} has been playing for - {hours} hours, {minutes} minutes, {seconds} seconds."
|
| 363 |
+
await ctx.send(uptime_message)
|
| 364 |
+
await ctx.message.delete()
|
| 365 |
|
| 366 |
|
| 367 |
@bot.event
|