Пример #1
0
def menu(screen, tasks, header=None):
    if not header: header = []
    task = None
    args = (screen,)
    while task is None:
        screen.clear()
        for item in header:
            if item is None: continue
            if isinstance(item, tuple):
                addstr(screen, "{}".format(item[0]), item[1])
            else:
                addstr(screen, "{}".format(item))
        for k, v in tasks.items():
            if len(v) > 2:
                addstr(screen, "{}. {}".format(k, v[0]), v[1])
            else:
                addstr(screen, "{}. {}".format(k, v[0]))
        data = get_str(screen)
        if not data.isnumeric(): continue
        data = int(data)
        if data not in tasks: continue
        selected_task = tasks[data]
        task = selected_task[1 if len(selected_task) < 3 else 2]
        if len(task) > 1: args = tuple(task[1:])
        task = task[0]
    if task is None: return menu(screen, tasks, header)
    task(*args)
Пример #2
0
def convert_from(screen):
    ess_dir = get_dir(screen,
                      header=[
                          ("You are converting from Essentials to RoyalCommands.", A_BOLD),
                          "Please fill out the following information in order to do so!",
                      ],
                      prompt="Essentials userdata directory path [Essentials/userdata]:\n",
                      default="Essentials/userdata",
                      clear=True)
    rcmds_dir = get_dir(screen,
                        prompt="RoyalCommands userdata directory path [RoyalCommands/userdata]:\n",
                        default="RoyalCommands/userdata",
                        clear=True)
    try:
        curs_set(0)
    except curses_error:
        pass
    uuids = CaseInsensitiveDict()
    do_later = []  # those without UUIDs already grabbed
    screen.clear()
    addstr(screen, "Scraping file for UUID: ")
    yx = screen.getyx()
    for f in listdir(ess_dir):
        if f[-4:].lower() != ".yml": continue
        screen.move(yx[0], yx[1])
        screen.clrtoeol()
        addstr(screen, f, newline=False)
        screen.refresh()
        ess_data = load(open("{}/{}".format(ess_dir, f), "r"), Loader=Loader)
        if not "uuid" in ess_data:
            do_later.append(f)
            continue
        uuids[f[-4:]] = str(UUID(ess_data['uuid']))
    do_later_chunks = list(chunks(do_later, 100))
    for i in range(len(do_later_chunks)):
        lst = do_later_chunks[i]
        screen.clear()
        addstr(screen,
               "({}/{}) Scraping Mojang's servers for UUIDs for {} player{}."
               .format(
                   i + 1,
                   len(do_later_chunks),
                   len(lst),
                   "" if len(lst) == 1 else "s"
               )
        )
        screen.refresh()
        data = []
        for player in lst:
            data.append({
                "name": player[:-4],
                "agent": "minecraft"
            })
        j = post("https://api.mojang.com/profiles/page/1",
                 data=dumps(data),
                 headers={"Content-Type": "application/json"}
                ).json()
        for profile in j['profiles']:
            uuids[profile['name']] = str(UUID(profile['id']))
    screen.clear()
    addstr(screen, "Converting userdata in file: ")
    yx = screen.getyx()
    for f in listdir(ess_dir):
        if f[-4:].lower() != ".yml": continue
        screen.move(yx[0], yx[1])
        screen.clrtoeol()
        addstr(screen, f, newline=False)
        screen.refresh()
        name = f[:-4]
        ess_data = load(open("{}/{}".format(ess_dir, f), "r"))
        if name not in uuids:
            continue
        rcmds_file = open("{}/{}.yml".format(rcmds_dir, uuids[name]), "w")
        converted = convert(ess_data, get_conversion())
        if "name" not in converted: converted['name'] = f[:-4]
        rcmds_file.write(dump(converted, default_flow_style=False, Dumper=Dumper))
        rcmds_file.flush()
        rcmds_file.close()
    screen.clear()
    addstr(screen, "Finished!", A_BOLD)
    addstr(screen, "Thank you for using RoyalCommands.")
    addstr(screen, "Press any key to exit.")
    noecho()
    cbreak()
    screen.getch()
Пример #3
0
def convert_to(screen):
    ess_dir = get_dir(screen,
                      header=[
                          ("You are converting from RoyalCommands to Essentials.", A_BOLD),
                          "Please fill out the following information in order to do so!",
                      ],
                      prompt="Essentials userdata directory path [Essentials/userdata]:",
                      default="Essentials/userdata",
                      clear=True)
    rcmds_dir = get_dir(screen,
                        prompt="RoyalCommands userdata directory path [RoyalCommands/userdata]:",
                        default="RoyalCommands/userdata",
                        clear=True)
    try:
        curs_set(0)
    except curses_error:
        pass
    names = CaseInsensitiveDict()
    do_later = []
    screen.clear()
    addstr(screen, "Scraping file for name: ")
    yx = screen.getyx()
    for f in listdir(rcmds_dir):
        if f[-4:].lower() != ".yml": continue
        uuid = UUID(f[:-4]).hex
        screen.move(yx[0], yx[1])
        screen.clrtoeol()
        addstr(screen, f, newline=False)
        screen.refresh()
        rcmds_data = load(open("{}/{}".format(rcmds_dir, f), "r"), Loader=Loader)
        if not "name" in rcmds_data:
            do_later.append(f)
            continue
        names[uuid] = rcmds_data['name']
    do_later_len = len(do_later)
    for i in range(len(do_later)):
        uuid = do_later[i][:-4]
        screen.clear()
        addstr(screen,
               "({}/{}) Scraping Mojang's servers for name for {}."
               .format(
                   i + 1,
                   do_later_len,
                   uuid
               )
        )
        screen.refresh()
        j = get("https://sessionserver.mojang.com/session/minecraft/profile/{}".format(uuid))
        names[j['id']] = j['name']
    screen.clear()
    addstr(screen, "Converting userdata in file: ")
    yx = screen.getyx()
    for f in listdir(rcmds_dir):
        if f[-4:].lower() != ".yml": continue
        screen.move(yx[0], yx[1])
        screen.clrtoeol()
        addstr(screen, f, newline=False)
        screen.refresh()
        uuid = UUID(f[:-4]).hex
        rcmds_data = load(open("{}/{}".format(rcmds_dir, f), "r"))
        ess_file = open("{}/{}.yml".format(ess_dir, names[uuid]), "w")
        ess_file.write(
            dump(convert_backwards(rcmds_data, get_conversion()), default_flow_style=False, Dumper=Dumper))
        ess_file.flush()
        ess_file.close()
    screen.clear()
    addstr(screen, "Finished!", A_BOLD)
    addstr(screen, "Thank you for using RoyalCommands.")
    addstr(screen, "Press any key to exit.")
    noecho()
    cbreak()
    screen.getch()