mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
Do not allow setting reminders without specifying a valid TimeSpan
Fixes #19 Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
8f9c71edf1
commit
a97341f9a9
7 changed files with 39 additions and 15 deletions
|
@ -150,12 +150,13 @@ public static class Boyfriend {
|
|||
mentions.Clear();
|
||||
}
|
||||
|
||||
_ = ulong.TryParse(config["StarterRole"], out var starterRoleId);
|
||||
foreach (var mData in data.MemberData.Values) {
|
||||
var user = guild.GetUser(mData.Id);
|
||||
if (now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id);
|
||||
if (!mData.IsInGuild) continue;
|
||||
if (!mData.Roles.Contains(starterRoleId) && mData.MutedUntil is null) _ = user.AddRoleAsync(starterRoleId);
|
||||
if (mData.MutedUntil is null
|
||||
&& ulong.TryParse(config["StarterRole"], out var starterRoleId)
|
||||
&& !mData.Roles.Contains(starterRoleId)) _ = user.AddRoleAsync(starterRoleId);
|
||||
|
||||
if (now >= mData.MutedUntil) {
|
||||
await Utils.UnmuteMemberAsync(
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Boyfriend;
|
|||
|
||||
public sealed class CommandProcessor {
|
||||
private static readonly string Mention = $"<@{Boyfriend.Client.CurrentUser.Id}>";
|
||||
private static readonly TimeSpan Infinity = TimeSpan.FromMilliseconds(-1);
|
||||
|
||||
public static readonly ICommand[] Commands = {
|
||||
new BanCommand(), new ClearCommand(), new HelpCommand(),
|
||||
|
@ -246,14 +247,13 @@ public sealed class CommandProcessor {
|
|||
}
|
||||
|
||||
public static TimeSpan GetTimeSpan(string[] args, int index) {
|
||||
var infinity = TimeSpan.FromMilliseconds(-1);
|
||||
if (index >= args.Length) return infinity;
|
||||
if (index >= args.Length) return Infinity;
|
||||
var chars = args[index].AsSpan();
|
||||
var numberBuilder = Boyfriend.StringBuilder;
|
||||
int days = 0, hours = 0, minutes = 0, seconds = 0;
|
||||
foreach (var c in chars)
|
||||
if (char.IsDigit(c)) { numberBuilder.Append(c); } else {
|
||||
if (numberBuilder.Length is 0) return infinity;
|
||||
if (numberBuilder.Length is 0) return Infinity;
|
||||
switch (c) {
|
||||
case 'd' or 'D' or 'д' or 'Д':
|
||||
days += int.Parse(numberBuilder.ToString());
|
||||
|
@ -271,7 +271,7 @@ public sealed class CommandProcessor {
|
|||
seconds += int.Parse(numberBuilder.ToString());
|
||||
numberBuilder.Clear();
|
||||
break;
|
||||
default: return infinity;
|
||||
default: return Infinity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,14 @@ public sealed class RemindCommand : ICommand {
|
|||
public Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) {
|
||||
// TODO: actually make this good
|
||||
var remindIn = CommandProcessor.GetTimeSpan(args, 0);
|
||||
if (remindIn.TotalSeconds < 1) {
|
||||
cmd.Reply(Messages.InvalidRemindIn, ReplyEmojis.InvalidArgument);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var reminderText = cmd.GetRemaining(cleanArgs, 1, "ReminderText");
|
||||
var reminderOffset = DateTimeOffset.Now.Add(remindIn);
|
||||
if (reminderText is not null) {
|
||||
var reminderOffset = DateTimeOffset.Now.Add(remindIn);
|
||||
GuildData.Get(cmd.Context.Guild).MemberData[cmd.Context.User.Id].Reminders.Add(
|
||||
new Reminder {
|
||||
RemindAt = reminderOffset,
|
||||
|
|
9
Messages.Designer.cs
generated
9
Messages.Designer.cs
generated
|
@ -1111,5 +1111,14 @@ namespace Boyfriend {
|
|||
return ResourceManager.GetString("FeedbackReminderAdded", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You need to specify when I should send you the reminder!.
|
||||
/// </summary>
|
||||
internal static string InvalidRemindIn {
|
||||
get {
|
||||
return ResourceManager.GetString("InvalidRemindIn", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@
|
|||
<value>You need to specify a guild member!</value>
|
||||
</data>
|
||||
<data name="InvalidMember" xml:space="preserve">
|
||||
<value>You did not specify a member of this guild!</value>
|
||||
<value>You need to specify a member of this guild!</value>
|
||||
</data>
|
||||
<data name="UserCannotBanMembers" xml:space="preserve">
|
||||
<value>You cannot ban users from this guild!</value>
|
||||
|
@ -468,4 +468,7 @@
|
|||
<data name="FeedbackReminderAdded" xml:space="preserve">
|
||||
<value>OK, I'll mention you on <t:{0}:f></value>
|
||||
</data>
|
||||
<data name="InvalidRemindIn" xml:space="preserve">
|
||||
<value>You need to specify when I should send you the reminder!</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -328,7 +328,7 @@
|
|||
<value>Надо указать участника сервера!</value>
|
||||
</data>
|
||||
<data name="InvalidMember" xml:space="preserve">
|
||||
<value>Тебе надо указать участника этого сервера!</value>
|
||||
<value>Надо указать участника этого сервера!</value>
|
||||
</data>
|
||||
<data name="UserCannotBanMembers" xml:space="preserve">
|
||||
<value>Ты не можешь банить пользователей на этом сервере!</value>
|
||||
|
@ -468,4 +468,7 @@
|
|||
<data name="FeedbackReminderAdded" xml:space="preserve">
|
||||
<value>Хорошо, я упомяну тебя <t:{0}:f></value>
|
||||
</data>
|
||||
<data name="InvalidRemindIn" xml:space="preserve">
|
||||
<value>Нужно указать время, через которое придёт напоминание!</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -468,4 +468,7 @@
|
|||
<data name="FeedbackReminderAdded" xml:space="preserve">
|
||||
<value>вас понял, упоминание будет <t:{0}:f></value>
|
||||
</data>
|
||||
<data name="InvalidRemindIn" xml:space="preserve">
|
||||
<value>шизоид у меня на часах такого нету</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
Loading…
Reference in a new issue