simple-helix-api
Advanced tools
Comparing version 3.3.0-beta.10 to 3.3.0
@@ -44,3 +44,3 @@ "use strict"; | ||
} | ||
if (~choices.findIndex(item => !item.title)) { | ||
if (choices.some(item => !item || !item.title)) { | ||
return this.handleError(this.ERRORS.INVALID_CHOICE_ITEM); | ||
@@ -47,0 +47,0 @@ } |
@@ -10,2 +10,4 @@ "use strict"; | ||
MAX_TITLE_LENGTH: 45, | ||
OUTCOMES_MIN: 2, | ||
OUTCOMES_MAX: 10, | ||
OUTCOMES_ITEM_TITLE_LENGTH: 25, | ||
@@ -21,3 +23,4 @@ MIN_TIMEOUT: 1, | ||
INVALID_TITLE: "Invalid prediction title", | ||
OUTCOMES_LENGTH: "Prediction must contain two outcomes", | ||
OUTCOMES_MIN: "Prediction must have at least 2 outcomes", | ||
OUTCOMES_MAX: "Preidction can have a maximum of 10 outcomes", | ||
INVALID_OUTCOME: "Outcomes must be an array", | ||
@@ -44,6 +47,9 @@ INVALID_OUTCOME_ITEM: "One of choise items is invalid", | ||
} | ||
if (outcomes.length !== 2) { | ||
return this.handleError(this.ERRORS.OUTCOMES_LENGTH); | ||
if (outcomes.length < predictionsConfig.OUTCOMES_MIN) { | ||
return this.handleError(this.ERRORS.OUTCOMES_MIN); | ||
} | ||
if (~outcomes.findIndex(item => !item.title)) { | ||
if (outcomes.length > predictionsConfig.OUTCOMES_MAX) { | ||
return this.handleError(this.ERRORS.OUTCOMES_MAX); | ||
} | ||
if (outcomes.some(item => !item || !item?.title)) { | ||
return this.handleError(this.ERRORS.INVALID_OUTCOME_ITEM); | ||
@@ -50,0 +56,0 @@ } |
@@ -32,2 +32,5 @@ "use strict"; | ||
} | ||
if (!password.startsWith("oauth")) { | ||
password = `oauth:${password}`; | ||
} | ||
const endpoint = options.secure | ||
@@ -34,0 +37,0 @@ ? this.secureEndpoint |
{ | ||
"name": "simple-helix-api", | ||
"version": "3.3.0-beta.10", | ||
"version": "3.3.0", | ||
"description": "The Simple Helix API allows developers to easily develop applications for Twitch", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
154
README.md
@@ -14,2 +14,25 @@ # About | ||
# Navigation | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Fetching access token](#access-token) | ||
- [Example](#example) | ||
- [EventSub (WebSocket)](/documentation/EVENTSUB.md) | ||
- [Twitch Chat Client](/documentation/CHAT.md) | ||
- [Contribution](#contribution) | ||
# Installation | ||
npm: | ||
```bash | ||
npm install simple-helix-api | ||
``` | ||
or using yarn: | ||
```bash | ||
yarn add simple-helix-api | ||
``` | ||
# Usage | ||
@@ -121,133 +144,2 @@ | ||
# EventSub Websocket | ||
``` | ||
Release version: 3.1.0 | ||
Description: You can receive realtime notifications using Websocket. | ||
``` | ||
You can check all events on [this page](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelsubscribe). | ||
### Example | ||
```javascript | ||
const HelixAPI = require("simple-helix-api"); // you can use import | ||
// Init Helix instance | ||
const Helix = new HelixAPI({ | ||
access_token: "xxxxxxx", | ||
client_id: "xxxxxxx" | ||
}); | ||
// Listen connect and disconnect events | ||
Helix.EventSub.events.on(Helix.EventSub.WebsocketEvents.CONNECTED, () => { | ||
console.log("Connected to WebSocket"); | ||
}); | ||
Helix.EventSub.events.on(Helix.EventSub.WebsocketEvents.DISCONNECTED, () => { | ||
console.log("Disconnected from WebSocket"); | ||
}); | ||
// List of conditions. Each event can have different from each other conditions, so please check Twitch docs. | ||
const conditions = [{ | ||
broadcaster_user_id: String("user_id here") // User ID and other numbers must be converted to string for condition | ||
}]; | ||
// Create EventSub client | ||
const EventSubClient = await Helix.EventSub.connect(); | ||
// Register listeners for events | ||
EventSubClient.subscribe("channel.follow", conditions[0], follow => { | ||
console.log(`Thank you for following, ${follow.user_name}`); | ||
}); | ||
``` | ||
# Chat Client | ||
``` | ||
Release version: 3.3.0 | ||
Description: Create your own chatbot. | ||
``` | ||
All you need to connecting to chat is [OAuth password](https://twitchapps.com/tmi/). | ||
Available chat events: | ||
``` | ||
sub, resub, subgift, submysterygift, giftpaidupgrade, rewardgift, anongiftpaidupgrade, raid, unraid, ritual, bitsbadgetier, clear, delete, ban | ||
``` | ||
You can check all available chat events and tags for chat events [here](https://dev.twitch.tv/docs/irc/tags#usernotice-tags). | ||
### Example | ||
```javascript | ||
const HelixAPI = require("simple-helix-api"); // you can use import | ||
// Init Helix instance | ||
const Helix = new HelixAPI({ | ||
access_token: "xxxxxxx", | ||
client_id: "xxxxxxx" | ||
}); | ||
const username = "USERNAME", // Bot or your channel username | ||
const password = "oauth:PASSWORD", // OAuth password | ||
const channels = ["channel1"] // Optional. Leave it blank or null to autoconnect to your channel | ||
const secure = true; // Optional. Use secure connection (443) | ||
Helix.tmi.events.on(Helix.tmi.WebsocketEvents.CONNECTED, () => { | ||
console.log("Chat client connected"); | ||
}); | ||
Helix.tmi.events.on(Helix.tmi.WebsocketEvents.DISCONNECTED, () => { | ||
console.log("Chat client disconnected"); | ||
}); | ||
const chat = await Helix.tmi.connect(username, password, channels, secure); | ||
// Listen regular messages, highlighted messages or reward messages | ||
chat.on("message", message => { | ||
const username = message["display-name"]; | ||
console.log(`${username}: ${message.text}`); | ||
}); | ||
/* | ||
Listen chat events. | ||
Chat events tags can be found here: | ||
https://dev.twitch.tv/docs/irc/tags#usernotice-tags | ||
*/ | ||
// Listen sub event | ||
chat.on("sub", sub => { | ||
const subscriber = sub["display-name"]; | ||
const plan = sub["msg-param-sub-plan-name"]; | ||
console.log(`${subscriber} has subscribed to the channel with ${plan}`); | ||
}); | ||
// Listen sub event | ||
chat.on("resub", resub => { | ||
const subscriber = resub["display-name"]; | ||
const streak = resub["msg-param-streak-months"]; | ||
console.log(`${subscriber} is resubscribed to the channel for the ${streak} month in a row`); | ||
}); | ||
// Listen raid event | ||
chat.on("raid", raid => { | ||
const raider = raid["msg-param-displayName"]; | ||
const viewers = raid["msg-param-viewerCount"]; | ||
console.log(`${raider} raiding with ${viewers} viewers`); | ||
}); | ||
// Listen clear chat event | ||
chat.on("clear", () => { | ||
console.log("Chat has been cleared"); | ||
}); | ||
// Sending commands | ||
// chat.command("ban", shine_discord21); // Pass single argumnet to chat command | ||
// chat.command("ban", ["shine_discord21", "Some bot account"]); // Pass multiple arguments to chat command | ||
chat.command("clearchat"); | ||
const date = new Date().toLocaleTimeString(); | ||
chat.say(`[Chat Client]: connected at ${date}`, channels); | ||
``` | ||
# Contribution | ||
@@ -254,0 +146,0 @@ Sometimes I may miss some changes in the Twitch API, so I will be glad of any help. Feel free to fork and share PR's. |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
98948
61
2241
1
146