Skip to content

Commit

Permalink
Merge pull request #106 from Xayanide/dev-hostskipper-improve-texts-a…
Browse files Browse the repository at this point in the history
…nd-error-messages

refactor(plugins#HostSkipper): improve texts and error messages
  • Loading branch information
Meowhal authored Jun 2, 2022
2 parents 9fe38ff + 427982f commit 37890e5
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/plugins/HostSkipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ export class HostSkipper extends LobbyPlugin {

private onParsedStat(player: Player, result: StatResult, isPm: boolean): void {
if (!isPm && this.lobby.host === player && this.statIsAfk(result.status) && !this.lobby.isMatching) {
this.logger.trace(`passed afk check ${result.name} -> ${StatStatuses[result.status]}`);
this.logger.trace(`Passed an AFK check ${result.name} -> ${StatStatuses[result.status]}`);
if (this.option.afk_check_do_skip) {
this.Skip();
} else {
if (this.isMapChanged) {
this.lobby.SendMessage('bot : players can start the match by !start vote.');
this.lobby.SendMessage('Bot: Players can start the match with !start to vote.');
} else {
this.lobby.SendMessage('bot : players can skip afk host by !skip vote.');
this.lobby.SendMessage('Bot: Players can skip the AFK host with !skip to vote.');
}
}
}
Expand All @@ -135,50 +135,50 @@ export class HostSkipper extends LobbyPlugin {

private vote(player: Player): void {
if (this.voting.passed) {
this.logger.debug(`vote from ${player.name} was ignored, already skipped`);
this.logger.debug(`A host skip vote from player ${player.name} was ignored, already skipped.`);
} else if (this.elapsedSinceHostChanged < this.option.vote_cooltime_ms) {
this.logger.debug(`vote from ${player.name} was ignored, at cool time.`);
this.logger.debug(`A host skip vote from player ${player.name} was ignored, done during cooltime.`);
if (player.isHost) {
const secs = (this.option.vote_cooltime_ms - this.elapsedSinceHostChanged) / 1000;
this.lobby.SendMessage(`skip command is in cooltime. you have to wait ${secs.toFixed(2)} sec(s).`);
this.lobby.SendMessage(`The host skip command is currently in cooltime. You have to wait ${secs.toFixed(2)} sec(s).`);
}
} else if (player.isHost) {
this.logger.debug(`host(${player.name}) sent !skip command`);
this.logger.debug(`The host (Player ${player.name}) sent !skip command.`);
this.Skip();
} else {
if (this.voting.Vote(player)) {
this.logger.trace(`accept skip request from ${player.name}`);
this.logger.trace(`Accepted a host skip request from player ${player.name}`);
this.checkSkipCount(true);
} else {
this.logger.debug(`vote from ${player.name} was ignored, double vote`);
this.logger.debug(`A host skip vote from player ${player.name} was ignored, voted twice.`);
}
}
}

// スキップ状況を確認して、必要数に達している場合は
private checkSkipCount(showMessage: boolean = false): void {
if (this.voting.count !== 0 && showMessage) {
this.lobby.DeferMessage(`bot : Host skip progress: ${this.voting.toString()}`, 'checkSkipCount', this.option.vote_msg_defer_ms, false);
this.lobby.DeferMessage(`Bot: Host skip progress: ${this.voting.toString()}`, 'checkSkipCount', this.option.vote_msg_defer_ms, false);
}
if (this.voting.passed) {
this.lobby.DeferMessage(`bot : Passed skip vote: ${this.voting.toString()}`, 'checkSkipCount', 100, true);
this.lobby.DeferMessage(`Bot: Passed a host skip vote: ${this.voting.toString()}`, 'checkSkipCount', 100, true);
this.Skip();
}
}

Skip(): void {
this.logger.info('do skip');
this.logger.info('Skipping host...');
this.StopTimer();
this.SendPluginMessage('skip');
this.timeHostChanged = Date.now();
}

SkipTo(username: string): void {
if (!this.lobby.Includes(username)) {
this.logger.info(`invalid username @skipto : ${username}`);
this.logger.info(`Cannot skip the host to an invalid username: ${username}`);
return;
}
this.logger.info(`do skipTo : ${username}`);
this.logger.info(`The host has been skipped to: ${username}`);
this.StopTimer();
this.SendPluginMessage('skipto', [username]);
}
Expand All @@ -192,19 +192,19 @@ export class HostSkipper extends LobbyPlugin {
StartTimer(isFirst: boolean): void {
if (this.option.afk_check_interval_ms === 0 || !this.lobby.host || this.lobby.status !== LobbyStatus.Entered || this.lobby.isMatching) return;
this.StopTimer();
this.logger.trace('start afk check timer');
this.logger.trace('Started the AFK check timer.');
const target = this.lobby.host;
this.afkTimer = setTimeout(async () => {
if (!this.lobby.isMatching && this.lobby.host === target) {
try {
const stat1 = await this.lobby.RequestStatAsync(target, true, this.option.afk_check_timeout_ms);
this.logger.trace(`stat check phase 1 ${stat1.name} -> ${StatStatuses[stat1.status]}`);
this.logger.trace(`Stat check phase 1 ${stat1.name} -> ${StatStatuses[stat1.status]}`);
if (this.afkTimer !== undefined && this.lobby.host === target && this.statIsAfk(stat1.status)) {
// double check and show stat for players
await this.lobby.RequestStatAsync(target, false, this.option.afk_check_timeout_ms);
}
} catch {
this.logger.warn('stat check timeout!');
this.logger.warn('Stat check timed out!');
}
// StopTimerが呼び出されていない、かつホストがターゲットと同じならタイマー再開
if (this.afkTimer !== undefined && this.lobby.host === target) {
Expand All @@ -216,7 +216,7 @@ export class HostSkipper extends LobbyPlugin {

StopTimer(): void {
if (this.afkTimer !== undefined) {
this.logger.trace('stop timer');
this.logger.trace('Stopping the AFK Check timer...');
clearTimeout(this.afkTimer);
this.afkTimer = undefined;
}
Expand All @@ -227,6 +227,8 @@ export class HostSkipper extends LobbyPlugin {
}

GetPluginStatus(): string {
return `-- Host Skipper -- timer : ${this.afkTimer !== undefined ? 'active' : '###'}, skip_vote : ${this.voting.toString()}`;
return `-- Host Skipper --
Timer: ${this.afkTimer !== undefined ? 'Active' : '###'}
Skip vote: ${this.voting.toString()}`;
}
}

0 comments on commit 37890e5

Please sign in to comment.