1
0
Fork 0
mirror of synced 2024-05-17 19:12:33 +12:00

Changed uptime to use pendulum instead of datetime

This commit is contained in:
phxntxm 2016-08-06 17:20:16 -05:00
parent f2a486c62f
commit b5df9ce404
2 changed files with 7 additions and 17 deletions

8
bot.py
View file

@ -4,6 +4,7 @@ import discord
import traceback
import logging
import datetime
import pendulum
from discord.ext import commands
from cogs.utils import config
@ -41,7 +42,7 @@ async def on_ready():
await bot.send_message(destination, "I have just finished restarting!")
config.saveContent('restart_server', 0)
if not hasattr(bot, 'uptime'):
bot.uptime = datetime.datetime.utcnow()
bot.uptime = pendulum.utcnow()
@bot.event
@ -85,13 +86,14 @@ async def on_command_error(error, ctx):
await bot.send_message(ctx.message.channel, fmt)
elif isinstance(error, commands.CommandOnCooldown):
m, s = divmod(error.retry_after, 60)
fmt = "This command is on cooldown! Hold your horses! >:c\nTry again in {} minutes and {} seconds"\
fmt = "This command is on cooldown! Hold your horses! >:c\nTry again in {} minutes and {} seconds" \
.format(round(m), round(s))
await bot.send_message(ctx.message.channel, fmt)
elif not isinstance(error, commands.CommandNotFound):
now = datetime.datetime.now()
with open("/home/phxntx5/public_html/Bonfire/error_log", 'a') as f:
print("In server '{0.message.server}' at {1}\nFull command: `{0.message.content}`".format(ctx,str(now)), file=f)
print("In server '{0.message.server}' at {1}\nFull command: `{0.message.content}`".format(ctx, str(now)),
file=f)
traceback.print_tb(error.original.__traceback__, file=f)
print('{0.__class__.__name__}: {0}'.format(error.original), file=f)

View file

@ -8,6 +8,7 @@ import glob
import random
import re
import calendar
import pendulum
import datetime
@ -16,19 +17,6 @@ class Core:
def __init__(self, bot):
self.bot = bot
def get_bot_uptime(self):
now = datetime.datetime.utcnow()
delta = now - self.bot.uptime
hours, remainder = divmod(int(delta.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
days, hours = divmod(hours, 24)
if days:
fmt = '{d} days, {h} hours, {m} minutes, and {s} seconds'
else:
fmt = '{h} hours, {m} minutes, and {s} seconds'
return fmt.format(d=days, h=hours, m=minutes, s=seconds)
@commands.command()
@checks.customPermsOrRole(send_messages=True)
@ -65,7 +53,7 @@ class Core:
@checks.customPermsOrRole(send_messages=True)
async def uptime(self):
"""Provides a printout of the current bot's uptime"""
await self.bot.say("Uptime: ```\n{}```".format(self.get_bot_uptime()))
await self.bot.say("Uptime: ```\n{}```".format((pendulum.utcnow() - self.bot.uptime).in_words()))
@commands.command()
@checks.customPermsOrRole(send_messages=True)