Skip to content

Commit

Permalink
Merge pull request #27 from twitchapis/main
Browse files Browse the repository at this point in the history
Launch twitchapis beta 13
  • Loading branch information
LoboMetalurgico authored Feb 17, 2021
2 parents 4f1aea5 + a9265d8 commit f36835c
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 228 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[<img src="https://cdn.discordapp.com/attachments/780245027212492812/780245250382757930/TwitchJS.png">]()
[<img src="https://media.discordapp.net/attachments/780245027212492812/804814808649433088/TwitchJSBanner.png">]()

<p>
<a href="https://twitchapis.org/discord"><img src="https://img.shields.io/discord/773920681246851083?style=for-the-badge&color=7289da&logo=discord&logoColor=FFFFFF"/></a>
Expand All @@ -8,7 +8,7 @@
<a href="https://github.com/twitchapis/twitch.js/blob/main/LICENSE"><img src="https://img.shields.io/github/license/twitchapis/twitch.js.svg?style=for-the-badge"/></a>
</p>

[<img src="https://media.discordapp.net/attachments/780245027212492812/785968486018318356/Novo_Projeto6.png?width=1440&height=480" align='right' width='300'/>](https://twitchapis.org/discord) [<span><br/><img src="https://nodei.co/npm/@twitchapis/twitch.js.png?downloads=true&stars=true" align='left'/></span>](https://www.npmjs.com/package/@twitchapis/twitch.js)
[<img src="https://media.discordapp.net/attachments/780245027212492812/804817170126995506/Novo_Projeto27.png" align='right' width='300'/>](https://twitchapis.org/discord) [<span><br/><img src="https://nodei.co/npm/@twitchapis/twitch.js.png?downloads=true&stars=true" align='left'/></span>](https://www.npmjs.com/package/@twitchapis/twitch.js)

<br/>
<br/>
Expand Down Expand Up @@ -36,21 +36,27 @@

## TODO

- [x] | Make a auto updated list of users of channels
- [x] Make a auto updated list of users of channels
- [x] | Create automatizated tests.
- [x] | Disconnect IRC function.
- [x] | Make reply uses new thread system of twitch. (beta ⚙️)
- [x] | FanMode (Anonymous mode).
- [x] | Remove global variables.
- [x] | Convert api/functions/chatters.js into class
- [x] | Convert api/twitchWebAPI.js into class
- [x] | Reduce generateUser method size
- [x] | Organize annotations. (not sure enough ⚙️)
- [x] | Transform logger in class
- [ ] | Create onUserJoin event. (Emitted everytime someone new enter in the chat)
- [ ] | Create onUserLeave event. (Emitted everytime someone leaves the chat)
- [ ] | Create Shard system.
- [ ] | Implement other types of connections with twitch (To alloy the bot to make things like follow someone, get stream details, ...)
- [ ] | Remove global variables.
- [ ] | Organize annotations.
- [ ] | Reduce generateUser function size
- [ ] | Implement other http methods (To make things like follow, get stream details, ...)
- [ ] | Split SleeptMethods because it is too much dirty
- [ ] | Convert api/getChatter.js into class
- [ ] | Create own parser
- [ ] | [Create own parser](#create-own-parser)
#### Create own parser
- [ ] | Plan the new object structure
- [ ] | Code the new parser
- [ ] | Replace old parser code

## About

Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@twitchapis/twitch.js",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"description": "twitch.js is a powerful Node.js module that allows you to easily interact with the TwitchTV making easy the way to make a TwitchTV bot, for a custom chat overlay for you OBS, or a moderation bot for you chat, or you just want a easy interface to TwitchTV.",
"main": "./src/index",
"scripts": {
Expand Down
54 changes: 27 additions & 27 deletions src/client/Client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const path = require('path');
const EventEmmiter = require('events');
const SLEEPTManager = require(path.resolve(__dirname,'..','sleept','SLEEPTMananger'));
const { autoEndLog, constants, logger, Util, collection } = require(path.resolve(__dirname,'..','utils'));
const { autoEndLog, constants, logger: LoggerC, Util, collection } = require(path.resolve(__dirname,'..','utils'));
const channel = require(path.resolve(__dirname,'..','structures','channels'));

var logger;

/**
* Creates the main class to generate clients.
* @extends {EventEmmiter}
Expand All @@ -21,36 +23,18 @@ class Client extends EventEmmiter {
this.options = Util.mergeDefault(constants.defaultOptions, options);
this._validateOptions();

/**
* Defines the options as a organized global variable to use in
*/
global.twitchApis = {
client: {
option: this.options,
methods: {
joinQueueTimeout: [],
leaveQueueTimeout: [],
},
},
};
logger = new LoggerC({debug:this.options.debug});

/**
* Active Debug if Debug have to be activate
* Display a message saying debug is active is debug is active
*/
if (this.options.debug) {
logger.activeDebug();
}

logger.debug('Debug is active!');

Object.defineProperty(this, 'token', { writable: true });

/**
* The SLEEPT manager of the client
* @type {SLEEPTManager}
* @private
* Load client token from process enviroment if its not passed on login
*/
this.sleept = new SLEEPTManager(this);

Object.defineProperty(this, 'token', { writable: true });
if (!this.token && 'CLIENT_TOKEN' in process.env) {
/**
* Authorization token for the logged in user/bot
Expand Down Expand Up @@ -82,6 +66,10 @@ class Client extends EventEmmiter {
*/
this.autoLogEnd = options.autoLogEnd;

/**
* Disable autoLogEnd if debug is actived for complete stacktraces
* also display a warn saying that
*/
if (this.options.debug && this.autoLogEnd) {
logger.warn('AutoLogEnd disabled because debug is enabled');
}
Expand All @@ -94,10 +82,13 @@ class Client extends EventEmmiter {
}

/**
* Creates a collecion to each channel
* A collection with all channels
* @type {Collection}
*/
this.channels = new collection();
/**
* Create the channel collection for each channel
*/
options.channels.forEach((channelName) => {
if (channelName.slice(0, 1) !== '#') {
channelName = '#' + channelName;
Expand All @@ -111,17 +102,26 @@ class Client extends EventEmmiter {
};
});

global.twitchApis.client.channels = this.channels;

/**
* Intervals set by {@link Client#setInterval} that are still active
* @type {Set<Timeout>}
* @private
*/
this._intervals = new Set();

/**
* If messageSweepInterval is bigger than 0 start a interval of this time to run the sweepMessage function
*/
if (options.messageSweepInterval > 0) {
setInterval(this.sweepMessages.bind(this), options.messageSweepInterval * 1000);
}

/**
* The SLEEPT manager of the client
* @type {SLEEPTManager}
* @private
*/
this.sleept = new SLEEPTManager(this);
}

/**
Expand Down
21 changes: 19 additions & 2 deletions src/sleept/SLEEPTMananger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ const UserAgentManager = require(path.resolve(__dirname,'UserAgentManager'));
const SLEEPTMethods = require(path.resolve(__dirname,'SLEEPTMethods'));
const SequentialRequestHandler = require(path.resolve(__dirname,'RequestHandlers','Sequential'));
const BurstRequestHandler = require(path.resolve(__dirname,'RequestHandlers','Burst'));
const { constants, logger } = require(path.resolve(__dirname,'..','utils'));

const { constants, logger: LoggerC } = require(path.resolve(__dirname,'..','utils'));
var logger;
/**
* The manager for all things than envolve Sleept
*/
class SLEEPTMananger {
constructor(client) {
this.client = client;
Expand All @@ -13,15 +16,25 @@ class SLEEPTMananger {
this.methods = new SLEEPTMethods(this);
this.rateLimitedEndpoints = {};
this.globallyRateLimited = false;
logger = new LoggerC({debug: this.client.options.debug});
}

/**
* Destroy all Sleept handlers
*/
destroy() {
for (const handlerKey of Object.keys(this.handlers)) {
const handler = this.handlers[handlerKey];
if (handler.destroy) handler.destroy();
}
}

/**
* push request to a handler
* @param {} [handler] the handler who will receive the request
* @param {} [apiRequest] the requrest who will be added to the handler
* @return {Promise<Pending>} returned once the request is solved or rejected
*/
push(handler, apiRequest) {
return new Promise((resolve, reject) => {
handler.push({
Expand All @@ -33,6 +46,10 @@ class SLEEPTMananger {
});
}

/**
* Gets a hequest handler
* @return {'SequentialRequestHandler'|'BurstRequestHandler'}
*/
getRequestHandler() {
switch (this.client.options.apiRequestMethod) {
case 'sequential':
Expand Down
Loading

0 comments on commit f36835c

Please sign in to comment.