Add broadcast command

This commit is contained in:
Dustin Pianalto 2020-08-18 00:59:39 -08:00
parent b4f7ac95b8
commit 043de8a9e8

View File

@ -559,83 +559,72 @@ class Rcon(commands.Cog):
# await ctx.send(f'{server} is not currently in the configuration for this guild.') # await ctx.send(f'{server} is not currently in the configuration for this guild.')
# 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.')
#
# @commands.group(case_insensitive=True) async def _broadcast(self, *, message: str, server_name: str,
# async def broadcast(self, ctx): msg: discord.Message, message_lock: asyncio.Lock):
# """Run help broadcast for more info""" suc = await self.bot.aio_session.get(
# pass f'{self.bot.api_base}/rcon/{msg.guild.id}/{server_name}/broadcast/',
# headers=self.bot.auth_header,
# @broadcast.command(name='all', aliases=['a']) json={'message': message}
# @commands.guild_only() )
# async def broadcast_all(self, ctx, *, message=None): if suc.status == 400:
# """Sends a broadcast message to all servers in the guild config. resp = (await suc.json())['details']
# The message will be prefixed with the Discord name of the person running the command. elif suc.status in (404, 408):
# Will print "Success" for each server once the broadcast is sent.""" resp = (await suc.json())['details']
# if await checks.is_rcon_admin(self.bot, ctx): else:
# if message is not None: resp = '\n'.join(await suc.json())
# if resp == 'Server received, But no response!!':
# # noinspection PyShadowingNames with await message_lock:
# async def _broadcast(*, message: str, server_con: arcon.ARKServer, server_name: str, msg = await msg.channel.get_message(msg.id)
# msg: discord.Message, message_lock: asyncio.Lock): await msg.edit(content=f'{msg.content}\n{server_name} Success')
# print(server_con.host, server_con.port) else:
# response = await server_con.broadcast(message) with await message_lock:
# if response == 'Server received, But no response!!': msg = await msg.channel.get_message(msg.id)
# with await message_lock: await msg.edit(content=f'{msg.content}\n{server_name} Failed')
# msg = await msg.channel.get_message(msg.id)
# await msg.edit(content=f'{msg.content}\n{server_name} Success') @commands.group(case_insensitive=True)
# else: @commands.guild_only()
# with await message_lock: async def broadcast(self, ctx, server_name, *, message=None):
# msg = await msg.channel.get_message(msg.id) """Sends a broadcast message to all servers in the guild config.
# await msg.edit(content=f'{msg.content}\n{server_name} Failed') The message will be prefixed with the Discord name of the person running the command.
# futures = [] Will print "Success" for each server once the broadcast is sent."""
# rcon_connections: dict = await self.get_rcon_server_by_name(guild_config=ctx.guild_config, if await checks.is_rcon_admin(self.bot, ctx):
# name='*') if message is not None:
# if rcon_connections: resp = await self.bot.aio_session.get(
# message = ''.join(i for i in f'{ctx.author.display_name}: {message}' if ord(i) < 128) f'{self.bot.api_base}/rcon/{ctx.guild.id}/',
# msg = await ctx.send(f'Broadcasting "{message}" to all servers.') headers=self.bot.auth_header
# lock = asyncio.Lock() )
# for server_name, server_con in rcon_connections.items(): if resp.status != 200:
# futures.append(_broadcast(message=message, server_con=server_con, server_name=server_name, await ctx.send('There was a problem getting the servers for this guild.')
# msg=msg, message_lock=lock)) return
# self.bot.loop.create_task(asyncio.gather(*futures)) guild_servers = await resp.json()
# await ctx.message.add_reaction('✅') # noinspection PyShadowingNames
# else:
# await ctx.send('There are no available servers for this guild.') futures = []
# else: if server_name == 'all':
# await ctx.send('You must include a message with this command.') message = ''.join(i for i in f'{ctx.author.display_name}: {message}' if ord(i) < 128)
# else: msg = await ctx.send(f'Broadcasting "{message}" to all servers.')
# await ctx.send(f'You are not authorized to run this command.') lock = asyncio.Lock()
# for server in guild_servers:
# @broadcast.command(name='server') futures.append(self._broadcast(message=message, server_name=server["name"],
# @commands.guild_only() msg=msg, message_lock=lock))
# async def broadcast_server(self, ctx, server, *, message=None): else:
# """Sends a broadcast message to the specified server that is in the guild's config. for server in guild_servers:
# The message will be prefixed with the Discord name of the person running the command. if server["name"].lower().replace(" ", "_") == server_name.lower():
# If <server> has more than one word in it's name it will either need to be surrounded msg = await ctx.send(f'Broadcasting "{message}" to {server["name"]}.')
# by double quotes or the words separated by _""" lock = asyncio.Lock()
# if await checks.is_rcon_admin(self.bot, ctx): futures.append(self._broadcast(message=message, server_name=server["name"],
# if server is not None: msg=msg, message_lock=lock))
# server = server.replace('_', ' ').title() break
# if message is not None: else:
# message = ''.join(i for i in f'{ctx.author.display_name}: {message}' if ord(i) < 128) await ctx.send('That server is not configured in this guild.')
# server_con: arcon.ARKServer = await self.get_rcon_server_by_name( self.bot.loop.create_task(asyncio.gather(*futures))
# guild_config=ctx.guild_config, name=server await ctx.message.add_reaction('')
# )
# if server_con: else:
# msg = await ctx.send(f'Broadcasting "{message}" to {server}.') await ctx.send('You must include a message with this command.')
# response = await server_con.broadcast(message) else:
# if response == 'Server received, But no response!!': await ctx.send(f'You are not authorized to run this command.')
# await msg.add_reaction(self.bot.unicode_emojis['y'])
# else:
# await msg.add_reaction(self.bot.unicode_emojis['x'])
# else:
# await ctx.send(f'{server} is not in the config for this guild')
# else:
# await ctx.send('You must include a message with this command.')
# else:
# await ctx.send('You must include a server with this command')
# else:
# await ctx.send(f'You are not authorized to run this command.')
# #
# @commands.command(aliases=['servers', 'list_servers']) # @commands.command(aliases=['servers', 'list_servers'])
# @commands.guild_only() # @commands.guild_only()