def test_minetest(num_task): pybotnick = "pt" + mtuser if len(pybotnick) > NICK_MAX_LEN: pybotnick = pybotnick[0:NICK_MAX_LEN] with open_irc(ircserver, mtuser, mtuserpass, mtbotnick, channel, pybotnick=pybotnick) as mc: task = int(mc.send_cmd("get_player_task " + mtuser)) if task > num_task: passed() return True else: failed( "Failed: Check 'Task " + str(num_task) + " Assessment' sign in minetest to find out what else is required") return False
from ircbuilder import open_irc from ircbuilder.building import Building from minetest_irc import ircserver, mtuser, mtuserpass, mtbotnick, channel, player_z b = Building() # player_z has been imported from the configuration file you created in first task ref_z = player_z glass = "default:obsidian_glass" for y in (13, 14, 15): b.build(99, y, ref_z - 1, glass) b.build(99, y, ref_z, glass) b.build(99, y, ref_z + 1, glass) print(y) with open_irc(ircserver, mtuser, mtuserpass, mtbotnick, channel) as mc: b.send(mc) # © Copyright 2018-2021 Triptera Pty Ltd - https://pythonator.com - See LICENSE.txt
def test_config(): # Stepik changes directory structure so check first which directory structure config_dir = "../../" config_file = "minetest_irc.py" if not os.path.exists(f"{config_dir}{config_file}"): if os.path.exists(f"../{config_dir}{config_file}"): config_dir = f"../{config_dir}" config_path = f"{config_dir}{config_file}" logging_config_path = f"{config_dir}logging_config.json" requirements_path = f"{config_dir}requirements.txt" logging_config_final = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'class': 'logging.StreamHandler', }, }, 'root': { 'handlers': ['console'], 'level': 'WARNING', }, } try: from task import logging_config logging_config_final = update(logging_config_final, logging_config) except ImportError: # logging_config not specified so no changes required pass with open(logging_config_path, "w") as file: json.dump(logging_config_final, file) logging.config.dictConfig(logging_config_final) # Check if ircserver is on LAN from task import mtuser, mtuserpass, mtbotnick, ircserver, channel, player_z try: # check if ircbuilder already installed from ircbuilder import open_irc except ImportError: ircbuilder_version = "0.0.11" # will get overridden later if requirements.txt set up properly with open(requirements_path) as file: for line in file: print(line) if line.startswith("ircbuilder>="): ircbuilder_version = line[len("ircbuilder>="):].strip() break if re.fullmatch(r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", ircserver): # install ircbuilder from LAN server logging.warning(f"LAN {ircserver}") subprocess.check_call([ sys.executable, "-m", "pip", "install", f"http://{ircserver}/download/pypi/ircbuilder/ircbuilder-{ircbuilder_version}.tar.gz" ]) else: # install ircbuilder from pypi.org subprocess.check_call([ sys.executable, "-m", "pip", "install", f"ircbuilder>={ircbuilder_version}" ]) with open(config_path, "w") as file: file.write('mtuser = "******" # your minetest username\n') file.write( 'mtuserpass = "******" # your minetest password. This file is not encrypted so don\'t use anything you want kept secret\n' ) file.write( 'player_z = ' + str(player_z) + ' # your z value from sign in minetest with your username on it\n' ) file.write('\n') file.write( '# The following must match your settings in minetest server > Settings > Advanced Settings > Mods > irc > Basic >\n' ) file.write('ircserver = "' + ircserver + '" # same as IRC server\n') file.write('mtbotnick = "' + mtbotnick + '" # same as Bot nickname\n') file.write('channel = "' + channel + '" # same as Channel to join\n') from ircbuilder import open_irc with open_irc(ircserver, mtuser, mtuserpass, mtbotnick, channel, port=6697) as mc: z = mc.send_cmd('get_player_z ' + mtuser) try: if int(z) != player_z: failed("Your player_z should be " + z + ", not " + str(player_z)) return False except TypeError: failed("Didn't get an int for player_z. Instead got " + str(z) + " which has type " + str(type(z))) return False except ValueError: failed("Didn't get an int for player_z. Instead got " + str(z) + " which has type " + str(type(z))) return False passed() return True