From bedf512318dba67af26ddc1ce461ce5dbe14687a Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Sat, 3 Apr 2021 23:19:31 +0200 Subject: [PATCH 1/8] setting listener no longer resets to null when no arguments are provided --- dmcompile/dmcompile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index f944b86..8a2d8e8 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -47,7 +47,7 @@ async def setcompile(self, ctx): pass @setcompile.command() - async def listener(self, ctx, url:str = None): + async def listener(self, ctx, url:str): """ Set the full URL for the listener From 390808fc13b6b0db154fbdc05cae3848f213c007 Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Sat, 3 Apr 2021 23:21:01 +0200 Subject: [PATCH 2/8] any byond version should now work added a config setting to set the default version added a way to do expression evaluation using single backticks --- dmcompile/dmcompile.py | 91 +++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index 8a2d8e8..789f4b4 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -32,7 +32,8 @@ def __init__(self, bot): self.config = Config.get_conf(self, 32174327454, force_registration=True) default_config = { - "listener_url": "http://localhost:5000/compile" + "listener_url": "http://localhost:5000/compile", + "default_version": "514.1549" } self.config.register_global(**default_config) @@ -59,6 +60,20 @@ async def listener(self, ctx, url:str): await ctx.send(f"Listener URL set to: {url}") except (ValueError, KeyError, AttributeError): await ctx.send("There was an error setting the listener's URL. Please check your entry and try again.") + + @setcompile.command() + async def default_version(self, ctx, version:str): + """ + Set the default version of BYOND used + + Should be similar to: 514.1549 + """ + + try: + await self.config.default_version.set(version) + await ctx.send(f"Default version set to: {version}") + except (ValueError, KeyError, AttributeError): + await ctx.send("There was an error setting the default version. Please check your entry and try again.") @commands.command() async def listbyond(self, ctx): @@ -75,35 +90,45 @@ async def listbyond(self, ctx): await ctx.send(f"The currently available BYOND versions are:\n> {chat_formatting.humanize_list(repo_tags)}") - @commands.command() - async def compile(self, ctx, version:str = "latest", *,code:str): + @commands.command(usage="[version] ") + async def compile(self, ctx, *, code:str): """ Compile and run DM code This command will attempt to compile and execute given DM code. It will respond with the full compile log along with any outputs given during runtime. If there are any errors during compilation, the bot will respond with a list provided by DreamMaker. The code must be contained within a codeblock, for example: - ``` - world.log << 'Hello world!' + ```c + world.log << "Hello world!" ``` If you're using multiple functions, or if your code requires indentation, you must define a `proc/main()` as shown below. - ``` + ```c proc/example() world.log << "I'm an example function!" proc/main() example() ``` + You can also do [p]compile `expression` to evaluate and print an expression. Example [p]compile `NORTH | EAST`. - Use `listbyond` to get a list of BYOND versions you can compile with. + You can include the target BYOND version before the code block. Example: [p]compile 514.1549 `world.byond_build` """ - if version.startswith('```'): - version = "latest" - code = f"```\n{code}" - else: - if version not in self.repo_tags: - return await ctx.send(f"That version of BYOND is not supported. Use `{ctx.prefix}listbyond` for a list of supported versions.") - + tiny_output = False + + version = await self.config.default_version() + + code_quote_char = '```' if '```' in code else '`' + if code_quote_char not in code: + return await ctx.send("Your code has to be in a code block!") + maybe_version, code = code.split(code_quote_char, 1) + code = code_quote_char + code + maybe_version = maybe_version.strip() + if maybe_version: + version = maybe_version + + if code_quote_char == '`': + tiny_output = True + code = self.cleanup_code(utils.chat_formatting.escape(code)) if code is None: return await ctx.send("Your code has to be in a code block!") @@ -132,24 +157,39 @@ async def compile(self, ctx, version:str = "latest", *,code:str): run_log = r['run_log'] if r['timeout']: - embed = discord.Embed(title="Execution timed out (30 seconds)", description=f"Compiler Output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}\nExecution Output:\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0xd3d3d3) - await ctx.send(embed=embed) - return await message.delete() + if tiny_output: + await ctx.send("Timed out") + return await message.delete() + else: + embed = discord.Embed(title="Execution timed out (30 seconds)", description=f"**Compiler Output:**\n{box(escape(compile_log, mass_mentions=True, formatting=True))}\n**Execution Output:**\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0xd3d3d3) + await ctx.send(embed=embed) + return await message.delete() errors = ERROR_PATTERN.search(compile_log) warnings = WARNING_PATTERN.search(compile_log) if int(errors.group(1)) > 0: - embed = discord.Embed(title="Compilation failed!", description=f"Compiler output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}", color=0xff0000) - await ctx.send(embed=embed) - return await message.delete() + if tiny_output: + await ctx.send("Compile error. Maybe you meant to use \\`\\`\\` instead of \\`?") + return await message.delete() + else: + embed = discord.Embed(title="Compilation failed!", description=f"Compiler output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}", color=0xff0000) + await ctx.send(embed=embed) + return await message.delete() elif int(warnings.group(1)) > 0: - embed = discord.Embed(title="Warnings found during compilation", description=f"Compiler Output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}\nExecution Output:\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0xffcc00) + embed = discord.Embed(title="Warnings found during compilation", description=f"**Compiler Output:**\n{box(escape(compile_log, mass_mentions=True, formatting=True))}**Execution Output:**\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0xffcc00) await ctx.send(embed=embed) return await message.delete() else: - embed = discord.Embed(description=f"Compiler Output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}\nExecution Output:\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0x00ff00) - await ctx.send(embed=embed) - return await message.delete() + if tiny_output: + output = run_log + output = '\n'.join(output.split('\n')[2:]).strip() + output = '`' + escape(output, mass_mentions=True, formatting=True) + '`' + await ctx.send(output) + return await message.delete() + else: + embed = discord.Embed(description=f"**Compiler Output:**\n{box(escape(compile_log, mass_mentions=True, formatting=True))}**Execution Output:**\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0x00ff00) + await ctx.send(embed=embed) + return await message.delete() except (httpx.NetworkError, httpx.ConnectTimeout): embed = discord.Embed(description=f"Error connecting to listener", color=0xff0000) @@ -163,9 +203,12 @@ async def compile(self, ctx, version:str = "latest", *,code:str): def cleanup_code(self, content): """clears those pesky codeblocks""" + content = content.strip() if content.startswith("```") and content.endswith("```"): content = CODE_BLOCK_RE.sub("", content)[:-3] return content.strip('\n') + elif content.startswith("`") and content.endswith("`"): + return 'world.log << json_encode(' + content[1:-1] + ')' else: return None From 3ec342874ed0f926e40d474b2030ad4b3706cd9f Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Sat, 3 Apr 2021 23:24:14 +0200 Subject: [PATCH 3/8] no compiler output if there are no warnings and errors --- dmcompile/dmcompile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index 789f4b4..15ea998 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -187,7 +187,7 @@ async def compile(self, ctx, *, code:str): await ctx.send(output) return await message.delete() else: - embed = discord.Embed(description=f"**Compiler Output:**\n{box(escape(compile_log, mass_mentions=True, formatting=True))}**Execution Output:**\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0x00ff00) + embed = discord.Embed(description=f"**Execution Output:**\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0x00ff00) await ctx.send(embed=embed) return await message.delete() From 226aa1be3504cd0e373fb888d92856bd0cfb2b0a Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Sat, 3 Apr 2021 23:26:46 +0200 Subject: [PATCH 4/8] removed listbyond commands since the versions are now unbounded --- dmcompile/dmcompile.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index 15ea998..a7f0b54 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -74,21 +74,6 @@ async def default_version(self, ctx, version:str): await ctx.send(f"Default version set to: {version}") except (ValueError, KeyError, AttributeError): await ctx.send("There was an error setting the default version. Please check your entry and try again.") - - @commands.command() - async def listbyond(self, ctx): - """ - List the available BYOND versions - - List generated from the beestation/byond docker repository. - - _This command also updates the internal list of available versions for the compiler._ - """ - - repo_tags = await self.version_list() - repo_tags.remove("latest") - - await ctx.send(f"The currently available BYOND versions are:\n> {chat_formatting.humanize_list(repo_tags)}") @commands.command(usage="[version] ") async def compile(self, ctx, *, code:str): From cf3bb0da98c868ee732ef07d4faa88773a5a59a2 Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Thu, 18 May 2023 19:21:36 +0200 Subject: [PATCH 5/8] bump byond default version --- dmcompile/dmcompile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index a7f0b54..1f9edef 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -33,7 +33,7 @@ def __init__(self, bot): default_config = { "listener_url": "http://localhost:5000/compile", - "default_version": "514.1549" + "default_version": "514.1589" } self.config.register_global(**default_config) From 93c1d1a6fef434d9974c67afdc1c2a5f6137cca1 Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Thu, 18 May 2023 19:24:08 +0200 Subject: [PATCH 6/8] change version in one other place --- dmcompile/dmcompile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index 1f9edef..0777b03 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -66,7 +66,7 @@ async def default_version(self, ctx, version:str): """ Set the default version of BYOND used - Should be similar to: 514.1549 + Should be in format similar to: 514.1589 """ try: From eae9fc478fe0ebbc16d9f5bd0e42d754e792145c Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Thu, 18 May 2023 19:25:45 +0200 Subject: [PATCH 7/8] show errors on ` ` variant --- dmcompile/dmcompile.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index 0777b03..3314d36 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -153,13 +153,10 @@ async def compile(self, ctx, *, code:str): errors = ERROR_PATTERN.search(compile_log) warnings = WARNING_PATTERN.search(compile_log) if int(errors.group(1)) > 0: - if tiny_output: - await ctx.send("Compile error. Maybe you meant to use \\`\\`\\` instead of \\`?") - return await message.delete() - else: - embed = discord.Embed(title="Compilation failed!", description=f"Compiler output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}", color=0xff0000) - await ctx.send(embed=embed) - return await message.delete() + embed = discord.Embed(title="Compilation failed!", description=f"Compiler output:\n{box(escape(compile_log, mass_mentions=True, formatting=True))}", color=0xff0000) + content = "Maybe you meant to use \\`\\`\\` instead of \\`?" if tiny_output else None + await ctx.send(content=content, embed=embed) + return await message.delete() elif int(warnings.group(1)) > 0: embed = discord.Embed(title="Warnings found during compilation", description=f"**Compiler Output:**\n{box(escape(compile_log, mass_mentions=True, formatting=True))}**Execution Output:**\n{box(escape(run_log, mass_mentions=True, formatting=True))}", color=0xffcc00) await ctx.send(embed=embed) From 7cb7d29cc608a93e64626f3491786e27fe6ad454 Mon Sep 17 00:00:00 2001 From: pali <6pali6@gmail.com> Date: Thu, 18 May 2023 19:28:22 +0200 Subject: [PATCH 8/8] bump version in one other place --- dmcompile/dmcompile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmcompile/dmcompile.py b/dmcompile/dmcompile.py index 3314d36..167c5fc 100644 --- a/dmcompile/dmcompile.py +++ b/dmcompile/dmcompile.py @@ -96,7 +96,7 @@ async def compile(self, ctx, *, code:str): ``` You can also do [p]compile `expression` to evaluate and print an expression. Example [p]compile `NORTH | EAST`. - You can include the target BYOND version before the code block. Example: [p]compile 514.1549 `world.byond_build` + You can include the target BYOND version before the code block. Example: [p]compile 514.1589 `world.byond_build` """ tiny_output = False