コード例 #1
0
 async def parse_command(self, args):
     try:
         if len(args) == 0:
             await self.no_command()
             return
         for i in self.commands:
             if i == args[0]:
                 await self.commands[i]["onCommand"](args[1:])
                 return
             for j in self.commands[i]["command"].alias:
                 if j == args[0]:
                     await self.commands[i]["onCommand"](args[1:])
                     return
         await self.ws.send(message_utils.error(ref_strings.unknown_command)
                            )
     except AssertionError as e:
         await self.ws.send(message_utils.error(ref_strings.fatal_exception)
                            )
         traceback.print_exc()
         sys.exit(-1)
     except Exception as e:
         await self.ws.send(message_utils.error(ref_strings.exception))
         await self.ws.send(
             message_utils.error('{0}: {1}'.format(type(e).__name__, e)))
         await self.ws.recv()
         traceback.print_exc()
コード例 #2
0
 async def open_file(self, args):
     if len(args) == 0:
         return
     try:
         arg1 = int(args[0])
         if arg1 < len(self.file_list):
             if not os.path.exists(self.file_list[arg1]):
                 await self.reload(args)
                 return
             self.index = arg1
             await self.open(arg1)
         else:
             await self.ws.send(
                 message_utils.error(ref_strings.file_not_exists))
     except ValueError:
         await self.ws.send(message_utils.error(ref_strings.invaild_id))
コード例 #3
0
 async def from_url(self, args):
     await self.ws.send(
         message_utils.info(ref_strings.pixel.download_image.format(
             args[0])))
     if len(args) == 0:
         return
     code = downloader.download_midi(args[0])
     if code[0] == -1:
         await self.ws.send(
             message_utils.error(ref_strings.pixel.web_error.format(
                 args[0])))
         return
     if code[0] == 1:
         await self.ws.send(
             message_utils.error(
                 ref_strings.pixel.mime_error.format(code[1])))
         return
     await self.open('files/cache/midi')
コード例 #4
0
 async def from_url(self, args):
     pos = await self.we.getPlayerBlockPos()
     await self.ws.send(
         message_utils.info(ref_strings.pixel.download_image.format(
             args[0])))
     if len(args) == 0:
         return
     code = downloader.download_image(args[0])
     if code[0] == -1:
         await self.ws.send(
             message_utils.error(ref_strings.pixel.web_error.format(
                 args[0])))
         return
     if code[0] == 1:
         await self.ws.send(
             message_utils.error(
                 ref_strings.pixel.mime_error.format(code[1])))
         return
     await self.generate('files/cache/img', pos)
コード例 #5
0
    async def parseCmd(self, args):
        if args[0] == ".set":
            if (len(args) == 1 or args[1] == ''):
                await self.ws.send(
                    message_utils.error(ref_strings.command_error))
                return
            if args[1] == "1":
                self.pos1 = await self.getPlayerBlockPos()
                if self.pos2 == None:
                    self.pos2 = self.pos1
                await self.ws.send(
                    message_utils.info(
                        ref_strings.worldedit.coor_1_msg.format(
                            str(self.pos1), self.pos1 * self.pos2)))
            if args[1] == "2":
                self.pos2 = await self.getPlayerBlockPos()
                if self.pos1 == None:
                    self.pos1 = self.pos2
                await self.ws.send(
                    message_utils.info(
                        ref_strings.worldedit.coor_2_msg.format(
                            str(self.pos2), self.pos1 * self.pos2)))
            await self.ws.send(message_utils.autocmd('closechat'))

        if args[0] == ".fill":
            if (len(args) == 1 or args[1] == ''):
                await self.ws.send(
                    message_utils.error(ref_strings.command_error))
                return
            if self.pos1 == None or self.pos2 == None:
                await self.ws.send(
                    message_utils.error(ref_strings.worldedit.no_coordinate))
                return
            if len(args) == 2:
                result = await self.fillAny(args[1])
            else:
                result = await self.fillAny(args[1], args[2])
            if result["success"]:
                await self.ws.send(message_utils.info(result["data"]))
            else:
                await self.ws.send(message_utils.error(result["data"]))
コード例 #6
0
 async def search_file(self, args):
     if len(args) == 0:
         await self.ws.send(message_utils.error(ref_strings.search_error))
         return
     results = self.search(args)
     if len(results) == 0:
         await self.ws.send(message_utils.info(ref_strings.empty_result))
     else:
         string = '\n'
         for i in results:
             string += ref_strings.list_format.format(i[0], i[1]) + '\n'
         await self.ws.send(message_utils.info(string))
コード例 #7
0
 async def set_mode(self, args):
     if len(args) > 0:
         if args[0] in self.modes:
             self.config['mode'] = args[0]
             await self.ws.send(
                 message_utils.info(
                     ref_strings.pixel.set_mode.format(self.config['mode']))
             )
         else:
             await self.ws.send(
                 message_utils.error(ref_strings.pixel.invaild_mode))
     else:
         await self.ws.send(
             message_utils.info(
                 ref_strings.pixel.current_mode.format(self.config['mode']))
         )
