From d89de7d852afa302e22cbd1f41ddb1b3556b29c4 Mon Sep 17 00:00:00 2001 From: Foretack <69414142+Foretack@users.noreply.github.com> Date: Sun, 17 Dec 2023 06:54:12 +0100 Subject: [PATCH] Update README.md --- MiniTwitch.Helix/README.md | 36 ++++++++++----------------- README.md | 51 ++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 53 deletions(-) diff --git a/MiniTwitch.Helix/README.md b/MiniTwitch.Helix/README.md index abd3817..844b94e 100644 --- a/MiniTwitch.Helix/README.md +++ b/MiniTwitch.Helix/README.md @@ -37,44 +37,33 @@ public class Program static async Task Main() { - Helix = new HelixWrapper("Access token", 7654321); + Helix = new HelixWrapper("Access token", 987654321); - await GetFirst1000Usernames(12345678); - await GetAllUsernames(12345678); + var chatters = await GetAllChatters(12345678); } - private static async Task> GetFirst1000Usernames(long broadcasterId) + private static async Task> GetAllChatters(long broadcasterId) { - List usernames = new(); + List usernames = []; HelixResult chatters = await Helix.GetChatters(broadcasterId, first: 1000); - // Make sure the result is a success and the value contains data - if (!chatters.Success) return Array.Empty(); - - foreach (var chatter in chatters.Value.Data) + if (!chatters.Success) { - usernames.Add(chatter.Username); + return []; } - return usernames; - } - - private static async Task> GetAllUsernames(long broadcasterId) - { - List usernames = new(); - HelixResult chatters = await Helix.GetChatters(broadcasterId, first: 1000); - - if (!chatters.Success) return Array.Empty(); - foreach (var chatter in chatters.Value.Data) { usernames.Add(chatter.Username); } // No more users - return what we got - if (!chatters.CanPaginate) return usernames; + if (!chatters.CanPaginate) + { + return usernames; + } - // Continue paginating if the result is a success and there is content + // Continue paginating if the result is a success while (await chatters.Paginate() is { Success: true } next) { foreach (var chatter in next.Value.Data) @@ -83,7 +72,8 @@ public class Program } // Return when pagination is no longer possible - if (!next.CanPaginate) return usernames; + if (!next.CanPaginate) + return usernames; chatters = next; } diff --git a/README.md b/README.md index 17e7576..fb8e4fd 100644 --- a/README.md +++ b/README.md @@ -193,45 +193,34 @@ public class Program static async Task Main() { - Helix = new HelixWrapper("Access token", "Client ID"); + Helix = new HelixWrapper("Access token", 987654321); - await GetFirst1000Usernames(12345678, 12345678); - await GetAllUsernames(12345678, 12345678); + var chatters = await GetAllChatters(12345678); } - private static async Task> GetFirst1000Usernames(long broadcasterId, long moderatorId) + private static async Task> GetAllChatters(long broadcasterId) { - List usernames = new(); - HelixResult chatters = await Helix.GetChatters(broadcasterId, moderatorId, first: 1000); + List usernames = []; + HelixResult chatters = await Helix.GetChatters(broadcasterId, first: 1000); - // Make sure the result is a success and the value contains data - if (!chatters.Success || !chatters.Value.HasContent) return Array.Empty(); - - foreach (var chatter in chatters.Value.Data) + if (!chatters.Success) { - usernames.Add(chatter.Username); + return []; } - return usernames; - } - - private static async Task> GetAllUsernames(long broadcasterId, long moderatorId) - { - List usernames = new(); - HelixResult chatters = await Helix.GetChatters(broadcasterId, moderatorId, first: 1000); - - if (!chatters.Success || !chatters.Value.HasContent) return Array.Empty(); - foreach (var chatter in chatters.Value.Data) { usernames.Add(chatter.Username); } // No more users - return what we got - if (!chatters.CanPaginate) return usernames; + if (!chatters.CanPaginate) + { + return usernames; + } - // Continue paginating if the result is a success and there is content - while (await chatters.Paginate() is { Success: true, Value.HasContent: true } next) + // Continue paginating if the result is a success + while (await chatters.Paginate() is { Success: true } next) { foreach (var chatter in next.Value.Data) { @@ -239,7 +228,8 @@ public class Program } // Return when pagination is no longer possible - if (!next.CanPaginate) return usernames; + if (!next.CanPaginate) + return usernames; chatters = next; } @@ -253,10 +243,12 @@ public class Program ### Subscribing to events -All events use either the `Func` or `Func` delegates. Meaning that subscribing methods must have the return type `ValueTask` and account for the `T` parameter when it's present (see `Client.OnMessage` in the example above), the parameter name you set does not matter. Also, if the method doesn't have any asynchronous code you should not mark it as `async` and return `ValueTask.CompletedTask`, `default`or some `ValueTask` object instead. +All events use either the `Func`, `Func` or `Func` delegates. Meaning that subscribing methods must have the return type `ValueTask` and account for the `T` parameters when present (see `client.OnStreamUp` in the PubSub example above), the parameter name you set does not matter. +If the method doesn't have any asynchronous code, it is recommended to not mark it as `async` and return `ValueTask.CompletedTask`, `default` or some `ValueTask` object instead. -Subscribing can be done either programmatically: + +Subscribing can be done either by declaring methods: ```c# Client.OnMessage += MessageEvent; @@ -276,7 +268,7 @@ Client.OnMessage += async message => }; ``` -Note that you cannot unsubscribe from events if you used anonymous functions. +Note that you cannot unsubscribe from anonymous functions. Read more about event subscriptions [here](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-subscribe-to-and-unsubscribe-from-events) @@ -288,9 +280,8 @@ You can add the packages to your project by searching for them with the package ```c# Install-Package MiniTwitch.Irc -``` -```c# Install-Package MiniTwitch.PubSub +Install-Package MiniTwitch.Helix ``` ## Dependencies