Skip to content

Commit b7d049f

Browse files
2 parents 912600d + 82302f1 commit b7d049f

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.Helpers.Exceptions;
5+
using SER.Code.Helpers.Extensions;
6+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
7+
using SER.Code.MethodSystem.MethodDescriptors;
8+
using SER.Code.ValueSystem;
9+
10+
namespace SER.Code.MethodSystem.Methods.TextMethods;
11+
12+
[UsedImplicitly]
13+
public class PadTextMethod : ReturningMethod<TextValue>, ICanError, IAdditionalDescription
14+
{
15+
public override string Description => "Fills the text from the left or right with the given character " +
16+
"until the specified length is met";
17+
18+
public string AdditionalDescription => "The \"character\" argument must have EXACTLY 1 character in it.";
19+
20+
public string[] ErrorReasons =>
21+
[
22+
"The \"character\" argument doesn't have EXACTLY 1 character in it."
23+
];
24+
25+
public override Argument[] ExpectedArguments { get; } =
26+
[
27+
new TextArgument("text to pad"),
28+
new OptionsArgument("pad direction",
29+
"left",
30+
"right"),
31+
new IntArgument("length"),
32+
new TextArgument("character")
33+
];
34+
35+
public override void Execute()
36+
{
37+
var text = Args.GetText("text to pad");
38+
var direction = Args.GetOption("pad direction");
39+
var length = Args.GetInt("length");
40+
var character = Args.GetText("character");
41+
42+
if (character.Length != 1)
43+
throw new ScriptRuntimeError(this, ErrorReasons[0]);
44+
45+
ReturnValue = (direction switch
46+
{
47+
"left" => text.PadLeft(length, character[0]),
48+
"right" => text.PadRight(length, character[0]),
49+
_ => throw new TosoksFuckedUpException("out of order")
50+
}).ToDynamicTextValue(Script);
51+
}
52+
}

Code/MethodSystem/Methods/TimeMethods/TimeInfoMethod.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,33 @@ public class TimeInfoMethod : LiteralValueReturningMethod
2323
"second",
2424
"minute",
2525
"hour",
26+
"month",
2627
"year",
2728
"dayOfWeek",
2829
new("dayOfWeekNumber", "Instead of returning e.g. 'Monday', will return 1"),
2930
"dayOfMonth",
30-
"dayOfYear")
31+
"dayOfYear",
32+
new("unixTimeUtc","Useful for making discord timestamps "),
33+
"unixTimeLocal")
3134
];
3235

3336
public override void Execute()
3437
{
35-
ReturnValue = Args.GetOption("options").ToLower() switch
38+
ReturnValue = Args.GetOption("options") switch
3639
{
3740
"second" => new NumberValue(DateTime.Now.Second),
3841
"minute" => new NumberValue(DateTime.Now.Minute),
3942
"hour" => new NumberValue(DateTime.Now.Hour),
43+
"month" => new NumberValue(DateTime.Now.Month),
4044
"year" => new NumberValue(DateTime.Now.Year),
4145
"dayofweek" => new StaticTextValue(DateTime.Now.DayOfWeek.ToString()),
4246
"dayofweeknumber" => (uint)DateTime.Now.DayOfWeek == 0
4347
? new NumberValue(7)
4448
: new NumberValue((uint)DateTime.Now.DayOfWeek),
4549
"dayofmonth" => new NumberValue(DateTime.Now.Day),
4650
"dayofyear" => new NumberValue(DateTime.Now.DayOfYear),
51+
"unixtimeutc" => new NumberValue(DateTimeOffset.UtcNow.ToUnixTimeSeconds()),
52+
"unixtimelocal" => new NumberValue(DateTimeOffset.Now.ToUnixTimeSeconds()),
4753
_ => throw new AndrzejFuckedUpException()
4854
};
4955
}

0 commit comments

Comments
 (0)