botpy
This commit is contained in:
38
c/tasks.py
Normal file
38
c/tasks.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import discord
|
||||
from discord.ext import commands, tasks
|
||||
from datetime import datetime
|
||||
|
||||
class Tasks(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.last_member = None
|
||||
self.update_status.start()
|
||||
|
||||
global timestamp
|
||||
timestamp = datetime.now()
|
||||
print(f"start time {timestamp}")
|
||||
|
||||
@tasks.loop(seconds=60)
|
||||
async def update_status(self):
|
||||
dt = datetime.today()
|
||||
delta = dt - timestamp
|
||||
sec = delta.total_seconds()
|
||||
minutes = int(sec) // 60
|
||||
hours = int(sec) // 3600
|
||||
days = int(sec) // 86400
|
||||
if minutes >= 60:
|
||||
minutes = (int(sec) - (hours * 3600)) // 60
|
||||
if hours >= 24:
|
||||
hours = (int(sec) - (days * 86400)) // 60 // 60
|
||||
total = f"d:{days} h:{hours} m:{minutes}"
|
||||
try:
|
||||
await self.bot.status_up(total)
|
||||
except:
|
||||
print("can't set discord status")
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
print('Tasks cog has been loaded')
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Tasks(bot))
|
||||
Reference in New Issue
Block a user