Пример #1
0
 public TwitchUser(string baseURL, ServiceEnum serviceType, StreamUser user) : base(baseURL, serviceType)
 {
     Id          = user.SourceID;
     Username    = user.Username;
     DisplayName = user.DisplayName;
     AvatarURL   = user.AvatarURL;
     ProfileURL  = user.ProfileURL;
 }
Пример #2
0
        public async Task <RuntimeResult> MonitorStop(ILiveBotUser user)
        {
            ILiveBotMonitor monitor = _GetServiceMonitor(user);

            DiscordGuild discordGuild = new DiscordGuild
            {
                DiscordId = Context.Guild.Id,
                Name      = Context.Guild.Name,
                IconUrl   = Context.Guild.IconUrl
            };
            await _work.GuildRepository.AddOrUpdateAsync(discordGuild, g => g.DiscordId == Context.Guild.Id);

            discordGuild = await _work.GuildRepository.SingleOrDefaultAsync(g => g.DiscordId == Context.Guild.Id);

            StreamUser streamUser = new StreamUser()
            {
                ServiceType = user.ServiceType,
                SourceID    = user.Id,
                Username    = user.Username,
                DisplayName = user.DisplayName,
                AvatarURL   = user.AvatarURL,
                ProfileURL  = user.ProfileURL
            };
            await _work.UserRepository.AddOrUpdateAsync(streamUser, (i => i.ServiceType == user.ServiceType && i.SourceID == user.Id));

            streamUser = await _work.UserRepository.SingleOrDefaultAsync(i => i.ServiceType == user.ServiceType && i.SourceID == user.Id);

            Expression <Func <StreamSubscription, bool> > streamSubscriptionPredicate = (i =>
                                                                                         i.User == streamUser &&
                                                                                         i.DiscordGuild == discordGuild
                                                                                         );
            IEnumerable <StreamSubscription> streamSubscriptions = await _work.SubscriptionRepository.FindAsync(streamSubscriptionPredicate);

            try
            {
                foreach (StreamSubscription streamSubscription in streamSubscriptions)
                {
                    await _work.SubscriptionRepository.RemoveAsync(streamSubscription.Id);
                }
                await ReplyAsync($"{Context.Message.Author.Mention}, I have removed the Subscription for {user.DisplayName}");

                return(MonitorResult.FromSuccess());
            }
            catch (Exception e)
            {
                Log.Error($"Error running MonitorStop for {Context.Message.Author.Id} {Context.Message.Author.Username}#{Context.Message.Author.Discriminator} GuildID: {Context.Guild.Id} ChannelID: {Context.Channel.Id}\n{e}");
                return(MonitorResult.FromSuccess($"{Context.Message.Author.Mention}, I couldn't remove the Subscription for user {user.DisplayName}. Please try again or contact my owner"));
            }
        }
Пример #3
0
        public async Task <RuntimeResult> MonitorStart(ILiveBotUser user)
        {
            ILiveBotMonitor monitor = _GetServiceMonitor(user);

            DiscordGuild discordGuild = new DiscordGuild
            {
                DiscordId = Context.Guild.Id,
                Name      = Context.Guild.Name,
                IconUrl   = Context.Guild.IconUrl
            };
            await _work.GuildRepository.AddOrUpdateAsync(discordGuild, g => g.DiscordId == Context.Guild.Id);

            discordGuild = await _work.GuildRepository.SingleOrDefaultAsync(g => g.DiscordId == Context.Guild.Id);

            // Get Notification Channel
            DiscordChannel discordChannel = await _RequestNotificationChannel(discordGuild);

            if (discordChannel == null)
            {
                return(MonitorResult.FromError($"{Context.Message.Author.Mention}, Please re-run the command and be sure to mention a channel."));
            }

            // Get Notification Message
            string notificationMessage = await _RequestNotificationMessage();

            if (notificationMessage == null)
            {
                return(MonitorResult.FromError($"{Context.Message.Author.Mention}, Please re-run the command and provide a valid message for notifications"));
            }

            // Get Notification Role
            DiscordRole discordRole = await _RequestNotificationRole(discordGuild);

            // Process their answers
            StreamUser streamUser = new StreamUser()
            {
                ServiceType = user.ServiceType,
                SourceID    = user.Id,
                Username    = user.Username,
                DisplayName = user.DisplayName,
                AvatarURL   = user.AvatarURL,
                ProfileURL  = user.ProfileURL
            };
            await _work.UserRepository.AddOrUpdateAsync(streamUser, (i => i.ServiceType == user.ServiceType && i.SourceID == user.Id));

            streamUser = await _work.UserRepository.SingleOrDefaultAsync(i => i.ServiceType == user.ServiceType && i.SourceID == user.Id);

            Expression <Func <StreamSubscription, bool> > streamSubscriptionPredicate = (i =>
                                                                                         i.User == streamUser &&
                                                                                         i.DiscordGuild == discordGuild
                                                                                         );

            StreamSubscription newSubscription = new StreamSubscription()
            {
                User           = streamUser,
                DiscordGuild   = discordGuild,
                DiscordChannel = discordChannel,
                DiscordRole    = discordRole,
                Message        = notificationMessage
            };

            try
            {
                StreamSubscription existingSubscription = await _work.SubscriptionRepository.SingleOrDefaultAsync(streamSubscriptionPredicate);

                if (existingSubscription != null)
                {
                    existingSubscription.DiscordGuild   = newSubscription.DiscordGuild;
                    existingSubscription.DiscordChannel = newSubscription.DiscordChannel;
                    existingSubscription.DiscordRole    = newSubscription.DiscordRole;
                    existingSubscription.Message        = newSubscription.Message;
                    await _work.SubscriptionRepository.UpdateAsync(existingSubscription);
                }
                else
                {
                    await _work.SubscriptionRepository.AddOrUpdateAsync(newSubscription, streamSubscriptionPredicate);
                }

                StreamSubscription streamSubscription = await _work.SubscriptionRepository.SingleOrDefaultAsync(streamSubscriptionPredicate);

                monitor.AddChannel(user);
                string escapedMessage = NotificationHelpers.EscapeSpecialDiscordCharacters(streamSubscription.Message);
                await ReplyAsync($"{Context.Message.Author.Mention}, I have setup a subscription for {user.DisplayName} on {user.ServiceType} with message {escapedMessage}");

                return(MonitorResult.FromSuccess());
            }
            catch (Exception e)
            {
                Log.Error($"Error running MonitorStart for {Context.Message.Author.Id} {Context.Message.Author.Username}#{Context.Message.Author.Discriminator} GuildID: {Context.Guild.Id} ChannelID: {Context.Channel.Id}\n{e}");
                return(MonitorResult.FromError($"{Context.Message.Author.Mention}, I wasn't able to create a subscription for the user {user.DisplayName} on {user.ServiceType}. Please try again or contact my owner"));
            }
        }