From cfeabc37274a79f76f484e857b2a93d836e629f3 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 20 Oct 2018 22:59:10 -0500 Subject: [PATCH] Added demote command to bot Updated Docs Fixes #12 --- api/api.py | 1 + api/bot.py | 19 +++++++++++++++++-- docs/source/getting-started.rst | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/api.py b/api/api.py index 8127661..411235f 100644 --- a/api/api.py +++ b/api/api.py @@ -18,6 +18,7 @@ PLUGIN_ACCEPT = 'accept' PLUGIN_DENY = 'deny' PLUGIN_GLOBAL_CHAT = 'global' PLUGIN_STAFF_CHAT = 'staff' +PLUGIN_DEMOTE = 'demote' def plugin(key, command): diff --git a/api/bot.py b/api/bot.py index 942bbc3..6febf6b 100644 --- a/api/bot.py +++ b/api/bot.py @@ -1,6 +1,7 @@ import discord, logging, re, sys, traceback, asyncio, datetime, os, time from minecraft_manager.models import Application, Player from minecraft_manager.api import api +from django.contrib.auth.models import User from django.conf import settings from django.db import close_old_connections from threading import Thread @@ -67,7 +68,8 @@ class Discord(discord.Client): embed.add_field(name="{}[app ]search ".format(self.prefix), value="Search for applications by partial or exact username.") embed.add_field(name="{}[app ]info ".format(self.prefix), value="Get detailed information about a specific application.") embed.add_field(name="{}[app ]accept|deny ".format(self.prefix), value="Take action on an application.") - embed.add_field(name="{}compare".format(self.prefix), value="Compare Discord users to the Whitelist") + embed.add_field(name="{}demote ".format(self.prefix), value="Demote a player to first accepted role.") + embed.add_field(name="{}compare".format(self.prefix), value="Compare Discord users to the Whitelist.") yield from self.discord_message(message.channel, embed) # APP COMMANDS WITH APP ID match = re.match("[{0}](?:app )?(i|info|a|accept|d|deny) (\d+)$".format(self.prefix), message.content) @@ -103,7 +105,7 @@ class Discord(discord.Client): match = re.match("[{0}](?:app )?(?:search|info) (\S+)?$".format(self.prefix), message.content) if match: search = match.group(1) - yield from self.discord_message(message.channel,"Searching for applications whose username contains '{0}'".format(search)) + yield from self.discord_message(message.channel, "Searching for applications whose username contains '{0}'".format(search)) applications = Application.objects.filter(username__icontains=search)[:10] count = Application.objects.filter(username__icontains=search).count() if count > 0: @@ -118,6 +120,19 @@ class Discord(discord.Client): else: info = "No applications matched that search." yield from self.discord_message(message.channel, info) + # DEMOTE A PLAYER TO MEMBER + match = re.match("[{0}]demote (\w+)$".format(self.prefix), message.content) + if match: + yield from self.delete_message(message) + username = match.group(1) + api.plugin(api.PLUGIN_DEMOTE, username) + deactivated = "" + if User.objects.filter(username__iexact=username).exists(): + user = User.objects.get(username__iexact=username) + user.is_active = False + user.save() + deactivated = " and de-activated" + yield from self.discord_message(message.channel, "{} has been demoted{}.".format(username, deactivated)) # COMPARE DISCORD USERS TO WHITELIST match = re.match("[{0}]compare".format(self.prefix), message.content) if match: diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst index d24cb3d..72a6031 100644 --- a/docs/source/getting-started.rst +++ b/docs/source/getting-started.rst @@ -47,6 +47,7 @@ Add MCM urls to your ``urls.py`` Django doesn't provide login/logout templates by default, so MCM has some generic ones if needed. :: + from django.contrib.auth import views as auth_views path('accounts/login/', auth_views.LoginView.as_view(template_name='minecraft_manager/login.html'), name='login'), path('accounts/logout/', auth_views.LogoutView.as_view(template_name='minecraft_manager/logged_out.html'), name='logout'),