Add whitelist command

This commit is contained in:
Dustin Pianalto 2019-12-16 22:07:04 -09:00
parent 477c58a8bd
commit 7c8d0a771d

View File

@ -1,9 +1,10 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Greedy
import logging import logging
from datetime import datetime from datetime import datetime
import asyncio import asyncio
import typing from typing import Union
from geeksbot.imports import arcon from geeksbot.imports import arcon
from geeksbot.imports import utils from geeksbot.imports import utils
from geeksbot.imports import checks from geeksbot.imports import checks
@ -251,7 +252,7 @@ class Rcon(commands.Cog):
msg = await ctx.send(f'**Getting Data for the {server_name} server**') msg = await ctx.send(f'**Getting Data for the {server_name} server**')
await ctx.channel.trigger_typing() await ctx.channel.trigger_typing()
resp = await self.bot.aio_session.get( resp = await self.bot.aio_session.get(
f'{self.bot.api_base}/rcon/{ctx.guild.id}/{server_name}/listplayers', f'{self.bot.api_base}/rcon/{ctx.guild.id}/{server_name}/listplayers/',
headers=self.bot.auth_header headers=self.bot.auth_header
) )
if resp.status == 200: if resp.status == 200:
@ -281,7 +282,7 @@ class Rcon(commands.Cog):
# noinspection PyShadowingNames # noinspection PyShadowingNames
async def _listplayers(server_name: str, msg: discord.Message): async def _listplayers(server_name: str, msg: discord.Message):
resp = await self.bot.aio_session.get( resp = await self.bot.aio_session.get(
f'{self.bot.api_base}/rcon/{ctx.guild.id}/{server_name}/listplayers', f'{self.bot.api_base}/rcon/{ctx.guild.id}/{server_name}/listplayers/',
headers=self.bot.auth_header headers=self.bot.auth_header
) )
if resp.status == 200: if resp.status == 200:
@ -357,68 +358,56 @@ class Rcon(commands.Cog):
# await ctx.send('{0} is not in my configuration.'.format(server)) # await ctx.send('{0} is not in my configuration.'.format(server))
# else: # else:
# await ctx.send(f'You are not authorized to run this command.') # await ctx.send(f'You are not authorized to run this command.')
#
# @staticmethod @staticmethod
# async def _whitelist(*, server_name: str, server_con: arcon.ARKServer, async def _whitelist(ctx, *, server_name: str, discord_id: str):
# player: patron.Patron, message: discord.Message, message_lock: asyncio.Lock): data = {
# result = await server_con.whitelist(player.steam_id) 'discord_id': discord_id
# if result == f'{player.steam_id} Allow Player To Join No Check': }
# with await message_lock: resp = await ctx.bot.aio_session.post(f'{ctx.bot.api_base}/rcon/{ctx.guild.id}/{server_name}/whitelist/',
# message = await message.channel.get_message(message.id) headers=ctx.bot.auth_header,
# await message.edit(content=f'{message.content}\n{server_name.replace("_", " ").title()}' json=data)
# f' Done!') return resp
# else:
# with await message_lock: @commands.command(name='add_whitelist')
# message = await message.channel.get_message(message.id) @commands.guild_only()
# await message.edit(content=f'{message.content}\n{server_name.replace("_", " ").title()}' @checks.is_admin()
# f' Failed!') async def add_whitelist(self, ctx, members: Greedy[discord.Member] = None):
# if members:
# @commands.command(name='add_whitelist') resp = await self.bot.aio_session.get(
# @commands.guild_only() f'{self.bot.api_base}/rcon/{ctx.guild.id}/',
# async def add_whitelist(self, ctx, *, members: str=None): headers=self.bot.auth_header
# if await checks.is_rcon_admin(self.bot, ctx): )
# if members: if resp.status != 200:
# futures = [] await ctx.send('There was a problem getting the servers for this guild.')
# members = members.replace(', ', '').split(',') return
# converter = commands.MemberConverter() guild_servers = await resp.json()
# for member in members: for member in members:
# try: await ctx.send(f'Whitelisting {member.display_name} on all servers:')
# member = await converter.convert(ctx, member) e = False
# except commands.errors.BadArgument: for server in guild_servers:
# try: suc = await self._whitelist(ctx,
# member = int(member) server_name=server["name"],
# except ValueError: discord_id=str(member.id)
# raise ValueError(f'Member {member} can\'t be found and is not a valid Steam64 ID.') )
# if suc.status == 400:
# if isinstance(member, discord.Member): error = (await suc.json())['details']
# player = await patron.Patron.from_name(self.bot, discord_name=member) await ctx.send(error)
# else: e = True
# player = await patron.Patron.from_id(self.bot, steam_id=member) break
# elif suc.status in (404, 408):
# if player == -1: msg = (await suc.json())['details']
# await ctx.send(f'{ctx.author.mention} I Cannot find a player with a discord name/steam id of ' e = True
# f'{member} in the current whitelist sheet. Did you forget to ' else:
# f'move them to the correct sheet?') msg = '\n'.join(await suc.json())
# else: await ctx.send(f'{server["name"]}: {msg}')
# rcon_connections: dict = await self.get_rcon_server_by_name(guild_config=ctx.guild_config, if e:
# name='*') await ctx.send(f'{ctx.author.mention} There were errors processing {member.display_name}.')
# if rcon_connections: else:
# msg = await ctx.send(f'**Whitelisting {player.discord_name} on all servers**') await ctx.send(f'{member.display_name} Done.')
# lock = asyncio.Lock()
# for server_name, server_con in rcon_connections.items(): else:
# futures.append(self._whitelist(server_name=server_name, server_con=server_con, await ctx.send('I need a list of members to whitelist.')
# player=player, message=msg, message_lock=lock))
#
# if futures:
# asyncio.ensure_future(asyncio.gather(*futures), loop=self.bot.loop)
# else:
# await ctx.send('Nothing for me to do')
# return
#
# else:
# await ctx.send('I need a list of members to whitelist.')
# else:
# await ctx.send(f'You are not authorized to run this command.')
# #
# @commands.command(name='new_patron') # @commands.command(name='new_patron')
# @commands.guild_only() # @commands.guild_only()