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

Update Modchecker #241

Closed
wants to merge 3 commits into from
Closed
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
35 changes: 31 additions & 4 deletions src/modchecker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@ class Modchecker extends Addon {
constructor(...args) {
super(...args);
this.inject('chat.badges');
this.inject('settings');

this.domain = 'https://modchecker.com';
this.apiBase = `${this.domain}/api/v1`;
this.badgeBase = this.domain;

this.clickRedirectLink = this.domain;
this.namespace = 'addon.modchecker';
this.badgeIds = new Set();

const autoRefreshId = `${this.name}.refresh_interval`
this.settings.add(autoRefreshId, {
default: 300000,
ui: {
path: 'Add-Ons > Modchecker',
title: 'Refresh interval',
description: 'Seconds between automatic badge refreshes. Set to 0 to disable. (Default: 5 minutes, Minimum: 20 seconds)',
component: 'setting-text-box',
process: 'to_int',
bounds: [0],
},
});
this.settings.getChanges(autoRefreshId, value => this.autoRefresh(value));
}

onEnable() {
this.loadBadges();
}

onDisable() {
this.unloadBadges();
}

async loadBadges() {
const badges = await this.fetchBadgeData();
this.log.info('Loaded', badges.length, 'badges');

for (const badge of badges) {
const badgeId = this.registerBadge(badge);
this.badges.setBulk(this.namespace, badgeId, badge.users);
this.badges.setBulk(this.name, badgeId, badge.users);
}

this.emit('chat:update-lines');
Expand All @@ -39,13 +54,25 @@ class Modchecker extends Addon {
this.emit('chat:update-lines');
}

autoRefresh(secondsInterval) {
clearInterval(this.refreshTimerId);

if (secondsInterval === 0) {
return this.refreshTimerId = null;
} else if (secondsInterval < 20) {
secondsInterval = 20;
}

this.refreshTimerId = setInterval(() => this.loadBadges(), secondsInterval * 1000);
}

createBadgeId(badgeName) {
// 1. translate into lower case
// 2. remove `modchecker` including spaces around
// 3. replace spaces with dashes
badgeName = badgeName.toLowerCase().replace(/\s*modchecker\s*/g, '').replace(/\s+/g, '-');

const badgeId = `${this.namespace}.badge-${badgeName}`;
const badgeId = `${this.name}.badge-${badgeName}`;
this.badgeIds.add(badgeId);
return badgeId;
}
Expand Down
6 changes: 3 additions & 3 deletions src/modchecker/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"enabled": true,
"requires": [],
"version": "1.0",
"version": "1.1",
"short_name": "Modchecker",
"name": "Modchecker",
"author": "MrPandir",
"description": "Adds Modchecker Badges into the Twitch Chat",
"website": "https://modchecker.com",
"created": "2024-08-07T00:00:00.000Z",
"updated": "2024-08-07T00:00:00.000Z"
}
"updated": "2024-08-14T00:00:00.000Z"
}
Loading