1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Added an uptime command to the bot

This commit is contained in:
Phxntxm 2016-07-30 09:59:35 -05:00
parent a4b9ce01e8
commit 6983cf8d6b
2 changed files with 29 additions and 3 deletions

10
bot.py
View file

@ -2,6 +2,8 @@
import discord
import traceback
import logging
import datetime
from discord.ext import commands
from cogs.utils import config
@ -17,7 +19,13 @@ extensions = ['cogs.interaction',
'cogs.tags']
bot = commands.Bot(command_prefix=config.commandPrefix, description=config.botDescription, pm_help=None)
discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.WARNING)
log = logging.getLogger()
log.setLevel(logging.INFO)
handler = logging.FileHandler(filename='bonfire.log', encoding='utf-8', mode='a')
log.addHandler(handler)
# Bot event overrides
@bot.event
@ -29,6 +37,8 @@ async def on_ready():
destination = discord.utils.find(lambda m: m.id == channel_id, bot.get_all_channels())
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.event

View file

@ -16,9 +16,19 @@ class Core:
def __init__(self, bot):
self.bot = bot
@commands.command()
async def test(self):
await self.bot.say((await self.bot.application_info()).id)
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)
@ -50,6 +60,12 @@ class Core:
year = datetime.datetime.today().year
cal = calendar.TextCalendar().formatmonth(year, month)
await self.bot.say("```{}```".format(cal))
@commands.command()
@checks.customPermsOrRole(send_messages=True)
async def uptime(self):
"""Provides a printout of the current bot's uptime"""
awayt self.bot.say("Uptime = ```{}```".format(get_bot_uptime()))
@commands.command()
@checks.customPermsOrRole(send_messages=True)