2017-12-04 13:01:02 +00:00
using Discord.Commands ;
2017-12-04 15:24:44 +00:00
using Microsoft.Extensions.Configuration ;
using System.IO ;
2017-12-04 15:58:42 +00:00
using System.Linq ;
2017-12-04 13:01:02 +00:00
using System.Threading.Tasks ;
namespace dotbot.Commands
{
public class AsciiArt : ModuleBase < SocketCommandContext >
{
2017-12-04 15:24:44 +00:00
private readonly IConfigurationRoot _config ;
public AsciiArt ( IConfigurationRoot config ) {
_config = config ;
}
2017-12-04 13:01:02 +00:00
[Command("ascii")]
[Summary("creates ascii word art")]
2017-12-04 14:51:23 +00:00
public async Task CreateAsciiArt (
2017-12-04 15:24:44 +00:00
[Summary("font you want to use")] string fontName ,
[Remainder] [ Summary ( "text to convert" ) ] string ArtString
) {
2017-12-04 14:51:23 +00:00
if ( fontName = = "list" ) {
2017-12-04 15:58:42 +00:00
await ReplyAsync ( $"available fonts for use with `{_config[" prefix "]}ascii`:\n```{string.Join(" , ", Directory.GetFiles(" Fonts ").ToList().Select(Path.GetFileNameWithoutExtension))}```" ) ;
2017-12-04 14:51:23 +00:00
} else if ( File . Exists ( $"Fonts/{fontName}.flf" ) ) {
2017-12-04 15:58:42 +00:00
using ( FileStream fs = File . OpenRead ( $"Fonts/{fontName}.flf" ) ) {
var font = new WenceyWang . FIGlet . FIGletFont ( fs ) ;
await ReplyAsync ( $"```\n{(new WenceyWang.FIGlet.AsciiArt(ArtString, font: font)).ToString()}\n```" ) ;
}
2017-12-04 14:51:23 +00:00
} else {
await ReplyAsync ( $"```\n{(new WenceyWang.FIGlet.AsciiArt(fontName + ArtString)).ToString()}\n```" ) ;
}
2017-12-04 13:01:02 +00:00
}
}
}
2017-12-04 15:24:44 +00:00