public async Task ReadUserMessages(DiscordRequest request, Contexts contexts) { var mention = request.GetMention(); var selectedUser = await this._usersService.GetUserByMentionAsync(contexts.Server, mention); if (selectedUser == null) { throw new UserNotFoundException(mention); } var timeRange = request.GetPastTimeRange(defaultTime: TimeSpan.FromHours(1)); var query = new GetMessagesQuery(contexts.Server.Id, selectedUser.Id) { SentDate = timeRange }; var messages = this._queryBus.Execute(query).Messages .OrderBy(x => x.SentAt) .ToList(); var messagesService = this._messagesServiceFactory.Create(contexts); var hasForceArgument = request.HasArgument("force") || request.HasArgument("f"); if (messages.Count > 200 && !hasForceArgument) { await messagesService.SendResponse(x => x.NumberOfMessagesIsHuge(messages.Count)); return; } if (!messages.Any()) { await messagesService.SendResponse(x => x.UserDidntWriteAnyMessageInThisTime(selectedUser)); return; } var header = $"Messages from user {selectedUser} starting at {timeRange.Start}"; var lines = messages.Select(x => $"{x.SentAt:yyyy-MM-dd HH:mm:ss} {x.Author.Name}: {x.Content.Replace("```", "")}"); var linesBuilder = new StringBuilder().PrintManyLines(lines.ToArray(), contentStyleBox: true); await this._directMessagesService.TrySendMessage(contexts.User.Id, header); await this._directMessagesService.TrySendMessage(contexts.User.Id, linesBuilder.ToString(), MessageType.BlockFormatted); await messagesService.SendResponse(x => x.SentByDmMessagesOfAskedUser(messages.Count, selectedUser)); }
public void PrintHelp(DiscordRequest request, Contexts contexts) { var messagesService = _messagesServiceFactory.Create(contexts); if (request.HasArgument(null, "json")) { var helpMessage = this._helpMessageGenerator.GenerateJsonHelp(contexts); messagesService.SendMessage(helpMessage, MessageType.Json); } else { var helpMessage = this._helpMessageGenerator.GenerateHelp(contexts); messagesService.SendResponse(x => x.PrintHelp(helpMessage), contexts); } }