コード例 #8
0
    def run(self):
        while True:
            if self.playing:
                self.isPlaying = True
                try:
                    if self.mcsMode:
                        self.play_mcs()
                    else:
                        self.play_midi()

                    if self.isPlaying:
                        if self.config['loop'] == 'song':
                            continue
                        else:
                            while True:
                                self.index += 1
                                if self.index > (len(self.file_list) - 1):
                                    self.index = 0
                                try:
                                    message_utils.runmain(
                                        self.open(self.index, False))
                                    break
                                except:
                                    message_utils.warning(
                                        'unable to open file ' +
                                        self.file_list[self.index])
                                    continue
                except Exception as e:
                    message_utils.runmain(self.ws.send(message_utils.error(e)))
                    self.playing = False
                    self.isPlaying = False
                    if self.config['loop'] != 'song':
                        self.index += 1
                        message_utils.runmain(self.open(self.index, True))
            else:
                time.sleep(0.05)
コード例 #9
0
    async def host_only(self, args):
        await self.we.parseCmd(args)

        if args[0] == ".getscore":
            await self.ws.send(
                message_utils.autocmd("scoreboard players list @s"))
            msg2 = json.loads(await self.ws.recv())
            match = re.findall(scoreRegex,
                               msg2.get("body").get("statusMessage"))
            out = {}
            for i in match:
                out[i[2]] = i[4]
            print(out)

        if args[0] == ".pixelart" and import_pixel:
            try:
                await self.pixelgen.parse_command(args[1:])
            except FileNotFoundError:
                await self.ws.send(
                    message_utils.error(ref_strings.file_not_exists))

        if args[0] == ".test":
            pass

        if args[0] == ".debug":
            if len(args) == 1:
                return
            if args[1] == '0':
                message_utils.log_command = False
            elif args[1] == '1':
                message_utils.log_command = True

        if args[0] == '.exit':
            await self.ws.send(message_utils.info('bye!'))
            raise KeyboardInterrupt

        if args[0] == '.copy':
            origin = worldedit.Position(2, 71, 10)
            destination = worldedit.Position(-60, 4, -75)
            for i in range(100):
                isEnd = await self.we.isBlock(
                    worldedit.Position(origin.x + i * 2, origin.y - 1,
                                       origin.z), 'command_block')
                if isEnd:
                    break
                for j in range(4):
                    for k in range(31):
                        detectPosition = worldedit.Position(
                            origin.x + i * 2, origin.y + k, origin.z + j * 2)
                        isBlock = await self.we.isBlock(
                            detectPosition, 'command_block')
                        isBlock2 = await self.we.isBlock(
                            detectPosition, 'chain_command_block')
                        if isBlock or isBlock2:
                            await self.we.copyBlock(
                                detectPosition,
                                worldedit.Position(destination.x - (j + i * 4),
                                                   destination.y + k,
                                                   destination.z))
                        else:
                            break

        if args[0] == '.save':
            self.save()
コード例 #10
0
    async def parse_command(self, msg):
        if msg["header"]["messagePurpose"] == "event":

            if msg["body"]["eventName"] == "PlayerMessage" and msg["body"][
                    "properties"]['MessageType'] == 'chat':

                self.log.log(msg)

                raw = message_utils.getChat(msg)

                args = raw.split(" ")

                executor = msg["body"]["properties"]["Sender"]

                if executor == self.log.host:
                    await self.host_only(args)

                if args[0] == ".info":
                    await self.ws.send(
                        message_utils.info(ref_strings.mcws.info))
                    await self.ws.send(
                        message_utils.info(ref_strings.pyversion))

                if args[0] == ".help":
                    for i in ref_strings.mcws.help:
                        await self.ws.send(
                            message_utils.info(i + " - " +
                                               ref_strings.mcws.help[i]))

                if args[0] == ".function":
                    arg1 = raw[10:]
                    if arg1 == "-ls":
                        for filename in glob.glob(
                                "files/functions/*.mcfunction"):
                            await self.ws.send(message_utils.info(filename))
                    else:
                        if os.path.exists("functions/" + arg1 + ".mcfunction"):
                            with open("functions/" + arg1 + ".mcfunction",
                                      "r") as file:
                                for i in file.readlines():
                                    await self.ws.send(message_utils.autocmd(i)
                                                       )
                        else:
                            await self.ws.send(
                                message_utils.error(
                                    ref_strings.file_not_exists))

                if args[0] == ".midi" and import_midiplayer:
                    await self.player.parse_command(args[1:])

                if args[0] == ".sier":
                    pass
                    '''
                    px = 50200
                    py = 100
                    pz = 50000
                    for x in range(-50, 50):
                        for z in range(-50, 50):
                            y = x ^ z
                            await ws.send(setBlock(px + x, py + y, pz + z, "redstone_block"))
                            time.sleep(0.001)'''

        elif msg["header"]["messagePurpose"] == "commandResponse":
            pass