forked from Minecraft/minecraft_manager
Discord reminder for applications and tickets (#34)
parent
df30af20e6
commit
8eb43887cd
|
@ -7,6 +7,9 @@ from enum import Enum
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from django.conf import settings
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -57,6 +60,26 @@ class Discord(commands.Bot):
|
||||||
print('------')
|
print('------')
|
||||||
print('Logged in as {0} ({1}) with discord.py v{2}'.format(self.user.name, self.user.id, discord.__version__))
|
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):
|
async def on_disconnect(self):
|
||||||
global discord_status
|
global discord_status
|
||||||
discord_status = DiscordStatus.STOPPED
|
discord_status = DiscordStatus.STOPPED
|
||||||
|
|
|
@ -49,7 +49,8 @@ def overview_data():
|
||||||
data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1) * 100, 2),
|
data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1) * 100, 2),
|
||||||
'banned': round((data['total']['player']['banned'] /
|
'banned': round((data['total']['player']['banned'] /
|
||||||
data['total']['player']['all'] if data['total']['player']['all'] != 0 else 1) * 100, 2),
|
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
|
# Unique logins
|
||||||
|
|
3
views.py
3
views.py
|
@ -466,7 +466,8 @@ class Bots(View):
|
||||||
else:
|
else:
|
||||||
bots.append(Bot(file.replace('.bot.py', ''), False, sys.executable))
|
bots.append(Bot(file.replace('.bot.py', ''), False, sys.executable))
|
||||||
# Also get packaged MCM bots
|
# 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
|
return bots
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
Loading…
Reference in New Issue