Change User Model and Add poll model, port !poll but ended up disabling it
This commit is contained in:
parent
74793c8ef7
commit
9354e5f83e
13 changed files with 138 additions and 92 deletions
|
@ -16,7 +16,6 @@ namespace Geekbot.net.Database
|
|||
public DbSet<SlapsModel> Slaps { get; set; }
|
||||
public DbSet<GlobalsModel> Globals { get; set; }
|
||||
public DbSet<RoleSelfServiceModel> RoleSelfService { get; set; }
|
||||
|
||||
// public DbSet<UserSettingsModel> UserSettings { get; set; }
|
||||
public DbSet<PollModel> Polls { get; set; }
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ namespace Geekbot.net.Database
|
|||
});
|
||||
}
|
||||
database.Database.EnsureCreated();
|
||||
database.Database.Migrate();
|
||||
if(!_runParameters.InMemory) database.Database.Migrate();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
27
Geekbot.net/Database/Models/PollModel.cs
Normal file
27
Geekbot.net/Database/Models/PollModel.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Geekbot.net.Database.Models
|
||||
{
|
||||
public class PollModel
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public long GuildId { get; set; }
|
||||
|
||||
[Required]
|
||||
public long ChannelId { get; set; }
|
||||
|
||||
public string Question { get; set; }
|
||||
|
||||
public long Creator { get; set; }
|
||||
|
||||
public long MessageId { get; set; }
|
||||
|
||||
public List<PollQuestionModel> Options { get; set; }
|
||||
|
||||
public bool IsFinshed { get; set; }
|
||||
}
|
||||
}
|
16
Geekbot.net/Database/Models/PollQuestionModel.cs
Normal file
16
Geekbot.net/Database/Models/PollQuestionModel.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Geekbot.net.Database.Models
|
||||
{
|
||||
public class PollQuestionModel
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int OptionId { get; set; }
|
||||
|
||||
public string OptionText { get; set; }
|
||||
|
||||
public int Votes { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Geekbot.net.Database.Models
|
||||
|
@ -24,6 +25,6 @@ namespace Geekbot.net.Database.Models
|
|||
|
||||
public DateTimeOffset Joined { get; set; }
|
||||
|
||||
public string[] UsedNames { get; set; }
|
||||
public List<UserUsedNamesModel> UsedNames { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Geekbot.net.Database.Models
|
||||
{
|
||||
public class UserSettingsModel
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public long UserId { get; set; }
|
||||
|
||||
// stuff to be added in the future
|
||||
}
|
||||
}
|
15
Geekbot.net/Database/Models/UserUsedNamesModel.cs
Normal file
15
Geekbot.net/Database/Models/UserUsedNamesModel.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Geekbot.net.Database.Models
|
||||
{
|
||||
public class UserUsedNamesModel
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public DateTimeOffset FirstSeen { get; set; }
|
||||
}
|
||||
}
|
|
@ -250,7 +250,7 @@ namespace Geekbot.net.Database
|
|||
case "ShowLeave":
|
||||
settings.ShowLeave = setting.Value.ToString() == "1";
|
||||
break;
|
||||
case "WikiDel":
|
||||
case "ShowDelete":
|
||||
settings.ShowDelete = setting.Value.ToString() == "1";
|
||||
break;
|
||||
case "WikiLang":
|
||||
|
@ -272,9 +272,9 @@ namespace Geekbot.net.Database
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(LogSource.Geekbot, $"Setting failed: {setting.Name} - {guild.Id}");
|
||||
_logger.Warning(LogSource.Geekbot, $"Setting failed: {setting.Name} - {guild.Id}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,7 +297,9 @@ namespace Geekbot.net.Database
|
|||
try
|
||||
{
|
||||
var namesSerialized = _redis.HashGet($"User:{user.Id}", "UsedNames").ToString();
|
||||
var names = Utf8Json.JsonSerializer.Deserialize<string[]>(namesSerialized);
|
||||
var names = namesSerialized != null
|
||||
? Utf8Json.JsonSerializer.Deserialize<string[]>(namesSerialized)
|
||||
: new string[] {user.Username};
|
||||
_database.Users.AddIfNotExists(new UserModel()
|
||||
{
|
||||
UserId = user.Id.AsLong(),
|
||||
|
@ -306,13 +308,13 @@ namespace Geekbot.net.Database
|
|||
AvatarUrl = user.GetAvatarUrl(ImageFormat.Auto, 1024),
|
||||
IsBot = user.IsBot,
|
||||
Joined = user.CreatedAt,
|
||||
UsedNames = names
|
||||
UsedNames = names.Select(name => new UserUsedNamesModel() {Name = name, FirstSeen = DateTimeOffset.Now}).ToList()
|
||||
}, model => model.UserId.Equals(user.Id.AsLong()));
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(LogSource.Geekbot, $"User failed: {user.Username}");
|
||||
_logger.Warning(LogSource.Geekbot, $"User failed: {user.Username}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue