Skip to content

Commit

Permalink
small touch-ups for file execution. like error handler for token file
Browse files Browse the repository at this point in the history
Will show error when token file not found. fixed issue with showing player list, and when running server_functions, need to input argument 'setup' to run setup process
  • Loading branch information
0n1udra committed Sep 24, 2020
1 parent 2795fcd commit 247535e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 12 deletions.
70 changes: 70 additions & 0 deletions source/bot_log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
2020-09-23 04:02:48.379631 | (Script) Bot PRIMED.
2020-09-23 04:02:49.985199 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:02:51.007996 | (4RDUB3RRY#7235) Fetched help page.
2020-09-23 04:03:01.482465 | (Script) Bot PRIMED.
2020-09-23 04:04:30.029937 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:04:37.709972 | (Script) Bot PRIMED.
2020-09-23 04:04:41.238267 | (4RDUB3RRY#7235) Updating server.jar...
2020-09-23 04:05:11.754222 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 04:05:11.763389 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:05:11.772719 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:05:11.781413 | (4RDUB3RRY#7235) Server Updated.
2020-09-23 04:09:09.860034 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 04:09:09.865210 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:09:42.965886 | (4RDUB3RRY#7235) Stopping server.
2020-09-23 04:09:52.496869 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 04:09:52.517323 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:09:52.544003 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:09:52.565822 | (4RDUB3RRY#7235) World Reset.
2020-09-23 04:15:12.867205 | (4RDUB3RRY#7235) Restarting server.
2020-09-23 04:15:28.175225 | (4RDUB3RRY#7235) Stopping server.
2020-09-23 04:15:39.651678 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 04:15:39.660667 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:15:39.680720 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:15:46.726633 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:15:49.799210 | (Script) Bot PRIMED.
2020-09-23 04:15:50.899987 | (4RDUB3RRY#7235) Restarting server.
2020-09-23 04:16:06.417070 | (4RDUB3RRY#7235) Stopping server.
2020-09-23 04:16:16.771864 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:16:16.783988 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:16:32.207220 | (4RDUB3RRY#7235) Updating server.jar...
2020-09-23 04:16:48.068137 | (4RDUB3RRY#7235) Stopping server.
2020-09-23 04:17:16.203534 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:17:16.212295 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:17:16.231015 | (4RDUB3RRY#7235) Server Updated.
2020-09-23 04:18:19.276902 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:18:27.332964 | (Script) Bot PRIMED.
2020-09-23 04:19:15.030971 | (Script) Bot PRIMED.
2020-09-23 04:19:30.936710 | (4RDUB3RRY#7235) Updating server.jar...
2020-09-23 04:19:58.992914 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:19:59.002079 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:19:59.011541 | (4RDUB3RRY#7235) Server Updated.
2020-09-23 04:32:50.829219 | (Script) Bot PRIMED.
2020-09-23 04:38:36.329551 | (4RDUB3RRY#7235) Server property: pdated Property:`online-mode=true
> `online-mode=false`.
Restart to apply changes
2020-09-23 04:38:50.890026 | (4RDUB3RRY#7235) Restarting server.
2020-09-23 04:39:01.291129 | (4RDUB3RRY#7235) Fetched server status.
2020-09-23 04:39:01.299668 | (4RDUB3RRY#7235) Starting server.
2020-09-23 04:53:12.383637 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:54:26.169182 | (Script) Bot PRIMED.
2020-09-23 04:54:41.869321 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:54:44.609491 | (Script) Bot PRIMED.
2020-09-23 04:54:59.940000 | (Script) Updated online-mode: true
2020-09-23 04:55:06.989081 | (Script) Updated online-mode: false
2020-09-23 04:55:55.359757 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:55:57.904409 | (Script) Updated online-mode: true
2020-09-23 04:55:58.038459 | (Script) Bot PRIMED.
2020-09-23 04:56:01.496343 | (Script) Updated online-mode: false
2020-09-23 04:58:08.776331 | (4RDUB3RRY#7235) Fetched help page.
2020-09-23 04:58:25.051278 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 04:58:27.758349 | (Script) Bot PRIMED.
2020-09-23 05:09:14.992679 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 19:10:12.251357 | (ARDU1N0#4107) Fetched player list.
2020-09-23 19:24:43.380214 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 19:25:44.274784 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 19:25:49.851588 | (Script) Bot PRIMED.
2020-09-23 19:25:59.241668 | (4RDUB3RRY#7235) Fetched player list.
2020-09-23 20:03:57.314385 | (4RDUB3RRY#7235) Restarting bot.
2020-09-23 20:07:39.793006 | (Script) Bot PRIMED.
2020-09-23 20:14:22.751181 | (Script) Bot PRIMED.
16 changes: 8 additions & 8 deletions source/discord_mc_bot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import discord, asyncio, os, sys, psutil, time, json, csv, datetime, server_functions
from discord.ext import commands, tasks
from server_functions import lprint
from server_functions import lprint, discord_bot_token_file

# Exits script if no token.
with open(server_functions.discord_bot_token_file, 'r') as file:
TOKEN = file.readline()
if not TOKEN: print("Token Error."), exit()
if os.path.isfile(discord_bot_token_file):
with open(discord_bot_token_file, 'r') as file:
TOKEN = file.readline()
else: print("Missing Token File:", discord_bot_token_file), exit()

# Make sure this doesn't conflict with other bots.
bot = commands.Bot(command_prefix='?')
Expand Down Expand Up @@ -50,7 +51,6 @@ async def server_command(ctx, *args):
time.sleep(1)
await ctx.invoke(bot.get_command('log'), lines=2)


@bot.command(aliases=['save', 'sa'])
async def server_save(ctx):
mc_command('/save-all')
Expand Down Expand Up @@ -90,7 +90,7 @@ async def list_players(ctx):
await ctx.send(text)
else:
# Outputs player names in special discord format.
players = [f"`{i.strip()}`" for i in (log_data[-1]).split(',')]
players = [f"`{i.strip()}`\n" for i in (log_data[-1]).split(',')]
await ctx.send(text + ':\n' + ''.join(players))
lprint(ctx, "Fetched player list.")

Expand Down Expand Up @@ -154,7 +154,7 @@ async def op_remove(ctx, player, *reason):
lprint(ctx, f"Removed server op: {player}")

@bot.command(aliases=['top', 'timedop'])
async def timed_op(ctx, player, time_limit=1):
async def op_timed(ctx, player, time_limit=1):
await ctx.send(f"Granting `{player}` OP status for {time_limit}m!")
mc_command(f"/say INFO | {player} granted God status for {time_limit}m!")
mc_command(f"/op {player}")
Expand Down Expand Up @@ -202,7 +202,7 @@ async def player_gamemode(ctx, player, state, *reason):
lprint(ctx, f"Set {player} to: {state}")

@bot.command(aliases=['timedgamemode', 'timedgm', 'tgm'])
async def player_timed_gamemode(ctx, player, state, duration=None, *reason):
async def player_gamemode_timed(ctx, player, state, duration=None, *reason):
try: duration = int(duration)
except:
await ctx.send("You buffoon, I need a number to set the duration!")
Expand Down
9 changes: 5 additions & 4 deletions source/server_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, shutil, datetime, fileinput, requests, time
import os, shutil, datetime, fileinput, requests, time, sys
from file_read_backwards import FileReadBackwards
from bs4 import BeautifulSoup

Expand Down Expand Up @@ -221,6 +221,7 @@ def delete_server(server): return delete_backup(server_backups_path + '/' + serv
def delete_world(world): return delete_backup(world_backups_path + '/' + world)

if __name__ == '__main__':
setup_directories()
start_tmux_session()
start_minecraft_server()
if 'setup' in sys.argv:
setup_directories()
start_tmux_session()
start_minecraft_server()

0 comments on commit 247535e

Please sign in to comment.