Added more item details in getitem

This commit is contained in:
Michael Chen 2022-01-16 22:15:11 +01:00
parent cd006fb268
commit 612435eb09
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB
3 changed files with 20 additions and 10 deletions

View File

@ -78,7 +78,7 @@ public class ConnectedComputer : CommandRouter, ITaskWaitSource {
public override Task<ResponseType> RootAnswer(SocketUserMessage message, CancellationToken ct)
=> Task.FromResult(ResponseType.AsString("The Minecraft server is connected!"));
public override Task<ResponseType> FallbackHandler(SocketUserMessage message, string method, string[] parameters, CancellationToken ct)
=> Task.FromResult(ResponseType.AsString($"What the fuck do you mean by '{method}'?"));
=> throw new ReplyException($"What the fuck do you mean by '{method}'?");
}
public interface ITaskWaitSource {
@ -118,6 +118,8 @@ public class Fluid {
public override string ToString() => Amount > 10000
? $"{Amount / 1000.0f:n2} B of {DisplayName}"
: $"{Amount:n0} mB of {DisplayName}";
[JsonIgnore]
public string CleanDisplayName => DisplayName[1..^2];
}
[JsonConverter(typeof(ModItemIdJsonConverter))]

View File

@ -228,8 +228,8 @@ public class Program : IDisposable, ICommandHandler<ResponseType> {
} catch (TaskCanceledException) {
return ResponseType.AsString("Your request could not be processed in time!");
} catch (ReplyException e) {
await LogWarningAsync(BotSource, e.Message);
return ResponseType.AsString($"Your request failed: {e.Message}");
await LogInfoAsync(BotSource, e.Message);
return ResponseType.AsString(e.Message);
} catch (Exception e) {
await LogErrorAsync(BotSource, e);
return ResponseType.AsString($"Oopsie doopsie, this should not have happened!");

View File

@ -8,7 +8,7 @@ public class RefinedStorageService : CommandRouter {
public override string HelpTextPrefix => "!rs ";
public RefinedStorageService(ITaskWaitSource taskSource) : base() => _taskSource = taskSource;
public override Task<ResponseType> FallbackHandler(SocketUserMessage message, string method, string[] parameters, CancellationToken ct)
=> Task.FromResult(ResponseType.AsString($"The RS system has no command '{method}'!"));
=> throw new ReplyException($"The RS system has no command '{method}'!");
public override Task<ResponseType> RootAnswer(SocketUserMessage message, CancellationToken ct)
=> Task.FromResult(ResponseType.AsString("The RS system is online!"));
@ -73,12 +73,13 @@ public class RefinedStorageService : CommandRouter {
if (parameters.Length is 1 or 2) {
itemid = parameters[0];
if (parameters.Length is 2)
if (int.TryParse(parameters[1], out var value)) amount = value;
else return ResponseType.AsString($"I expected an amount to craft, not '{parameters[1]}'!");
amount = int.TryParse(parameters[1], out var value)
? value
: throw new ReplyException($"I expected an amount to craft, not '{parameters[1]}'!");
} else return parameters.Length is < 1
? ResponseType.AsString("You have to give me at least an item name!")
? throw new ReplyException("You have to give me at least an item name!")
: parameters.Length is > 2
? ResponseType.AsString("Yo, those are way too many arguments! I want only item name and maybe an amount!")
? throw new ReplyException("Yo, those are way too many arguments! I want only item name and maybe an amount!")
: throw new InvalidOperationException($"Forgot to match parameter length {parameters.Length}!");
return await CraftItem(itemid, amount, ct)
? ResponseType.AsString($"Alright, I'm starting to craft {amount} {itemid}.")
@ -98,8 +99,15 @@ public class RefinedStorageService : CommandRouter {
: parameters.Length is > 2
? ResponseType.AsString("Yo, those are way too many arguments! I want only item name and maybe an amount!")
: throw new InvalidOperationException($"Forgot to match parameter length {parameters.Length}!");
var data = await GetItemData(itemid, ct);
return ResponseType.AsString(data.ToString());
var item = await GetItemData(itemid, ct);
var sb = new StringBuilder();
sb.Append($"We currently have {item.Amount:n0} {item.CleanDisplayName}!");
if (item.Tags is not null and var tags) {
sb.AppendLine("\nThis item has the following tags:");
sb.AppendJoin('\n',tags.Select(tag => $"- {tag}"));
}
sb.Append($"\nRefer to this item with fingerprint {item.Fingerprint}");
return ResponseType.AsString(sb.ToString());
}
[CommandHandler(CmdItemName, HelpText = "Filter items by name.")]
public async Task<ResponseType> HandleItemName(SocketUserMessage message, string[] parameters, CancellationToken ct) {