public async Task AddReminder([Remainder] string args) { try { string[] splittedArgs = { }; if (args.ToLower().Contains(" in ")) { splittedArgs = args.ToLower().Split(new[] { " in " }, StringSplitOptions.None); } else if (args.ToLower().Contains(" in ")) { splittedArgs = args.ToLower().Split(new[] { " in " }, StringSplitOptions.None); } else if (args.ToLower().Contains(" in ")) { splittedArgs = args.ToLower().Split(new[] { " in " }, StringSplitOptions.None); } else if (args.ToLower().Contains(" in ")) { splittedArgs = args.ToLower().Split(new[] { " in " }, StringSplitOptions.None); } if (splittedArgs == null) { const string bigmess = "boole-boole... you are using this command incorrectly!!\n" + "Right way: `Remind [text] in [time]`\n" + "Between message and time **HAVE TO BE** written `in` part" + "(Time can be different, but follow the rules! **day-hour-minute-second**. You can skip any of those parts, but they have to be in the same order. One space or without it between each of the parts\n" + "I'm a loving order octopus!"; await SendMessAsync(bigmess); return; } var account = _accounts.GetAccount(Context.User); var accountForTimeZone = _accounts.GetAccount(Context.User); var timezone = accountForTimeZone.TimeZone ?? "UTC"; TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById($"{timezone}"); var timeString = splittedArgs[splittedArgs.Length - 1]; if (timeString == "24h") { timeString = "1d"; } splittedArgs[splittedArgs.Length - 1] = ""; var reminderString = string.Join(" in ", splittedArgs, 0, splittedArgs.Length - 1); var timeDateTime = DateTime.UtcNow + TimeSpan.ParseExact(timeString, ReminderFormat.Formats, CultureInfo.CurrentCulture); var randomIndex = _secureRandom.Random(0, _octoNamePull.OctoNameRu.Length - 1); var randomOcto = _octoNamePull.OctoNameRu[randomIndex]; var extra = randomOcto.Split(new[] { "](" }, StringSplitOptions.RemoveEmptyEntries); var name = extra[0].Remove(0, 1); var url = extra[1].Remove(extra[1].Length - 1, 1); var localTime = TimeZoneInfo.ConvertTimeFromUtc(timeDateTime, tz); var bigmess2 = $"{reminderString}\n\n" + $"We will send you a DM in __**{localTime}**__ `by {timezone}`\n"; var embed = new EmbedBuilder(); embed.WithAuthor(Context.User); embed.WithTimestamp(DateTimeOffset.UtcNow); embed.WithColor(_secureRandom.Random(0, 254), _secureRandom.Random(0, 254), _secureRandom.Random(0, 254)); embed.AddField($"**____**", $"{bigmess2}"); embed.WithTitle($"{name} напомнит тебе:"); embed.WithUrl(url); var newReminder = new AccountSettings.CreateReminder(timeDateTime, reminderString); account.ReminderList.Add(newReminder); await SendMessAsync(embed); } catch (Exception e) { var botMess = await ReplyAsync( "boo... An error just appear >_< \n" + "Say `HelpRemind`"); _helperFunctions.DeleteMessOverTime(botMess, 5); _log.Error($" [REMINDER][Exception] ({Context.User.Username}) - {e.Message}"); Console.WriteLine(e.Message); } }
public async Task AddReminderMinute(uint minute = 0, [Remainder] string reminderString = null) { try { if (minute > 1439) { await SendMessAsync( "Booole. [time] have to be in range 0-1439 (in minutes)"); return; } var hour = 0; var timeFormat = $"{minute}m"; if (minute >= 60) { for (var i = 0; minute >= 59; i++) { minute = minute - 59; hour++; timeFormat = $"{hour}h {minute}m"; } } var timeString = timeFormat; //// MAde t ominutes var timeDateTime = DateTime.UtcNow + TimeSpan.ParseExact(timeString, ReminderFormat.Formats, CultureInfo.CurrentCulture); var randomIndex = _secureRandom.Random(0, _octoNamePull.OctoNameRu.Length - 1); var randomOcto = _octoNamePull.OctoNameRu[randomIndex]; var extra = randomOcto.Split(new[] { "](" }, StringSplitOptions.RemoveEmptyEntries); var name = extra[0].Remove(0, 1); var url = extra[1].Remove(extra[1].Length - 1, 1); var bigmess = $"{reminderString}\n\n" + $"We will send you a DM in __**{timeDateTime}**__ `by UTC`\n" + $"**Time Now: {DateTime.UtcNow}** `by UTC`"; var embed = new EmbedBuilder(); embed.WithAuthor(Context.User); embed.WithTimestamp(DateTimeOffset.UtcNow); embed.WithColor(_secureRandom.Random(0, 255), _secureRandom.Random(0, 255), _secureRandom.Random(0, 255)); embed.AddField($"**____**", $"{bigmess}"); embed.WithTitle($"{name} напомнит тебе:"); embed.WithUrl(url); await SendMessAsync(embed); var account = _accounts.GetAccount(Context.User); //account.SocketUser = SocketGuildUser(Context.User); var newReminder = new AccountSettings.CreateReminder(timeDateTime, reminderString); account.ReminderList.Add(newReminder); } catch { var botMess = await ReplyAsync( "boo... An error just appear >_< \n" + "Say `HelpRemind`"); _helperFunctions.DeleteMessOverTime(botMess, 5); } }