1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-10 07:53:15 +03:00

Merge branch 'master' into profile-editremind

Signed-off-by: Macintxsh <95250141+mctaylors@users.noreply.github.com>
This commit is contained in:
Macintxsh 2024-01-28 18:39:34 +03:00 committed by GitHub
commit bdef465a41
Signed by: GitHub
GPG key ID: B5690EEEBB952194
15 changed files with 164 additions and 35 deletions

View file

@ -115,7 +115,7 @@ public class AboutCommandGroup : CommandGroup
.WithSmallTitle(string.Format(Messages.AboutBot, bot.Username), bot)
.WithDescription(builder.ToString())
.WithColour(ColorsList.Cyan)
.WithImageUrl("https://cdn.mctaylors.ru/octobot-banner.png")
.WithImageUrl("https://i.ibb.co/fS6wZhh/octobot-banner.png")
.Build();
var repositoryButton = new ButtonComponent(

View file

@ -57,7 +57,7 @@ public class BanCommandGroup : CommandGroup
/// A slash command that bans a Discord user with the specified reason.
/// </summary>
/// <param name="target">The user to ban.</param>
/// <param name="stringDuration">The duration for this ban. The user will be automatically unbanned after this duration.</param>
/// <param name="duration">The duration for this ban. The user will be automatically unbanned after this duration.</param>
/// <param name="reason">
/// The reason for this ban. Must be encoded with <see cref="StringExtensions.EncodeHeader" /> when passed to
/// <see cref="IDiscordRestGuildAPI.CreateGuildBanAsync" />.
@ -79,8 +79,7 @@ public class BanCommandGroup : CommandGroup
[Description("User to ban")] IUser target,
[Description("Ban reason")] [MaxLength(256)]
string reason,
[Description("Ban duration")] [Option("duration")]
string? stringDuration = null)
[Description("Ban duration")] string? duration = null)
{
_profiler.Push("ban_command");
_profiler.Push("preparation");
@ -120,7 +119,7 @@ public class BanCommandGroup : CommandGroup
Messages.Culture = GuildSettings.Language.Get(data.Settings);
_profiler.Pop();
if (stringDuration is null)
if (duration is null)
{
_profiler.Pop();
return _profiler.ReportWithResult(await BanUserAsync(executor, target, reason, null, guild, data, channelId,
@ -128,8 +127,8 @@ public class BanCommandGroup : CommandGroup
CancellationToken));
}
var parseResult = TimeSpanParser.TryParse(stringDuration);
if (!parseResult.IsDefined(out var duration))
var parseResult = TimeSpanParser.TryParse(duration);
if (!parseResult.IsDefined(out var timeSpan))
{
_profiler.Push("invalid_timespan_send");
var failedEmbed = new EmbedBuilder()
@ -142,7 +141,7 @@ public class BanCommandGroup : CommandGroup
}
_profiler.Pop();
return _profiler.ReportWithResult(await BanUserAsync(executor, target, reason, duration, guild, data, channelId,
return _profiler.ReportWithResult(await BanUserAsync(executor, target, reason, timeSpan, guild, data, channelId,
bot, CancellationToken));
}

View file

@ -236,6 +236,132 @@ public class RemindCommandGroup : CommandGroup
return _profiler.PopWithResult(await _feedback.SendContextualEmbedResultAsync(embed, ct: ct));
}
public enum Parameters
{
[UsedImplicitly] Time,
[UsedImplicitly] Text
}
/// <summary>
/// A slash command that edits a scheduled reminder using the specified text or time.
/// </summary>
/// <param name="position">The list position of the reminder to edit.</param>
/// <param name="parameter">The reminder's parameter to edit.</param>
/// <param name="value">The new value for the reminder as a text or time.</param>
/// <returns>A feedback sending result which may or may not have succeeded.</returns>
[Command("editremind")]
[Description("Edit a reminder")]
[DiscordDefaultDMPermission(false)]
[RequireContext(ChannelContext.Guild)]
[UsedImplicitly]
public async Task<Result> ExecuteEditReminderAsync(
[Description("Position in list")] [MinValue(1)]
int position,
[Description("Parameter to edit")] Parameters parameter,
[Description("Parameter's new value")] string value)
{
if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId))
{
return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context");
}
var botResult = await _userApi.GetCurrentUserAsync(CancellationToken);
if (!botResult.IsDefined(out var bot))
{
return Result.FromError(botResult);
}
var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken);
if (!executorResult.IsDefined(out var executor))
{
return Result.FromError(executorResult);
}
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
var memberData = data.GetOrCreateMemberData(executor.ID);
if (parameter is Parameters.Time)
{
return await EditReminderTimeAsync(position - 1, value, memberData, bot, executor, CancellationToken);
}
return await EditReminderTextAsync(position - 1, value, memberData, bot, executor, CancellationToken);
}
private async Task<Result> EditReminderTimeAsync(int index, string value, MemberData data,
IUser bot, IUser executor, CancellationToken ct = default)
{
if (index >= data.Reminders.Count)
{
var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.InvalidReminderPosition, bot)
.WithColour(ColorsList.Red)
.Build();
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: ct);
}
var parseResult = TimeSpanParser.TryParse(value);
if (!parseResult.IsDefined(out var timeSpan))
{
var failedEmbed = new EmbedBuilder()
.WithSmallTitle(Messages.InvalidTimeSpan, bot)
.WithColour(ColorsList.Red)
.Build();
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: ct);
}
var oldReminder = data.Reminders[index];
var remindAt = DateTimeOffset.UtcNow.Add(timeSpan);
data.Reminders.Add(oldReminder with { At = remindAt });
data.Reminders.RemoveAt(index);
var builder = new StringBuilder()
.AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(oldReminder.Text)))
.AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt)));
var embed = new EmbedBuilder().WithSmallTitle(
string.Format(Messages.ReminderEdited, executor.GetTag()), executor)
.WithDescription(builder.ToString())
.WithColour(ColorsList.Cyan)
.WithFooter(string.Format(Messages.ReminderPosition, data.Reminders.Count))
.Build();
return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct);
}
private async Task<Result> EditReminderTextAsync(int index, string value, MemberData data,
IUser bot, IUser executor, CancellationToken ct = default)
{
if (index >= data.Reminders.Count)
{
var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.InvalidReminderPosition, bot)
.WithColour(ColorsList.Red)
.Build();
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: ct);
}
var oldReminder = data.Reminders[index];
data.Reminders.Add(oldReminder with { Text = value });
data.Reminders.RemoveAt(index);
var builder = new StringBuilder()
.AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(value)))
.AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(oldReminder.At)));
var embed = new EmbedBuilder().WithSmallTitle(
string.Format(Messages.ReminderEdited, executor.GetTag()), executor)
.WithDescription(builder.ToString())
.WithColour(ColorsList.Cyan)
.WithFooter(string.Format(Messages.ReminderPosition, data.Reminders.Count))
.Build();
return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct);
}
/// <summary>
/// A slash command that deletes a reminder using its list position.
/// </summary>

