Discord reminder for applications and tickets (#34)

reminder^2
Etzelia 2019-09-28 03:29:13 +02:00 committed by Gitea
parent df30af20e6
commit 8eb43887cd
3 changed files with 27 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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):