Comparing version 2.0.5 to 2.1.0
@@ -0,19 +1,59 @@ | ||
import { MarkovGenerateOptions, MarkovResult } from "markov-strings"; | ||
interface ICrispyOptions { | ||
[key: string]: any; | ||
stateSize: number; | ||
minLength: number; | ||
minWords: number; | ||
minScore: number; | ||
maxTries?: number; | ||
prng?: () => number; | ||
filter?: (result: MarkovResult) => boolean; | ||
} | ||
export declare class Crispy { | ||
db: any; | ||
user: any; | ||
private token; | ||
private events; | ||
private io; | ||
constructor(token: string); | ||
options: ICrispyOptions; | ||
cooldown: Set<string>; | ||
private _api; | ||
private _url; | ||
private _token; | ||
private _globalCorpus; | ||
private _userCorpus; | ||
private _events; | ||
private _io; | ||
constructor(token: string, options?: ICrispyOptions); | ||
readonly io: SocketIOClient.Socket; | ||
getEventPrefix(eventName: string): string | null; | ||
connect(): Promise<unknown>; | ||
join(room: string, user?: object): void; | ||
getIgnoreList(roomName: string): void; | ||
checkYoutube(notify?: boolean): void; | ||
handleChange(handle: string): void; | ||
isStillJoined(room: string): void; | ||
message(room: string, message: string): void; | ||
command(room: string, command: string, value?: string): void; | ||
on(event: string, handler: (data?: any) => void): void; | ||
join(room: string, user?: object): SocketIOClient.Socket; | ||
getIgnoreList(roomName: string): SocketIOClient.Socket; | ||
checkYoutube(notify?: boolean): SocketIOClient.Socket; | ||
handleChange(handle: string): SocketIOClient.Socket; | ||
isStillJoined(room: string): SocketIOClient.Socket; | ||
message(room: string, message: string): SocketIOClient.Socket; | ||
command(room: string, command: string, value?: string): SocketIOClient.Socket; | ||
on(event: string, handler: (data?: any) => void): SocketIOClient.Emitter; | ||
emit(event: string, data?: any): void; | ||
getCurrentUser(): Promise<unknown>; | ||
getUserProfile(userId: string): Promise<unknown>; | ||
getUnreadMessages(userId: string): Promise<unknown>; | ||
checkCanBroadcast(room: string): Promise<unknown>; | ||
getRoomEmojis(room: string): Promise<unknown>; | ||
getRoomPlaylist(room: string): Promise<unknown>; | ||
searchYoutube(query: string): Promise<unknown>; | ||
getTurnServer(): Promise<unknown>; | ||
getJanusToken(): Promise<unknown>; | ||
getJanusEndpoints(): Promise<unknown>; | ||
addUniqueMessage(message: string, user?: string): boolean; | ||
addMessage(message: string, user?: string): void; | ||
getMessages(user?: string): any; | ||
hasUser(user: string): any; | ||
getUsers(): any; | ||
generateMessage(user?: string, options?: MarkovGenerateOptions): any; | ||
cleanCooldown(): void; | ||
private _initCorpus; | ||
private _buildCorpus; | ||
private _requestPromise; | ||
} | ||
export {}; | ||
//# sourceMappingURL=crispy.d.ts.map |
@@ -6,8 +6,25 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const low = require("lowdb"); | ||
const FileSync = require("lowdb/adapters/FileSync"); | ||
const markov_strings_1 = __importDefault(require("markov-strings")); | ||
const request_1 = __importDefault(require("request")); | ||
const socket_io_client_1 = __importDefault(require("socket.io-client")); | ||
class Crispy { | ||
constructor(token) { | ||
constructor(token, options = {}) { | ||
this.user = {}; | ||
this.token = token; | ||
this.events = { | ||
this.cooldown = new Set(); | ||
this.options = Object.assign({}, { | ||
cooldownInterval: 5, | ||
minLength: 0, | ||
minScore: 0, | ||
minWords: 0, | ||
stateSize: 3, | ||
}, options); | ||
this.db = low(new FileSync("db.json")); | ||
this.db.defaults({ messages: [] }).write(); | ||
this._api = "https://jumpin.chat/api"; | ||
this._url = "https://jumpin.chat"; | ||
this._token = token; | ||
this._userCorpus = {}; | ||
this._events = { | ||
client: [ | ||
@@ -36,6 +53,32 @@ "stillConnected", | ||
}; | ||
if (!this.options.prng) { | ||
this.options.prng = () => (Math.random() * (new Date()).getTime()) % 1; | ||
} | ||
if (!this.options.filter) { | ||
this.options.filter = (result) => { | ||
return result.string.length >= this.options.minLength && | ||
result.string.split(" ").length >= this.options.minWords && | ||
!result.refs.map((o) => o.string).includes(result.string) && | ||
result.score >= this.options.minScore && | ||
!this.cooldown.has(result.string); | ||
}; | ||
} | ||
this._initCorpus(); | ||
setInterval(this.cleanCooldown); | ||
} | ||
get io() { | ||
if (this._io) { | ||
if (this._io.disconnected) { | ||
this._io.connect(); | ||
} | ||
return this._io; | ||
} | ||
else { | ||
this._io = socket_io_client_1.default.connect(this._url, { query: { token: this._token } }); | ||
return this._io; | ||
} | ||
} | ||
getEventPrefix(eventName) { | ||
for (const prefix in this.events) { | ||
if (this.events[prefix].includes(eventName)) { | ||
for (const prefix in this._events) { | ||
if (this._events[prefix].includes(eventName)) { | ||
return prefix; | ||
@@ -48,13 +91,10 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.io = socket_io_client_1.default("https://jumpin.chat", { query: { token: this.token } }); | ||
this.io.on("connect", (e) => { | ||
resolve(e); | ||
if (this.io) { | ||
this.on("handleChange", (c) => { | ||
this.user.handle = c.handle; | ||
}); | ||
this.on("join", (j) => { | ||
this.user = j.user; | ||
}); | ||
} | ||
this.on("handleChange", (c) => { | ||
this.user.handle = c.handle; | ||
}); | ||
this.on("join", (j) => { | ||
this.user = j.user; | ||
}); | ||
}); | ||
@@ -67,78 +107,163 @@ this.io.on("error", (e) => { | ||
join(room, user) { | ||
if (this.io) { | ||
this.io.emit("room::join", { room, user }); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("room::join", { room, user }); | ||
} | ||
getIgnoreList(roomName) { | ||
if (this.io) { | ||
this.io.emit("room::getIgnoreList", { roomName }); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("room::getIgnoreList", { roomName }); | ||
} | ||
checkYoutube(notify = true) { | ||
if (this.io) { | ||
this.io.emit("youtube::checkisplaying", { notify }); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("youtube::checkisplaying", { notify }); | ||
} | ||
handleChange(handle) { | ||
if (this.io) { | ||
this.io.emit("room::handleChange", { handle }); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("room::handleChange", { handle }); | ||
} | ||
isStillJoined(room) { | ||
if (this.io) { | ||
this.io.emit("room::isStillJoined", { room }); | ||
return this.io.emit("room::isStillJoined", { room }); | ||
} | ||
message(room, message) { | ||
return this.io.emit("room::message", { room, message }); | ||
} | ||
command(room, command, value) { | ||
return this.io.emit("room::command", { room, message: { command, value } }); | ||
} | ||
on(event, handler) { | ||
const prefix = this.getEventPrefix(event); | ||
if (prefix) { | ||
return this.io.on(`${prefix}::${event}`, handler); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
return this.io.on(event, handler); | ||
} | ||
} | ||
message(room, message) { | ||
if (this.io) { | ||
this.io.emit("room::message", { room, message }); | ||
emit(event, data) { | ||
this.io.emit(event, data); | ||
} | ||
getCurrentUser() { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + "/user", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getUserProfile(userId) { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + `/user/${userId}/profile`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getUnreadMessages(userId) { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + `/message/${userId}/unread`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
checkCanBroadcast(room) { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + `/user/checkCanBroadcast/${room}`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getRoomEmojis(room) { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + `/rooms/${room}/emoji`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getRoomPlaylist(room) { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + `/youtube/${room}/playlist`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
searchYoutube(query) { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + `/youtube/search/${query}`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getTurnServer() { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + "/turn", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getJanusToken() { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + "/janus/token", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
getJanusEndpoints() { | ||
return new Promise((resolve, reject) => { | ||
request_1.default.get(this._api + "/janus/endpoints", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
addUniqueMessage(message, user) { | ||
if (this.db.get("messages").filter({ user, message }).size().value() === 0) { | ||
this.db.get("messages").push({ user, message }).write(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
addMessage(message, user) { | ||
this.db.get("messages").push({ user, message }).write(); | ||
this._buildCorpus(user); | ||
} | ||
getMessages(user) { | ||
if (user) { | ||
return this.db.get("messages").filter({ user }).map("message").value(); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
return this.db.get("messages").map("message").value(); | ||
} | ||
} | ||
command(room, command, value) { | ||
if (this.io) { | ||
this.io.emit("room::command", { room, message: { command, value } }); | ||
hasUser(user) { | ||
return this.db.get("messages").map("user").has(user).value(); | ||
} | ||
getUsers() { | ||
return this.db.get("messages").map("user").uniq().value(); | ||
} | ||
generateMessage(user, options = {}) { | ||
if (!options.maxTries) { | ||
options.maxTries = this.options.maxTries; | ||
} | ||
if (!options.prng) { | ||
options.prng = this.options.prng; | ||
} | ||
if (!options.filter) { | ||
options.filter = this.options.filter; | ||
} | ||
let message; | ||
if (user) { | ||
message = this._userCorpus[user].generate(options); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
message = this._globalCorpus.generate(options); | ||
} | ||
this.cooldown.add(message.string); | ||
return message; | ||
} | ||
on(event, handler) { | ||
if (this.io) { | ||
const prefix = this.getEventPrefix(event); | ||
if (prefix) { | ||
this.io.on(`${prefix}::${event}`, handler); | ||
cleanCooldown() { | ||
this.cooldown = new Set(); | ||
} | ||
_initCorpus() { | ||
this._buildCorpus(); | ||
for (const user of this.getUsers()) { | ||
this._buildCorpus(user); | ||
} | ||
} | ||
_buildCorpus(user) { | ||
const messages = this.getMessages(user); | ||
if (messages.length > 0) { | ||
if (user) { | ||
this._userCorpus[user] = new markov_strings_1.default(messages, { stateSize: this.options.stateSize }); | ||
this._userCorpus[user].buildCorpus(); | ||
} | ||
else { | ||
this.io.on(event, handler); | ||
this._globalCorpus = new markov_strings_1.default(messages, { stateSize: this.options.stateSize }); | ||
this._globalCorpus.buildCorpus(); | ||
} | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
} | ||
emit(event, data) { | ||
if (this.io) { | ||
this.io.emit(event, data); | ||
} | ||
else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
_requestPromise(resolve, reject) { | ||
return (err, res, body) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
else { | ||
if (`${res.statusCode}`[0] !== "2") { | ||
return reject({ statusCode: res.statusCode, statusMessage: res.statusMessage }); | ||
} | ||
return resolve(body); | ||
} | ||
}; | ||
} | ||
@@ -145,0 +270,0 @@ } |
{ | ||
"name": "crispybot", | ||
"version": "2.0.5", | ||
"version": "2.1.0", | ||
"description": "An annoying bot.", | ||
@@ -10,3 +10,3 @@ "main": "dist/crispy.js", | ||
"scripts": { | ||
"build": "if exist dist ( rd /s /q dist ) & tsc --build" | ||
"build": "tsc --build" | ||
}, | ||
@@ -24,6 +24,11 @@ "repository": { | ||
"dependencies": { | ||
"lowdb": "^1.0.0", | ||
"markov-strings": "^2.1.0", | ||
"request": "^2.88.0", | ||
"socket.io-client": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/lowdb": "^1.0.9", | ||
"@types/node": "^12.7.3", | ||
"@types/request": "^2.48.2", | ||
"@types/socket.io-client": "^1.4.32", | ||
@@ -30,0 +35,0 @@ "ts-loader": "^6.0.4", |
@@ -0,12 +1,68 @@ | ||
/** | ||
* Crispy - An annoying bot. | ||
* Copyright (C) 2018 Guilherme Caulada (Sighmir) | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
import low = require("lowdb"); | ||
import FileSync = require("lowdb/adapters/FileSync"); | ||
import Markov, { MarkovGenerateOptions, MarkovResult } from "markov-strings"; | ||
import request from "request"; | ||
import io from "socket.io-client"; | ||
interface ICrispyOptions { | ||
[key: string]: any; | ||
stateSize: number; | ||
minLength: number; | ||
minWords: number; | ||
minScore: number; | ||
maxTries?: number; | ||
prng?: () => number; | ||
filter?: (result: MarkovResult) => boolean; | ||
} | ||
export class Crispy { | ||
public db: any; | ||
public user: any; | ||
private token: string; | ||
private events: { [index: string]: string[] }; | ||
private io: SocketIOClient.Socket | undefined; | ||
constructor(token: string) { | ||
public options: ICrispyOptions; | ||
public cooldown: Set<string>; | ||
private _api: string; | ||
private _url: string; | ||
private _token: string; | ||
private _globalCorpus: any; | ||
private _userCorpus: { [index: string]: any }; | ||
private _events: { [index: string]: string[] }; | ||
private _io: SocketIOClient.Socket | undefined; | ||
constructor(token: string, options = {} as ICrispyOptions) { | ||
this.user = {}; | ||
this.token = token; | ||
this.events = { | ||
this.cooldown = new Set(); | ||
this.options = Object.assign({}, { | ||
cooldownInterval: 5, | ||
minLength: 0, | ||
minScore: 0, | ||
minWords: 0, | ||
stateSize: 3, | ||
}, options); | ||
this.db = low(new FileSync("db.json")); | ||
this.db.defaults({ messages: [] }).write(); | ||
this._api = "https://jumpin.chat/api"; | ||
this._url = "https://jumpin.chat"; | ||
this._token = token; | ||
this._userCorpus = {}; | ||
this._events = { | ||
client: [ | ||
@@ -35,7 +91,36 @@ "stillConnected", | ||
}; | ||
if (!this.options.prng) { | ||
this.options.prng = () => (Math.random() * (new Date()).getTime()) % 1; | ||
} | ||
if (!this.options.filter) { | ||
this.options.filter = (result: MarkovResult) => { | ||
return result.string.length >= this.options.minLength && | ||
result.string.split(" ").length >= this.options.minWords && | ||
!result.refs.map((o) => o.string).includes(result.string) && | ||
result.score >= this.options.minScore && | ||
!this.cooldown.has(result.string); | ||
}; | ||
} | ||
this._initCorpus(); | ||
setInterval(this.cleanCooldown); | ||
} | ||
get io() { | ||
if (this._io) { | ||
if (this._io.disconnected) { | ||
this._io.connect(); | ||
} | ||
return this._io; | ||
} else { | ||
this._io = io.connect(this._url, { query: { token: this._token } }); | ||
return this._io; | ||
} | ||
} | ||
public getEventPrefix(eventName: string) { | ||
for (const prefix in this.events) { | ||
if (this.events[prefix].includes(eventName)) { | ||
for (const prefix in this._events) { | ||
if (this._events[prefix].includes(eventName)) { | ||
return prefix; | ||
@@ -49,14 +134,11 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.io = io("https://jumpin.chat", { query: { token: this.token } }); | ||
this.io.on("connect", (e: any) => { | ||
resolve(e); | ||
if (this.io) { | ||
this.on("handleChange", (c: any) => { | ||
this.user.handle = c.handle; | ||
}); | ||
this.on("handleChange", (c: any) => { | ||
this.user.handle = c.handle; | ||
}); | ||
this.on("join", (j: any) => { | ||
this.user = j.user; | ||
}); | ||
} | ||
this.on("join", (j: any) => { | ||
this.user = j.user; | ||
}); | ||
}); | ||
@@ -70,289 +152,190 @@ this.io.on("error", (e: any) => { | ||
public join(room: string, user?: object) { | ||
if (this.io) { | ||
this.io.emit("room::join", { room, user }); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("room::join", { room, user }); | ||
} | ||
public getIgnoreList(roomName: string) { | ||
if (this.io) { | ||
this.io.emit("room::getIgnoreList", { roomName }); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("room::getIgnoreList", { roomName }); | ||
} | ||
public checkYoutube(notify = true) { | ||
if (this.io) { | ||
this.io.emit("youtube::checkisplaying", { notify }); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("youtube::checkisplaying", { notify }); | ||
} | ||
public handleChange(handle: string) { | ||
if (this.io) { | ||
this.io.emit("room::handleChange", { handle }); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
return this.io.emit("room::handleChange", { handle }); | ||
} | ||
public isStillJoined(room: string) { | ||
if (this.io) { | ||
this.io.emit("room::isStillJoined", { room }); | ||
return this.io.emit("room::isStillJoined", { room }); | ||
} | ||
public message(room: string, message: string) { | ||
return this.io.emit("room::message", { room, message }); | ||
} | ||
public command(room: string, command: string, value?: string) { | ||
return this.io.emit("room::command", { room, message: { command, value } }); | ||
} | ||
public on(event: string, handler: (data?: any) => void) { | ||
const prefix = this.getEventPrefix(event); | ||
if (prefix) { | ||
return this.io.on(`${prefix}::${event}`, handler); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
return this.io.on(event, handler); | ||
} | ||
} | ||
public message(room: string, message: string) { | ||
if (this.io) { | ||
this.io.emit("room::message", { room, message }); | ||
public emit(event: string, data?: any) { | ||
this.io.emit(event, data); | ||
} | ||
public getCurrentUser() { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + "/user", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getUserProfile(userId: string) { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + `/user/${userId}/profile`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getUnreadMessages(userId: string) { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + `/message/${userId}/unread`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public checkCanBroadcast(room: string) { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + `/user/checkCanBroadcast/${room}`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getRoomEmojis(room: string) { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + `/rooms/${room}/emoji`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getRoomPlaylist(room: string) { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + `/youtube/${room}/playlist`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public searchYoutube(query: string) { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + `/youtube/search/${query}`, this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getTurnServer() { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + "/turn", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getJanusToken() { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + "/janus/token", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public getJanusEndpoints() { | ||
return new Promise((resolve, reject) => { | ||
request.get(this._api + "/janus/endpoints", this._requestPromise(resolve, reject)); | ||
}); | ||
} | ||
public addUniqueMessage(message: string, user?: string) { | ||
if (this.db.get("messages").filter({ user, message }).size().value() === 0) { | ||
this.db.get("messages").push({ user, message }).write(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
public addMessage(message: string, user?: string) { | ||
this.db.get("messages").push({ user, message }).write(); | ||
this._buildCorpus(user); | ||
} | ||
public getMessages(user?: string) { | ||
if (user) { | ||
return this.db.get("messages").filter({ user }).map("message").value(); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
return this.db.get("messages").map("message").value(); | ||
} | ||
} | ||
public command(room: string, command: string, value?: string) { | ||
if (this.io) { | ||
this.io.emit("room::command", { room, message: { command, value } }); | ||
public hasUser(user: string) { | ||
return this.db.get("messages").map("user").has(user).value(); | ||
} | ||
public getUsers() { | ||
return this.db.get("messages").map("user").uniq().value(); | ||
} | ||
public generateMessage(user?: string, options = {} as MarkovGenerateOptions) { | ||
if (!options.maxTries) { | ||
options.maxTries = this.options.maxTries; | ||
} | ||
if (!options.prng) { | ||
options.prng = this.options.prng; | ||
} | ||
if (!options.filter) { | ||
options.filter = this.options.filter; | ||
} | ||
let message; | ||
if (user) { | ||
message = this._userCorpus[user].generate(options); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
message = this._globalCorpus.generate(options); | ||
} | ||
this.cooldown.add(message.string); | ||
return message; | ||
} | ||
public on(event: string, handler: (data?: any) => void) { | ||
if (this.io) { | ||
const prefix = this.getEventPrefix(event); | ||
if (prefix) { | ||
this.io.on(`${prefix}::${event}`, handler); | ||
public cleanCooldown() { | ||
this.cooldown = new Set(); | ||
} | ||
private _initCorpus() { | ||
this._buildCorpus(); | ||
for (const user of this.getUsers()) { | ||
this._buildCorpus(user); | ||
} | ||
} | ||
private _buildCorpus(user?: string) { | ||
const messages = this.getMessages(user); | ||
if (messages.length > 0) { | ||
if (user) { | ||
this._userCorpus[user] = new Markov(messages, { stateSize: this.options.stateSize }); | ||
this._userCorpus[user].buildCorpus(); | ||
} else { | ||
this.io.on(event, handler); | ||
this._globalCorpus = new Markov(messages, { stateSize: this.options.stateSize }); | ||
this._globalCorpus.buildCorpus(); | ||
} | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
} | ||
public emit(event: string, data?: any) { | ||
if (this.io) { | ||
this.io.emit(event, data); | ||
} else { | ||
throw new Error("Socket disconnected!"); | ||
} | ||
private _requestPromise(resolve: any, reject: any) { | ||
return (err: any, res: any, body: any) => { | ||
if (err) { | ||
return reject(err); | ||
} else { | ||
if (`${res.statusCode}`[0] !== "2") { | ||
return reject({ statusCode: res.statusCode, statusMessage: res.statusMessage }); | ||
} | ||
return resolve(body); | ||
} | ||
}; | ||
} | ||
} | ||
/** | ||
* Jumpin.chat Events | ||
* | ||
* Sent events: | ||
* | ||
* "room::setUserIsBroadcasting", {"isBroadcasting":true} | ||
* | ||
* "room::getIgnoreList", {"roomName":"room"} | ||
* | ||
* "room::command", {"message":{"command":"kick","value":"crispybot"},"room":"room"} | ||
* | ||
* "youtube::checkisplaying", {"notify":true} | ||
* | ||
* "room::handleChange", {"handle":"crispybot"} | ||
* | ||
* "room::isStillJoined", {"room":"room"} | ||
* | ||
* "room::message", {"message":"Hello World","room":"room"} | ||
* | ||
* "room::join", { | ||
* "room":"room", | ||
* "user":{ | ||
* "user_id":"USER_ID", | ||
* "username":"username", | ||
* "isAdmin":false, | ||
* "isSupporter":true, | ||
* "isGold":true, | ||
* "userIcon":"user-icons/username.gif?t=1546621108180", | ||
* "settings":{ | ||
* "playYtVideos":true, | ||
* "allowPrivateMessages":true, | ||
* "pushNotificationsEnabled":false, | ||
* "receiveUpdates":true, | ||
* "receiveMessageNotifications":false, | ||
* "darkTheme":true, | ||
* "videoQuality":"VIDEO_240", | ||
* "userIcon":"user-icons/username.gif?t=1546621108180", | ||
* "ignoreList":[{ | ||
* "expiresAt":"2018-09-10T18:59:41.452Z", | ||
* "userListId":"LIST_ID", | ||
* "userId":null, | ||
* "sessionId":"SESSION_ID", | ||
* "_id":"REQUEST_ID", | ||
* "id":"EVENT_ID", | ||
* "handle":"stopitgetsome", | ||
* "timestamp":"2018-09-09T18:59:41.452Z", | ||
* }], | ||
* }, | ||
* "videoQuality":{ | ||
* "id":"VIDEO_240", | ||
* "label":"240p", | ||
* "dimensions":{ | ||
* "width":320, | ||
* "height":240, | ||
* }, | ||
* "frameRate":15, | ||
* "bitRate":128000, | ||
* }, | ||
* }, | ||
* } | ||
* | ||
* ========================================================= | ||
* | ||
* Received events: | ||
* | ||
* "client::stillConnected" | ||
* | ||
* "client::handleChange", {"handle":"crispybot"} | ||
* | ||
* "room::updateIgnore", {"ignoreList":[]} | ||
* | ||
* "room::handleChange", {"userId":"USER_ID","handle":"crispybot"} | ||
* | ||
* "room::status", { | ||
* "notification_type":"room", | ||
* "message":"guest narrow_magic has joined the room", | ||
* "timestamp":"2019-09-03T22:59:27.361Z", | ||
* "id":"733c9ecd-d79b-4964-9e64-75e3fabbb5e0", | ||
* } | ||
* | ||
* "room::message", { | ||
* "handle":"crispybot", | ||
* "color":"orangealt", | ||
* "userId":"USER_ID", | ||
* "message":"Hello World", | ||
* "timestamp":"2019-09-03T23:11:21.596Z", | ||
* "id":"bcc73a79-d469-4e01-b6f9-7395a3ba1980", | ||
* } | ||
* | ||
* "room::disconnect", { | ||
* "user": { | ||
* "_id":"REQUEST_ID" | ||
* "handle":"STONER" | ||
* "operator_id":null | ||
* "user_id":null | ||
* "username":null | ||
* "isBroadcasting":true | ||
* "assignedBy":null | ||
* "isAdmin":false | ||
* "isSupporter":false | ||
* "userIcon":null | ||
* "color":"purplealt" | ||
* } | ||
* } | ||
* | ||
* "room::updateUserList", { | ||
* "user":{ | ||
* "_id":"REQUEST_ID", | ||
* "handle":"high-pitched_amount", | ||
* "operator_id":"OPERATOR_ID", | ||
* "user_id":"USER_ID", | ||
* "username":"username", | ||
* "isBroadcasting":false, | ||
* "assignedBy":null, | ||
* "isAdmin":false, | ||
* "isSupporter":true, | ||
* "userIcon":"user-icons/username.gif?t=1546621108180", | ||
* "color":"redalt", | ||
* } | ||
* } | ||
* | ||
* "room::updateUser", { | ||
* "user":{ | ||
* "_id":"REQUEST_ID", | ||
* "handle":"STONER", | ||
* "operator_id":null, | ||
* "user_id":null, | ||
* "username":null, | ||
* "isBroadcasting":true, | ||
* "assignedBy":null, | ||
* "isAdmin":false, | ||
* "isSupporter":false, | ||
* "userIcon":null, | ||
* "color":"purplealt", | ||
* }, | ||
* } | ||
* | ||
* "self::join", { | ||
* "user":{ | ||
* "user_id":"USER_ID", | ||
* "operator_id":"OPERATOR_ID", | ||
* "assignedBy":null, | ||
* "username":"username", | ||
* "isBroadcasting":false, | ||
* "isAdmin":false, | ||
* "isSupporter":true, | ||
* "userIcon":"user-icons/username.gif?t=1546621108180", | ||
* "_id":"REQUEST_ID", | ||
* "handle":"high-pitched_amount", | ||
* "color":"redalt", | ||
* "createdAt":"2019-09-04T01:10:03.701Z", | ||
* "joinTime":"2019-09-04T01:10:03.701Z", | ||
* "operatorPermissions":{ | ||
* "ban":true, | ||
* "close_cam":true, | ||
* "mute_user_audio":true, | ||
* "mute_user_chat":true, | ||
* "mute_room_chat":false, | ||
* "mute_room_audio":false, | ||
* "apply_password":false, | ||
* "assign_operator":true, | ||
* "play_youtube":true, | ||
* } | ||
* } | ||
* } | ||
* | ||
* "youtube::play", {"videoId":"w0c_dv0TUmU","title":"Alborosie - Kingston Town"} | ||
* | ||
* "youtube::playlistUpdate", [ | ||
* { | ||
* "startTime":null, | ||
* "endTime":null, | ||
* "description":null, | ||
* "channelId":"UChf0Knt-e9Pw8VywfuTZCjA", | ||
* "pausedAt":null, | ||
* "_id":"REQUEST_ID", | ||
* "mediaId":"Nco_kh8xJDs", | ||
* "title":"Alice In Chains - Would? (Official Video)", | ||
* "link":"https://youtu.be/Nco_kh8xJDs", | ||
* "duration":208, | ||
* "thumb":"https://i.ytimg.com/vi/Nco_kh8xJDs/default.jpg", | ||
* "mediaType":"TYPE_YOUTUBE", | ||
* "startedBy":"5b3d6ca49215550007bcefe2", | ||
* "createdAt":"2019-09-04T01:13:27.136Z", | ||
* }, | ||
* ] | ||
* | ||
* "youtube::playvideo", { | ||
* "startTime":"2019-09-04T01:13:27.239Z", | ||
* "endTime":"2019-09-04T01:16:55.239Z", | ||
* "description":null, | ||
* "channelId":"UChf0Knt-e9Pw8VywfuTZCjA", | ||
* "pausedAt":null, | ||
* "createdAt":"2019-09-04T01:13:27.136Z", | ||
* "_id":"REQUEST_ID", | ||
* "mediaId":"Nco_kh8xJDs", | ||
* "title":"Alice In Chains - Would? (Official Video)", | ||
* "link":"https://youtu.be/Nco_kh8xJDs", | ||
* "duration":208, | ||
* "thumb":"https://i.ytimg.com/vi/Nco_kh8xJDs/default.jpg", | ||
* "mediaType":"TYPE_YOUTUBE", | ||
* "startedBy":{ | ||
* "profile":{ | ||
* "pic":"user-avatar/avatar-blank.png" | ||
* } | ||
* "_id":"REQUEST_ID" | ||
* "username":"leafs" | ||
* } | ||
* "startAt":0 | ||
* } | ||
*/ |
@@ -51,3 +51,5 @@ { | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
// "typeRoots": [], /* List of folders to include type definitions from. */ | ||
"typeRoots": [ | ||
"types/*" | ||
], /* List of folders to include type definitions from. */ | ||
// "types": [], /* Type declaration files to be included in compilation. */ | ||
@@ -70,3 +72,4 @@ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
"include": [ | ||
"src/*" | ||
"src/*", | ||
"types/*" | ||
], | ||
@@ -73,0 +76,0 @@ "exclude": [ |
@@ -8,3 +8,4 @@ { | ||
"rules": { | ||
"no-console": false | ||
"no-console": false, | ||
"variable-name": false | ||
}, | ||
@@ -11,0 +12,0 @@ "rulesDirectory": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
79151
724
4
7
3
1
+ Addedlowdb@^1.0.0
+ Addedmarkov-strings@^2.1.0
+ Addedrequest@^2.88.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlowdb@1.0.0(transitive)
+ Addedmarkov-strings@2.1.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedsteno@0.4.4(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)