TwitchLib / TwitchLib.PubSub

PubSub component of TwitchLib.
38 stars 51 forks source link

CommunityPointsChannel Error on Accept / Reject #65

Closed Omsad closed 4 years ago

Omsad commented 4 years ago

Hi,

You're currently treating any redemption that isn't "custom-reward-created", "custom-reward-updated" or "custom-reward-deleted" as a "reward-redeemed" message as the CommunityPointsChannelType enumeration will default to 0, e.g. RewardRedeemed.

This looks to be working for a "redemption-status-update" message, e.g. when an individual redemption is accepted or rejected, as it's looks identical apart from the fact that the status is "ACTION_TAKEN" rather than "UNFULFILLED".

This isn't working for an "update-redemption-statuses-progress" message, e.g. when multiple redemptions are accepted or rejected, as that wont parse into a "reward-redeemed" message.

JSON for redemption-status-update Accept or Reject

{
  "type": "redemption-status-update",
  "data": {
    "timestamp": "2020-09-22T08:24:54.957851305Z",
    "redemption": {
      "id": "fe6e9461-cfbd-4dce-95f8-38cce2ed63ce",
      "user": {
        "id": "132584336",
        "login": "omsad",
        "display_name": "Omsad"
      },
      "channel_id": "129484732",
      "redeemed_at": "2020-09-22T08:24:17.721175891Z",
      "reward": {
        "id": "5f7c47b5-5221-4615-a1a3-01d926ec8045",
        "channel_id": "129484732",
        "title": "Viewerkit",
        "prompt": "Bring me my next loadout",
        "cost": 10000,
        "is_user_input_required": false,
        "is_sub_only": false,
        "image": null,
        "default_image": null,
        "background_color": "#000000",
        "is_enabled": false,
        "is_paused": false,
        "is_in_stock": false,
        "max_per_stream": {
          "is_enabled": false,
          "max_per_stream": 0
        },
        "should_redemptions_skip_request_queue": false,
        "template_id": null,
        "updated_for_indicator_at": null,
        "max_per_user_per_stream": {
          "is_enabled": false,
          "max_per_user_per_stream": 0
        },
        "global_cooldown": {
          "is_enabled": false,
          "global_cooldown_seconds": 0
        },
        "redemptions_redeemed_current_stream": null,
        "cooldown_expires_at": null
      },
      "status": "ACTION_TAKEN",
      "cursor": "ZmU2ZTk0NjEtY2ZiZC00ZGNlLTk1ZjgtMzhjY2UyZWQ2M2NlX18yMDIwLTA5LTIyVDA4OjI0OjE3LjcyMTE3NTg5MVo="
    }
  }
}

JSON for update-redemption-statuses-progress Accept or Reject

{
  "type": "update-redemption-statuses-progress",
  "data": {
    "timestamp": "2020-09-22T08:29:14.317483705Z",
    "progress": {
      "id": "Y29wb0J1bGtFZGl0UmVkZW1wdGlvblN0YXR1c1Byb2dyZXNzOjEyOTQ4NDczMjpCVUxLX0VESVRfUkVERU1QVElPTl9TVEFUVVNfTUVUSE9EX0JZX0NIQU5ORUw6",
      "channel_id": "129484732",
      "method": "BY_CHANNEL",
      "new_status": "CANCELED",
      "processed": 0,
      "total": 0
    }
  }
}

As the redemption-status-update message doesn't help in anyway at the moment and update-redemption-statuses-progress message causes PubSub service to throw an exception I have changed my local copy of the code to:

JToken json = JObject.Parse(jsonStr);
switch (json.SelectToken("type").ToString())
{
    //Existing cases removed for breviary...

    default:
    case "redemption-status-update":
    case "update-redemption-statuses-progress":
        Type = (CommunityPointsChannelType)(-1);
        break;
}

This will then cause the messages to be ignored.

I would like to update the code so that a "redemption-status-update" message would raise the same event as an "reward-redeemed" message but with a correct status, is there anyway of figuring out the status from the json provided?

Also is it true that an "update-redemption-statuses-progress" message could accept or reject all messages sent previous before or on the timestamp, e.g. is there any additional logic which I would need to implement to make sure I'm not rejecting anything which has already been accepted or vice versa?

Omsad commented 4 years ago

I've created a pull request #66 to fix the above.

Syzuna commented 4 years ago

Your PR to fix that and other issues was merged and a new prerelease version containing it, is already available on nuget.

Thanks again and sorry that you had to wait :)