@@ -14,28 +14,40 @@ public static bool GetBooleanValue(this StringSegment segment)
1414 public static readonly StarscriptHypervisor MathHypervisor = StarscriptHypervisor . Create ( ) . WithStandardLibraryMath ( ) ;
1515
1616
17- public static StringSegment Run ( string source , IStarscriptObject environment )
18- => Run ( source , environment . ToStarscript ( ) ) ;
17+ public static StringSegment Run ( this IGuild currentGuild , string source , IStarscriptObject environment )
18+ => currentGuild . Run ( source , environment . ToStarscript ( ) ) ;
1919
2020 public static StringSegment Run ( Script script , IStarscriptObject environment )
2121 => Run ( script , environment . ToStarscript ( ) ) ;
2222
23- public static StringSegment Run ( string source , ValueMap environment )
24- => Run ( Compile ( source ) , environment ) ;
23+ public static StringSegment Run ( this IGuild currentGuild , string source , ValueMap environment )
24+ => Run ( Compile ( source , currentGuild ) , environment ) ;
2525
2626 public static StringSegment Run ( Script script , ValueMap environment )
2727 => Hypervisor . ReplaceLocals ( environment ) . Run ( script , environment ) ;
2828
29- public static StringSegment RunExpression ( string expression )
30- => CompileExpression ( expression ) . Execute ( MathHypervisor ) ;
29+ public static StringSegment RunExpression ( string expression , IGuild guild )
30+ => CompileExpression ( expression , guild ) . Execute ( MathHypervisor ) ;
3131
32- public static Script Compile ( string source )
32+ public static Script Compile ( string source , IGuild guild )
3333 {
3434 if ( ! Parser . TryParse ( source , out var result ) )
3535 throw new ParseException ( result . Errors . First ( ) ) ;
3636
37- return Compiler . SingleCompile ( result ) ;
37+ var script = Compiler . SingleCompile ( result ) ;
38+
39+ if ( script . Code . Length > 150 )
40+ {
41+ Warn ( LogSource . Service ,
42+ $ "Large compiled Starscript (>150 bytes): {{ Guild: \" { guild . Name } \" ({ guild . Id } )," +
43+ $ "CodeLength: { script . Code . Length } , ConstantsCount: { script . Constants . Length } }}") ;
44+
45+ if ( script . Code . Length > 500 )
46+ Warn ( LogSource . Service , "It's over 500 bytes, should probably take a look!" ) ;
47+ }
48+
49+ return script ;
3850 }
3951
40- public static Script CompileExpression ( string source ) => Compile ( $ "{{{source}}}") ;
52+ public static Script CompileExpression ( string source , IGuild guild ) => Compile ( $ "{{{source}}}", guild ) ;
4153}
0 commit comments