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.
This commit is contained in:
Daniel_I_Am 2021-09-20 17:03:00 +02:00
parent 336a3ac7ec
commit 655813836d

View File

@ -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);
}
}
}
}