Skip to content
Merged
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
3 changes: 2 additions & 1 deletion default-locales.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@
},
"twitch-notifications": {
"channel-not-found": "Channel with ID %c could not be found",
"user-not-on-twitch": "Could not find user %u on twitch"
"user-not-on-twitch": "Could not find user %u on twitch",
"message-not-found": "The Message for the Streamer %s is invalid"
},
"economy-system": {
"work-earned-money": "The user %u gained %m %c by working",
Expand Down
58 changes: 0 additions & 58 deletions modules/twitch-notifications/configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,6 @@
"humanname-de": "Konfiguration",
"humanname-en": "Configuration",
"content": [
{
"field_name": "liveMessage",
"humanname-de": "Live-Nachricht",
"humanname-en": "Live-Messages",
"default-en": "Hey, %streamer% is live on Twitch streaming %game%! Check it out: %url%",
"default-de": "Hi, %streamer% ist Live auf Twitch und streamt %game%! Jetzt anschauen: %url%",
"type": "string",
"allowEmbed": true,
"description-en": "Message that gets send if the streamer goes live",
"description-de": "Nachricht, die gesendet wird, wenn ein Streamer anfängt zu streamen",
"params-en": [
{
"name": "%streamer%",
"description": "Name of the Streamer"
},
{
"name": "%game%",
"description": "Game which is streamed"
},
{
"name": "%url%",
"description": "Link to the stream"
}
],
"params-de": [
{
"name": "%streamer%",
"description": "Name des Streamers"
},
{
"name": "%game%",
"description": "Spiel, welches gestreamt wird"
},
{
"name": "%url%",
"description": "Link zum Twitch-Stream"
}
]
},
{
"field_name": "liveMessageChannels",
"humanname-en": "Channel",
"default": [],
"type": "array",
"content": "channelID",
"description-en": "Channel in which live-messages should get sent",
"description-de": "Kanal, in welchen Benachrichtigungen gesendet werden sollen"
},
{
"field_name": "twitchClientID",
"default": "",
Expand All @@ -65,16 +17,6 @@
"type": "string",
"description": "Secret of the Twitch-Client, which is used to check if the Streamer is live"
},
{
"field_name": "streamers",
"humanname-en": "Streamers",
"humanname-de": "Streamer",
"default": [],
"type": "array",
"content": "string",
"description-en": "Streamers where a notification should send when they start streaming",
"description-de": "Steamer, bei denen eine Benachrichtigung gesendet werden soll, wenn sie anfangen, zu streamen"
},
{
"field_name": "interval",
"default": 180,
Expand Down
64 changes: 64 additions & 0 deletions modules/twitch-notifications/configs/streamers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"filename": "streamers.json",
"humanname-de": "Streamers",
"humanname-en": "Streamers",
"configElements": true,
"content": [
{
"field_name": "liveMessage",
"humanname-de": "Live-Nachricht",
"humanname-en": "Live-Messages",
"default-en": "Hey, %streamer% is live on Twitch streaming %game%! Check it out: %url%",
"default-de": "Hi, %streamer% ist Live auf Twitch und streamt %game%! Jetzt anschauen: %url%",
"type": "string",
"allowEmbed": true,
"description-en": "Message that gets send if the streamer goes live",
"description-de": "Nachricht, die gesendet wird, wenn ein Streamer anfängt zu streamen",
"params-en": [
{
"name": "%streamer%",
"description": "Name of the Streamer"
},
{
"name": "%game%",
"description": "Game which is streamed"
},
{
"name": "%url%",
"description": "Link to the stream"
}
],
"params-de": [
{
"name": "%streamer%",
"description": "Name des Streamers"
},
{
"name": "%game%",
"description": "Spiel, welches gestreamt wird"
},
{
"name": "%url%",
"description": "Link zum Twitch-Stream"
}
]
},
{
"field_name": "liveMessageChannel",
"humanname-en": "Channel",
"default": "",
"type": "channelID",
"description-en": "Channel in which live-message should get sent",
"description-de": "Kanal, in welchen Benachrichtigung gesendet werden soll"
},
{
"field_name": "streamer",
"humanname-en": "Streamer",
"humanname-de": "Streamer",
"default": "",
"type": "string",
"description-en": "Streamer where a notification should send when they start streaming",
"description-de": "Steamer, bei denen eine Benachrichtigung gesendet werden soll, wenn sie anfangen, zu streamen"
}
]
}
28 changes: 15 additions & 13 deletions modules/twitch-notifications/events/botReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@
*/
const {embedType} = require('../../../src/functions/helpers');

const {ApiClient} = require('twitch');
const {ClientCredentialsAuthProvider} = require('twitch-auth');
const {ApiClient} = require('@twurple/api');
const {ClientCredentialsAuthProvider} = require('@twurple/auth');
const {localize} = require('../../../src/functions/localize');

/**
* General program
* @param {object} client Discord js Client
* @param {Client} client Discord js Client
* @param {object} apiClient Twitch API Client
* @private
*/
function twitchNotifications(client, apiClient) {
const config = client.configurations['twitch-notifications']['config'];
const streamers = client.configurations['twitch-notifications']['streamers'];

/**
* Sends the live-message
* @param {string} username Username of the streamer
* @param {string} game Game that is streamed
* @param {string} thumbnailUrl URL of the thumbnail of the stream
* @param {number} channelID ID of the live-message-channel
* @param {number} i Index of the config-element-object
* @returns {*}
* @private
*/
function sendMsg(username, game, thumbnailUrl, channelID) {
function sendMsg(username, game, thumbnailUrl, channelID, i) {
const channel = client.channels.cache.get(channelID);
if (!channel) return client.logger.fatal(`[twitch-notifications] ` + localize('twitch-notifications', 'channel-not-found', {c: channelID}));
channel.send(embedType(config['liveMessage'], {
if (!streamers[i]['liveMessage']) return client.logger.fatal(`[twitch-notifications] ` + localize('twitch-notifications', 'message-not-found', {s: username}));
channel.send(embedType(streamers[i]['liveMessage'], {
'%streamer%': username,
'%game%': game,
'%url%': `https://twitch.tv/${username.toLowerCase()}`,
Expand All @@ -43,12 +45,12 @@ function twitchNotifications(client, apiClient) {
* @private
*/
async function isStreamLive(userName) {
const user = await apiClient.helix.users.getUserByName(userName.toLowerCase());
const user = await apiClient.users.getUserByName(userName.toLowerCase());
if (!user) return 'userNotFound';
return await user.getStream();
}

config['streamers'].forEach(start);
streamers.forEach(start);

/**
* Starts checking if the streamer is live
Expand All @@ -60,22 +62,22 @@ function twitchNotifications(client, apiClient) {
async function start(value, index) {
const streamer = await client.models['twitch-notifications']['streamer'].findOne({
where: {
name: value.toLowerCase()
name: value.streamer.toLowerCase()
}
});
const stream = await isStreamLive(value);
const stream = await isStreamLive(value.streamer);
if (stream === 'userNotFound') {
return client.logger.error(`[twitch-notifications] ` + localize('twitch-notifications', 'user-not-on-twitch', {u: value}));
} else if (stream !== null && !streamer) {
client.models['twitch-notifications']['streamer'].create({
name: value.toLowerCase(),
name: value.streamer.toLowerCase(),
startedAt: stream.startDate.toString()
});
sendMsg(stream.userDisplayName, stream.gameName, stream.thumbnailUrl, config['liveMessageChannels'][index]);
sendMsg(stream.userDisplayName, stream.gameName, stream.thumbnailUrl, streamers[index]['liveMessageChannel'], index);
} else if (stream !== null && stream.startDate.toString() !== streamer.startedAt) {
streamer.startedAt = stream.startDate.toString();
streamer.save();
sendMsg(stream.userDisplayName, stream.gameName, stream.thumbnailUrl, config['liveMessageChannels'][index]);
sendMsg(stream.userDisplayName, stream.gameName, stream.thumbnailUrl, streamers[index]['liveMessageChannel'], index);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/twitch-notifications/module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "twitch-notifications",
"author": {
"name": "ja.teute",
"name": "jateute",
"link": "https://github.com/jateute",
"scnxOrgID": "4"
},
Expand All @@ -10,6 +10,7 @@
"events-dir": "/events",
"models-dir": "/models",
"config-example-files": [
"configs/config.json"
"configs/config.json",
"configs/streamers.json"
]
}
Loading