I have no idea what I changed

It has been too long, the things just piled up
This commit is contained in:
Lan
2020-11-08 19:38:40 +02:00
parent f5edaf545d
commit 2b8312c0c6
12 changed files with 1135 additions and 195 deletions

View File

@@ -15,7 +15,9 @@ namespace Kehyeedra3.Services.Models
public ulong LastMine { get; set; } = 0;
[Column(TypeName = "LONGTEXT")]
public string GeneralInventory { get; set; } = "{}";
public ICollection<BattleFishObject> BattleFish { get; set; }
[Column(TypeName = "TINYINT")]
public BattleFish CurrentBattlefish { get; set; } = 0;
public bool GrantMoney(User bank, long amount)
@@ -30,18 +32,6 @@ namespace Kehyeedra3.Services.Models
return false;
}
//public void SetGenInv(List<Item> newInv)
//{
// GeneralInventory = JsonConvert.SerializeObject(newInv);
//}
//public List<Item> GetGenInv()
//{
// if (string.IsNullOrEmpty(GeneralInventory))
// {
// return new List<Item>();
// }
// return JsonConvert.DeserializeObject<List<Item>>(GeneralInventory);
//}
public Dictionary<Items, int[]> GetGenInve()
{
@@ -68,6 +58,12 @@ namespace Kehyeedra3.Services.Models
Name = "Lan's Love",
Price = 100
},
new Item()
{
Id = Items.Lettuce,
Name = "Lettuce",
Price = 50
}
};
}
public class Item
@@ -76,20 +72,33 @@ namespace Kehyeedra3.Services.Models
public string Name { get; set; }
public int Price { get; set; }
}
public class BattleFishObject
{
[Key]
public ulong FishId { get; set; }
public byte FishType { get; set; } = 0;
[Required]
public ulong UserId { get; set; }
[Column(TypeName = "TINYINT")]
public BattleFish FishType { get; set; } = 0;
public ulong Xp { get; set; } = 0;
public ulong NextXp { get; set; } = 50;
public int Lvl { get; set; } = 0;
public string Name { get; set; } = "Unnamed";
}
}
public enum BattleFish
{
None = 0,
Herring = 1,
Birgus = 2,
Abama = 3,
Pistashrimp = 4
}
public enum Items
{
DirtyBoot = 0,
Lettuce = 1
}
public class ItemSlot
{

View File

@@ -11,73 +11,82 @@ namespace Kehyeedra3.Services
{
private static async Task SendReminderAsync(Reminder reminder)
{
var dmchannel = await Bot._bot.GetUser(reminder.UserId).GetOrCreateDMChannelAsync();
if (dmchannel != null)
{
ulong m = (reminder.Send - reminder.Created) / 60;
ulong h = 0;
ulong d = 0;
while (m > 59)
try {
var dmchannel = await Bot._bot.GetUser(reminder.UserId).GetOrCreateDMChannelAsync();
if (dmchannel != null)
{
h += 1;
m -= 60;
}
while (h > 23)
{
d += 1;
h -= 24;
}
string remin = "";
if (d > 0)
{
remin += $" {d} day";
if (d > 1)
ulong m = (reminder.Send - reminder.Created) / 60;
ulong h = 0;
ulong d = 0;
while (m > 59)
{
remin += $"s";
h += 1;
m -= 60;
}
}
if (h > 0)
{
remin += $" {h} hour";
if (h > 1)
while (h > 23)
{
remin += $"s";
d += 1;
h -= 24;
}
}
if (m > 0)
{
remin += $" {m} minute";
if (m > 1)
string remin = "";
if (d > 0)
{
remin += $"s";
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";
}
}
await dmchannel.SendMessageAsync($"**Reminder from{remin} ago:**\n\n''{reminder.Message}''");
}
await dmchannel.SendMessageAsync($"**Reminder from{remin} ago:**\n\n''{reminder.Message}''");
}
catch { await (await Bot._bot.GetUser(242040333309837327).GetOrCreateDMChannelAsync()).SendMessageAsync($"Time of error ^\n" +
$"A fucky wucky has occurred, uwu\nFix wemindew sewwis dimwiwt" +
$"\nThis was the reminder: {reminder.Id} {reminder.UserId} {reminder.Send.FromYeedraStamp()}"); }
}
public async Task Tick()
{
while (true)
{
using (var Database = new ApplicationDbContextFactory().CreateDbContext())
{
var reminders = Database.Reminders.ToList();
if(Database.Reminders.Any() && Bot._bot != null && Bot._bot.ConnectionState == Discord.ConnectionState.Connected)
if(Bot.IsReady)
{
using (var Database = new ApplicationDbContextFactory().CreateDbContext())
{
bool hasChanged = false;
foreach (var x in reminders)
var reminders = Database.Reminders.ToList();
if (Database.Reminders.Any() && Bot._bot != null && Bot._bot.ConnectionState == Discord.ConnectionState.Connected)
{
if (x.Send <= DateTime.UtcNow.ToYeedraStamp())
bool hasChanged = false;
foreach (var x in reminders)
{
await SendReminderAsync(x).ConfigureAwait(false);
Database.Reminders.Remove(x);
hasChanged = true;
if (x.Send <= DateTime.UtcNow.ToYeedraStamp())
{
await SendReminderAsync(x).ConfigureAwait(false);
Database.Reminders.Remove(x);
hasChanged = true;
}
}
}
if (hasChanged)
{
await Database.SaveChangesAsync().ConfigureAwait(false);
if (hasChanged)
{
await Database.SaveChangesAsync().ConfigureAwait(false);
}
}
}
}