コード例 #1
0
        public async Task Subscribe(ulong channelId, string subRedditName, Sort sort)
        {
            var subReddit = await _subRedditFactory.GetSubRedditByName(subRedditName);

            if (!(_discord.GetChannel(channelId) is ITextChannel textChannel))
            {
                return;
            }

            //Validation
            if (subReddit is null)
            {
                await textChannel.SendMessageAsync("The requested subreddit doesn't exist");

                return;
            }
            if (subReddit.IsNsfw && !textChannel.IsNsfw)
            {
                await textChannel.SendMessageAsync("You can only subscribe to this subreddit in nsfw channels.");
            }

            await _channelFactory.AddIfNotExisting(channelId);

            var subscription = await _subscriptionAppService.AddIfNotExisting(subReddit.Id, sort);

            if (await IsAlreadySubscribed(subscription.Id, channelId))
            {
                await textChannel.SendMessageAsync("This channel is already subscribed to the subreddit");

                return;
            }

            await _subscriptionMapperAppService.Insert(new ChannelSubscriptionMapper(channelId, subscription.Id));

            await textChannel.SendMessageAsync("Successfully subscribed");
        }