.clparew finished

This commit is contained in:
Kwoth 2017-04-02 00:01:02 +02:00
parent 7e23877fd8
commit 3cec4f14d0
9 changed files with 1583 additions and 35 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class patreonrewards : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "RewardedUsers",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
AmountRewardedThisMonth = table.Column<int>(nullable: false),
DateAdded = table.Column<DateTime>(nullable: true),
LastReward = table.Column<DateTime>(nullable: false),
UserId = table.Column<ulong>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RewardedUsers", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_RewardedUsers_UserId",
table: "RewardedUsers",
column: "UserId",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RewardedUsers");
}
}
}

View File

@ -931,6 +931,27 @@ namespace NadekoBot.Migrations
b.ToTable("Reminders");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.RewardedUser", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AmountRewardedThisMonth");
b.Property<DateTime?>("DateAdded");
b.Property<DateTime>("LastReward");
b.Property<ulong>("UserId");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("RewardedUsers");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
{
b.Property<int>("Id")

View File

@ -12,6 +12,7 @@ using System.Collections.Immutable;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions;
using Discord;
namespace NadekoBot.Modules.Utility
{
@ -31,10 +32,11 @@ namespace NadekoBot.Modules.Utility
{
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
return;
if (DateTime.UtcNow.Day < 5)
{
await ReplyErrorLocalized("clpa_too_early").ConfigureAwait(false);
}
//if (DateTime.UtcNow.Day < 5)
//{
// await ReplyErrorLocalized("clpa_too_early").ConfigureAwait(false);
// return;
//}
int amount = 0;
try
{
@ -50,12 +52,13 @@ namespace NadekoBot.Modules.Utility
await ReplyConfirmLocalized("clpa_success", amount + NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
return;
}
await Context.Channel.EmbedAsync(new Discord.EmbedBuilder().WithOkColor()
var helpcmd = Format.Code(NadekoBot.ModulePrefixes[typeof(Help.Help).Name] + "donate");
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription(GetText("clpa_fail"))
.AddField(efb => efb.WithName(GetText("clpa_fail_already_title")).WithValue(GetText("clpa_fail_already")))
.AddField(efb => efb.WithName(GetText("clpa_fail_wait_title")).WithValue(GetText("clpa_fail_wait")))
.AddField(efb => efb.WithName(GetText("clpa_fail_sup_title")).WithValue(GetText("clpa_fail_sup"))))
.AddField(efb => efb.WithName(GetText("clpa_fail_conn_title")).WithValue(GetText("clpa_fail_conn")))
.AddField(efb => efb.WithName(GetText("clpa_fail_sup_title")).WithValue(GetText("clpa_fail_sup", helpcmd))))
.ConfigureAwait(false);
}
}
@ -129,9 +132,10 @@ namespace NadekoBot.Modules.Utility
public async Task<int> ClaimReward(ulong userId)
{
await claimLockJustInCase.WaitAsync();
var now = DateTime.UtcNow;
try
{
var data = Pledges.FirstOrDefault(x => x.User.id == userId.ToString());
var data = Pledges.FirstOrDefault(x => x.User.attributes?.social_connections?.discord?.user_id == userId.ToString());
if (data == null)
return 0;
@ -148,11 +152,22 @@ namespace NadekoBot.Modules.Utility
users.Add(new RewardedUser()
{
UserId = userId,
LastReward = DateTime.UtcNow,
LastReward = now,
AmountRewardedThisMonth = amount,
});
await CurrencyHandler.AddCurrencyAsync(usr.UserId, "Patreon reward", amount, uow).ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync(userId, "Patreon reward - new", amount, uow).ConfigureAwait(false);
await uow.CompleteAsync().ConfigureAwait(false);
return amount;
}
if (usr.LastReward.Month != now.Month)
{
usr.LastReward = now;
usr.AmountRewardedThisMonth = amount;
await CurrencyHandler.AddCurrencyAsync(userId, "Patreon reward - recurring", amount, uow).ConfigureAwait(false);
await uow.CompleteAsync().ConfigureAwait(false);
return amount;
@ -162,10 +177,10 @@ namespace NadekoBot.Modules.Utility
{
var toAward = amount - usr.AmountRewardedThisMonth;
usr.LastReward = DateTime.UtcNow;
usr.LastReward = now;
usr.AmountRewardedThisMonth = amount;
await CurrencyHandler.AddCurrencyAsync(usr.UserId, "Patreon reward", toAward, uow).ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync(usr.UserId, "Patreon reward - update", toAward, uow).ConfigureAwait(false);
await uow.CompleteAsync().ConfigureAwait(false);
return toAward;

View File

@ -6035,7 +6035,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to Maybe you have already received your reward for this month. You can receive rewards only once a month unless you increase your pledge..
/// Looks up a localized string similar to Maybe you&apos;ve already received your reward for this month. You can receive rewards only once a month unless you increase your pledge..
/// </summary>
public static string utility_clpa_fail_already {
get {
@ -6053,7 +6053,25 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to In order to be eligible for the reward, you must support the project on patreon. Use {0} command to get the link..
/// Looks up a localized string similar to Your discord account might not be connected to Patreon.. If you are unsure what that means, or don&apos;t know how to connect it - you have to go to [Patreon account settings page](https://patreon.com/settings/account) and click &apos;Connect to discord&apos; button..
/// </summary>
public static string utility_clpa_fail_conn {
get {
return ResourceManager.GetString("utility_clpa_fail_conn", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Discord account not connected.
/// </summary>
public static string utility_clpa_fail_conn_title {
get {
return ResourceManager.GetString("utility_clpa_fail_conn_title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to In order to be eligible for the reward, you must support the project on patreon. You can use {0} command to get the link..
/// </summary>
public static string utility_clpa_fail_sup {
get {
@ -6071,7 +6089,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to You have to wait a few hours after making your pledge, if you didn&apos;t, waiut a bit and then try again later..
/// Looks up a localized string similar to You have to wait a few hours after making your pledge, if you didn&apos;t, try again later..
/// </summary>
public static string utility_clpa_fail_wait {
get {

View File

@ -2373,19 +2373,25 @@ Owner ID: {2}</value>
<value>Failed claiming rewards due to one of the following reasons:</value>
</data>
<data name="utility_clpa_fail_already" xml:space="preserve">
<value>Maybe you have already received your reward for this month. You can receive rewards only once a month unless you increase your pledge.</value>
<value>Maybe you've already received your reward for this month. You can receive rewards only once a month unless you increase your pledge.</value>
</data>
<data name="utility_clpa_fail_already_title" xml:space="preserve">
<value>Already rewarded</value>
</data>
<data name="utility_clpa_fail_conn" xml:space="preserve">
<value>Your discord account might not be connected to Patreon.. If you are unsure what that means, or don't know how to connect it - you have to go to [Patreon account settings page](https://patreon.com/settings/account) and click 'Connect to discord' button.</value>
</data>
<data name="utility_clpa_fail_conn_title" xml:space="preserve">
<value>Discord account not connected</value>
</data>
<data name="utility_clpa_fail_sup" xml:space="preserve">
<value>In order to be eligible for the reward, you must support the project on patreon. Use {0} command to get the link.</value>
<value>In order to be eligible for the reward, you must support the project on patreon. You can use {0} command to get the link.</value>
</data>
<data name="utility_clpa_fail_sup_title" xml:space="preserve">
<value>Not supporting</value>
</data>
<data name="utility_clpa_fail_wait" xml:space="preserve">
<value>You have to wait a few hours after making your pledge, if you didn't, waiut a bit and then try again later.</value>
<value>You have to wait a few hours after making your pledge, if you didn't, try again later.</value>
</data>
<data name="utility_clpa_fail_wait_title" xml:space="preserve">
<value>Wait some time</value>

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database.Models
{
public class PatreonRewards : DbEntity
{
public ulong UserId { get; set; }
public ulong PledgeCents { get; set; }
public ulong Awarded { get; set; }
}
}

View File

@ -2,7 +2,7 @@
namespace NadekoBot.Services.Database.Models
{
public class RewardedUser
public class RewardedUser : DbEntity
{
public ulong UserId { get; set; }
public int AmountRewardedThisMonth { get; set; }

View File

@ -51,6 +51,7 @@ namespace NadekoBot.Services.Database
public DbSet<EightBallResponse> EightBallResponses { get; set; }
public DbSet<RaceAnimal> RaceAnimals { get; set; }
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
public DbSet<RewardedUser> RewardedUsers { get; set; }
public NadekoContext() : base()
{
@ -277,6 +278,12 @@ namespace NadekoBot.Services.Database
#region Warnings
var warn = modelBuilder.Entity<Warning>();
#endregion
#region PatreonRewards
var pr = modelBuilder.Entity<RewardedUser>();
pr.HasIndex(x => x.UserId)
.IsUnique();
#endregion
}
}
}