Skip to content

Commit

Permalink
Fixed some badge-related functions for chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Reboot0 committed Feb 21, 2022
1 parent c139305 commit ca062e8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/se-tools.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/module-ChatMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -1390,8 +1390,8 @@ <h4 class="name" id="getTierBadge">


<div class="description">
<p>Returns the users current subscription-tier as number. (1 = tier 1, 2 = tier 2, 3 = tier 3)</p>
<p>Prime subs still count as tier 1.</p>
<p>Returns the users current subscription-tier as number. (1 = tier 1, 2 = tier 2, 3 = tier 3, 0 = no sub)</p>
<p>Prime subs still count as tier 1 and non-subs return 0</p>
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial-ChatMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ <h1>Class properties</h1>
<tr>
<td>userId</td>
<td>string</td>
<td>The unique ID of the message's sender</td>
<td>The unique ID of the author.</td>
<td><code>&quot;123456789&quot;</code></td>
</tr>
<tr>
<td>username</td>
<td>string</td>
<td>The username of the message's sender. Capitalization may vary</td>
<td>The username of the author. Capitalization may vary</td>
<td><code>&quot;SenderName&quot;</code></td>
</tr>
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions jsdoc/tutorials/ChatMessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ The class object has the following properties available:
|roles | Object | An object with boolean values for each possible user-role in the channel | `{ staff: false, broadcaster: true, moderator: false, vip: false, subscriber: true }` |
|text | string | The plain-text content of the message | `"Nice PogChamp"` |
|time | Date | A Date object referring to the time the message was sent | A [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance |
|userId | string | The unique ID of the message's sender | `"123456789"` |
|username | string | The username of the message's sender. Capitalization may vary | `"SenderName"` |
|userId | string | The unique ID of the author. | `"123456789"` |
|username | string | The username of the author. Capitalization may vary | `"SenderName"` |


# Text Operations
Expand Down Expand Up @@ -275,4 +275,4 @@ There are other functions which are not as significant as the other functions, b

`getDisplayColor()` returns either the users set color or generates a new random hex-string. This will always return a color value.

`getWordList()` returns an array with every word that was used in the message.
`getWordList()` returns an array with every word that was used in the message.
19 changes: 10 additions & 9 deletions modules/ChatMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,19 @@ export default class ChatMessage
}

/**
* Returns the users current subscription-tier as number. (1 = tier 1, 2 = tier 2, 3 = tier 3)
* Returns the users current subscription-tier as number. (1 = tier 1, 2 = tier 2, 3 = tier 3, 0 = no sub)
*
* Prime subs still count as tier 1.
* Prime subs still count as tier 1 and non-subs return 0
* @return {number}
* @since 1.0.0
*/
getTierBadge()
{
const groups = Utils.matchRegexGroups(this.raw.tags.badges, /subscriber\/(?<tier>[2|3]0)[1-9][0-9]*/i);
if(!groups?.tier) return 1;
if(groups.tier === "20") return 2;
if(groups.tier === "30") return 3;
const match = new RegExp("subscriber\\/(?<tier>[2|3]0)?[0-9]+", "i").exec(this.raw.data.tags.badges);
if(match === null) { return 0; }
if(match?.groups?.tier === '20') return 2;
if(match?.groups?.tier === '30') return 3;
return 1;
}

/**
Expand All @@ -222,7 +223,7 @@ export default class ChatMessage
*/
getBitsBadge()
{
const groups = Utils.matchRegexGroups(this.raw.tags.badges, /bits\/(?<bits>[1-9][0-9]*)/i);
const groups = Utils.matchRegexGroups(this.raw.data.tags.badges, /bits\/(?<bits>[1-9][0-9]*)/i);
return (groups?.bits) ? parseInt(groups.bits) : 0;
}

Expand All @@ -235,7 +236,7 @@ export default class ChatMessage
*/
getGiftsBadge()
{
const groups = Utils.matchRegexGroups(this.raw.tags.badges, /sub-gifter\/(?<gifts>[1-9][0-9]*)/i);
const groups = Utils.matchRegexGroups(this.raw.data.tags.badges, /sub-gifter\/(?<gifts>[1-9][0-9]*)/i);
return (groups?.gifts) ? parseInt(groups.gifts) : 0;
}

Expand Down Expand Up @@ -387,4 +388,4 @@ export default class ChatMessage
{
return Utils.matchesRegex(this.username, regex);
}
}
}

0 comments on commit ca062e8

Please sign in to comment.