From e6dd36dffd8e0939db8f93d21898a45c1cdb9e74 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Thu, 26 Sep 2019 21:54:53 -0500 Subject: [PATCH] Discord reminder for applications and tickets Other misc cleanup Signed-off-by: Etzelia --- bot/discord.py | 23 +++++++++++++++++++++++ overview.py | 3 ++- views.py | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bot/discord.py b/bot/discord.py index c2a8c0b..0a4ebd8 100644 --- a/bot/discord.py +++ b/bot/discord.py @@ -7,6 +7,9 @@ from enum import Enum import discord from discord.ext import commands from django.conf import settings +from django.shortcuts import reverse +from minecraft_manager.models import Application, Ticket +from minecraft_manager.utils import url_path logger = logging.getLogger(__name__) @@ -57,6 +60,26 @@ class Discord(commands.Bot): print('------') print('Logged in as {0} ({1}) with discord.py v{2}'.format(self.user.name, self.user.id, discord.__version__)) + channel_id = getattr(settings, 'DISCORD_MCM_CHANNEL', None) + if channel_id: + channel = self.get_channel(channel_id) + embed = discord.Embed(color=8311585) + content = "" + unanswered_applications = Application.objects.filter(accepted=None) + if len(unanswered_applications) > 0: + link = url_path(settings.MCM_BASE_LINK, 'dashboard/application') + content += "[Unanswered Applications: {}]({})".format(len(unanswered_applications), link) + unclaimed_tickets = Ticket.objects.filter(staff=None, resolved=False) + if len(unclaimed_tickets) > 0: + link = url_path(settings.MCM_BASE_LINK, 'dashboard/ticket') + if content: + content += "\n\n" + content += "[Unclaimed Tickets: {}]({})".format(len(unclaimed_tickets), link) + if content: + embed.title = "MCM Reminder" + embed.description = content + await self.discord_message(channel, embed) + async def on_disconnect(self): global discord_status discord_status = DiscordStatus.STOPPED diff --git a/overview.py b/overview.py index 4f1ffe4..2b5f56c 100644 --- a/overview.py +++ b/overview.py @@ -49,7 +49,8 @@ def overview_data(): data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1) * 100, 2), 'banned': round((data['total']['player']['banned'] / data['total']['player']['all'] if data['total']['player']['all'] != 0 else 1) * 100, 2), - 'applied': round((data['total']['application']['all'] / data['total']['player']['all']) * 100, 2) + 'applied': round((data['total']['application']['all'] / + data['total']['player']['all'] if data['total']['player']['all'] != 0 else 1) * 100, 2) } # Unique logins diff --git a/views.py b/views.py index 3e02034..845e129 100644 --- a/views.py +++ b/views.py @@ -466,7 +466,8 @@ class Bots(View): else: bots.append(Bot(file.replace('.bot.py', ''), False, sys.executable)) # Also get packaged MCM bots - bots.append(Bot("Discord-MCM", True, None, discord_start, discord_stop, discord_restart, discord_status, discord_display)) + if getattr(settings, 'DISCORD_BOT_TOKEN', None): + bots.append(Bot("Discord-MCM", True, None, discord_start, discord_stop, discord_restart, discord_status, discord_display)) return bots def get(self, request):