mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
update descriptions and add command
This commit is contained in:
@@ -16,7 +16,7 @@ Commands:
|
|||||||
Add running server check to prevent multiple servers running
|
Add running server check to prevent multiple servers running
|
||||||
-Add list command to see currently running servers
|
-Add list command to see currently running servers
|
||||||
-Add server stop command
|
-Add server stop command
|
||||||
Add server command command
|
-Add server command command
|
||||||
Add server message passthrough
|
Add server message passthrough
|
||||||
Add help command
|
-Add help command
|
||||||
-Add discord message passthrough
|
-Add discord message passthrough
|
||||||
55
bot.py
55
bot.py
@@ -61,6 +61,12 @@ async def send_message(message):
|
|||||||
'''
|
'''
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def startserver(ctx, *args):
|
async def startserver(ctx, *args):
|
||||||
|
'''
|
||||||
|
Start a server
|
||||||
|
args:
|
||||||
|
servername: The name of the server
|
||||||
|
|
||||||
|
'''
|
||||||
global active_server
|
global active_server
|
||||||
# Check if the user is an admin
|
# Check if the user is an admin
|
||||||
if not ctx.author.guild_permissions.administrator:
|
if not ctx.author.guild_permissions.administrator:
|
||||||
@@ -109,7 +115,11 @@ async def startserver(ctx, *args):
|
|||||||
active_server = servername
|
active_server = servername
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def stopserver(ctx, *args):
|
async def stopserver(ctx):
|
||||||
|
'''
|
||||||
|
Stop the server by sending 'stop' to the server
|
||||||
|
|
||||||
|
'''
|
||||||
global active_server
|
global active_server
|
||||||
# Check if the user is an admin
|
# Check if the user is an admin
|
||||||
if not ctx.author.guild_permissions.administrator:
|
if not ctx.author.guild_permissions.administrator:
|
||||||
@@ -123,8 +133,30 @@ async def stopserver(ctx, *args):
|
|||||||
await ctx.send("Server stopped.")
|
await ctx.send("Server stopped.")
|
||||||
active_server = None
|
active_server = None
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
async def command(ctx, *args):
|
||||||
|
'''
|
||||||
|
Send a command to the server
|
||||||
|
args:
|
||||||
|
command: The command to send
|
||||||
|
|
||||||
|
'''
|
||||||
|
global active_server
|
||||||
|
# Check if the user is an admin
|
||||||
|
if not ctx.author.guild_permissions.administrator:
|
||||||
|
await ctx.send("You don't have permission to run this command.")
|
||||||
|
return
|
||||||
|
# Send the command to the server
|
||||||
|
await ctx.send("Sending command...")
|
||||||
|
command = " ".join(args)
|
||||||
|
subprocess.Popen(f"screen -S {active_server} -p 0 -X stuff '{command}\n'", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def list(ctx):
|
async def list(ctx):
|
||||||
|
'''
|
||||||
|
Lists currently running server and available servers
|
||||||
|
|
||||||
|
'''
|
||||||
global active_server
|
global active_server
|
||||||
# Load server data from json
|
# Load server data from json
|
||||||
servers = None
|
servers = None
|
||||||
@@ -161,7 +193,11 @@ async def list(ctx):
|
|||||||
await ctx.send(listofservers)
|
await ctx.send(listofservers)
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def forcestopserver(ctx, *args):
|
async def forcestopserver(ctx):
|
||||||
|
'''
|
||||||
|
Force stop the server by sending keyboard interrupt
|
||||||
|
|
||||||
|
'''
|
||||||
global active_server
|
global active_server
|
||||||
# Check if the user is an admin
|
# Check if the user is an admin
|
||||||
if not ctx.author.guild_permissions.administrator:
|
if not ctx.author.guild_permissions.administrator:
|
||||||
@@ -179,10 +215,25 @@ async def forcestopserver(ctx, *args):
|
|||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def ping(ctx):
|
async def ping(ctx):
|
||||||
|
'''
|
||||||
|
Ping the bot
|
||||||
|
|
||||||
|
'''
|
||||||
await ctx.send('Pong!')
|
await ctx.send('Pong!')
|
||||||
|
|
||||||
|
# @bot.command()
|
||||||
|
# async def help(ctx):
|
||||||
|
# string = "Available commands:\n"
|
||||||
|
# for command in bot.commands:
|
||||||
|
# string += f"{command.name}: {command.description}\n"
|
||||||
|
# await ctx.send(string)
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def botstop(ctx):
|
async def botstop(ctx):
|
||||||
|
'''
|
||||||
|
Stop the bot
|
||||||
|
|
||||||
|
'''
|
||||||
await bot.close()
|
await bot.close()
|
||||||
|
|
||||||
bot.run(TOKEN)
|
bot.run(TOKEN)
|
||||||
Reference in New Issue
Block a user