Added demote command to bot

Updated Docs
Fixes #12
reminder
Etzelia 2018-10-20 22:59:10 -05:00
parent a314e51262
commit cfeabc3727
3 changed files with 19 additions and 2 deletions

View File

@ -18,6 +18,7 @@ PLUGIN_ACCEPT = 'accept'
PLUGIN_DENY = 'deny' PLUGIN_DENY = 'deny'
PLUGIN_GLOBAL_CHAT = 'global' PLUGIN_GLOBAL_CHAT = 'global'
PLUGIN_STAFF_CHAT = 'staff' PLUGIN_STAFF_CHAT = 'staff'
PLUGIN_DEMOTE = 'demote'
def plugin(key, command): def plugin(key, command):

View File

@ -1,6 +1,7 @@
import discord, logging, re, sys, traceback, asyncio, datetime, os, time import discord, logging, re, sys, traceback, asyncio, datetime, os, time
from minecraft_manager.models import Application, Player from minecraft_manager.models import Application, Player
from minecraft_manager.api import api from minecraft_manager.api import api
from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.db import close_old_connections from django.db import close_old_connections
from threading import Thread from threading import Thread
@ -67,7 +68,8 @@ class Discord(discord.Client):
embed.add_field(name="{}[app ]search <username>".format(self.prefix), value="Search for applications by partial or exact username.") embed.add_field(name="{}[app ]search <username>".format(self.prefix), value="Search for applications by partial or exact username.")
embed.add_field(name="{}[app ]info <app ID>".format(self.prefix), value="Get detailed information about a specific application.") embed.add_field(name="{}[app ]info <app ID>".format(self.prefix), value="Get detailed information about a specific application.")
embed.add_field(name="{}[app ]accept|deny <app ID>".format(self.prefix), value="Take action on an application.") embed.add_field(name="{}[app ]accept|deny <app ID>".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 <username>".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) yield from self.discord_message(message.channel, embed)
# APP COMMANDS WITH APP ID # APP COMMANDS WITH APP ID
match = re.match("[{0}](?:app )?(i|info|a|accept|d|deny) (\d+)$".format(self.prefix), message.content) match = re.match("[{0}](?:app )?(i|info|a|accept|d|deny) (\d+)$".format(self.prefix), message.content)
@ -118,6 +120,19 @@ class Discord(discord.Client):
else: else:
info = "No applications matched that search." info = "No applications matched that search."
yield from self.discord_message(message.channel, info) 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 # COMPARE DISCORD USERS TO WHITELIST
match = re.match("[{0}]compare".format(self.prefix), message.content) match = re.match("[{0}]compare".format(self.prefix), message.content)
if match: if match:

View File

@ -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. 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/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'), path('accounts/logout/', auth_views.LogoutView.as_view(template_name='minecraft_manager/logged_out.html'), name='logout'),