Skip to content

Commit

Permalink
refactor(poster): Move borrel mode to gewis handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperVK committed Nov 27, 2024
1 parent 353db9f commit eb001e5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
39 changes: 0 additions & 39 deletions src/modules/handlers/screen/poster/base-poster-screen-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,9 @@ import { TrelloPosterManager } from './trello/trello-poster-manager';
export default class BasePosterScreenHandler extends BaseScreenHandler {
public posterManager: PosterManager;

private borrelModeDay: number | undefined;

public borrelModeInterval: NodeJS.Timeout;

constructor(socket: Namespace) {
super(socket);
this.posterManager = new TrelloPosterManager();

// Check whether we need to enable/disable borrel mode
this.borrelModeInterval = setInterval(this.checkBorrelMode.bind(this), 60 * 1000);
}

public get borrelMode() {
return this.borrelModeDay !== undefined;
}

private checkBorrelMode() {
const now = new Date();

// If borrelmode is enabled, but we arrive at the next day, disable borrelmode again
if (this.borrelMode && this.borrelModeDay !== now.getDay()) {
this.borrelModeDay = undefined;
return;
}
// if borrelmode is enabled, we do not have to check whether we can enable it
if (this.borrelMode) return;

// By default, enable borrelmode on Thursdays 16:30 local time
if (
now.getDay() === 4 &&
((now.getHours() === 16 && now.getMinutes() >= 30) || now.getHours() >= 17)
) {
this.borrelModeDay = now.getDay();
}
}

public setBorrelModeEnabled(enabled: boolean) {
if (enabled) {
this.borrelModeDay = new Date().getDay();
} else {
this.borrelModeDay = undefined;
}
}

forceUpdate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,47 @@ import { Namespace } from "socket.io";


export default class GewisPosterScreenHandler extends BasePosterScreenHandler {
private borrelModeDay: number | undefined;

public borrelModeInterval: NodeJS.Timeout;

constructor(socket: Namespace) {
super(socket);

// Check whether we need to enable/disable borrel mode
this.borrelModeInterval = setInterval(this.checkBorrelMode.bind(this), 60 * 1000);
}


public get borrelMode() {
return this.borrelModeDay !== undefined;
}

private checkBorrelMode() {
const now = new Date();

// If borrelmode is enabled, but we arrive at the next day, disable borrelmode again
if (this.borrelMode && this.borrelModeDay !== now.getDay()) {
this.borrelModeDay = undefined;
return;
}
// if borrelmode is enabled, we do not have to check whether we can enable it
if (this.borrelMode) return;

// By default, enable borrelmode on Thursdays 16:30 local time
if (
now.getDay() === 4 &&
((now.getHours() === 16 && now.getMinutes() >= 30) || now.getHours() >= 17)
) {
this.borrelModeDay = now.getDay();
}
}

public setBorrelModeEnabled(enabled: boolean) {
if (enabled) {
this.borrelModeDay = new Date().getDay();
} else {
this.borrelModeDay = undefined;
}
}
}

0 comments on commit eb001e5

Please sign in to comment.