Patreon id logic change
This commit is contained in:
		
							
								
								
									
										1555
									
								
								src/NadekoBot/Migrations/20170501103455_patreon-id.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1555
									
								
								src/NadekoBot/Migrations/20170501103455_patreon-id.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										24
									
								
								src/NadekoBot/Migrations/20170501103455_patreon-id.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/NadekoBot/Migrations/20170501103455_patreon-id.cs
									
									
									
									
									
										Normal 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");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -966,6 +966,8 @@ namespace NadekoBot.Migrations
 | 
			
		||||
 | 
			
		||||
                    b.Property<DateTime>("LastReward");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("PatreonUserId");
 | 
			
		||||
 | 
			
		||||
                    b.Property<ulong>("UserId");
 | 
			
		||||
 | 
			
		||||
                    b.HasKey("Id");
 | 
			
		||||
 
 | 
			
		||||
@@ -173,13 +173,14 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
                    using (var uow = DbHandler.UnitOfWork())
 | 
			
		||||
                    {
 | 
			
		||||
                        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)
 | 
			
		||||
                        {
 | 
			
		||||
                            users.Add(new RewardedUser()
 | 
			
		||||
                            {
 | 
			
		||||
                                UserId = userId,
 | 
			
		||||
                                PatreonUserId = data.User.id,
 | 
			
		||||
                                LastReward = now,
 | 
			
		||||
                                AmountRewardedThisMonth = amount,
 | 
			
		||||
                            });
 | 
			
		||||
@@ -194,6 +195,7 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
                        {
 | 
			
		||||
                            usr.LastReward = now;
 | 
			
		||||
                            usr.AmountRewardedThisMonth = amount;
 | 
			
		||||
                            usr.PatreonUserId = data.User.id;
 | 
			
		||||
 | 
			
		||||
                            await CurrencyHandler.AddCurrencyAsync(userId, "Patreon reward - recurring", amount, uow).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
@@ -207,6 +209,7 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
 | 
			
		||||
                            usr.LastReward = now;
 | 
			
		||||
                            usr.AmountRewardedThisMonth = amount;
 | 
			
		||||
                            usr.PatreonUserId = data.User.id;
 | 
			
		||||
 | 
			
		||||
                            await CurrencyHandler.AddCurrencyAsync(usr.UserId, "Patreon reward - update", toAward, uow).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ namespace NadekoBot.Services.Database.Models
 | 
			
		||||
    public class RewardedUser : DbEntity
 | 
			
		||||
    {
 | 
			
		||||
        public ulong UserId { get; set; }
 | 
			
		||||
        public string PatreonUserId { get; set; }
 | 
			
		||||
        public int AmountRewardedThisMonth { get; set; }
 | 
			
		||||
        public DateTime LastReward { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user