Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record a member's parole date right before banning them. #85

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async function UpdateTrial(cu) {
}
let outcomeString = 'NOT GUILTY';
const guilty = VoteDuration.SimpleMajority(yesVoteCount, noVoteCount);
let banPardonTime;
if (guilty) {
// How guilty the defendant is based on the vote margin. Ranges between 0 and 1.
// One extra "mercy vote" is added to the denominator. This creates a bias in the
Expand All @@ -144,6 +145,8 @@ async function UpdateTrial(cu) {
const degrees90 = 0.5 * Math.PI;
const radians = howGuilty * degrees90;
const sentenceYears = Math.tan(radians);
const banLengthInSeconds = Math.round(sentenceYears * 365.25 * 86400);
banPardonTime = moment().add(banLengthInSeconds, 'seconds').format();
outcomeString = 'banned for ' + SentenceLengthAsString(sentenceYears);
}
const caseTitle = `THE GOVERNMENT v ${cu.getNicknameWithInsignia()}`;
Expand Down Expand Up @@ -190,6 +193,7 @@ async function UpdateTrial(cu) {
if (guilty) {
// Record the conviction even if the member has left. That way if they rejoin we can kick them back out.
await cu.setBanConvictionTime(currentTime.format());
await cu.setBanPardonTime(banPardonTime);
}
if (guilty && member != null) {
console.log('About to ban a guild member.');
Expand All @@ -208,7 +212,7 @@ async function UpdateTrial(cu) {
`${underline}\n` +
`Voting YES to ban: ${yesVoteCount}\n` +
`Voting NO against the ban:${noVoteCount}\n\n` +
`${cu.getNicknameWithInsignia()} is ${outcomeString}.` +
`${cu.getNicknameWithInsignia()} is ${outcomeString}` +
`${threeTicks}`
);
await message.edit(trialSummary);
Expand Down Expand Up @@ -389,6 +393,7 @@ async function HandleConvictCommand(discordMessage) {
return;
}
await defendantUser.setBanConvictionTime(moment().format());
await defendantUser.setBanPardonTime(moment().add(365, 'days').format());
const guild = await DiscordUtil.GetMainDiscordGuild();
try {
const defendantMember = await guild.members.resolve(defendantUser.discord_id);
Expand Down
12 changes: 11 additions & 1 deletion commissar-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class CommissarUser {
ban_vote_message,
yen,
inactivity_tax_paid_until,
ban_conviction_time) {
ban_conviction_time,
ban_pardon_time) {
this.commissar_id = commissar_id;
this.discord_id = discord_id;
this.nickname = nickname;
Expand All @@ -48,6 +49,7 @@ class CommissarUser {
this.yen = parseInt(yen);
this.inactivity_tax_paid_until = inactivity_tax_paid_until;
this.ban_conviction_time = ban_conviction_time;
this.ban_pardon_time = ban_pardon_time;
}

async setDiscordId(discord_id) {
Expand Down Expand Up @@ -224,6 +226,14 @@ class CommissarUser {
await this.updateFieldInDatabase('ban_conviction_time', this.ban_conviction_time);
}

async setBanPardonTime(ban_pardon_time) {
if (ban_pardon_time === this.ban_pardon_time) {
return;
}
this.ban_pardon_time = ban_pardon_time;
await this.updateFieldInDatabase('ban_pardon_time', this.ban_pardon_time);
}

async updateFieldInDatabase(fieldName, fieldValue) {
//console.log(`DB update ${fieldName} = ${fieldValue} for ${this.nickname} (ID:${this.commissar_id}).`);
const sql = `UPDATE users SET ${fieldName} = ? WHERE commissar_id = ?`;
Expand Down
1 change: 1 addition & 0 deletions setup-database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE TABLE users
yen INT, -- How many yen this user has. yen are for-fun currency.
inactivity_tax_paid_until TIMESTAMP, -- Last time this user was taxed.
ban_conviction_time TIMESTAMP, -- When this user was convicted & banned in ban court.
ban_pardon_time TIMESTAMP, -- When this user was convicted & banned in ban court.
PRIMARY KEY (commissar_id),
INDEX discord_index (discord_id)
);
Expand Down
1 change: 1 addition & 0 deletions user-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function LoadAllUsersFromDatabase() {
row.yen,
row.inactivity_tax_paid_until,
row.ban_conviction_time,
row.ban_pardon_time,
);
newCache[row.commissar_id] = newUser;
});
Expand Down
Loading