1
1
import re
2
- import time
3
2
4
3
5
4
def render_message (interpreter , message ):
@@ -13,31 +12,19 @@ def render_message(interpreter, message):
13
12
# Split the message into parts by {{ and }}, including multi-line strings
14
13
parts = re .split (r"({{.*?}})" , message , flags = re .DOTALL )
15
14
16
- for i in range (len (parts )):
17
- part = parts [i ]
15
+ for i , part in enumerate (parts ):
18
16
# If the part is enclosed in {{ and }}
19
17
if part .startswith ("{{" ) and part .endswith ("}}" ):
20
18
# Run the code inside the brackets
21
19
output = interpreter .computer .run (
22
20
"python" , part [2 :- 2 ].strip (), display = interpreter .verbose
23
21
)
24
22
25
- # Turn it into just a simple string
26
- outputs = []
27
- for line in output :
28
- if interpreter .debug :
29
- print (line )
30
- if line .get ("format" ) == "output" :
31
- if "IGNORE_ALL_ABOVE_THIS_LINE" in line ["content" ]:
32
- outputs .append (
33
- line ["content" ].split ("IGNORE_ALL_ABOVE_THIS_LINE" )[1 ]
34
- )
35
- else :
36
- outputs .append (line ["content" ])
37
- output = "\n " .join (outputs )
23
+ # Extract the output content
24
+ outputs = (line ["content" ] for line in output if line .get ("format" ) == "output" and "IGNORE_ALL_ABOVE_THIS_LINE" not in line ["content" ])
38
25
39
26
# Replace the part with the output
40
- parts [i ] = output
27
+ parts [i ] = " \n " . join ( outputs )
41
28
42
29
# Join the parts back into the message
43
30
rendered_message = "" .join (parts ).strip ()
0 commit comments