[CHANGE] Discord service

This commit is contained in:
Peter Pfeufer 2023-10-31 09:48:29 +01:00
parent 63afb13d25
commit 773288072a
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27
2 changed files with 49 additions and 35 deletions

View File

@ -70,22 +70,21 @@ class DiscordService(ServicesHook):
discord_username = self.get_discord_username(
username=username, discriminator=discriminator
)
# if username and discriminator:
# discord_username = f'{username}#{discriminator}'
#
# # New Discord user name format
# if discriminator == '0':
# discord_username = f'@{username}'
# else:
# discord_username = ''
else:
discord_username = ''
user_has_account = False
urls = self.Urls()
urls.auth_activate = 'discord:activate'
urls.auth_deactivate = 'discord:deactivate'
urls.auth_reset = 'discord:reset'
urls.auth_add_bot = 'discord:add_bot'
return render_to_string(
self.service_ctrl_template,
{
'service_name': self.title,
'urls': urls,
'server_name': server_name(),
'user_has_account': user_has_account,
'discord_username': discord_username

View File

@ -1,34 +1,49 @@
{% extends "services/services_ctrl_base.html" %}
{% load i18n %}
<div class="card text-center m-4" style="min-width: 18rem; min-height: 18rem;">
<div class="card-body ">
<h5 class="card-title ">{% translate "Discord" %}</h5>
<p class="card-text">{% if server_name %}{{ server_name }}{% else %}{% translate "Unlinked Server" %}{% endif %}</p>
<p class="card-text"><span class="badge {% if user_has_account %}bg-success{% else %}bg-warning{% endif %}">{% if user_has_account %}{% translate "Active" %}{% else %}{% translate "Disabled" %}{% endif %}</span></p>
<p class="card-text">
{% if not user_has_account %}
{% translate "(not activated)" %}
{% else %}
{{ discord_username }}
{% endif %}
</p>
</div>
<div class="card-footer">
{% if not user_has_account %}
<a href="{% url 'discord:activate' %}" title="{% translate 'Join the Discord server' %}" class="btn btn-primary">
{% block title %}
{{ service_name }}
{% endblock %}
{% block url %}
{{ server_name }}
{% endblock %}
{% block active %}
{% include "services/service_status.html" with username=discord_username %}
{% endblock %}
{% block user %}
{% if discord_username %}
{{ discord_username }}
{% endif %}
{% endblock %}
{% block controls %}
{% if username == "" %}
{% if urls.auth_activate %}
<a class="btn btn-warning" href="{% url urls.auth_activate %}" title="{% translate 'Activate' %}">
<span class="fas fa-check fa-fw"></span>
</a>
{% else %}
<a href="{% url 'discord:reset' %}" title="{% translate 'Leave- and rejoin the Discord Server (Reset)' %}" class="btn btn-warning">
{% endif %}
{% else %}
{% if urls.auth_reset %}
<a class="btn btn-primary" href="{% url urls.auth_reset %}" title="{% translate 'Reset Password' %}">
<span class="fas fa-sync fa-fw"></span>
</a>
<a href="{% url 'discord:deactivate' %}" title="{% translate 'Leave the Discord server' %}" class="btn btn-danger">
{% endif %}
{% if urls.auth_deactivate %}
<a class="btn btn-danger" href="{% url urls.auth_deactivate %}" title="{% translate 'Deactivate' %}">
<span class="fas fa-times fa-fw"></span>
</a>
{% endif %}
{% if request.user.is_superuser %}
<a type="button" id="btnLinkDiscordServer" class="btn btn-primary" href="{% url 'discord:add_bot' %}">
<span class="fas fa-link fa-fw"></span>
</a>
{% endif %}
</div>
</div>
{% endif %}
{% if request.user.is_superuser %}
<a class="btn btn-primary" type="button" id="btnLinkDiscordServer" href="{% url urls.auth_add_bot %}" title="{% translate 'Link Discord Server' %}">
<span class="fas fa-link fa-fw"></span>
</a>
{% endif %}
{% endblock %}