Create timeout command (#302)
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- Create timeout command #98 Co-authored-by: Ethan Lane <ethan@vylpes.com> Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/302
This commit is contained in:
parent
46226d37a7
commit
4f2c186244
7 changed files with 1036 additions and 9 deletions
|
@ -13,6 +13,8 @@ export default class AuditTools {
|
|||
return "Kick";
|
||||
case AuditType.Ban:
|
||||
return "Ban";
|
||||
case AuditType.Timeout:
|
||||
return "Timeout";
|
||||
default:
|
||||
return "Other";
|
||||
}
|
||||
|
@ -30,6 +32,8 @@ export default class AuditTools {
|
|||
return AuditType.Kick;
|
||||
case "ban":
|
||||
return AuditType.Ban;
|
||||
case "timeout":
|
||||
return AuditType.Timeout;
|
||||
default:
|
||||
return AuditType.General;
|
||||
}
|
||||
|
|
119
src/helpers/TimeLengthInput.ts
Normal file
119
src/helpers/TimeLengthInput.ts
Normal file
|
@ -0,0 +1,119 @@
|
|||
export default class TimeLengthInput {
|
||||
public readonly value: string;
|
||||
|
||||
constructor(input: string) {
|
||||
this.value = input;
|
||||
}
|
||||
|
||||
public GetDays(): number {
|
||||
return this.GetValue('d');
|
||||
}
|
||||
|
||||
public GetHours(): number {
|
||||
return this.GetValue('h');
|
||||
}
|
||||
|
||||
public GetMinutes(): number {
|
||||
return this.GetValue('m');
|
||||
}
|
||||
|
||||
public GetSeconds(): number {
|
||||
return this.GetValue('s');
|
||||
}
|
||||
|
||||
public GetMilliseconds(): number {
|
||||
const days = this.GetDays();
|
||||
const hours = this.GetHours();
|
||||
const minutes = this.GetMinutes();
|
||||
const seconds = this.GetSeconds();
|
||||
|
||||
let milliseconds = 0;
|
||||
|
||||
milliseconds += seconds * 1000;
|
||||
milliseconds += minutes * 60 * 1000;
|
||||
milliseconds += hours * 60 * 60 * 1000;
|
||||
milliseconds += days * 24 * 60 * 60 * 1000;
|
||||
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
public GetDateFromNow(): Date {
|
||||
const now = Date.now();
|
||||
|
||||
const dateFromNow = now
|
||||
+ (1000 * this.GetSeconds())
|
||||
+ (1000 * 60 * this.GetMinutes())
|
||||
+ (1000 * 60 * 60 * this.GetHours())
|
||||
+ (1000 * 60 * 60 * 24 * this.GetDays());
|
||||
|
||||
return new Date(dateFromNow);
|
||||
}
|
||||
|
||||
public GetLength(): string {
|
||||
const days = this.GetDays();
|
||||
const hours = this.GetHours();
|
||||
const minutes = this.GetMinutes();
|
||||
const seconds = this.GetSeconds();
|
||||
|
||||
const value = [];
|
||||
|
||||
if (days) {
|
||||
value.push(`${days} days`);
|
||||
}
|
||||
|
||||
if (hours) {
|
||||
value.push(`${hours} hours`);
|
||||
}
|
||||
|
||||
if (minutes) {
|
||||
value.push(`${minutes} minutes`);
|
||||
}
|
||||
|
||||
if (seconds) {
|
||||
value.push(`${seconds} seconds`);
|
||||
}
|
||||
|
||||
return value.join(", ");
|
||||
}
|
||||
|
||||
public GetLengthShort(): string {
|
||||
const days = this.GetDays();
|
||||
const hours = this.GetHours();
|
||||
const minutes = this.GetMinutes();
|
||||
const seconds = this.GetSeconds();
|
||||
|
||||
const value = [];
|
||||
|
||||
if (days) {
|
||||
value.push(`${days}d`);
|
||||
}
|
||||
|
||||
if (hours) {
|
||||
value.push(`${hours}h`);
|
||||
}
|
||||
|
||||
if (minutes) {
|
||||
value.push(`${minutes}m`);
|
||||
}
|
||||
|
||||
if (seconds) {
|
||||
value.push(`${seconds}s`);
|
||||
}
|
||||
|
||||
return value.join(" ");
|
||||
}
|
||||
|
||||
private GetValue(designation: string): number {
|
||||
const valueSplit = this.value.split(' ');
|
||||
|
||||
const desString = valueSplit.find(x => x.charAt(x.length - 1) == designation);
|
||||
|
||||
if (!desString) return 0;
|
||||
|
||||
const desNumber = Number(desString.substring(0, desString.length - 1));
|
||||
|
||||
if (!desNumber) return 0;
|
||||
|
||||
return desNumber;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue