Added an uptime command to the bot
This commit is contained in:
parent
a4b9ce01e8
commit
6983cf8d6b
10
bot.py
10
bot.py
|
@ -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
|
||||
|
|
22
cogs/core.py
22
cogs/core.py
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue