1+ using JetBrains . Annotations ;
2+ using SER . Code . ArgumentSystem . Arguments ;
3+ using SER . Code . ArgumentSystem . BaseArguments ;
4+ using SER . Code . ArgumentSystem . Structures ;
5+ using SER . Code . FlagSystem ;
6+ using SER . Code . Helpers . Exceptions ;
7+ using SER . Code . MethodSystem . BaseMethods ;
8+ using SER . Code . ScriptSystem ;
9+ using SER . Code . ValueSystem ;
10+
11+ namespace SER . Code . MethodSystem . Methods . ScriptMethods ;
12+
13+ [ UsedImplicitly ]
14+ public class ThisMethod : ReturningMethod
15+ {
16+ public override string Description => "Returns info about the current script" ;
17+
18+ public override Argument [ ] ExpectedArguments { get ; } =
19+ [
20+ new OptionsArgument ( "info to receive" ,
21+ "flags" ,
22+ new ( "caller" , "The name of the script that called this script" ) ,
23+ Option . Enum < RunContext > ( "context" ) ,
24+ new ( "duration" , "The amount of time the script's been running for" ) ,
25+ "name" ,
26+ new ( "path" , "The path to the script on the local directory of the server" ) ,
27+ new ( "variables" , $ "Returns a { nameof ( CollectionValue ) } containing the names of all the variables in the script") )
28+ ] ;
29+
30+ public override TypeOfValue Returns => new TypesOfValue ( [
31+ typeof ( CollectionValue ) ,
32+ typeof ( TextValue ) ,
33+ typeof ( DurationValue ) ,
34+ ] ) ;
35+
36+ public override void Execute ( )
37+ {
38+ ReturnValue = Args . GetOption ( "info to receive" ) switch
39+ {
40+ "flags" => new CollectionValue ( ScriptFlagHandler . GetScriptFlags ( Script . Name )
41+ . Select ( f => f . GetType ( ) . Name . Replace ( "Flag" , "" ) ) ) ,
42+ "caller" => new TextValue ( Script . Caller ? . Name ?? "none" ) ,
43+ "context" => new TextValue ( Script . Context . ToString ( ) ) ,
44+ "duration" => new DurationValue ( Script . TimeRunning ) ,
45+ "name" => new TextValue ( Script . Name ) ,
46+ "path" => new TextValue ( FileSystem . FileSystem . GetScriptPath ( Script ) ) ,
47+ "variables" => new CollectionValue ( Script . Variables . Select ( v => v . Prefix + v . Name ) ) ,
48+ _ => throw new TosoksFuckedUpException ( "out of order" )
49+ } ;
50+ }
51+ }
0 commit comments