コード例 #1
0
        public async Task Handle(DirectMessageReceivedNotification notification, CancellationToken cancellationToken)
        {
            if (!_behaviourConfigurationService.HasValidConfiguration())
            {
                await notification.ReceivedMessage.Channel.SendMessageAsync(
                    "Staff on the receiving server have not set up the bot, the message could not be sent!");

                return;
            }

            var userId = notification.ReceivedMessage.Author.Id;

            var hasOpenThread = await _threadService.HasOpenThread(userId);

            ulong channelId;

            if (!hasOpenThread)
            {
                channelId = await _workflowService.CreateChannelForThread(notification.ReceivedMessage.Author);

                await _threadService.StartThread(userId, channelId);
            }
            else
            {
                channelId = await _threadService.GetOpenThreadChannelId(userId);
            }

            var channel = _discordGuildService.GetChannel(channelId);

            await channel.SendMessageAsync(notification.ReceivedMessage.Content);
        }