Skip to content

Commit

Permalink
Add a "check-in" (non-competitive) option alongside first etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Aug 12, 2024
1 parent 56af3d5 commit ec3994a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions httpstatic/chan_minigames.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function render(data) {
LI(LABEL([INPUT({type: "checkbox", name: "second", checked: Boolean(first.second)}), " Second"])),
LI(LABEL([INPUT({type: "checkbox", name: "third", checked: Boolean(first.third)}), " Third"])),
LI(LABEL([INPUT({type: "checkbox", name: "last", checked: Boolean(first.last)}), " Last"])),
LI(LABEL([INPUT({type: "checkbox", name: "checkin", checked: Boolean(first.checkin)}), " Check-in (may be redeemed once each by all users)"])),
]));
}

Expand Down
41 changes: 41 additions & 0 deletions modules/http/chan_minigames.pike
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ constant sections = ([
"second": 0,
"third": 0,
"last": 0,
"checkin": 0,
]),
]);

Expand Down Expand Up @@ -217,9 +218,21 @@ constant first_code = #"
}
}
";
constant checkin_code = #"
#access \"none\"
#visibility \"hidden\"
#redemption \"%s\"
try {
chan_pointsrewards(\"{rewardid}\", \"fulfil\", \"{redemptionid}\") \"\"
}
catch \"Unexpected error: {error}\"
$*checkins$ += \"1\"
\"Thank you for signing the guest book for today, {username}! You have signed it $*checkins$ times.\"
";

__async__ void update_first(object channel, mapping game) {
//First (pun intended), some validation. Sequential rewards depend on each other.
//(Note that "checkin" doesn't require "first" or any others.)
int changed = 0;
if (!game->first && (game->second || game->last)) {
game->second = game->last = 0;
Expand Down Expand Up @@ -272,6 +285,33 @@ __async__ void update_first(object channel, mapping game) {
if (channel->commands["rwd" + which]) G->G->cmdmgr->update_command(channel, "", "rwd" + which, "");
}
}
if (game->checkin) {
if (!game->checkinrwd) {
mapping resp = await(twitch_api_request("https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=" + channel->userid,
(["Authorization": channel->userid]),
(["json": ([
"title": "Check-in!",
"cost": 1,
"prompt": "Daily check-in! Non-competitive.",
"is_max_per_user_per_stream_enabled": Val.true, "max_per_user_per_stream": 1,
]), "return_errors": 1])));
if (resp->data && sizeof(resp->data)) game->checkinrwd = resp->data[0]->id; //As above, otherwise what?
changed = 1;
}
if (!channel->commands->rwdcheckin) {
string code = sprintf(checkin_code, game->checkinrwd || "");
werror("CODE:\n%s\n", code);
G->G->cmdmgr->update_command(channel, "", "rwdcheckin", code, (["language": "mustard"]));
}
} else {
if (string id = m_delete(game, "checkinrwd")) {
await(twitch_api_request("https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=" + channel->userid + "&id=" + id,
(["Authorization": channel->userid]),
(["method": "DELETE"])));
changed = 1;
}
if (channel->commands["rwdcheckin"]) G->G->cmdmgr->update_command(channel, "", "rwdcheckin", "");
}
if (changed) {
await(G->G->DB->mutate_config(channel->userid, "minigames") {__ARGS__[0]->first = game;});
send_updates_all(channel, "");
Expand All @@ -283,6 +323,7 @@ constant builtin_name = "Minigame";
constant builtin_param = ({"/Game/first", "Extra info"});
constant vars_provided = ([
"{shame}": "1 if user should be shamed for duplicate claiming",
"{count}": "Number of times the user has checked in (once per stream)",
]);

//Should this be stored somewhere other than ephemeral memory? If the bot hops, this gets lost, with the (tragic) result
Expand Down

0 comments on commit ec3994a

Please sign in to comment.