Skip to content

Commit

Permalink
Tweaked server_status()
Browse files Browse the repository at this point in the history
Removed channel.send function in server_status(). 
Tweaked what happens when server is offline and user uses certain commands, like banlist, opadd, opremove, etc
  • Loading branch information
0n1udra committed Apr 10, 2022
1 parent 50253d4 commit 15de68b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions source/backend_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def server_command(command, stop_at_checker=True, skip_check=False, discor
global mc_subprocess, server_active

async def inactive_msg():
if discord_msg: await channel_send("**Server INACTIVE** :red_circle:\nUse `?stats` or `?check` to check if server is back online.")
if discord_msg: await channel_send("**Server INACTIVE** :red_circle:\nUse `?check` to update server status.")

# This is so user can't keep sending commands to RCON if server is unreachable. Use ?stat or ?check to actually check if able to send command to server.
# Without this, the user might try sending multiple commands to a unreachable RCON server which will hold up the bot.
Expand Down Expand Up @@ -258,7 +258,6 @@ async def server_status(discord_msg=False):

global server_active

if discord_msg: await channel_send('***Checking Server Status...***')
lprint("Checking Minecraft server status...")

# server_command() will send random number, server is online if match is found in log.
Expand Down
36 changes: 18 additions & 18 deletions source/slime_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,9 @@ async def pardon(self, ctx, player='', *reason):
async def banlist(self, ctx):
"""Show list of current bans."""

# Gets online players, formats output for Discord depending on using RCON or reading from server log.
if not await server_status(): return

banned_players = ''
response = await server_command("banlist")
if not response: return
response = response[0]

if slime_vars.use_rcon is True:
Expand All @@ -805,9 +803,9 @@ async def banlist(self, ctx):
banner = line[0].split(' ')[-1].strip()
if len(player) < 2:
continue
banned_players += f"`{player}` banned by `{banner}` : `{reason}`\n"
banned_players += f"**{player}** banned by `{banner}` : `{reason}`\n"

banned_players += data[0] + '.' # Gets line that says 'There are x bans'.
banned_players += data[0].strip() + '.' # Gets line that says 'There are x bans'.

else:
if log_data := backend_functions.server_log('banlist'):
Expand Down Expand Up @@ -861,10 +859,8 @@ async def whitelist(self, ctx, arg='', arg2=''):
# Checks if inputted any arguments.
if not arg: await ctx.send(f"\nUsage Examples: `?whitelist add MysticFrogo`, `?whitelist on`, `?whitelist enforce on`, use `?help whitelist` or `?help2` for more.")

# Checks if can send command to server.
if not await server_status():
await ctx.send("Server Offline.")
return
# Checks if server online.
if not await server_status(discord_msg=True): return

# Enable/disable whitelisting.
if arg.lower() in backend_functions.enable_inputs:
Expand Down Expand Up @@ -955,9 +951,8 @@ async def opadd(self, ctx, player='', *reason):
await ctx.send("Usage: `?op <player> [reason]`\nExample: `?op R3diculous Need to be a God!`")
return False

if not await server_status(): return

reason = format_args(reason, return_no_reason=True)
if not reason: return

if slime_vars.use_rcon:
command_success = await server_command(f"op {player}")[0]
Expand Down Expand Up @@ -990,20 +985,22 @@ async def opremove(self, ctx, player='', *reason):
await ctx.send("Usage: `?deop <player> [reason]`\nExample: `?op MysticFrogo Was abusing God powers!`")
return False

if not await server_status(): return

reason = format_args(reason, return_no_reason=True)
command_success = False

if slime_vars.use_rcon:
command_success = await server_command(f"deop {player}")[0]
else:
response = await server_command(f"deop {player}")
command_success = backend_functions.server_log(player, stopgap_str=response[1])
if response := await server_command(f"deop {player}"):
command_success = backend_functions.server_log(player, stopgap_str=response[1])

if command_success:
await server_command(f"say ---INFO--- {player} no longer OP : {reason}")
await ctx.send(f"**Player OP Removed:** `{player}`")
else: await ctx.send("**ERROR:** Problem removing OP status.")
lprint(ctx, f"Removed server OP: {player}")
lprint(ctx, f"Removed server OP: {player}")
else:
await ctx.send("**ERROR:** Problem removing OP status.")
lprint(ctx, f"Error: removing server OP: {player}")

@commands.command(aliases=['optime', 'opt', 'optimedlimit'])
async def optimed(self, ctx, player='', time_limit=1, *reason):
Expand All @@ -1019,6 +1016,8 @@ async def optimed(self, ctx, player='', time_limit=1, *reason):
?top jesse 60
"""

if not await server_status(discord_msg=True): return

if not player:
await ctx.send("Usage: `?optimed <player> <minutes> [reason]`\nExample: `?optimed R3diculous Testing purposes`")
return False
Expand Down Expand Up @@ -1115,7 +1114,7 @@ async def timeset(self, ctx, set_time=''):
?time 12
"""

if not await server_status(): return
if not await server_status(discord_msg=True): return

if set_time:
await server_command(f"time set {set_time}")
Expand Down Expand Up @@ -1244,6 +1243,7 @@ async def servercheck(self, ctx, show_msg=True):
"""Checks if server is online."""

await server_status(discord_msg=show_msg)
await ctx.send('***Checking Server Status...***')
await ctx.invoke(self.bot.get_command('_control_panel_msg'))

@commands.command(aliases=['mstatus'])
Expand Down

0 comments on commit 15de68b

Please sign in to comment.