public async Task AddStreamer(CommandContext ctx, [Description("Twitch felhasználónév")] string name) { //open the Twitch config file var tjson = ""; using (var fs = File.OpenRead("twitchconfig.json")) using (var sr = new StreamReader(fs, new UTF8Encoding(false))) tjson = await sr.ReadToEndAsync(); var tcfgjson = JsonConvert.DeserializeObject <twitchconfig>(tjson); //set the twitch related configs api = new TwitchAPI(); api.Settings.ClientId = tcfgjson.clientid; api.Settings.AccessToken = tcfgjson.accesstoken; //load the StreamerInformation to store the data in the filestream StreamerInformation si = StreamerInformation.Instance(); si.Load(); //check the user is valid on Twitch side or not User[] userList = api.V5.Users.GetUserByNameAsync(name).Result.Matches; string userid = null; try { userid = userList[0].Id; } catch (System.IndexOutOfRangeException) { var emoji1 = DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:"); await ctx.TriggerTypingAsync(); await ctx.RespondAsync($"{emoji1} Sajnos nincs ilyen Twitch user."); } //Check the user is streaming or not bool islive = false; var stream = await api.V5.Streams.GetStreamByUserAsync(userid); if (stream?.Stream?.Channel?.Status != null) { islive = true; } else { islive = false; } //Add the user to the Streamers file string DiscordName = ctx.User.Username; string TwitchName = name; string TwitchUserID = userid; bool IsLive = islive; await si.AddStreamer(ctx, DiscordName, TwitchName, TwitchUserID, IsLive); si.Save(); si.Print(); }
public async Task DeleteStreamer(CommandContext ctx) { //load the StreamerInformation to store the data in the filestream StreamerInformation si = StreamerInformation.Instance(); si.Load(); //delete the user from the Streamers file string DiscordName = ctx.User.Username; await si.RemoveStreamer(ctx, DiscordName); si.Save(); si.Print(); }