Exemple #1
0
        /// <summary>
        /// Service. Removes an entire user's stream alerts.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task RemoveShoutEntity(ICommandContext context, SocketGuildUser user)
        {
            UserShout item = shoutEntities.FirstOrDefault(x => x.userID == user.Id);

            if (item != null)
            {
                //That user is already in the list. Cool! Check the channel and alter nothing else.

                shoutEntities.Remove(item);
                await context.Channel.SendMessageAsync($"Removed {(await context.Guild.GetUserAsync(item.userID)).Username}'s stream alert.");
            }
            else
            {
                await context.Channel.SendMessageAsync($"Hey! This user doesn't have any stream alerts. Try that again please.");

                return;
            }
            //Save shouts.json.
            using (FileStream fs = File.Create("shouts.json"))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine(JsonConvert.SerializeObject(shoutEntities, Formatting.Indented));//Output and save a file.
                    sw.Flush();
                }
            }
        }
Exemple #2
0
        public async Task ShoutTest(ICommandContext context)
        {
            await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", "HEY!!! TEST!"));

            foreach (SocketGuild guild in _client.Guilds)
            {
                foreach (SocketGuildUser arg2 in guild.Users)
                {
                    if (arg2.Game?.StreamType == StreamType.Twitch)
                    {
                        await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", "user streamtype twitch." + arg2.Username));

                        await arg2.AddRoleAsync(arg2.Guild.GetRole(arg2.Guild.Roles.FirstOrDefault(x => x.Name == "🔴 Live!").Id));
                        await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", arg2.Username + " is live!"));

                        //add role.
                        await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", arg2.Username + " went live! [Guild: " + arg2.Guild.Name + "]"));

                        UserShout Shout = shoutEntities.FirstOrDefault(x => x.userID == arg2.Id);
                        if (Shout != null)
                        {
                            foreach (var item in Shout.ChannelIDs)
                            {
                                SocketTextChannel ch    = _client.GetChannel(item) as SocketTextChannel;
                                string[]          array = arg2.Game?.StreamUrl.Split('/');
                                if (ch.Guild == arg2.Guild)
                                {
                                    if (Shout.SupressEveryone)
                                    {
                                        await ch.SendMessageAsync(array.Last() + " just went live! " + arg2.Game?.StreamUrl);
                                    }
                                    else
                                    {
                                        await ch.SendMessageAsync("@everyone " + array.Last() + " just went live! " + arg2.Game?.StreamUrl);
                                    }
                                }
                            }
                        }
                    }
                    if (arg2.Game?.StreamType == StreamType.NotStreaming)
                    {
                        await arg2.RemoveRoleAsync(arg2.Guild.GetRole(arg2.Guild.Roles.FirstOrDefault(x => x.Name == "🔴 Live!").Id));
                        await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", arg2.Username + " is not live"));
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Service. Add a new shout entity.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <param name="SupressEveryone"></param>
        /// <returns></returns>
        public async Task AddShoutEntity(ICommandContext context, SocketGuildUser user, bool SupressEveryone)
        {
            UserShout item = shoutEntities.FirstOrDefault(x => x.userID == user.Id);

            if (item != null)
            {
                //That user is already in the list. Cool! Check the channel and alter nothing else.

                if (item.ChannelIDs.Contains(context.Channel.Id))
                {
                    await context.Channel.SendMessageAsync("This channel already has a notification for this user. Please use a different channel.\r\n" +
                                                           "**Please note: You cannot add multiple twitch accounts to the same user.**");

                    return;//Cancel the operation. NO SAVE.
                }
                else
                {
                    item.AddChannel(context.Channel.Id);//An existing channelID wasn't found. Add it to the list.
                    await context.Channel.SendMessageAsync($"This channel is now subscribed to going live alerts from (Discord user: {user.Username})");
                }
            }
            else
            {
                shoutEntities.Add(new UserShout(user.Id, context.Channel.Id, SupressEveryone));
                //Add a brand new item to our shout list.
                await context.Channel.SendMessageAsync($"This channel is now subscribed to going live alerts from (Discord user: {user.Username})");
            }
            //Save shouts.json.
            using (FileStream fs = File.Create("shouts.json"))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine(JsonConvert.SerializeObject(shoutEntities, Formatting.Indented));//Output and save a file.
                    sw.Flush();
                }
            }
        }
Exemple #4
0
        private async Task _client_GuildMemberUpdated(SocketGuildUser arg1, SocketGuildUser arg2)
        {
            if (arg1.Game?.StreamType == StreamType.NotStreaming && arg2.Game?.StreamType == StreamType.Twitch)//Event gets fired for every guild??
            {
                //add role.
                await arg2.AddRoleAsync(arg2.Guild.GetRole(arg2.Guild.Roles.FirstOrDefault(x => x.Name == "🔴 Live!").Id));
                await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", arg2.Username + " went live! [Guild: " + arg2.Guild.Name + "]"));

                UserShout Shout = shoutEntities.FirstOrDefault(x => x.userID == arg2.Id);
                if (Shout != null)
                {
                    foreach (var item in Shout.ChannelIDs)
                    {
                        SocketTextChannel ch    = _client.GetChannel(item) as SocketTextChannel;
                        string[]          array = arg2.Game?.StreamUrl.Split('/');
                        if (ch.Guild == arg2.Guild)
                        {
                            if (Shout.SupressEveryone)
                            {
                                await ch.SendMessageAsync(array.Last() + " just went live! " + arg2.Game?.StreamUrl);
                            }
                            else
                            {
                                await ch.SendMessageAsync("@everyone " + array.Last() + " just went live! " + arg2.Game?.StreamUrl);
                            }
                        }
                    }
                }
            }
            if (arg1.Game?.StreamType == StreamType.Twitch && arg2.Game?.StreamType == StreamType.NotStreaming)
            {
                //remove the role
                await arg2.RemoveRoleAsync(arg2.Guild.GetRole(arg2.Guild.Roles.FirstOrDefault(x => x.Name == "🔴 Live!").Id));
                await Client_Log(new LogMessage(LogSeverity.Info, "GoLive", arg2.Username + " Ended stream. [Guild: " + arg2.Guild.Name + "]"));
            }
        }