latex bot discord
-rw-r--r--.gitmodules7
-rw-r--r--Latex.gd30
-rw-r--r--export_presets.cfg2
-rw-r--r--project.godot11
m---------submodules/discord.gd0
5 files changed, 36 insertions, 14 deletions
diff --git a/.gitmodules b/.gitmodules
index a2aa44f..1c12d99 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,3 @@
[submodule "submodules/discord.gd"]
- path = submodules/discord.gd
- url = https://github.com/3ddelano/discord.gd
-[submodule "submodules/GodoTeX"]
- path = submodules/GodoTeX
- url = https://github.com/file-acomplaint/GodoTeX/
+path = submodules/discord.gd
+url = https://github.com/bend-n/discord.gd
diff --git a/Latex.gd b/Latex.gd
index 28b880e..5ba74e4 100644
--- a/Latex.gd
+++ b/Latex.gd
@@ -25,11 +25,17 @@ func _ready() -> void:
bot.TOKEN = token
bot.connect("bot_ready", self, "_on_bot_ready")
bot.connect("message_create", self, "_on_message_create")
+ bot.connect("interaction_create", self, "_on_interaction_create")
bot.login()
func _on_bot_ready(bot: DiscordBot) -> void:
bot.set_presence({"activity": {"type": "Game", "name": "Printing LaTeX"}})
+ var latex_cmd: ApplicationCommand = ApplicationCommand.new() \
+ .set_name("latex") \
+ .add_option(ApplicationCommand.string_option("latex", "The LaTeX to render", { required = true })) \
+ .set_description("Render LaTeX")
+ bot.register_command(latex_cmd)
print("Logged in as " + bot.user.username + "#" + bot.user.discriminator)
print("Listening on " + str(bot.channels.size()) + " channels and " + str(bot.guilds.size()) + " guilds.")
@@ -54,12 +60,32 @@ func _on_message_create(bot: DiscordBot, message: Message, _channel: Dictionary)
if !msg:
return
- print("----\n%s\n----" % msg)
var img := latex2img(msg)
- bot.reply(message, "Tex:", {"files": [{"name": "code.png", "media_type": "image/png", "data": img}]})
+ bot.reply(message, "Tex:", {"files": [{"name": "latex.png", "media_type": "image/png", "data": img}]})
+func _on_interaction_create(_bot: DiscordBot, interaction: DiscordInteraction) -> void:
+ if not interaction.is_command():
+ return
+
+ var command_data := interaction.data
+
+ match command_data.name:
+ "latex":
+ var pay: String = command_data.options[0].value.strip_edges()
+ if pay:
+ interaction.defer_reply();
+ var t := Time.get_ticks_usec()
+ var img := latex2img(command_data.options[0].value)
+ print_debug("took %.2f seconds" % ((Time.get_ticks_usec() - t) / 1000000.0))
+ interaction.edit_reply({"files": [{"content": "", "name": "latex.png", "media_type": "image/png", "data": img}]})
+ else:
+ interaction.reply({"content": "Bad latex"})
+ _:
+ interaction.reply({"content": "Invalid command"})
+
func latex2img(latex: String) -> PoolByteArray:
+ print_debug("----\n%s\n----" % latex)
var tex := laTeXture.new()
tex.LatexExpression = latex
tex.MathColor = Color.white
diff --git a/export_presets.cfg b/export_presets.cfg
index fb88f7e..5b959e3 100644
--- a/export_presets.cfg
+++ b/export_presets.cfg
@@ -6,7 +6,7 @@ runnable=true
custom_features=""
export_filter="all_resources"
include_filter=""
-exclude_filter=""
+exclude_filter="token"
export_path=""
script_export_mode=1
script_encryption_key=""
diff --git a/project.godot b/project.godot
index a2e1d17..989d6ff 100644
--- a/project.godot
+++ b/project.godot
@@ -103,13 +103,12 @@ gdscript/warnings/return_value_discarded=false
[display]
-window/size/width=320
-window/size/height=180
-window/size/test_width=1280
-window/size/test_height=720
+window/size/width=40
+window/size/height=40
+window/size/resizable=false
+window/size/test_width=40
+window/size/test_height=40
window/dpi/allow_hidpi=true
-window/stretch/mode="2d"
-window/stretch/aspect="keep"
[editor_plugins]
diff --git a/submodules/discord.gd b/submodules/discord.gd
-Subproject a6ace61217f3edeee9c8254f638f2d85cbde7bd
+Subproject b740c6a04f4d3804ac8567590534338113ba37e