View file

@ -1052,5 +1052,11 @@ namespace Octobot {
return ResourceManager.GetString("UserInfoKicked", resourceCulture);
}
}
internal static string ReminderEdited {
get {
return ResourceManager.GetString("ReminderEdited", resourceCulture);
}
}
}
}

View file

@ -28,7 +28,7 @@ namespace Octobot;
public sealed class Octobot
{
public const string RepositoryUrl = "https://github.com/LabsDevelopment/Octobot";
public const string RepositoryUrl = "https://github.com/TeamOctolings/Octobot";
public const string IssuesUrl = $"{RepositoryUrl}/issues";
public static readonly AllowedMentions NoMentions = new(

View file

@ -28,9 +28,10 @@ public class MessageCreateResponder : IResponder<IMessageCreate>
"whoami" => "`nobody`",
"сука !!" => "`root`",
"воооо" => "`removing /...`",
"пон" => "https://cdn.upload.systems/uploads/2LNfUSwM.jpg",
"пон" => "https://i.ibb.co/Kw6QVcw/parry.jpg",
"++++" => "#",
"осу" => "https://github.com/ppy/osu",
"лан" => "https://i.ibb.co/VYH2QLc/lan.jpg",
_ => default(Optional<string>)
});
return Task.FromResult(Result.FromSuccess());