-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from rGunti/249-feature-special-raid-message-…
…for-stream-team-members Implemented automated Raid Messages
- Loading branch information
Showing
33 changed files
with
500 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace FloppyBot.Chat.Twitch.Events; | ||
|
||
public record TwitchRaidEvent( | ||
string ChannelName, | ||
string ChannelDisplayName, | ||
int ViewerCount, | ||
StreamTeam? StreamTeam | ||
) : TwitchEvent(TwitchEventTypes.RAID); | ||
|
||
public record StreamTeam(string Name, string DisplayName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace FloppyBot.Chat.Twitch.Api.Dtos; | ||
|
||
public record StreamTeam(string Id, string Name, string DisplayName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using FloppyBot.Chat.Twitch.Api.Dtos; | ||
using TwitchLib.Api.Helix.Models.Teams; | ||
using TwitchLib.Api.Interfaces; | ||
|
||
namespace FloppyBot.Chat.Twitch.Api; | ||
|
||
public interface ITwitchApiService | ||
{ | ||
IEnumerable<StreamTeam> GetStreamTeamsOfChannel(string channel); | ||
string? GetBroadcasterId(string channel); | ||
} | ||
|
||
public class TwitchApiService : ITwitchApiService | ||
{ | ||
private readonly ITwitchAPI _twitchApi; | ||
|
||
public TwitchApiService(ITwitchAPI twitchApi) | ||
{ | ||
_twitchApi = twitchApi; | ||
} | ||
|
||
public IEnumerable<StreamTeam> GetStreamTeamsOfChannel(string channel) | ||
{ | ||
return DoGetStreamTeamName(channel).GetAwaiter().GetResult(); | ||
} | ||
|
||
public string? GetBroadcasterId(string channel) | ||
{ | ||
return DoGetBroadcasterId(channel).GetAwaiter().GetResult(); | ||
} | ||
|
||
private static StreamTeam ConvertToStreamTeam(Team team) | ||
{ | ||
return new StreamTeam(team.Id, team.TeamName, team.TeamDisplayName); | ||
} | ||
|
||
private async Task<IEnumerable<StreamTeam>> DoGetStreamTeamName(string channel) | ||
{ | ||
var broadcasterId = await DoGetBroadcasterId(channel); | ||
if (broadcasterId == null) | ||
{ | ||
return Enumerable.Empty<StreamTeam>(); | ||
} | ||
|
||
var teams = await _twitchApi.Helix.Teams.GetTeamsAsync(broadcasterId); | ||
return teams.Teams.Select(ConvertToStreamTeam); | ||
} | ||
|
||
private async Task<string?> DoGetBroadcasterId(string channel) | ||
{ | ||
var program = await _twitchApi.Helix.Users.GetUsersAsync(logins: [channel]); | ||
return program.Users.Select(u => u.Id).FirstOrDefault(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.