From b5df9ce4046fa1c881d8402c7c7a0e54041cbdb8 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Sat, 6 Aug 2016 17:20:16 -0500 Subject: [PATCH] Changed uptime to use pendulum instead of datetime --- bot.py | 8 +++++--- cogs/core.py | 16 ++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/bot.py b/bot.py index 96ac889..ea348da 100644 --- a/bot.py +++ b/bot.py @@ -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) diff --git a/cogs/core.py b/cogs/core.py index d976105..ce0c973 100644 --- a/cogs/core.py +++ b/cogs/core.py @@ -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)