Compare commits
No commits in common. "947b454faff11bbd777a63576aaa9ba87818aef8" and "ae5d183172cbfa7cb5ee19dc88342380636bf417" have entirely different histories.
947b454faf
...
ae5d183172
|
@ -25,7 +25,7 @@ def rewriter(file_name):
|
||||||
@rewriter('eula.txt')
|
@rewriter('eula.txt')
|
||||||
def confirm_eula(line : str, line_no : int, data):
|
def confirm_eula(line : str, line_no : int, data):
|
||||||
"""Confirm the Minecraft EULA"""
|
"""Confirm the Minecraft EULA"""
|
||||||
if not config.EULA:
|
if os.getenv('EULA') is None or os.getenv('EULA').lower() != 'true':
|
||||||
return line
|
return line
|
||||||
else:
|
else:
|
||||||
return line.replace('eula=false', 'eula=true')
|
return line.replace('eula=false', 'eula=true')
|
||||||
|
@ -36,13 +36,9 @@ def fill_in_server_settings(line : str, line_no : int, data):
|
||||||
if line.strip().startswith('#'):
|
if line.strip().startswith('#'):
|
||||||
return line
|
return line
|
||||||
|
|
||||||
key = line.split('=')[0]
|
value = line.split('=')[0]
|
||||||
|
|
||||||
server_settings = config.at(['minecraft']) or {}
|
if value in config.SERVER_SETTINGS:
|
||||||
|
return value + '=' + str(config.SERVER_SETTINGS[value]) + '\n'
|
||||||
try:
|
|
||||||
value = server_settings[key]
|
|
||||||
except IndexError:
|
|
||||||
return line
|
|
||||||
else:
|
else:
|
||||||
return key + '=' + str(value) + '\n'
|
return line
|
41
config.py
41
config.py
|
@ -1,41 +1,9 @@
|
||||||
import os
|
import os
|
||||||
import yaml
|
|
||||||
from typing import Any, List, Optional
|
|
||||||
|
|
||||||
with open('config.yaml', 'r') as open_file:
|
|
||||||
SETTINGS = yaml.load(open_file)
|
|
||||||
|
|
||||||
def at(keys : List[str]) -> Optional[Any]:
|
|
||||||
"""
|
|
||||||
Potentially get a value. If it doesn't exist, return None.
|
|
||||||
"""
|
|
||||||
return at_value(keys, SETTINGS)
|
|
||||||
|
|
||||||
def at_value(keys : List[str], value : Any) -> Optional[Any]:
|
|
||||||
try:
|
|
||||||
head, tail = keys[0], keys[1:]
|
|
||||||
except IndexError:
|
|
||||||
return value
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
new_value = value[head]
|
|
||||||
except TypeError:
|
|
||||||
return None
|
|
||||||
except KeyError:
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return at_value(tail, new_value)
|
|
||||||
|
|
||||||
# EULA
|
|
||||||
EULA = at(['minecraft', 'eula']) or False
|
|
||||||
|
|
||||||
# Minecraft bridge credentials
|
# Minecraft bridge credentials
|
||||||
MATRIX_HOMESERVER = at(['matrix', 'homeserver']) or "https://matrix.example.org/"
|
MATRIX_HOMESERVER = os.getenv('MATRIX_HOMESERVER') or "https://homeserv.er"
|
||||||
MATRIX_USERNAME = at(['matrix', 'username']) or "@alice:example.org"
|
MATRIX_USERNAME = os.getenv('MATRIX_USERNAME') or "@bridge_username:homeserv.er"
|
||||||
MATRIX_PASSWORD = at(['matrix', 'password']) or "bridge_password"
|
MATRIX_PASSWORD = os.getenv('MATRIX_PASSWORD') or "bridge_password"
|
||||||
|
|
||||||
# Matrix bridge room
|
|
||||||
MATRIX_ROOM = at(['matrix', 'room_id']) or "!channel_id:example.org"
|
|
||||||
|
|
||||||
SERVER_IP = os.getenv('SERVER_ADDRESS') or 'unknown ip'
|
SERVER_IP = os.getenv('SERVER_ADDRESS') or 'unknown ip'
|
||||||
|
|
||||||
|
@ -48,6 +16,9 @@ MC_ADMINS = [
|
||||||
if os.getenv('MATRIX_ADMINS') is not None:
|
if os.getenv('MATRIX_ADMINS') is not None:
|
||||||
MC_ADMINS = os.getenv('MATRIX_ADMINS').split(',')
|
MC_ADMINS = os.getenv('MATRIX_ADMINS').split(',')
|
||||||
|
|
||||||
|
# Matrix channel that the bot should talk to
|
||||||
|
MC_CHANNEL = os.getenv('MC_CHANNEL') or "!channel_id:homeserv.er"
|
||||||
|
|
||||||
make_bool = lambda os_value, default_value : default_value if not os_value else (
|
make_bool = lambda os_value, default_value : default_value if not os_value else (
|
||||||
False if os_value.lower() == 'false' else True
|
False if os_value.lower() == 'false' else True
|
||||||
)
|
)
|
||||||
|
|
175
config.yaml
175
config.yaml
|
@ -1,175 +0,0 @@
|
||||||
# Matrix bridge configurations
|
|
||||||
matrix:
|
|
||||||
# Homeserver URL
|
|
||||||
homeserver: https://matrix.example.org/
|
|
||||||
|
|
||||||
# Bridge login credentials
|
|
||||||
username: "@alice:example.org"
|
|
||||||
password: bridge_password
|
|
||||||
|
|
||||||
# Matrix room
|
|
||||||
room_id: "!channel_id:example.org"
|
|
||||||
|
|
||||||
# IP address or domain where users can join the server
|
|
||||||
server_address: unknown ip
|
|
||||||
|
|
||||||
# List of Matrix users that can send commands to the bridge.
|
|
||||||
# When a message starts with a slash, (/) the bridge will interpret it as a
|
|
||||||
# Minecraft command and will put that as a command into the console.
|
|
||||||
mc-admins:
|
|
||||||
- "@bram:matrix.directory"
|
|
||||||
# - "@alice:example.org"
|
|
||||||
# -
|
|
||||||
|
|
||||||
# When users have bridged from other platforms, you can indicate accordingly.
|
|
||||||
alternative_platforms:
|
|
||||||
Discord:
|
|
||||||
match: "@_?discord_\d+:.+"
|
|
||||||
text: D
|
|
||||||
color: aqua
|
|
||||||
WhatsApp:
|
|
||||||
match: "@whatsapp_\d+:.+"
|
|
||||||
text: W
|
|
||||||
color: green
|
|
||||||
|
|
||||||
# Settings that directly affect running the Minecraft server.
|
|
||||||
minecraft:
|
|
||||||
# Confirm the Minecraft EULA. Defaults to false.
|
|
||||||
# eula: true
|
|
||||||
|
|
||||||
# --------------------
|
|
||||||
# MINECRAFT SERVER
|
|
||||||
|
|
||||||
# Exposed port. Defaults to 25565
|
|
||||||
server-port: 25565
|
|
||||||
|
|
||||||
# Maximum amount of players welcome on the server at a time.
|
|
||||||
# Defaults to 20.
|
|
||||||
# max-players: 7
|
|
||||||
|
|
||||||
# Whether to enable command blocks. Defaults to false.
|
|
||||||
# enable-command-block: true
|
|
||||||
|
|
||||||
# Controls how close entities need to be before being sent to clients.
|
|
||||||
# Higher values means they'll be rendered from farther away,
|
|
||||||
# potentially causing more lag.
|
|
||||||
# Value must be between 10 and 1000
|
|
||||||
# entity-broadcast-range-percentage: 150
|
|
||||||
|
|
||||||
# Server description
|
|
||||||
# This is the message that is displayed in the server list of the client,
|
|
||||||
# below the name. It supports color formatting!
|
|
||||||
# Defaults to a Minecraft server.
|
|
||||||
# motd: A Minecraft server
|
|
||||||
|
|
||||||
# --------------------
|
|
||||||
# SECURITY
|
|
||||||
|
|
||||||
# Whether the server appears "online" to clients. Defaults to true.
|
|
||||||
# When set to false, the server appears offline but users can still join.
|
|
||||||
# enable-status: false
|
|
||||||
|
|
||||||
# If the whitelist is reloaded and/or enabled, any online player not on
|
|
||||||
# the whitelist, gets kicked immediately. Defaults to false.
|
|
||||||
# enforce-whitelist: true
|
|
||||||
|
|
||||||
# Hide online players. This effectively hides who's online when looking
|
|
||||||
# at the server's online status. Defaults to false.
|
|
||||||
# hide-online-players: true
|
|
||||||
|
|
||||||
# Server checks connecting players against Minecraft account database.
|
|
||||||
# Set this to false only if the player's server is not connected to the
|
|
||||||
# Internet. Hackers with fake accounts can connect if this is set to false!
|
|
||||||
# If minecraft.net is down or inaccessible, no players can connect if this
|
|
||||||
# is set to true. Setting this variable to off purposely is called "cracking"
|
|
||||||
# a server, and servers that are present with online mode off are called
|
|
||||||
# "cracked" servers, allowing players with unlicensed copies of Minecraft
|
|
||||||
# to join.
|
|
||||||
# Defaults to true.
|
|
||||||
# online-mode: false
|
|
||||||
|
|
||||||
# Sets whether the server sends snoop data regularly
|
|
||||||
# to http://snoop.minecraft.net.
|
|
||||||
# Defaults to true.
|
|
||||||
snooper-enabled: false
|
|
||||||
|
|
||||||
# Enables a whitelist on the server. Defaults to false.
|
|
||||||
# white-list: true
|
|
||||||
|
|
||||||
# --------------------
|
|
||||||
# ANTI ABUSE
|
|
||||||
|
|
||||||
# Allow users to use flight on the server. Defaults to false.
|
|
||||||
# When set to false, players in the air for at least 5 seconds get kicked
|
|
||||||
# allow-flight: true
|
|
||||||
|
|
||||||
# Allow only players with a confirmed Mojang account to join the server.
|
|
||||||
# When set to false, users might have a cracked Minecraft account when joining.
|
|
||||||
# enforce-secure-profile: false
|
|
||||||
|
|
||||||
# If non-zero, players are kicked from the server if they are idle for
|
|
||||||
# more than that many minutes.
|
|
||||||
# Defaults to zero.
|
|
||||||
# player-idle-timeout: 15
|
|
||||||
|
|
||||||
# Enable PvP on the server. Defaults to true.
|
|
||||||
# pvp: false
|
|
||||||
|
|
||||||
# --------------------
|
|
||||||
# WORLD SETTINGS
|
|
||||||
|
|
||||||
# Whether nether portals work. Defaults to true.
|
|
||||||
# allow-nether: false
|
|
||||||
|
|
||||||
# Force players into the "default" gamemode when they (re)join the server.
|
|
||||||
# Defaults to false.
|
|
||||||
# force-gamemode: true
|
|
||||||
|
|
||||||
# Whether structures (such as villages) can be generated. Defaults to true.
|
|
||||||
# generate-structures: false
|
|
||||||
|
|
||||||
# Sets a world seed for the player's world, as in singleplayer.
|
|
||||||
# If omitted, the world generates with a random seed.
|
|
||||||
# level-seed: ''
|
|
||||||
|
|
||||||
# Sets the maximum distance from players that living entities may be located
|
|
||||||
# in order to be updated by the server, measured in chunks in each direction
|
|
||||||
# of the player (radius, not diameter).
|
|
||||||
# Options: 3 - 32. Defaults to 10, which is recommended.
|
|
||||||
# simulation-distance: 5
|
|
||||||
|
|
||||||
# Whether animals can spawn. Defaults to true.
|
|
||||||
# spawn-animals: false
|
|
||||||
|
|
||||||
# Whether monsters can spawn. Defaults to true.
|
|
||||||
# spawn-monsters: false
|
|
||||||
|
|
||||||
# Whether villagers can spawn. Defaults to true.
|
|
||||||
# spawn-npcs: false
|
|
||||||
|
|
||||||
# Determines the side length of the square spawn protection area as 2x+1.
|
|
||||||
# Setting this to 0 disables the spawn protection. A value of 1 protects
|
|
||||||
# a 3×3 square centered on the spawn point. 2 protects 5×5, 3 protects 7×7,
|
|
||||||
# etc. If there are no ops set on the server, the spawn protection is
|
|
||||||
# disabled automatically as well.
|
|
||||||
# Defaults to 16.
|
|
||||||
# spawn-protection: 9
|
|
||||||
|
|
||||||
# --------------------
|
|
||||||
# GAMEPLAY
|
|
||||||
|
|
||||||
# Set the difficulty of the server. Defaults to easy.
|
|
||||||
# Options: peaceful, easy, medium, hard
|
|
||||||
difficulty: easy
|
|
||||||
|
|
||||||
# Default gamemode. Defaults to survival.
|
|
||||||
# Options: survival, creative, adventure, spectator
|
|
||||||
gamemode: survival
|
|
||||||
|
|
||||||
# Enable hardcore mode. Defaults to false.
|
|
||||||
# If set to true, server difficulty is ignored and set to hard,
|
|
||||||
# and players are set to spectator mode when they die.
|
|
||||||
# hardcore: true
|
|
||||||
|
|
||||||
# Maximum view distance. Defaults to 10.
|
|
||||||
# view-distance: 15
|
|
2
main.py
2
main.py
|
@ -13,7 +13,7 @@ STARTUP_TIME = time.time()
|
||||||
client = AsyncClient(config.MATRIX_HOMESERVER, config.MATRIX_USERNAME)
|
client = AsyncClient(config.MATRIX_HOMESERVER, config.MATRIX_USERNAME)
|
||||||
|
|
||||||
async def message_callback(room: MatrixRoom, event: RoomMessageText) -> None:
|
async def message_callback(room: MatrixRoom, event: RoomMessageText) -> None:
|
||||||
if room.machine_name != config.MATRIX_ROOM:
|
if room.machine_name != config.MC_CHANNEL:
|
||||||
return
|
return
|
||||||
if event.sender == client.user_id:
|
if event.sender == client.user_id:
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
aiofiles==23.2.1
|
aiofiles==0.6.0
|
||||||
aiohttp==3.8.5
|
aiohttp==3.7.4.post0
|
||||||
aiohttp-socks==0.7.1
|
aiohttp-socks==0.6.0
|
||||||
aiosignal==1.3.1
|
appdirs==1.4.4
|
||||||
async-timeout==4.0.3
|
async-timeout==3.0.1
|
||||||
attrs==23.1.0
|
attrs==21.2.0
|
||||||
charset-normalizer==3.3.0
|
chardet==4.0.0
|
||||||
frozenlist==1.4.0
|
distlib==0.3.2
|
||||||
future==0.18.3
|
filelock==3.0.12
|
||||||
h11==0.14.0
|
future==0.18.2
|
||||||
h2==4.1.0
|
h11==0.12.0
|
||||||
|
h2==4.0.0
|
||||||
hpack==4.0.0
|
hpack==4.0.0
|
||||||
hyperframe==6.0.1
|
hyperframe==6.0.1
|
||||||
idna==3.4
|
idna==3.2
|
||||||
jsonschema==4.19.1
|
jsonschema==3.2.0
|
||||||
jsonschema-specifications==2023.7.1
|
Logbook==1.5.3
|
||||||
matrix-nio==0.21.2
|
matrix-nio==0.18.3
|
||||||
multidict==6.0.4
|
multidict==5.1.0
|
||||||
pycryptodome==3.19.0
|
pycryptodome==3.10.1
|
||||||
python-socks==2.4.3
|
pyrsistent==0.17.3
|
||||||
PyYAML==6.0.1
|
python-socks==1.2.4
|
||||||
referencing==0.30.2
|
six==1.16.0
|
||||||
rpds-py==0.10.3
|
typing-extensions==3.10.0.0
|
||||||
unpaddedbase64==2.1.0
|
unpaddedbase64==2.1.0
|
||||||
yarl==1.9.2
|
virtualenv==20.4.7
|
||||||
|
yarl==1.6.3
|
||||||
|
|
Loading…
Reference in New Issue