Patreon id logic change

This commit is contained in:
Master Kwoth 2017-05-02 10:52:15 +02:00
parent 8b320ef0c1
commit 3ff989cf92
5 changed files with 1586 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class patreonid : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "PatreonUserId",
table: "RewardedUsers",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PatreonUserId",
table: "RewardedUsers");
}
}
}

View File

@ -966,6 +966,8 @@ namespace NadekoBot.Migrations
b.Property<DateTime>("LastReward"); b.Property<DateTime>("LastReward");
b.Property<string>("PatreonUserId");
b.Property<ulong>("UserId"); b.Property<ulong>("UserId");
b.HasKey("Id"); b.HasKey("Id");

View File

@ -173,13 +173,14 @@ namespace NadekoBot.Modules.Utility
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
var users = uow._context.Set<RewardedUser>(); var users = uow._context.Set<RewardedUser>();
var usr = users.FirstOrDefault(x => x.UserId == userId); var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id);
if (usr == null) if (usr == null)
{ {
users.Add(new RewardedUser() users.Add(new RewardedUser()
{ {
UserId = userId, UserId = userId,
PatreonUserId = data.User.id,
LastReward = now, LastReward = now,
AmountRewardedThisMonth = amount, AmountRewardedThisMonth = amount,
}); });
@ -194,6 +195,7 @@ namespace NadekoBot.Modules.Utility
{ {
usr.LastReward = now; usr.LastReward = now;
usr.AmountRewardedThisMonth = amount; usr.AmountRewardedThisMonth = amount;
usr.PatreonUserId = data.User.id;
await CurrencyHandler.AddCurrencyAsync(userId, "Patreon reward - recurring", amount, uow).ConfigureAwait(false); await CurrencyHandler.AddCurrencyAsync(userId, "Patreon reward - recurring", amount, uow).ConfigureAwait(false);
@ -207,6 +209,7 @@ namespace NadekoBot.Modules.Utility
usr.LastReward = now; usr.LastReward = now;
usr.AmountRewardedThisMonth = amount; usr.AmountRewardedThisMonth = amount;
usr.PatreonUserId = data.User.id;
await CurrencyHandler.AddCurrencyAsync(usr.UserId, "Patreon reward - update", toAward, uow).ConfigureAwait(false); await CurrencyHandler.AddCurrencyAsync(usr.UserId, "Patreon reward - update", toAward, uow).ConfigureAwait(false);

View File

@ -5,6 +5,7 @@ namespace NadekoBot.Services.Database.Models
public class RewardedUser : DbEntity public class RewardedUser : DbEntity
{ {
public ulong UserId { get; set; } public ulong UserId { get; set; }
public string PatreonUserId { get; set; }
public int AmountRewardedThisMonth { get; set; } public int AmountRewardedThisMonth { get; set; }
public DateTime LastReward { get; set; } public DateTime LastReward { get; set; }
} }