forked from Minecraft/minecraft_manager
Add link to applications in Discord (#41)
parent
aa221fb398
commit
6cb25c0b4f
|
@ -4,7 +4,8 @@ from django.contrib.auth.models import User
|
||||||
from django.db import close_old_connections
|
from django.db import close_old_connections
|
||||||
|
|
||||||
from minecraft_manager.api import api
|
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
|
from minecraft_manager.models import Application, Player
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ class Commands(commands.Cog):
|
||||||
except:
|
except:
|
||||||
is_id = False
|
is_id = False
|
||||||
|
|
||||||
|
application = None
|
||||||
if is_id:
|
if is_id:
|
||||||
application = get_application(key)
|
application = get_application(key)
|
||||||
if not application:
|
if not application:
|
||||||
|
@ -99,7 +101,7 @@ class Commands(commands.Cog):
|
||||||
if not found:
|
if not found:
|
||||||
await self.bot.discord_message(ctx.message.channel, "An exact Application could not be found. Try search instead.")
|
await self.bot.discord_message(ctx.message.channel, "An exact Application could not be found. Try search instead.")
|
||||||
return
|
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()
|
@commands.command()
|
||||||
async def accept(self, ctx, app_id: int):
|
async def accept(self, ctx, app_id: int):
|
||||||
|
@ -164,7 +166,7 @@ class Commands(commands.Cog):
|
||||||
count = Application.objects.filter(username__icontains=search).count()
|
count = Application.objects.filter(username__icontains=search).count()
|
||||||
if count > 0:
|
if count > 0:
|
||||||
if count == 1:
|
if count == 1:
|
||||||
info = build_info(applications[0])
|
info = build_application(applications[0])
|
||||||
else:
|
else:
|
||||||
info = "**Found the following applications**"
|
info = "**Found the following applications**"
|
||||||
for app in applications:
|
for app in applications:
|
||||||
|
@ -177,7 +179,7 @@ class Commands(commands.Cog):
|
||||||
if count > 0:
|
if count > 0:
|
||||||
if count == 1:
|
if count == 1:
|
||||||
await self.bot.discord_message(ctx.message.channel, "**No applications matched, however there is a player match**")
|
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:
|
else:
|
||||||
info = "**No applications matched, however there are player matches**"
|
info = "**No applications matched, however there are player matches**"
|
||||||
for player in players:
|
for player in players:
|
||||||
|
|
21
bot/utils.py
21
bot/utils.py
|
@ -1,23 +1,4 @@
|
||||||
import discord
|
from minecraft_manager.models import Application
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def get_application(app_id):
|
def get_application(app_id):
|
||||||
|
|
1
utils.py
1
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="Read the Rules", value=application.read_rules)
|
||||||
embed.add_field(name="Date", value=application.date_display)
|
embed.add_field(name="Date", value=application.date_display)
|
||||||
embed.add_field(name="Status", value=application.status)
|
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
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue