@ginstone/nga-api
Version:
85 lines (84 loc) • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CanceledLog = exports.PunishmentLog = exports.RewardLog = exports.ReputationLog = exports.LastEdit = exports.AlterInfo = void 0;
const TimeUtils_1 = require("../../utils/TimeUtils");
const ReputationLogType_1 = require("../../enums/ReputationLogType");
const reg = /\[(.+?)]/g;
class AlterInfo {
constructor(s) {
let matcher;
while (matcher = reg.exec(s)) {
const group = matcher[1].toString();
const split = group.substring(1).split(" ");
const type = group.charAt(0);
switch (type) {
case 'E':
this.lastEdit = new LastEdit(split);
break;
case 'A':
this.logs = this.logs ? this.logs : [];
this.logs.push(new RewardLog(split));
break;
case 'L':
this.logs = this.logs ? this.logs : [];
this.logs.push(new PunishmentLog(split));
break;
case 'U':
this.logs = this.logs ? this.logs : [];
this.logs.push(new CanceledLog(split));
break;
default:
console.warn("未识别的操作类型: " + group);
}
}
}
}
exports.AlterInfo = AlterInfo;
class LastEdit {
constructor(s) {
const [second, id, name] = s;
this.timestamp = (0, TimeUtils_1.secondsToDate)(parseInt(second));
if (!isNaN(parseInt(id)) && "0" !== id) {
this.userId = parseInt(id);
this.username = name;
}
}
}
exports.LastEdit = LastEdit;
/**
* 声望操作日志
*/
class ReputationLog {
constructor(reputation, prestige, type, money) {
this.reputation = reputation;
this.prestige = prestige;
this.money = money;
this.type = type;
}
}
exports.ReputationLog = ReputationLog;
class RewardLog extends ReputationLog {
constructor(split) {
super(Number(split[0]), Number(split[1]) * 10, ReputationLogType_1.ReputationLogType.reward, Number(split[2]) * 10000);
this.reason = split.length > 4 ? split[4] : undefined;
}
}
exports.RewardLog = RewardLog;
class PunishmentLog extends ReputationLog {
constructor(split) {
super(parseInt(split[3]) * -1, parseInt(split[4]) * -1, ReputationLogType_1.ReputationLogType.punishment, Number(split[2]) * 10000);
if (split[1] !== "0")
this.forumId = Number(split[1]);
this.days = parseInt(split[0]);
this.reason = split.length > 5 ? split[5] : undefined;
}
}
exports.PunishmentLog = PunishmentLog;
class CanceledLog extends ReputationLog {
constructor(split) {
super(parseInt(split[0]), parseInt(split[1]), ReputationLogType_1.ReputationLogType.canceled, Number(split[2]) * 10000);
if (split[3])
this.remark = split[3];
}
}
exports.CanceledLog = CanceledLog;