Nestor

Mon petit bot Discord
Log | Files | Refs

commit 5c15991e1077e1b12c521adba121f72704f6c33b
parent 3e0ee912c0aa0ae9e3c9fb4a314be240d8697fb9
Author: Doshirae <doshirae@doshirae.fr>
Date:   Thu, 11 Oct 2018 13:06:27 +0200

Latex command : normally able to process unicode in input

Diffstat:
commandes.rb | 10++++++++++
replacements.json | 5+++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/commandes.rb b/commandes.rb @@ -1,5 +1,8 @@ require_relative "insultotron.rb" require "httparty" +require "json" + +REPLACEMENTS = JSON.parse(File.read("test.json")) def random(*args) if args[1] @@ -72,6 +75,7 @@ end def latex(*args) input = args.join(" ") + input = process_input(input) latex = %q( \documentclass{article} @@ -104,6 +108,12 @@ $$) + input + %q($$ download_file(file) end +def process_input(latex) + latex.split("").map do |char| + REPLACEMENTS[char] || char # if replacement exists, replace + end.join("") +end + def download_file(file) %x(wget -O latex.png "http://rtex.probablyaweb.site/api/v2/#{file}") convert_file("latex.png") diff --git a/replacements.json b/replacements.json @@ -0,0 +1,5 @@ +{ + "π": "\\pi", + "ℝ": "\\mathbb{R}", + "∞": "\\infty" +}