From 6cb25c0b4f32d06077a90e9afba714539034aef5 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Tue, 1 Oct 2019 22:24:02 +0200 Subject: [PATCH] Add link to applications in Discord (#41) --- bot/commands.py | 10 ++++++---- bot/utils.py | 21 +-------------------- utils.py | 1 + 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/bot/commands.py b/bot/commands.py index b084530..9d6f4c1 100644 --- a/bot/commands.py +++ b/bot/commands.py @@ -4,7 +4,8 @@ from django.contrib.auth.models import User from django.db import close_old_connections from minecraft_manager.api import api -from minecraft_manager.bot.utils import get_application, build_info +from minecraft_manager.bot.utils import get_application +from minecraft_manager.utils import build_application from minecraft_manager.models import Application, Player @@ -79,6 +80,7 @@ class Commands(commands.Cog): except: is_id = False + application = None if is_id: application = get_application(key) if not application: @@ -99,7 +101,7 @@ class Commands(commands.Cog): if not found: await self.bot.discord_message(ctx.message.channel, "An exact Application could not be found. Try search instead.") return - await self.bot.discord_message(ctx.message.channel, build_info(application)) + await self.bot.discord_message(ctx.message.channel, build_application(application)) @commands.command() async def accept(self, ctx, app_id: int): @@ -164,7 +166,7 @@ class Commands(commands.Cog): count = Application.objects.filter(username__icontains=search).count() if count > 0: if count == 1: - info = build_info(applications[0]) + info = build_application(applications[0]) else: info = "**Found the following applications**" for app in applications: @@ -177,7 +179,7 @@ class Commands(commands.Cog): if count > 0: if count == 1: await self.bot.discord_message(ctx.message.channel, "**No applications matched, however there is a player match**") - info = build_info(players[0].application) + info = build_application(players[0].application) else: info = "**No applications matched, however there are player matches**" for player in players: diff --git a/bot/utils.py b/bot/utils.py index 9a87c2b..93c86d5 100644 --- a/bot/utils.py +++ b/bot/utils.py @@ -1,23 +1,4 @@ -import discord -from minecraft_manager.models import Application, Player - - -def build_info(application): - embed = discord.Embed(colour=discord.Colour(0x417505)) - embed.set_thumbnail( - url="https://minotar.net/helm/{0}/100.png".format(application.username)) - embed.add_field(name="Application ID", value=application.id) - embed.add_field(name="Username", value=application.username.replace("_", "\\_")) - embed.add_field(name="Age", value=application.age) - embed.add_field(name="Type of Player", value=application.player_type) - embed.add_field(name="Ever been banned", value=application.ever_banned) - if application.ever_banned: - embed.add_field(name="Reason for being banned", value=application.ever_banned_explanation) - embed.add_field(name="Reference", value=application.reference) - embed.add_field(name="Read the Rules", value=application.read_rules) - embed.add_field(name="Date", value=application.date_display) - embed.add_field(name="Status", value=application.status) - return embed +from minecraft_manager.models import Application def get_application(app_id): diff --git a/utils.py b/utils.py index 7c94daa..11d3716 100644 --- a/utils.py +++ b/utils.py @@ -38,6 +38,7 @@ def build_application(application): embed.add_field(name="Read the Rules", value=application.read_rules) embed.add_field(name="Date", value=application.date_display) embed.add_field(name="Status", value=application.status) + embed.add_field(name="Link", value="{}".format(url_path(settings.MCM_BASE_LINK, 'dashboard/application', application.id))) return embed