Umi.User = function(userId, userName, userColour, userPerms) {
    userId = (userId || '').toString();
    userColour = (userColour || 'inherit').toString();

    const userIdInt = parseInt(userId);

    const setName = name => {
        userName = (name || '').toString().replace('&lt;', '<').replace('&gt;', '>');
    };
    setName(userName);

    const setColour = colour => {
        userColour = (colour || 'inherit').toString();
    };
    setColour(userColour);

    let userRank = 0;
    let canBan = false;
    let canSetNickName = false;
    let canCreateChannel = false;

    const setPerms = function(perms) {
        perms = (perms || '').toString();
        perms = perms.split(perms.includes("\f") ? "\f" : ' ');

        userRank = parseInt(perms[0] || 0);
        canBan = (perms[1] || '0') === '1';
        canSetNickName = (perms[3] || '0') === '1';
        canCreateChannel = (perms[4] || '0') === '1' || (perms[4] || '0') === '2';
    };
    setPerms(userPerms);

    let avatarTime = Date.now();

    return {
        getId: () => userId,
        getIdInt: () => userIdInt,

        getName: () => userName,
        setName: setName,

        getColour: () => userColour,
        setColour: setColour,

        setPermissions: setPerms,

        getRank: () => userRank,
        isCurrentUser: () => Umi.User.currentUser && Umi.User.currentUser.userId === userId,
        canBan: () => canBan,
        canSilence: () => canBan,
        canCreateChannel: () => canCreateChannel,
        canSetNickName: () => canSetNickName,
        getAvatarTime: () => avatarTime,
        bumpAvatarTime: () => { avatarTime = Date.now(); },

        isBot: () => userId === '-1',
    };
};
Umi.User.currentUser = undefined;
Umi.User.hasCurrentUser = () => Umi.User.currentUser !== undefined;
Umi.User.getCurrentUser = () => Umi.User.currentUser;
Umi.User.setCurrentUser = user => { Umi.User.currentUser = user; };
Umi.User.isCurrentUser = user => user !== null && typeof user === 'object' && typeof user.getId === 'function'
    && Umi.User.currentUser !== null && typeof Umi.User.currentUser === 'object'
    && typeof Umi.User.currentUser.getId === 'function'
    && (Umi.User.currentUser === user || Umi.User.currentUser.getId() === user.getId());
