From 655813836dc020ecdc02a8f82452c735801f0c0a Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Mon, 20 Sep 2021 17:03:00 +0200 Subject: [PATCH] Implement fortune command This code seems fine, but I don't have a dev environment set up at the moment. This might be a dead end due to lacking the fortune package. --- ChaosBot/Discord/Modules/User/Fortune.cs | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ChaosBot/Discord/Modules/User/Fortune.cs diff --git a/ChaosBot/Discord/Modules/User/Fortune.cs b/ChaosBot/Discord/Modules/User/Fortune.cs new file mode 100644 index 0000000..1908073 --- /dev/null +++ b/ChaosBot/Discord/Modules/User/Fortune.cs @@ -0,0 +1,60 @@ +using System; +using System.Text; +using System.Diagnostics; +using System.Threading.Tasks; +using ChaosBot.ConfigHelpers; +using ChaosBot.Discord.PreConditions; +using Discord; +using Discord.Commands; +using Microsoft.Extensions.Configuration; + +namespace ChaosBot.Discord.Modules.User +{ + public class Fortune : ModuleBase + { + [Command("fortune")] + [CheckCommandPerm("User")] + public async Task ShowInfo() + { + try + { + var sb = new StringBuilder(); + var embed = new EmbedBuilder(); + Configuration config = new Configuration(); + + var process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "fortune", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + process.Start(); + string fortuneResult = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + embed.WithColor(new Color(255, 255, 0)); + embed.Title = "Fortune"; + sb.AppendLine(fortuneResult); + + /* + * Add the string to the Embed + */ + embed.Description = sb.ToString(); + + /* + * Reply with the Embed created above + */ + await ReplyAsync(null, false, embed.Build()); + } + catch(Exception ex) + { + LoggingFacade.Exception(ex); + } + } + } +}