.clparew finished
This commit is contained in:
parent
7e23877fd8
commit
3cec4f14d0
1456
src/NadekoBot/Migrations/20170401205753_patreon-rewards.Designer.cs
generated
Normal file
1456
src/NadekoBot/Migrations/20170401205753_patreon-rewards.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
src/NadekoBot/Migrations/20170401205753_patreon-rewards.cs
Normal file
40
src/NadekoBot/Migrations/20170401205753_patreon-rewards.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -931,6 +931,27 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("Reminders");
|
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 =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
|
@ -12,6 +12,7 @@ using System.Collections.Immutable;
|
|||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
|
using Discord;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Utility
|
namespace NadekoBot.Modules.Utility
|
||||||
{
|
{
|
||||||
@ -31,10 +32,11 @@ namespace NadekoBot.Modules.Utility
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
|
||||||
return;
|
return;
|
||||||
if (DateTime.UtcNow.Day < 5)
|
//if (DateTime.UtcNow.Day < 5)
|
||||||
{
|
//{
|
||||||
await ReplyErrorLocalized("clpa_too_early").ConfigureAwait(false);
|
// await ReplyErrorLocalized("clpa_too_early").ConfigureAwait(false);
|
||||||
}
|
// return;
|
||||||
|
//}
|
||||||
int amount = 0;
|
int amount = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -50,12 +52,13 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await ReplyConfirmLocalized("clpa_success", amount + NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
|
await ReplyConfirmLocalized("clpa_success", amount + NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var helpcmd = Format.Code(NadekoBot.ModulePrefixes[typeof(Help.Help).Name] + "donate");
|
||||||
await Context.Channel.EmbedAsync(new Discord.EmbedBuilder().WithOkColor()
|
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
||||||
.WithDescription(GetText("clpa_fail"))
|
.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_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_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);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,9 +132,10 @@ namespace NadekoBot.Modules.Utility
|
|||||||
public async Task<int> ClaimReward(ulong userId)
|
public async Task<int> ClaimReward(ulong userId)
|
||||||
{
|
{
|
||||||
await claimLockJustInCase.WaitAsync();
|
await claimLockJustInCase.WaitAsync();
|
||||||
|
var now = DateTime.UtcNow;
|
||||||
try
|
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)
|
if (data == null)
|
||||||
return 0;
|
return 0;
|
||||||
@ -148,11 +152,22 @@ namespace NadekoBot.Modules.Utility
|
|||||||
users.Add(new RewardedUser()
|
users.Add(new RewardedUser()
|
||||||
{
|
{
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
LastReward = DateTime.UtcNow,
|
LastReward = now,
|
||||||
AmountRewardedThisMonth = amount,
|
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);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
return amount;
|
return amount;
|
||||||
@ -162,10 +177,10 @@ namespace NadekoBot.Modules.Utility
|
|||||||
{
|
{
|
||||||
var toAward = amount - usr.AmountRewardedThisMonth;
|
var toAward = amount - usr.AmountRewardedThisMonth;
|
||||||
|
|
||||||
usr.LastReward = DateTime.UtcNow;
|
usr.LastReward = now;
|
||||||
usr.AmountRewardedThisMonth = amount;
|
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);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
return toAward;
|
return toAward;
|
||||||
|
24
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
24
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
@ -6035,7 +6035,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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've already received your reward for this month. You can receive rewards only once a month unless you increase your pledge..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string utility_clpa_fail_already {
|
public static string utility_clpa_fail_already {
|
||||||
get {
|
get {
|
||||||
@ -6053,7 +6053,25 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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'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..
|
||||||
|
/// </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>
|
/// </summary>
|
||||||
public static string utility_clpa_fail_sup {
|
public static string utility_clpa_fail_sup {
|
||||||
get {
|
get {
|
||||||
@ -6071,7 +6089,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to You have to wait a few hours after making your pledge, if you didn'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't, try again later..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string utility_clpa_fail_wait {
|
public static string utility_clpa_fail_wait {
|
||||||
get {
|
get {
|
||||||
|
@ -2373,19 +2373,25 @@ Owner ID: {2}</value>
|
|||||||
<value>Failed claiming rewards due to one of the following reasons:</value>
|
<value>Failed claiming rewards due to one of the following reasons:</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="utility_clpa_fail_already" xml:space="preserve">
|
<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>
|
||||||
<data name="utility_clpa_fail_already_title" xml:space="preserve">
|
<data name="utility_clpa_fail_already_title" xml:space="preserve">
|
||||||
<value>Already rewarded</value>
|
<value>Already rewarded</value>
|
||||||
</data>
|
</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">
|
<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>
|
||||||
<data name="utility_clpa_fail_sup_title" xml:space="preserve">
|
<data name="utility_clpa_fail_sup_title" xml:space="preserve">
|
||||||
<value>Not supporting</value>
|
<value>Not supporting</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="utility_clpa_fail_wait" xml:space="preserve">
|
<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>
|
||||||
<data name="utility_clpa_fail_wait_title" xml:space="preserve">
|
<data name="utility_clpa_fail_wait_title" xml:space="preserve">
|
||||||
<value>Wait some time</value>
|
<value>Wait some time</value>
|
||||||
|
@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace NadekoBot.Services.Database.Models
|
namespace NadekoBot.Services.Database.Models
|
||||||
{
|
{
|
||||||
public class RewardedUser
|
public class RewardedUser : DbEntity
|
||||||
{
|
{
|
||||||
public ulong UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
public int AmountRewardedThisMonth { get; set; }
|
public int AmountRewardedThisMonth { get; set; }
|
||||||
|
@ -51,6 +51,7 @@ namespace NadekoBot.Services.Database
|
|||||||
public DbSet<EightBallResponse> EightBallResponses { get; set; }
|
public DbSet<EightBallResponse> EightBallResponses { get; set; }
|
||||||
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
||||||
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
||||||
|
public DbSet<RewardedUser> RewardedUsers { get; set; }
|
||||||
|
|
||||||
public NadekoContext() : base()
|
public NadekoContext() : base()
|
||||||
{
|
{
|
||||||
@ -277,6 +278,12 @@ namespace NadekoBot.Services.Database
|
|||||||
#region Warnings
|
#region Warnings
|
||||||
var warn = modelBuilder.Entity<Warning>();
|
var warn = modelBuilder.Entity<Warning>();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region PatreonRewards
|
||||||
|
var pr = modelBuilder.Entity<RewardedUser>();
|
||||||
|
pr.HasIndex(x => x.UserId)
|
||||||
|
.IsUnique();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user