Repository: twitch-apis/twitch-js
Pull request #179 (2018-11-16 02:08:16)

Feature: add USERNOTICE event anongiftpaidupgrade
## Proposed changes

Adding USERNOTICE event ``anongiftpaidupgrade``

## Types of changes

* [x] New feature (non-breaking change which adds functionality)

## Checklist

* [x] I have read the [CONTRIBUTING](https://github.com/twitch-apis/twitch-js/blob/master/CONTRIBUTING.md) doc
* [x] My PR is named according to [CONTRIBUTING](https://github.com/twitch-apis/twitch-js/blob/master/CONTRIBUTING.md) doc
* [x] Lint and unit tests pass locally with my changes
* [ ] I have added tests that prove my fix is effective or that my feature works
* [x] I have added necessary documentation (if appropriate)
* [ ] Any dependent changes have been merged and published in downstream modules

## Further comments

I saw there is now anonymous gifting and with that, the ``anongiftpaidupgrade`` USERNOTICE event
The anon gift itself comes through as a ``submysterygift`` and ``subgift`` from the user 'ananonymousgifter'

Here are those raw messages in case we want to do something with them
``@badges=;color=;display-name=AnAnonymousGifter;emotes=;flags=;id=8d7b77b1-a7a2-481f-9e66-d855f028f930;login=ananonymousgifter;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=1;msg-param-origin-id=df\s01\sf1\s1b\sc0\s02\sb4\s9e\s2a\s8a\s56\s61\s75\s4a\sd9\s53\s3d\s20\sae\sdd;msg-param-sub-plan=1000;room-id=51533859;subscriber=0;system-msg=An\sanonymous\suser\sis\sgifting\s1\sTier\s1\sSubs\sto\sAnneMunition's\scommunity!;tmi-sent-ts=1542333218921;turbo=0;user-id=274598607;user-type= :tmi.twitch.tv USERNOTICE #annemunition``


``@badges=;color=;display-name=AnAnonymousGifter;emotes=;flags=;id=d513c6e8-2b7b-4806-a0ac-21c40180d092;login=ananonymousgifter;mod=0;msg-id=subgift;msg-param-fun-string=FunStringFive;msg-param-months=1;msg-param-origin-id=da\s39\sa3\see\s5e\s6b\s4b\s0d\s32\s55\sbf\sef\s95\s60\s18\s90\saf\sd8\s07\s09;msg-param-recipient-display-name=CHEESEoMUNCHIES;msg-param-recipient-id=29044717;msg-param-recipient-user-name=cheeseomunchies;msg-param-sub-plan-name=Armory\sEnlistment;msg-param-sub-plan=1000;room-id=51533859;subscriber=0;system-msg=An\sanonymous\suser\sgifted\sa\sTier\s1\ssub\sto\sCHEESEoMUNCHIES!\s;tmi-sent-ts=1542333219839;turbo=0;user-id=274598607;user-type= :tmi.twitch.tv USERNOTICE #annemunition``


I think I got everything added everywhere for the docs and such? Let me know if I missed something. Thanks! 😄 

codecov[bot]: # [Codecov](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=h1) Report
> Merging [#179](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=desc) into [next](https://codecov.io/gh/twitch-apis/twitch-js/commit/8563d3b684b296d592aa3c7064ad3f44e0a01225?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/twitch-apis/twitch-js/pull/179/graphs/tree.svg?width=650&token=qKety0Jenl&height=150&src=pr)](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##             next     #179      +/-   ##
==========================================
+ Coverage   97.22%   97.22%   +<.01%     
==========================================
  Files          21       21              
  Lines         540      541       +1     
  Branches       75       75              
==========================================
+ Hits          525      526       +1     
  Misses         15       15
```


| [Impacted Files](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/Chat/utils/parsers/index.js](https://codecov.io/gh/twitch-apis/twitch-js/pull/179/diff?src=pr&el=tree#diff-c3JjL0NoYXQvdXRpbHMvcGFyc2Vycy9pbmRleC5qcw==) | `100% <ø> (ø)` | :arrow_up: |
| [src/Chat/index.js](https://codecov.io/gh/twitch-apis/twitch-js/pull/179/diff?src=pr&el=tree#diff-c3JjL0NoYXQvaW5kZXguanM=) | `97.38% <ø> (ø)` | :arrow_up: |
| [src/Chat/constants.js](https://codecov.io/gh/twitch-apis/twitch-js/pull/179/diff?src=pr&el=tree#diff-c3JjL0NoYXQvY29uc3RhbnRzLmpz) | `100% <100%> (ø)` | :arrow_up: |
| [src/Chat/utils/parsers/tags.js](https://codecov.io/gh/twitch-apis/twitch-js/pull/179/diff?src=pr&el=tree#diff-c3JjL0NoYXQvdXRpbHMvcGFyc2Vycy90YWdzLmpz) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=footer). Last update [8563d3b...50568c7](https://codecov.io/gh/twitch-apis/twitch-js/pull/179?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/__mocks__/ws/__fixtures__/tags.json b/__mocks__/ws/__fixtures__/tags.json
index fb73dfd..2528805 100644
--- a/__mocks__/ws/__fixtures__/tags.json
+++ b/__mocks__/ws/__fixtures__/tags.json
@@ -16,6 +16,7 @@
     "UPDATE_SLOW": "@slow=10 :tmi.twitch.tv ROOMSTATE #dallas"
   },
   "USERNOTICE": {
+    "ANON_GIFT_PAID_UPGRADE": "@badges=subscriber/0,premium/1;color=#8A2BE2;display-name=MrSquidzilla;emotes=;flags=;id=0717057c-510d-4da4-8d25-b592803bdeac;login=mrsquidzilla;mod=0;msg-id=anongiftpaidupgrade;room-id=51533859;subscriber=1;system-msg=MrSquidzilla\\sis\\scontinuing\\sthe\\sGift\\sSub\\sthey\\sgot\\sfrom\\san\\sanonymous\\suser!;tmi-sent-ts=1542326428725;turbo=0;user-id=43818429;user-type= :tmi.twitch.tv USERNOTICE #annemunition",
     "GIFT_PAID_UPGRADE": "@badges=subscriber/0,premium/1;color=#8A2BE2;display-name=ElizabethSwann;emotes=;id=5bd3e064-c1e4-451b-9d7e-afe8cf5a44a2;login=elizabethswann;mod=0;msg-id=giftpaidupgrade;msg-param-promo-gift-total=123816;msg-param-promo-name=Subtember;msg-param-sender-login=cannibulcake;msg-param-sender-name=CannibulCake;room-id=7236692;subscriber=1;system-msg=ElizabethSwann\\sis\\scontinuing\\sthe\\sGift\\sSub\\sthey\\sgot\\sfrom\\sCannibulCake!\\sThey're\\sone\\sof\\s123816\\sgift\\ssubs\\sto\\scontinue\\sthis\\sSubtember.;tmi-sent-ts=1536880884587;turbo=0;user-id=85946347;user-type= :tmi.twitch.tv USERNOTICE #dansgaming",
     "SUBSCRIPTION": "@badges=staff/1,broadcaster/1,turbo/1;color=#008000;display-name=ronni;emotes=;id=db25007f-7a18-43eb-9379-80131e44d633;login=ronni;mod=0;msg-id=sub;msg-param-months=1;msg-param-sub-plan=Prime;msg-param-sub-plan-name=Prime;room-id=1337;subscriber=1;system-msg=ronni\\sjust\\ssubscribed\\swith\\sTwitch\\sPrime!;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=staff :tmi.twitch.tv USERNOTICE #dallas :Great stream -- keep it up!",
     "RESUBSCRIPTION": "@badges=staff/1,broadcaster/1,turbo/1;color=#008000;display-name=ronni;emotes=;id=db25007f-7a18-43eb-9379-80131e44d633;login=ronni;mod=0;msg-id=resub;msg-param-months=6;msg-param-sub-plan=Prime;msg-param-sub-plan-name=Prime;room-id=1337;subscriber=1;system-msg=ronni\\shas\\ssubscribed\\sfor\\s6\\smonths!;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=staff :tmi.twitch.tv USERNOTICE #dallas :Great stream -- keep it up!",
diff --git a/docs/reference/class.md b/docs/reference/class.md
index 150fd64..291879b 100644
--- a/docs/reference/class.md
+++ b/docs/reference/class.md
@@ -218,7 +218,7 @@ Chat client
 
 **Kind**: global class  
 **Extends**: [<code>EventEmitter3</code>](external#external_EventEmitter3)  
-**Emits**: [<code>\*</code>](#Chat+event_*), [<code>CLEARCHAT</code>](#Chat+event_CLEARCHAT), [<code>CLEARCHAT/USER_BANNED</code>](#Chat+event_CLEARCHAT/USER_BANNED), [<code>GLOBALUSERSTATE</code>](#Chat+event_GLOBALUSERSTATE), [<code>HOSTTARGET</code>](#Chat+event_HOSTTARGET), [<code>JOIN</code>](#Chat+event_JOIN), [<code>MODE</code>](#Chat+event_MODE), [<code>NAMES</code>](#Chat+event_NAMES), [<code>NAMES_END</code>](#Chat+event_NAMES_END), [<code>NOTICE</code>](#Chat+event_NOTICE), [<code>NOTICE/ROOM_MODS</code>](#Chat+event_NOTICE/ROOM_MODS), [<code>PART</code>](#Chat+event_PART), [<code>PRIVMSG</code>](#Chat+event_PRIVMSG), [<code>PRIVMSG/CHEER</code>](#Chat+event_PRIVMSG/CHEER), [<code>ROOMSTATE</code>](#Chat+event_ROOMSTATE), <code>Chat#event:USERNOTICE</code>, [<code>USERNOTICE/GIFT_PAID_UPGRADE</code>](#Chat+event_USERNOTICE/GIFT_PAID_UPGRADE), [<code>USERNOTICE/RAID</code>](#Chat+event_USERNOTICE/RAID), [<code>USERNOTICE/RESUBSCRIPTION</code>](#Chat+event_USERNOTICE/RESUBSCRIPTION), [<code>USERNOTICE/RITUAL</code>](#Chat+event_USERNOTICE/RITUAL), [<code>USERNOTICE/SUBSCRIPTION</code>](#Chat+event_USERNOTICE/SUBSCRIPTION), [<code>USERNOTICE/SUBSCRIPTION_GIFT</code>](#Chat+event_USERNOTICE/SUBSCRIPTION_GIFT), [<code>USERSTATE</code>](#Chat+event_USERSTATE)  
+**Emits**: [<code>\*</code>](#Chat+event_*), [<code>CLEARCHAT</code>](#Chat+event_CLEARCHAT), [<code>CLEARCHAT/USER_BANNED</code>](#Chat+event_CLEARCHAT/USER_BANNED), [<code>GLOBALUSERSTATE</code>](#Chat+event_GLOBALUSERSTATE), [<code>HOSTTARGET</code>](#Chat+event_HOSTTARGET), [<code>JOIN</code>](#Chat+event_JOIN), [<code>MODE</code>](#Chat+event_MODE), [<code>NAMES</code>](#Chat+event_NAMES), [<code>NAMES_END</code>](#Chat+event_NAMES_END), [<code>NOTICE</code>](#Chat+event_NOTICE), [<code>NOTICE/ROOM_MODS</code>](#Chat+event_NOTICE/ROOM_MODS), [<code>PART</code>](#Chat+event_PART), [<code>PRIVMSG</code>](#Chat+event_PRIVMSG), [<code>PRIVMSG/CHEER</code>](#Chat+event_PRIVMSG/CHEER), [<code>ROOMSTATE</code>](#Chat+event_ROOMSTATE), <code>Chat#event:USERNOTICE</code>, [<code>USERNOTICE/ANON_GIFT_PAID_UPGRADE</code>](#Chat+event_USERNOTICE/ANON_GIFT_PAID_UPGRADE), [<code>USERNOTICE/GIFT_PAID_UPGRADE</code>](#Chat+event_USERNOTICE/GIFT_PAID_UPGRADE), [<code>USERNOTICE/RAID</code>](#Chat+event_USERNOTICE/RAID), [<code>USERNOTICE/RESUBSCRIPTION</code>](#Chat+event_USERNOTICE/RESUBSCRIPTION), [<code>USERNOTICE/RITUAL</code>](#Chat+event_USERNOTICE/RITUAL), [<code>USERNOTICE/SUBSCRIPTION</code>](#Chat+event_USERNOTICE/SUBSCRIPTION), [<code>USERNOTICE/SUBSCRIPTION_GIFT</code>](#Chat+event_USERNOTICE/SUBSCRIPTION_GIFT), [<code>USERSTATE</code>](#Chat+event_USERSTATE)  
 
 * [Chat](#Chat) ⇐ [<code>EventEmitter3</code>](external#external_EventEmitter3)
     * [new Chat(options)](#new_Chat_new)
@@ -250,6 +250,7 @@ Chat client
     * ["PRIVMSG"](#Chat+event_PRIVMSG)
     * ["PRIVMSG/CHEER"](#Chat+event_PRIVMSG/CHEER)
     * ["PRIVMSG/HOSTED"](#Chat+event_PRIVMSG/HOSTED)
+    * ["USERNOTICE/ANON_GIFT_PAID_UPGRADE"](#Chat+event_USERNOTICE/ANON_GIFT_PAID_UPGRADE)
     * ["USERNOTICE/GIFT_PAID_UPGRADE"](#Chat+event_USERNOTICE/GIFT_PAID_UPGRADE)
     * ["USERNOTICE/RAID"](#Chat+event_USERNOTICE/RAID)
     * ["USERNOTICE/RESUBSCRIPTION"](#Chat+event_USERNOTICE/RESUBSCRIPTION)
@@ -900,6 +901,30 @@ When a user hosts your channel while connected as broadcaster.
 </table>
 
 
+* * *
+
+<a name="Chat+event_USERNOTICE/ANON_GIFT_PAID_UPGRADE"></a>
+
+### "USERNOTICE/ANON_GIFT_PAID_UPGRADE"
+On anonymous gifted subscription paid upgrade to a channel.
+
+**Kind**: event emitted by [<code>Chat</code>](class#Chat)  
+**Mixes**: [<code>UserStateMessage</code>](mixin#UserStateMessage)  
+**Properties**
+
+<table>
+  <thead>
+    <tr>
+      <th>Name</th><th>Type</th>
+    </tr>
+  </thead>
+  <tbody>
+<tr>
+    <td>event</td><td><code>&#x27;ANON_GIFT_PAID_UPGRADE&#x27;</code></td>
+    </tr>  </tbody>
+</table>
+
+
 * * *
 
 <a name="Chat+event_USERNOTICE/GIFT_PAID_UPGRADE"></a>
diff --git a/src/Chat/constants.js b/src/Chat/constants.js
index 1e58698..9db75d3 100644
--- a/src/Chat/constants.js
+++ b/src/Chat/constants.js
@@ -146,6 +146,7 @@ export const NOTICE_MESSAGE_IDS = {
 
 // See https://dev.twitch.tv/docs/irc/tags#usernotice-twitch-tags.
 export const USER_NOTICE_MESSAGE_IDS = {
+  ANON_GIFT_PAID_UPGRADE: 'anongiftpaidupgrade',
   GIFT_PAID_UPGRADE: 'giftpaidupgrade',
   RAID: 'raid',
   RESUBSCRIPTION: 'resub',
@@ -178,6 +179,7 @@ export const EVENTS = {
   ERROR_ENCOUNTERED: 'ERROR_ENCOUNTERED',
   PARSE_ERROR_ENCOUNTERED: 'PARSE_ERROR_ENCOUNTERED',
 
+  ANON_GIFT_PAID_UPGRADE: 'ANON_GIFT_PAID_UPGRADE',
   GIFT_PAID_UPGRADE: 'GIFT_PAID_UPGRADE',
   RAID: 'RAID',
   RESUBSCRIPTION: 'RESUBSCRIPTION',
diff --git a/src/Chat/index.js b/src/Chat/index.js
index 010b9d2..b2a30eb 100644
--- a/src/Chat/index.js
+++ b/src/Chat/index.js
@@ -39,6 +39,7 @@ import * as validators from './utils/validators'
  * @emits Chat#PRIVMSG/CHEER
  * @emits Chat#ROOMSTATE
  * @emits Chat#USERNOTICE
+ * @emits Chat#USERNOTICE/ANON_GIFT_PAID_UPGRADE
  * @emits Chat#USERNOTICE/GIFT_PAID_UPGRADE
  * @emits Chat#USERNOTICE/RAID
  * @emits Chat#USERNOTICE/RESUBSCRIPTION
diff --git a/src/Chat/utils/parsers/index.js b/src/Chat/utils/parsers/index.js
index fd8153e..96b3f4b 100644
--- a/src/Chat/utils/parsers/index.js
+++ b/src/Chat/utils/parsers/index.js
@@ -397,7 +397,14 @@ const userNoticeMessage = baseMessage => {
 
   /* eslint-disable no-fallthrough */
   switch (tags.msgId) {
-    case constants.USER_NOTICE_MESSAGE_IDS.GIFT_PAID_UPGRADE:
+    /**
+     * On anonymous gifted subscription paid upgrade to a channel.
+     * @event Chat#USERNOTICE/ANON_GIFT_PAID_UPGRADE
+     * @mixes UserStateMessage AnonGiftPaidUpgradeMessage
+     * @property {'ANON_GIFT_PAID_UPGRADE'} event
+     */
+    case constants.USER_NOTICE_MESSAGE_IDS.ANON_GIFT_PAID_UPGRADE:
+
     /**
      * On gifted subscription paid upgrade to a channel.
      * @event Chat#USERNOTICE/GIFT_PAID_UPGRADE
@@ -409,6 +416,7 @@ const userNoticeMessage = baseMessage => {
      * @property {string} parameters.senderLogin
      * @property {string} parameters.senderName
      */
+    case constants.USER_NOTICE_MESSAGE_IDS.GIFT_PAID_UPGRADE:
 
     /**
      * On channel raid.
diff --git a/src/Chat/utils/parsers/tags.js b/src/Chat/utils/parsers/tags.js
index 85cc7f3..0b34b40 100644
--- a/src/Chat/utils/parsers/tags.js
+++ b/src/Chat/utils/parsers/tags.js
@@ -95,6 +95,8 @@ const userNoticeMessageParameters = tags =>
 
 const userNoticeEvent = tags => {
   switch (tags.msgId) {
+    case constants.USER_NOTICE_MESSAGE_IDS.ANON_GIFT_PAID_UPGRADE:
+      return constants.EVENTS.ANON_GIFT_PAID_UPGRADE
     case constants.USER_NOTICE_MESSAGE_IDS.GIFT_PAID_UPGRADE:
       return constants.EVENTS.GIFT_PAID_UPGRADE
     case constants.USER_NOTICE_MESSAGE_IDS.RESUBSCRIPTION:


Test patch:
diff --git a/src/Chat/__tests__/__snapshots__/index.test.js.snap b/src/Chat/__tests__/__snapshots__/index.test.js.snap
index e9022b6..99b6be1 100644
--- a/src/Chat/__tests__/__snapshots__/index.test.js.snap
+++ b/src/Chat/__tests__/__snapshots__/index.test.js.snap
@@ -1010,6 +1010,47 @@ Object {
 
 exports[`Chat should handle messages PRIVMSG whisper when anonymous 1`] = `[Error: Not authenticated]`;
 
+exports[`Chat should handle messages USERNOTICE ANON_GIFT_PAID_UPGRADE 1`] = `
+Object {
+  "_raw": "@badges=subscriber/0,premium/1;color=#8A2BE2;display-name=MrSquidzilla;emotes=;flags=;id=0717057c-510d-4da4-8d25-b592803bdeac;login=mrsquidzilla;mod=0;msg-id=anongiftpaidupgrade;room-id=51533859;subscriber=1;system-msg=MrSquidzilla\\\\sis\\\\scontinuing\\\\sthe\\\\sGift\\\\sSub\\\\sthey\\\\sgot\\\\sfrom\\\\san\\\\sanonymous\\\\suser!;tmi-sent-ts=1542326428725;turbo=0;user-id=43818429;user-type= :tmi.twitch.tv USERNOTICE #annemunition",
+  "channel": "#annemunition",
+  "command": "USERNOTICE",
+  "event": "ANON_GIFT_PAID_UPGRADE",
+  "isSelf": false,
+  "message": undefined,
+  "parameters": Object {},
+  "systemMessage": "MrSquidzilla is continuing the Gift Sub they got from an anonymous user!",
+  "tags": Object {
+    "badges": Object {
+      "premium": 1,
+      "subscriber": 0,
+    },
+    "bits": undefined,
+    "color": "#8A2BE2",
+    "displayName": "MrSquidzilla",
+    "emoteSets": undefined,
+    "emotes": Array [],
+    "flags": true,
+    "id": "0717057c-510d-4da4-8d25-b592803bdeac",
+    "isModerator": false,
+    "isSubGifter": false,
+    "isSubscriber": true,
+    "isTurboSubscriber": false,
+    "login": "mrsquidzilla",
+    "mod": "0",
+    "msgId": "anongiftpaidupgrade",
+    "roomId": "51533859",
+    "subscriber": "1",
+    "systemMsg": "MrSquidzilla is continuing the Gift Sub they got from an anonymous user!",
+    "tmiSentTs": "1542326428725",
+    "turbo": "0",
+    "userId": "43818429",
+    "userType": undefined,
+  },
+  "timestamp": Any<Date>,
+}
+`;
+
 exports[`Chat should handle messages USERNOTICE GIFT_PAID_UPGRADE 1`] = `
 Object {
   "_raw": "@badges=subscriber/0,premium/1;color=#8A2BE2;display-name=ElizabethSwann;emotes=;id=5bd3e064-c1e4-451b-9d7e-afe8cf5a44a2;login=elizabethswann;mod=0;msg-id=giftpaidupgrade;msg-param-promo-gift-total=123816;msg-param-promo-name=Subtember;msg-param-sender-login=cannibulcake;msg-param-sender-name=CannibulCake;room-id=7236692;subscriber=1;system-msg=ElizabethSwann\\\\sis\\\\scontinuing\\\\sthe\\\\sGift\\\\sSub\\\\sthey\\\\sgot\\\\sfrom\\\\sCannibulCake!\\\\sThey're\\\\sone\\\\sof\\\\s123816\\\\sgift\\\\ssubs\\\\sto\\\\scontinue\\\\sthis\\\\sSubtember.;tmi-sent-ts=1536880884587;turbo=0;user-id=85946347;user-type= :tmi.twitch.tv USERNOTICE #dansgaming",