mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-05 21:46:28 +03:00
Add /timestamp
Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
parent
d837745b11
commit
6ba2127b35
5 changed files with 95 additions and 1 deletions
|
@ -654,4 +654,10 @@
|
||||||
<data name="RandomOutput" xml:space="preserve">
|
<data name="RandomOutput" xml:space="preserve">
|
||||||
<value>Your random number is:</value>
|
<value>Your random number is:</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TimestampTitle" xml:space="preserve">
|
||||||
|
<value>Timestamp for {0}:</value>
|
||||||
|
</data>
|
||||||
|
<data name="TimestampOffset" xml:space="preserve">
|
||||||
|
<value>Offset: {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -654,4 +654,10 @@
|
||||||
<data name="RandomOutput" xml:space="preserve">
|
<data name="RandomOutput" xml:space="preserve">
|
||||||
<value>Ваше случайное число:</value>
|
<value>Ваше случайное число:</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TimestampTitle" xml:space="preserve">
|
||||||
|
<value>Временная метка для {0}:</value>
|
||||||
|
</data>
|
||||||
|
<data name="TimestampOffset" xml:space="preserve">
|
||||||
|
<value>Офсет: {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -654,4 +654,10 @@
|
||||||
<data name="RandomOutput" xml:space="preserve">
|
<data name="RandomOutput" xml:space="preserve">
|
||||||
<value>ваше рандомное число:</value>
|
<value>ваше рандомное число:</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TimestampTitle" xml:space="preserve">
|
||||||
|
<value>таймштамп для {0}:</value>
|
||||||
|
</data>
|
||||||
|
<data name="TimestampOffset" xml:space="preserve">
|
||||||
|
<value>офсет: {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -19,7 +19,7 @@ using Remora.Results;
|
||||||
namespace Octobot.Commands;
|
namespace Octobot.Commands;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles tool commands: /showinfo, /random.
|
/// Handles tool commands: /showinfo, /random, /timestamp.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class ToolsCommandGroup : CommandGroup
|
public class ToolsCommandGroup : CommandGroup
|
||||||
|
@ -289,4 +289,64 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
|
|
||||||
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A slash command that shows current or counted timestamp.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="offset">The offset to count timestamp.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A feedback sending result which may or may not have succeeded.
|
||||||
|
/// </returns>
|
||||||
|
[Command("timestamp")]
|
||||||
|
[DiscordDefaultDMPermission(false)]
|
||||||
|
[Description("Gets timestamp")]
|
||||||
|
[UsedImplicitly]
|
||||||
|
public async Task<Result> ExecuteTimestampAsync(
|
||||||
|
[Description("Add an offset from now")]
|
||||||
|
TimeSpan? offset = null)
|
||||||
|
{
|
||||||
|
if (!_context.TryGetContextIDs(out var guildId, out _, out var userId))
|
||||||
|
{
|
||||||
|
return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context");
|
||||||
|
}
|
||||||
|
|
||||||
|
var userResult = await _userApi.GetUserAsync(userId, CancellationToken);
|
||||||
|
if (!userResult.IsDefined(out var user))
|
||||||
|
{
|
||||||
|
return Result.FromError(userResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = await _guildData.GetData(guildId, CancellationToken);
|
||||||
|
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||||
|
|
||||||
|
return await SendRandomNumberAsync(offset, user, CancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Result> SendRandomNumberAsync(TimeSpan? offset, IUser user, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var timestamp = DateTimeOffset.UtcNow.Add(offset ?? TimeSpan.Zero).ToUnixTimeSeconds().ToString();
|
||||||
|
|
||||||
|
var description = new StringBuilder().Append("# ").AppendLine(timestamp);
|
||||||
|
|
||||||
|
if (offset is not null)
|
||||||
|
{
|
||||||
|
description.AppendLine(string.Format(
|
||||||
|
Messages.TimestampOffset, Markdown.InlineCode(offset.ToString() ?? string.Empty))).AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] options = { "d", "D", "t", "T", "f", "F", "R" };
|
||||||
|
foreach (var option in options)
|
||||||
|
{
|
||||||
|
description.Append("- ").Append(Markdown.InlineCode($"<t:{timestamp}:{option}>"))
|
||||||
|
.Append(" — ").AppendLine($"<t:{timestamp}:{option}>");
|
||||||
|
}
|
||||||
|
|
||||||
|
var embed = new EmbedBuilder().WithSmallTitle(
|
||||||
|
string.Format(Messages.TimestampTitle, user.GetTag()), user)
|
||||||
|
.WithDescription(description.ToString())
|
||||||
|
.WithColour(ColorsList.Blue)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/Messages.Designer.cs
generated
16
src/Messages.Designer.cs
generated
|
@ -1135,5 +1135,21 @@ namespace Octobot {
|
||||||
return ResourceManager.GetString("RandomOutput", resourceCulture);
|
return ResourceManager.GetString("RandomOutput", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string TimestampTitle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ResourceManager.GetString("TimestampTitle", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string TimestampOffset
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ResourceManager.GetString("TimestampOffset", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue