Exemple #1
0
        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 static StreamerInformation Instance()
 {
     if (streamerInformation == null)
     {
         streamerInformation = new StreamerInformation();
     }
     return(streamerInformation);
 }
Exemple #3
0
        public async Task StratStreamNotif(CommandContext ctx)
        {
            //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
            StreamerInformation si = StreamerInformation.Instance();

            si.Load();

            if (ctx.Channel.Name.Equals("stream📡") && Global.token == false)
            {
                //set the token
                Global.token = true;
                var emoji2 = DiscordEmoji.FromName(ctx.Client, ":white_check_mark:");
                await ctx.TriggerTypingAsync();

                await ctx.RespondAsync($"{emoji2} A stream értesítések elindítva.");

                while (Global.token == true)
                {
                    await si.SendNotification(ctx, api);

                    Console.WriteLine($"{DateTime.Now} The next cycle of the stream notification.");
                    System.Threading.Thread.Sleep(30000);
                }
            }
            else if (Global.token == true)
            {
                var emoji2 = DiscordEmoji.FromName(ctx.Client, ":white_check_mark:");
                await ctx.TriggerTypingAsync();

                await ctx.RespondAsync($"{emoji2} A stream értesítések már el vannak indítva.");
            }
            else if (!ctx.Channel.Name.Equals("stream📡"))
            {
                var emoji1 = DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:");
                await ctx.TriggerTypingAsync();

                await ctx.RespondAsync($"{emoji1} Csak a stream-értesítés szobában adható ki a parancs.");
            }
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        public async Task StopStreamNotif(CommandContext ctx)
        {
            //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;

            StreamerInformation si = StreamerInformation.Instance();

            si.Load();

            if (ctx.Channel.Name.Equals("stream📡"))
            {
                Global.token = false;
                //await si.SendNotification(ctx, api);

                var emoji2 = DiscordEmoji.FromName(ctx.Client, ":white_check_mark:");
                await ctx.TriggerTypingAsync();

                await ctx.RespondAsync($"{emoji2} A stream értesítések leállítva.");
            }
            else
            {
                var emoji1 = DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:");
                await ctx.TriggerTypingAsync();

                await ctx.RespondAsync($"{emoji1} Csak a stream-értesítés szobában adható ki a parancs.");
            }
        }