reminder edits

master
Lan 5 years ago
parent 7adcb813c4
commit db936fdffe
  1. 66
      Kehyeedra3/Commands/Stuff.cs
  2. 3
      Kehyeedra3/Services/ReminderService.cs

@ -2,6 +2,7 @@
using Discord.Addons.Interactive; using Discord.Addons.Interactive;
using Discord.Commands; using Discord.Commands;
using Kehyeedra3.Services.Models; using Kehyeedra3.Services.Models;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@ -103,15 +104,19 @@ namespace Kehyeedra3.Commands
await Context.Channel.SendMessageAsync($"{Context.User.Mention}\n{output+1}"); await Context.Channel.SendMessageAsync($"{Context.User.Mention}\n{output+1}");
} }
[Command("remind"), Summary("Reminds you in a given time. (days, hours, minutes) Eg. 'remind 1 2 3 wash hands' would remind you in 1 day, 2 hours, 3 minutes to wash your hands")] [Command("remind"), Summary("Reminds you in a given time. (days, hours, minutes) Eg. 'remind 1 2 3 wash hands' would remind you in 1 day, 2 hours, 3 minutes to wash your hands")]
public async Task Reminder(ulong d, ulong h, ulong m, [Remainder] string r) public async Task Reminder(ulong d, ulong h, ulong m, [Remainder] string r = null)
{ {
DateTime dt = DateTime.UtcNow;
string time = dt.ToString("dd/MM/yyyy HH:mm");
string remin = ""; string remin = "";
string refix = "";
string resuff = "";
ulong sen = (d * 86400) + (h * 3600) + (m * 60); ulong sen = (d * 86400) + (h * 3600) + (m * 60);
ulong yeedraStamp = DateTime.UtcNow.ToYeedraStamp(); ulong yeedraStamp = DateTime.UtcNow.ToYeedraStamp();
if (r == null)
{
r = "Fill the text field next time you make a reminder.";
}
while (m > 59) while (m > 59)
{ {
h += 1; h += 1;
@ -123,12 +128,48 @@ namespace Kehyeedra3.Commands
h -= 24; h -= 24;
} }
if (d > 0)
{
remin += $" {d} day";
if (d > 1)
{
remin += $"s";
}
}
if (h > 0)
{
remin += $" {h} hour";
if (h > 1)
{
remin += $"s";
}
}
if (m > 0)
{
remin += $" {m} minute";
if (m > 1)
{
remin += $"s";
}
}
if (d == 0 && h == 0 && m == 0)
{
refix += "right now";
resuff += " just now";
}
else
{
refix += "in";
resuff += " ago";
}
if (sen < 63072000) if (sen < 63072000)
{ {
var reminder = new Reminder var reminder = new Reminder
{ {
UserId = Context.User.Id, UserId = Context.User.Id,
Message = ($"At **UTC {time}** you wanted me to remind you:\n**'{r}'**"), Message = $"**Reminder from{remin}{resuff}:**\n\n''{r}''",
Created = yeedraStamp, Created = yeedraStamp,
Send = sen + yeedraStamp Send = sen + yeedraStamp
}; };
@ -146,20 +187,7 @@ namespace Kehyeedra3.Commands
return; return;
} }
await Context.Channel.SendMessageAsync($"{Context.User.Mention}\n Ok, I'll remind you {refix}{remin}.");
if (d > 0)
{
remin += $" {d} days";
}
if (h > 0)
{
remin += $" {h} hours";
}
if (m > 0)
{
remin += $" {m} minutes";
}
await Context.Channel.SendMessageAsync($"{Context.User.Mention}\n Ok, I'll remind you in{remin}.");
} }
[Command("dab"), Summary("Dabs a person")] [Command("dab"), Summary("Dabs a person")]

@ -11,8 +11,11 @@ namespace Kehyeedra3.Services
private static async Task SendReminderAsync(Reminder reminder) private static async Task SendReminderAsync(Reminder reminder)
{ {
var dmchannel = await Bot._bot.GetUser(reminder.UserId).GetOrCreateDMChannelAsync(); var dmchannel = await Bot._bot.GetUser(reminder.UserId).GetOrCreateDMChannelAsync();
if (dmchannel != null)
{
await dmchannel.SendMessageAsync(reminder.Message); await dmchannel.SendMessageAsync(reminder.Message);
} }
}
public async Task Tick() public async Task Tick()
{ {
while (true) while (true)

Loading…
Cancel
Save