Skip to content

Commit

Permalink
utils: add hasOwn instead of hasOwnProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
AlcaDesign committed Mar 12, 2021
1 parent 0c236b4 commit 90ab699
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,10 @@ client.prototype.handleMessage = function handleMessage(message) {
message.tags.channel = channel;
this.emit("roomstate", channel, message.tags);

if(!message.tags.hasOwnProperty("subs-only")) {
if(!_.hasOwn(message.tags, "subs-only")) {
// Handle slow mode here instead of the slow_on/off notice..
// This room is now in slow mode. You may send messages every slow_duration seconds.
if(message.tags.hasOwnProperty("slow")) {
if(_.hasOwn(message.tags, "slow")) {
if(typeof message.tags.slow === "boolean" && !message.tags.slow) {
var disabled = [channel, false, 0];
this.log.info(`[${channel}] This room is no longer in slow mode.`);
Expand All @@ -895,7 +895,7 @@ client.prototype.handleMessage = function handleMessage(message) {
// duration is in minutes (string)
// -1 when /followersoff (string)
// false when /followers with no duration (boolean)
if(message.tags.hasOwnProperty("followers-only")) {
if(_.hasOwn(message.tags, "followers-only")) {
if(message.tags["followers-only"] === "-1") {
let disabled = [channel, false, 0];
this.log.info(`[${channel}] This room is no longer in followers-only mode.`);
Expand Down Expand Up @@ -1010,7 +1010,7 @@ client.prototype.handleMessage = function handleMessage(message) {
this.log.info(`[WHISPER] <${nick}>: ${msg}`);

// Update the tags to provide the username..
if(!message.tags.hasOwnProperty("username")) {
if(!_.hasOwn(message.tags, "username")) {
message.tags.username = nick;
}
message.tags["message-type"] = "whisper";
Expand Down Expand Up @@ -1052,22 +1052,22 @@ client.prototype.handleMessage = function handleMessage(message) {
message.tags["message-type"] = actionMessage ? "action" : "chat";
msg = actionMessage ? actionMessage[1] : msg;
// Check for Bits prior to actions message
if (message.tags.hasOwnProperty("bits")) {
if(_.hasOwn(message.tags, "bits")) {
this.emit("cheer", channel, message.tags, msg);
}
else {
//Handle Channel Point Redemptions (Require's Text Input)
if (message.tags.hasOwnProperty("msg-id")) {
if (message.tags["msg-id"] === "highlighted-message") {
if(_.hasOwn(message.tags, "msg-id")) {
if(message.tags["msg-id"] === "highlighted-message") {
let rewardtype = message.tags["msg-id"];
this.emit("redeem", channel, message.tags.username, rewardtype, message.tags, msg);
}
else if (message.tags["msg-id"] === "skip-subs-mode-message") {
else if(message.tags["msg-id"] === "skip-subs-mode-message") {
let rewardtype = message.tags["msg-id"];
this.emit("redeem", channel, message.tags.username, rewardtype, message.tags, msg);
}
}
else if (message.tags.hasOwnProperty("custom-reward-id")) {
else if(_.hasOwn(message.tags, "custom-reward-id")) {
let rewardtype = message.tags["custom-reward-id"];
this.emit("redeem", channel, message.tags.username, rewardtype, message.tags, msg);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var _ = module.exports = {
// Return the second value if the first value is undefined..
get: (obj1, obj2) => typeof obj1 === "undefined" ? obj2 : obj1,

// Indirectly use hasOwnProperty
hasOwn: (obj, key) => ({}).hasOwnProperty.call(obj, key),

// Race a promise against a delay..
promiseDelay: time => new Promise(resolve => setTimeout(resolve, time)),

Expand Down

0 comments on commit 90ab699

Please sign in to comment.