Skip to content

Commit 68918f8

Browse files
jateuteSCDerox
andauthored
feat(Twitch-Notifications): Added live-Roles (#81)
* feat(Twitch-Notifications): Added live-Roles * feat(twitch-notifications): Improved the live-roles * feat(twitch-notifications): Switched to new type Co-authored-by: Simon <[email protected]> * fix(Twitch-Notifications): Fixed an Error Co-authored-by: Simon <[email protected]>
1 parent 4590f58 commit 68918f8

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

locales/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@
433433
},
434434
"twitch-notifications": {
435435
"channel-not-found": "Der Kanal mit der ID %c konnte nicht gefunden werden",
436-
"user-not-on-twitch": "Nutzer %u konnte auf Twitch nicht gefunden werden"
436+
"user-not-on-twitch": "Nutzer %u konnte auf Twitch nicht gefunden werden",
437+
"user-not-found": "Der Benutzer mit der ID %u konnte nicht gefunden werden"
437438
},
438439
"fun": {
439440
"slap-command-description": "Schlägt einen Nutzer ins Gesicht",

locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@
465465
},
466466
"twitch-notifications": {
467467
"channel-not-found": "Channel with ID %c could not be found",
468-
"user-not-on-twitch": "Could not find user %u on twitch"
468+
"user-not-on-twitch": "Could not find user %u on twitch",
469+
"user-not-found": "Could not find the user with the id %u"
469470
},
470471
"hunt-the-code": {
471472
"admin-command-description": "Manage the current Code-Hunt",

modules/twitch-notifications/configs/streamers.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@
7979
"type": "string",
8080
"description-en": "Streamer where a notification should send when they start streaming",
8181
"description-de": "Steamer, bei denen eine Benachrichtigung gesendet werden soll, wenn sie anfangen, zu streamen"
82+
},
83+
{
84+
"field_name": "liveRole",
85+
"humanname-en": "Use Live-Role",
86+
"humanname-de": "Live-Rolle Aktivieren",
87+
"default": false,
88+
"type": "boolean",
89+
"description-en": "Should the Live-Role be activated?",
90+
"description-de": "Soll die Live-Rolle aktiviert sein?"
91+
},
92+
{
93+
"field_name": "id",
94+
"humanname-en": "Discord-User ID",
95+
"humanname-de": "Discord-Benutzer ID",
96+
"default": "",
97+
"type": "userID",
98+
"description-en": "ID of the Discord-Account of the Streamer",
99+
"description-de": "ID des Discord-Accounts des Streamers",
100+
"dependsOn": "liveRole"
101+
},
102+
{
103+
"field_name": "role",
104+
"humanname-en": "Live Role",
105+
"humanname-de": "Live Rolle",
106+
"default": "",
107+
"type": "roleID",
108+
"description-en": "ID of the Role that the Streamer should get, when live",
109+
"description-de": "ID der Rolle, die der streamer bekommen soll, wenn er live ist",
110+
"allowNull": true,
111+
"dependsOn": "liveRole"
82112
}
83113
]
84114
}

modules/twitch-notifications/events/botReady.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ const {localize} = require('../../../src/functions/localize');
1616
function twitchNotifications(client, apiClient) {
1717
const streamers = client.configurations['twitch-notifications']['streamers'];
1818

19+
/**
20+
* Function to add the Live-Role
21+
* @param {string} userID ID of the User
22+
* @param {String} roleID ID of the Role
23+
* @param {boolean} liveRole Should the live-role be active
24+
*/
25+
async function addLiveRole(userID, roleID, liveRole) {
26+
if (!liveRole) return;
27+
if (!userID || userID === '' || !roleID || roleID === '') return;
28+
await client.guild.members.fetch();
29+
const member = client.guild.members.cache.get(userID);
30+
if (!member) {
31+
client.logger.error(localize('twitch-notifications', 'user-not-found', {u: userID}));
32+
return;
33+
}
34+
await member.roles.add(roleID);
35+
}
36+
1937
/**
2038
* Sends the live-message
2139
* @param {string} username Username of the streamer
@@ -75,10 +93,24 @@ function twitchNotifications(client, apiClient) {
7593
startedAt: stream.startDate.toString()
7694
});
7795
sendMsg(stream.userDisplayName, stream.gameName, stream.thumbnailUrl, streamers[index]['liveMessageChannel'], stream.title, index);
96+
addLiveRole(streamers[index]['id'], streamers[index]['role'], streamers[index]['liveRole']);
7897
} else if (stream !== null && stream.startDate.toString() !== streamer.startedAt) {
7998
streamer.startedAt = stream.startDate.toString();
8099
streamer.save();
81100
sendMsg(stream.userDisplayName, stream.gameName, stream.thumbnailUrl, streamers[index]['liveMessageChannel'], stream.title, index);
101+
addLiveRole(streamers[index]['id'], streamers[index]['role'], streamers[index]['liveRole']);
102+
} else if (stream === null) {
103+
if (!streamers[index]['liveRole']) return;
104+
if (!streamers[index]['id'] || streamers[index]['id'] === '' || !streamers[index]['role'] || streamers[index]['role'] === '') return;
105+
await client.guild.members.fetch();
106+
const member = client.guild.members.cache.get(streamers[index]['id']);
107+
if (!member) {
108+
client.logger.error(localize('twitch-notifications', 'user-not-found', {u: streamers[index]['id']}));
109+
return;
110+
}
111+
if (member.roles.cache.has(streamers[index]['role'])) {
112+
await member.roles.remove(streamers[index]['role']);
113+
}
82114
}
83115
}
84116
}

0 commit comments

Comments
 (0)