mirror of
https://github.com/Specoolazius/mcserver-discordbot.git
synced 2024-11-24 21:09:42 +01:00
workz
This commit is contained in:
parent
d9d42ad735
commit
dbf34c639d
0
bot/config/discord_example.ini
Normal file
0
bot/config/discord_example.ini
Normal file
13
bot/extensions/developer.py
Normal file
13
bot/extensions/developer.py
Normal file
@ -0,0 +1,13 @@
|
||||
import discord
|
||||
|
||||
from libs import ServerBot
|
||||
|
||||
|
||||
class Developer(discord.Cog):
|
||||
|
||||
def __init__(self, bot: ServerBot):
|
||||
self.bot = bot
|
||||
|
||||
|
||||
def setup(bot: ServerBot):
|
||||
bot.add_cog(Developer(bot))
|
37
bot/extensions/executer.py
Normal file
37
bot/extensions/executer.py
Normal file
@ -0,0 +1,37 @@
|
||||
import asyncio
|
||||
import os.path
|
||||
|
||||
import discord
|
||||
from discord.commands import slash_command
|
||||
|
||||
from libs import ServerBot
|
||||
|
||||
|
||||
class Executer(discord.Cog):
|
||||
|
||||
def __init__(self, bot: ServerBot):
|
||||
self.bot = bot
|
||||
|
||||
@slash_command(name='start')
|
||||
async def __start_server(self, ctx: discord.ApplicationContext) -> None:
|
||||
await ctx.defer()
|
||||
|
||||
await asyncio.create_subprocess_exec(
|
||||
os.path.join('scripts', 'start-server.sh'),
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
|
||||
await ctx.respond('starting server')
|
||||
|
||||
@slash_command(name='stop')
|
||||
async def __stop_server(self, ctx: discord.ApplicationContext) -> None:
|
||||
if ctx.user.id not in self.bot.admin_ids:
|
||||
await ctx.respond('You don\'t have permissions to do that', ephemeral=True)
|
||||
return
|
||||
|
||||
await ctx.respond('Stopping server')
|
||||
|
||||
|
||||
def setup(bot: ServerBot):
|
||||
bot.add_cog(Executer(bot))
|
1
bot/libs/__init__.py
Normal file
1
bot/libs/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .bot import ServerBot
|
43
bot/libs/bot.py
Normal file
43
bot/libs/bot.py
Normal file
@ -0,0 +1,43 @@
|
||||
import os.path
|
||||
from abc import ABC
|
||||
from typing import Any
|
||||
|
||||
from mcstatus import JavaServer
|
||||
|
||||
import discord
|
||||
from discord.commands import slash_command
|
||||
|
||||
TOKEN = "OTU4Njg2Mjg3MDIyNDIwMDE4.YkQ8Lg.cjdTR7syrHPsXVBUINhq3COQQc4"
|
||||
|
||||
|
||||
class ServerBot(discord.Bot, ABC):
|
||||
|
||||
def __init__(self):
|
||||
super(ServerBot, self).__init__(
|
||||
# general config
|
||||
owner_id=448814943857410058,
|
||||
|
||||
# starting presence
|
||||
activity=discord.Game('Beep Boop! Loading...'),
|
||||
# activity=discord.Game('with 10 people on sfs.ddnss.org'),
|
||||
status=discord.Status.idle,
|
||||
|
||||
# debug
|
||||
debug_guilds=[848137923101982741, 958692739065720832],
|
||||
)
|
||||
|
||||
# loading extensions
|
||||
from extensions.executer import Executer
|
||||
self.add_cog(Executer(self))
|
||||
from extensions.developer import Developer
|
||||
self.add_cog(Developer(self))
|
||||
|
||||
self.admin_ids = [448814943857410058]
|
||||
|
||||
def run(self, *args: Any, **kwargs: Any) -> None:
|
||||
super(ServerBot, self).run(TOKEN, *args, **kwargs)
|
||||
|
||||
async def on_ready(self) -> None:
|
||||
print('online')
|
||||
|
||||
|
0
bot/libs/logger.py
Normal file
0
bot/libs/logger.py
Normal file
16
bot/run.py
Normal file
16
bot/run.py
Normal file
@ -0,0 +1,16 @@
|
||||
import sys
|
||||
from aiohttp import ClientConnectorError
|
||||
|
||||
from libs.bot import ServerBot
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
bot = ServerBot()
|
||||
|
||||
try:
|
||||
bot.run()
|
||||
|
||||
except ClientConnectorError as e:
|
||||
sys.exit(-59)
|
||||
|
||||
sys.exit(0)
|
3
bot/scripts/start-server.sh
Normal file
3
bot/scripts/start-server.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
wakeonlan 90:1B:0E:A5:45:82
|
18
tests/minecraft.py
Normal file
18
tests/minecraft.py
Normal file
@ -0,0 +1,18 @@
|
||||
from mcstatus import JavaServer
|
||||
|
||||
server = JavaServer.lookup('sfs.ddnss.org:25565', 10)
|
||||
server = JavaServer('sfs.ddnss.org', 25565)
|
||||
|
||||
print('got server')
|
||||
|
||||
status = server.status()
|
||||
print(f"The server has {status.players.online} players and replied in {status.latency} ms")
|
||||
|
||||
|
||||
print(server.status())
|
||||
print(vars(server.status()))
|
||||
|
||||
print(server.query())
|
||||
|
||||
query = server.query()
|
||||
print(f"The server has the following players online: {', '.join(query.players.names)}")
|
Loading…
Reference in New Issue
Block a user