3
3
using System . Net . Http ;
4
4
using System . Threading . Tasks ;
5
5
using Fritz . StreamLib . Core ;
6
+ using Microsoft . Extensions . Logging ;
6
7
7
8
namespace Fritz . Chatbot . Commands
8
9
{
9
10
public class ShoutoutCommand : IBasicCommand2
10
11
{
11
12
private readonly HttpClient _HttpClient ;
13
+ private readonly ILogger _Logger ;
12
14
13
- public ShoutoutCommand ( IHttpClientFactory httpClientFactory )
15
+ public ShoutoutCommand ( IHttpClientFactory httpClientFactory , ILoggerFactory logger )
14
16
{
15
17
16
18
_HttpClient = httpClientFactory . CreateClient ( "ShoutoutCommand" ) ;
19
+ _HttpClient . BaseAddress = new Uri ( "https://api.twitch.tv/helix/users" ) ;
20
+
21
+ _Logger = logger . CreateLogger ( nameof ( ShoutoutCommand ) ) ;
17
22
18
23
}
19
24
@@ -24,19 +29,23 @@ public ShoutoutCommand(IHttpClientFactory httpClientFactory)
24
29
25
30
public TimeSpan ? Cooldown => TimeSpan . FromSeconds ( 5 ) ;
26
31
27
- public async Task Execute ( IChatService chatService , string userName , bool isModerator , bool isBroadcaster , ReadOnlyMemory < char > rhs )
32
+ public async Task Execute ( IChatService chatService , string userName , bool isModerator , bool isVip , bool isBroadcaster , ReadOnlyMemory < char > rhs )
28
33
{
29
34
30
- if ( ! ( isModerator || isBroadcaster ) ) return ;
35
+ if ( ! ( isModerator || isVip || isBroadcaster ) ) return ;
31
36
32
37
var rhsTest = rhs . ToString ( ) ;
33
38
if ( rhsTest . StartsWith ( "@" ) ) rhsTest = rhsTest . Substring ( 1 ) ;
34
39
if ( rhsTest . StartsWith ( "http" ) ) return ;
35
40
if ( rhsTest . Contains ( " " ) ) return ;
36
41
37
42
rhsTest = WebUtility . UrlEncode ( rhsTest ) ;
38
- var result = await _HttpClient . GetAsync ( rhsTest ) ;
39
- if ( result . StatusCode != HttpStatusCode . OK ) return ;
43
+ var result = await _HttpClient . GetAsync ( $ "?login={ rhsTest } ") ;
44
+ if ( result . StatusCode != HttpStatusCode . OK )
45
+ {
46
+ _Logger . LogWarning ( $ "Unable to verify Shoutout for { rhsTest } ") ;
47
+ return ;
48
+ }
40
49
41
50
await chatService . SendMessageAsync ( $ "Please follow @{ rhsTest } at: https://twitch.tv/{ rhsTest } ") ;
42
51
0 commit comments