Permission and DPermitter

fukurou

the supreme coder
ADMIN
translate from java to python

Java:
package LG_Core;
public class Permission {
    /*
     * uses two names as lv1,2 permission levels
     * requires password to change password or said names
     */
    private static Permission singleton;
    private String password, lv1Name, lv2Name;
    private int permissionLevel;

    private Permission(String password, String lv1Name, String lv2Name) {
        super();
        this.password = password;
        this.lv1Name = lv1Name;
        this.lv2Name = lv2Name;
    }

    public static Permission newInstance(String password, String lv1Name, String lv2Name) {
        if (singleton == null) {
            singleton = new Permission(password, lv1Name, lv2Name);
        }
        return singleton;
    }

    public int getPermissionLevel() {
        int result = this.permissionLevel;
        this.permissionLevel = 0;
        return result;
    }

    public void setPermissionLevel(String input) {
        if (input.contains(this.lv2Name)) {
            this.permissionLevel = 2;
        } else if (input.contains(this.lv1Name)) {
            this.permissionLevel = 1;
        }
        if (input.contains(this.lv2Name + " reset")) {
            this.permissionLevel = 0;
        }
    }

    public Boolean setPassword(String oldPassword, String newPassword) {
        if (this.password.equals(oldPassword)) {
            this.password = newPassword;
            return true;
        }
        return false;
    }

    public Boolean setLv2Name(String password, String newName2) {
        if (this.password.equals(password)) {
            this.lv2Name = newName2;
            return true;
        }
        return false;
    }

    public String getLv1Name() {
        return lv1Name;
    }

    public String getLv2Command(String command) {
        // returns cmd without lv2 name
        String result = command;
        result = result.replace(this.lv2Name, "");
        return result.trim();
    }
    public Boolean setLv1Name(String password, String newName) {
        if (this.password.equals(password)) {
            this.lv1Name = newName;
            return true;
        }
        return false;
    }

    public static String clsmsg() {
        return "chaos ritual\r\n" + "\r\n" + "create two names\r\n" + "one soul will be called to the light\r\n"
                + "and one will be led by the darkness\r\n"
                + "and those souls of light and darkness will combine to create\r\n" + "the light of chaos\r\n"
                + "...\r\n" + "A.G.I descended!";
    }
}

Java:
package LG_Core;


import java.util.ArrayList;

/* handles permissions using 2 names for the chobit :
 * name one : permission lv1 (engages with friend)
 * name 2 : permission level2 (for doing things with the owner only)
 * */
public class DPermitter extends AbsCmdReq implements Neuronable {
    /*
     * conjuratis : change pass : oldPass new password newPassword change lv1 name :
     * pass your name is newName change lv2 name : pass you are newName
     */
    Permission permission;
    private int permissionLevel = 2;
    private int relevantCase = 0;
    private RegexUtil regexer = new RegexUtil();
    public DPermitter(Permission permission) {
        super();
        this.permission = permission;
    }

    @Override
    public void output(Neuron noiron) {
        switch (this.relevantCase) {
            case 1:
                requipSayAlg(noiron, permission.getLv1Name());
                break;
            case 2:
                requipSayAlg(noiron, "got it");
                break;
            case 3:
            requipSayAlg(noiron, "new nickname has been established");
                break;
            case 4:
            requipSayAlg(noiron, "new password accepted");
                break;
            default:
                break;
        }
        this.relevantCase = 0;
    }

    @Override
    public void input(String ear, String skin, String eye) {
        permission.setPermissionLevel(ear);
        this.permissionLevel = this.permission.getPermissionLevel();
        if (ear.contains("what is your name")) {
            this.relevantCase = 1;
            return;
        }
        String password = regexer.regexChecker("(\\w+)(?= you are)", ear);
        String newName = regexer.regexChecker("(?<=you are)(.*)", ear);
        if (permission.setLv2Name(password, newName)) {
            this.relevantCase = 2;
            return;
        }
        ;
        password = regexer.regexChecker("(\\w+)(?= your name is)", ear);
        newName = regexer.regexChecker("(?<=your name is)(.*)", ear);
        if (permission.setLv1Name(password, newName)) {
            this.relevantCase = 3;
            return;
        }
        ;
        String oldPass = regexer.regexChecker("(\\w+)(?= new password)", ear);
        String newPass = regexer.regexChecker("(?<=new password)(.*)", ear);
        if (permission.setPassword(oldPass, newPass)) {
            this.relevantCase = 4;
            return;
        }
        ;
    }

    public int getPermissionLevel() {
        return permissionLevel;
    }

    private void requipSayAlg(Neuron noiron, String replay) {
        AbsAlgPart itte = new APSay(1, replay);
        ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
        algParts1.add(itte);
        String represantation = "say " + replay;
        Algorithm algorithm = new Algorithm("say", represantation, algParts1);
        noiron.algParts.add(algorithm);
    }
}
 
Top