Skip to content

Commit 58d62f8

Browse files
committed
initial implementation of emotes by tiers
1 parent d71ae60 commit 58d62f8

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Homestead.json
77
/access.log
88
/error.log
99
.phpintel
10-
.idea
10+
.idea
11+
.vscode

app/Http/Controllers/TwitchController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ public function subEmotes(Request $request, $channel = null)
18331833
{
18341834
$channel = $channel ?: $request->input('channel', null);
18351835
$wantsJson = (($request->wantsJson() || $request->exists('json')) ? true : false);
1836+
$wantsPlans = ($request -> exists('tiers') && $wantsJson);
18361837
$id = $request->input('id', 'false');
18371838

18381839
if (empty($channel)) {
@@ -1913,6 +1914,16 @@ public function subEmotes(Request $request, $channel = null)
19131914
}
19141915

19151916
// We only care about the emote codes.
1917+
// or do we?
1918+
if ($wantsPlans) {
1919+
$plans = $emotes['plans'];
1920+
$emotesData = $emotes['emotes'];
1921+
$emotesTiers = $plans->sortEmotes($emotesData);
1922+
return $this->json([
1923+
'emotes' => $emotesTiers,
1924+
]);
1925+
}
1926+
19161927
$emotes = $emotes['emotes'];
19171928
$emoteCodes = $emotes->codes();
19181929

app/Http/Resources/TwitchEmotes/Channel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function toArray($request)
1717
$res = $this->resource;
1818

1919
$emotes = EmotesCollection::make(collect($res['emotes']));
20+
$plans = Plans::make($res['plans']);
2021

2122
return [
2223
'name' => $res['channel_name'],
@@ -27,7 +28,7 @@ public function toArray($request)
2728
'generated_at' => $res['generated_at'],
2829

2930
'emotes' => $emotes,
30-
'plans' => $res['plans'],
31+
'plans' => $plans,
3132
'badges' => [
3233
'subscribers' => $res['subscriber_badges'] ?? null,
3334
'bits' => $res['bits_badges'] ?? null,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
// aaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
4+
5+
namespace App\Http\Resources\TwitchEmotes;
6+
7+
use Illuminate\Http\Resources\Json\ResourceCollection;
8+
use Log;
9+
10+
class Plans extends ResourceCollection
11+
{
12+
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
13+
public function toArray($request)
14+
{
15+
$res = $this->resource;
16+
17+
return [
18+
'tier1' => $res['$4.99'],
19+
'tier2' => $res['$9.99'],
20+
'tier3' => $res['$24.99'],
21+
];
22+
}
23+
24+
// i have no idea
25+
// so yeah.. I know this could be done better
26+
// for example, it could return tier1, tier2, tier3 instead of dollar values
27+
// how do i do that documentation thing?
28+
public function sortEmotes($emotes)
29+
{
30+
return $this->collection
31+
->map(function($plans, $AAAAAa) use($emotes){
32+
$accumulator = array();
33+
foreach($emotes as $emote){
34+
if($emote['emoticon_set'] == $plans){
35+
array_push($accumulator, $emote['code']);
36+
};
37+
}
38+
return($accumulator);
39+
})
40+
->toArray();
41+
}
42+
}

0 commit comments

Comments
 (0)