Bump version to 1.1.2
Cleaner item list display Allow full item list as file Fixed online status message with new handler
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Discord.WebSocket;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using MinecraftDiscordBot.Commands;
|
||||
using MinecraftDiscordBot.Models;
|
||||
using System.Text;
|
||||
@ -146,6 +147,7 @@ public class RefinedStorageService : CommandRouter {
|
||||
|
||||
[CommandHandler(CmdListItems, HelpText = "Gets a list of items that are currently stored in the RS system.")]
|
||||
public async Task<ResponseType> HandleItemListing(SocketUserMessage message, string[] parameters, CancellationToken ct) {
|
||||
if (parameters.Length is 1 && parameters[0] == "full") return await SendFullItemList(message, ct);
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("The Refined Storage system currently stores these items:");
|
||||
var items = await RefreshItemList(ct);
|
||||
@ -153,11 +155,29 @@ public class RefinedStorageService : CommandRouter {
|
||||
var taken = 0;
|
||||
foreach (var item in items) {
|
||||
if (sb.Length > 500) break;
|
||||
sb.AppendFormat("\n{0:n0}x {1}", item.Amount, item.DisplayName);
|
||||
sb.Append('\n');
|
||||
sb.Append(item.ToString());
|
||||
taken++;
|
||||
}
|
||||
if (items.Count > taken) sb.AppendFormat("\nand {0} more items.", items.Skip(taken).Sum(i => i.Amount));
|
||||
if (items.Count > taken) sb.AppendFormat("\nand {0:n0} more items.", items.Skip(taken).Sum(i => i.Amount));
|
||||
}
|
||||
return ResponseType.AsString(sb.ToString());
|
||||
}
|
||||
|
||||
private async Task<ResponseType> SendFullItemList(SocketUserMessage message, CancellationToken ct) {
|
||||
var path = await GetItemListFile(ct);
|
||||
return ResponseType.File(path, $"{message.Author.Mention} Here you go:");
|
||||
}
|
||||
|
||||
private async Task<string> GetItemListFile(CancellationToken ct) {
|
||||
var items = await RefreshItemList(ct);
|
||||
var file = Path.Combine(Path.GetTempPath(), "itemlist.txt");
|
||||
var fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write);
|
||||
using (var sw = new StreamWriter(fs, Encoding.UTF8)) {
|
||||
await sw.WriteLineAsync("The RS System stores the following items:");
|
||||
foreach (var item in items)
|
||||
await sw.WriteLineAsync(item.DetailString);
|
||||
};
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user