diff --git a/README.md b/README.md
index 08a0a73..08fa695 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
-# SubNotifier (v1.0.4)
+# SubNotifier (v1.0.5)

##### A Simple Sub and Resub Notifier for Twitch Chat
- [](https://discord.gg/bSd4cYJ) []()
+ [](https://discord.gg/bSd4cYJ) []()
### Want to use SubNotifier but need a Host? Follow + Tweet me [@d0p3t](https://twitter.com/d0p3t)
@@ -141,6 +141,11 @@ Also a great thank you to [Ikatzuki](https://twitter.com/lolIkatzuki) and [dinu]
---
## Changelog
+v1.0.5 (10 July 2018)
+* Added `message` variable support to resubscriptions
+* Added reconnecting and reconnected messages for clarity
+* Fixed linting errors (1 remaining due to twitch-js constructor)
+
v1.0.4 (20 June 2018)
* Fixed security vulnerabilities
* Upgraded package.json
diff --git a/src/config/config.sample.js b/src/config/config.sample.js
index a2fd0cd..d8ce5ed 100644
--- a/src/config/config.sample.js
+++ b/src/config/config.sample.js
@@ -26,44 +26,44 @@ const Config = {
subscriptions: {
custom1: 'PogChamp SUB Thank you for subscribing {{username}}',
custom2: 'CoolStoryBob SUB Thank you for subscribing {{username}}',
- custom3: 'DansGame SUB Thank you for subscribing {{username}}'
+ custom3: 'DansGame SUB Thank you for subscribing {{username}}',
},
giftsubscriptions: {
custom1: 'PogChamp GIFTED SUB Thank you for gifting {{recipient}} a subscription, {{username}}',
custom2: 'CoolStoryBob GIFTED SUB Thank you for gifting {{recipient}} a subscription, {{username}}',
- custom3: 'DansGame GIFTED SUB Thank you for gifting {{recipient}} a subscription, {{username}}'
- },
+ custom3: 'DansGame GIFTED SUB Thank you for gifting {{recipient}} a subscription, {{username}}',
+ },
resubscriptions: {
custom1: 'PogChamp RESUB Thank you {{username}} for resubscribing for {{months}} months! {{years}}',
custom2: 'WutFace RESUB Thank you {{username}} for resubscribing for {{months}} months! {{years}}',
- custom3: '<3 RESUB Thank you {{username}} for resubscribing for {{months}} months! {{years}}'
+ custom3: '<3 RESUB Thank you {{username}} for resubscribing for {{months}} months! {{years}}',
},
bits: {
custom1: 'Wowzers, {{username}} cheered {{bits}} BITS!',
custom2: 'Oh so kind, {{username}} with the {{bits}} BITS!',
- custom3: 'LUL we got a happy cheerer over here ({{username}}: {{bits}} bits)!'
+ custom3: 'LUL we got a happy cheerer over here ({{username}}: {{bits}} bits)!',
},
},
'#channel2': {
subscriptions: {
custom1: '',
custom2: '',
- custom3: ''
+ custom3: '',
},
giftsubscriptions: {
custom1: '',
custom2: '',
- custom3: ''
- },
+ custom3: '',
+ },
resubscriptions: {
custom1: '',
custom2: '',
- custom3: ''
+ custom3: '',
},
bits: {
custom1: '',
custom2: '',
- custom3: ''
+ custom3: '',
},
},
},
diff --git a/src/index.js b/src/index.js
index 075dea9..ccd5635 100644
--- a/src/index.js
+++ b/src/index.js
@@ -21,7 +21,8 @@ const bot = new TwitchBot(
Config.clientId,
Config.username,
Config.token,
- Config.channels);
+ Config.channels,
+);
bot.Start();
diff --git a/src/lib/TwitchBot.js b/src/lib/TwitchBot.js
index 95f5cf4..0002aba 100644
--- a/src/lib/TwitchBot.js
+++ b/src/lib/TwitchBot.js
@@ -77,27 +77,29 @@ class TwitchBot {
this._messagesCount = [];
for (let i = 0; i < this._channels.length; i += 1) {
- const channel = this._channels[i];
- this._messagesCount.push({ channel: channel });
- const allMsgs = Object.getOwnPropertyNames(Config.customMessages[channel]);
- this._messagesCount[channel] = { subscriptions: 0, resubscriptions: 0, bits: 0, giftsubscriptions: 0 };
+ const thisChannel = this._channels[i];
+ this._messagesCount.push({ channel: thisChannel });
+ const allMsgs = Object.getOwnPropertyNames(Config.customMessages[thisChannel]);
+ this._messagesCount[thisChannel] = {
+ subscriptions: 0, resubscriptions: 0, bits: 0, giftsubscriptions: 0,
+ };
for (const type of allMsgs) {
- const messagesOfThisType = Config.customMessages[channel][type];
- for (let message in messagesOfThisType) {
- if (messagesOfThisType.hasOwnProperty(message)) {
- ++this._messagesCount[channel][`${type}`];
- Logger.debug(`FOUND [ ${type} ] message for channel [ ${channel} ]`);
+ const messagesOfThisType = Config.customMessages[thisChannel][type];
+ for (const message in messagesOfThisType) {
+ if (Object.prototype.hasOwnProperty.call(messagesOfThisType, message)) {
+ this._messagesCount[thisChannel][`${type}`] = this._messagesCount[thisChannel][`${type}`] + 1;
+ Logger.debug(`FOUND [ ${type} ] message for channel [ ${thisChannel} ]`);
}
}
if (this._messagesCount[type] < 1) {
- Logger.error(`You MUST have at least 1 custom message for ${type} in channel [ ${channel} ]!`);
+ Logger.error(`You MUST have at least 1 custom message for ${type} in channel [ ${thisChannel} ]!`);
process.exit(1);
} else {
- Logger.debug(`COUNTED ${this._messagesCount[channel][type]} ${type} messages for channel [ ${channel} ]`);
+ Logger.debug(`COUNTED ${this._messagesCount[thisChannel][type]} ${type} messages for channel [ ${thisChannel} ]`);
}
}
- Logger.debug(`TOTAL MESSAGES IN CHANNEL [ ${channel} ] :`);
- Logger.debug(JSON.stringify(this._messagesCount[channel]));
+ Logger.debug(`TOTAL MESSAGES IN CHANNEL [ ${thisChannel} ] :`);
+ Logger.debug(JSON.stringify(this._messagesCount[thisChannel]));
}
Logger.info('ENABLED Custom Messages!');
@@ -105,8 +107,7 @@ class TwitchBot {
this._client.connect()
.then((data) => {
- Logger.debug(`CONNECTED to chat on ${data[0]}:${data[1]}`);
- Logger.info('CONNECTED: Waiting for events...');
+ Logger.debug(`CONNECTION ESTABLISHED on ${data[0]}:${data[1]}`);
})
.catch((err) => {
Logger.error(`ERROR Could not connect to chat (${err})`);
@@ -115,6 +116,14 @@ class TwitchBot {
this._client.on('disconnected', (reason) => {
Logger.warn(`DISCONNECTED from chat, trying to reconnect... (reason: ${reason})`);
});
+
+ this._client.on('reconnect', () => {
+ Logger.info('RECONNECTING...');
+ });
+
+ this._client.on('connected', () => {
+ Logger.info('CONNECTED: Waiting for events...');
+ });
}
/**
@@ -136,7 +145,7 @@ class TwitchBot {
* @return {[none]} [description]
*/
SubAlert() {
- this._client.on('subscription', (channel, username, method, message, userstate) => {
+ this._client.on('subscription', (channel, username, method, message) => {
if (Config.enableCustomMessages) {
const subAlertMessages = Config.customMessages[channel].subscriptions;
if (subAlertMessages !== undefined) {
@@ -192,7 +201,7 @@ class TwitchBot {
* @return {[none]} [description]
*/
GiftSubAlert() {
- this._client.on('subgift', (channel, username, recipient, method, userstate) => {
+ this._client.on('subgift', (channel, username, recipient) => {
if (Config.enableCustomMessages) {
const giftSubAlertMessages = Config.customMessages[channel].giftsubscriptions;
if (giftSubAlertMessages !== undefined) {
@@ -249,7 +258,7 @@ class TwitchBot {
* @return {[none]} [description]
*/
ResubAlert() {
- this._client.on('resub', (channel, username, months, message, userstate, methods) => {
+ this._client.on('resub', (channel, username, months, message) => {
if (Config.enableCustomMessages) {
const resubAlertMessages = Config.customMessages[channel].resubscriptions;
if (resubAlertMessages !== undefined) {
@@ -262,6 +271,7 @@ class TwitchBot {
const yearMonths = months % 12;
let finalAlert = alert.replace(/{{username}}/gi, username);
finalAlert = finalAlert.replace(/{{months}}/gi, months);
+ finalAlert = finalAlert.replace(/{{message}}/gi, message);
if (years === 0) {
finalAlert = finalAlert.replace(/{{years}}/gi, '');
} else {
diff --git a/src/twitch-js.d.ts b/src/twitch-js.d.ts
new file mode 100644
index 0000000..5b08608
--- /dev/null
+++ b/src/twitch-js.d.ts
@@ -0,0 +1 @@
+declare module 'twitch-js'
\ No newline at end of file