Fix check for broadcast
This commit is contained in:
parent
043de8a9e8
commit
bbf454aabc
@ -584,47 +584,45 @@ class Rcon(commands.Cog):
|
|||||||
|
|
||||||
@commands.group(case_insensitive=True)
|
@commands.group(case_insensitive=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@checks.is_moderator()
|
||||||
async def broadcast(self, ctx, server_name, *, message=None):
|
async def broadcast(self, ctx, server_name, *, message=None):
|
||||||
"""Sends a broadcast message to all servers in the guild config.
|
"""Sends a broadcast message to all servers in the guild config.
|
||||||
The message will be prefixed with the Discord name of the person running the command.
|
The message will be prefixed with the Discord name of the person running the command.
|
||||||
Will print "Success" for each server once the broadcast is sent."""
|
Will print "Success" for each server once the broadcast is sent."""
|
||||||
if await checks.is_rcon_admin(self.bot, ctx):
|
if message is not None:
|
||||||
if message is not None:
|
resp = await self.bot.aio_session.get(
|
||||||
resp = await self.bot.aio_session.get(
|
f'{self.bot.api_base}/rcon/{ctx.guild.id}/',
|
||||||
f'{self.bot.api_base}/rcon/{ctx.guild.id}/',
|
headers=self.bot.auth_header
|
||||||
headers=self.bot.auth_header
|
)
|
||||||
)
|
if resp.status != 200:
|
||||||
if resp.status != 200:
|
await ctx.send('There was a problem getting the servers for this guild.')
|
||||||
await ctx.send('There was a problem getting the servers for this guild.')
|
return
|
||||||
return
|
guild_servers = await resp.json()
|
||||||
guild_servers = await resp.json()
|
# noinspection PyShadowingNames
|
||||||
# noinspection PyShadowingNames
|
|
||||||
|
|
||||||
futures = []
|
futures = []
|
||||||
if server_name == 'all':
|
if server_name == 'all':
|
||||||
message = ''.join(i for i in f'{ctx.author.display_name}: {message}' if ord(i) < 128)
|
message = ''.join(i for i in f'{ctx.author.display_name}: {message}' if ord(i) < 128)
|
||||||
msg = await ctx.send(f'Broadcasting "{message}" to all servers.')
|
msg = await ctx.send(f'Broadcasting "{message}" to all servers.')
|
||||||
lock = asyncio.Lock()
|
lock = asyncio.Lock()
|
||||||
for server in guild_servers:
|
for server in guild_servers:
|
||||||
|
futures.append(self._broadcast(message=message, server_name=server["name"],
|
||||||
|
msg=msg, message_lock=lock))
|
||||||
|
else:
|
||||||
|
for server in guild_servers:
|
||||||
|
if server["name"].lower().replace(" ", "_") == server_name.lower():
|
||||||
|
msg = await ctx.send(f'Broadcasting "{message}" to {server["name"]}.')
|
||||||
|
lock = asyncio.Lock()
|
||||||
futures.append(self._broadcast(message=message, server_name=server["name"],
|
futures.append(self._broadcast(message=message, server_name=server["name"],
|
||||||
msg=msg, message_lock=lock))
|
msg=msg, message_lock=lock))
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
for server in guild_servers:
|
await ctx.send('That server is not configured in this guild.')
|
||||||
if server["name"].lower().replace(" ", "_") == server_name.lower():
|
self.bot.loop.create_task(asyncio.gather(*futures))
|
||||||
msg = await ctx.send(f'Broadcasting "{message}" to {server["name"]}.')
|
await ctx.message.add_reaction('✅')
|
||||||
lock = asyncio.Lock()
|
|
||||||
futures.append(self._broadcast(message=message, server_name=server["name"],
|
|
||||||
msg=msg, message_lock=lock))
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
await ctx.send('That server is not configured in this guild.')
|
|
||||||
self.bot.loop.create_task(asyncio.gather(*futures))
|
|
||||||
await ctx.message.add_reaction('✅')
|
|
||||||
|
|
||||||
else:
|
|
||||||
await ctx.send('You must include a message with this command.')
|
|
||||||
else:
|
else:
|
||||||
await ctx.send(f'You are not authorized to run this command.')
|
await ctx.send('You must include a message with this command.')
|
||||||
#
|
#
|
||||||
# @commands.command(aliases=['servers', 'list_servers'])
|
# @commands.command(aliases=['servers', 'list_servers'])
|
||||||
# @commands.guild_only()
|
# @commands.guild_only()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user