- Fixed some potential causes for ratelimit due to default message retry settings

- Fixed a patron rewards bug caused by monthly donation checking not accounting for year increase
- Fixed a patron rewards bug for users who connected the same discord account with multiple patreon accounts
This commit is contained in:
Kwoth
2023-01-09 02:05:23 +01:00
parent c869f2e335
commit 9b9fa2f357
19 changed files with 10575 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ public static class MedusaExtensions
embed: embed.Build(),
options: new()
{
RetryMode = RetryMode.AlwaysRetry
RetryMode = RetryMode.Retry502
});
// unlocalized

View File

@@ -69,7 +69,7 @@ public sealed class Bot
: GatewayIntents.AllUnprivileged,
LogGatewayIntentWarnings = false,
FormatUsersInBidirectionalUnicode = false,
DefaultRetryMode = RetryMode.AlwaysRetry ^ RetryMode.RetryRatelimit
DefaultRetryMode = RetryMode.Retry502
});
_commandService = new(new()

View File

@@ -27,6 +27,7 @@ public enum FeatureType
public class PatronUser
{
public int Id { get; set; }
public string UniquePlatformUserId { get; set; }
public ulong UserId { get; set; }
public int AmountCents { get; set; }

View File

@@ -431,7 +431,8 @@ public abstract class NadekoContext : DbContext
modelBuilder.Entity<PatronUser>(pu =>
{
pu.HasIndex(x => x.UniquePlatformUserId).IsUnique();
pu.HasKey(x => x.UserId);
pu.HasKey(x => x.Id);
pu.HasIndex(x => x.UserId).IsUnique(false);
});
// quotes are per user id

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Migrations.Mysql
{
public partial class patronfix : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "pk_patrons",
table: "patrons");
migrationBuilder.AlterColumn<ulong>(
name: "userid",
table: "patrons",
type: "bigint unsigned",
nullable: false,
oldClrType: typeof(ulong),
oldType: "bigint unsigned")
.OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);
migrationBuilder.AddColumn<int>(
name: "id",
table: "patrons",
type: "int",
nullable: false,
defaultValue: 0)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);
migrationBuilder.AddPrimaryKey(
name: "pk_patrons",
table: "patrons",
column: "id");
migrationBuilder.CreateIndex(
name: "ix_patrons_userid",
table: "patrons",
column: "userid");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "pk_patrons",
table: "patrons");
migrationBuilder.DropIndex(
name: "ix_patrons_userid",
table: "patrons");
migrationBuilder.DropColumn(
name: "id",
table: "patrons");
migrationBuilder.AlterColumn<ulong>(
name: "userid",
table: "patrons",
type: "bigint unsigned",
nullable: false,
oldClrType: typeof(ulong),
oldType: "bigint unsigned")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);
migrationBuilder.AddPrimaryKey(
name: "pk_patrons",
table: "patrons",
column: "userid");
}
}
}

View File

@@ -319,10 +319,10 @@ namespace NadekoBot.Migrations.Mysql
modelBuilder.Entity("NadekoBot.Db.Models.PatronUser", b =>
{
b.Property<ulong>("UserId")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint unsigned")
.HasColumnName("userid");
.HasColumnType("int")
.HasColumnName("id");
b.Property<int>("AmountCents")
.HasColumnType("int")
@@ -336,17 +336,24 @@ namespace NadekoBot.Migrations.Mysql
.HasColumnType("varchar(255)")
.HasColumnName("uniqueplatformuserid");
b.Property<ulong>("UserId")
.HasColumnType("bigint unsigned")
.HasColumnName("userid");
b.Property<DateTime>("ValidThru")
.HasColumnType("datetime(6)")
.HasColumnName("validthru");
b.HasKey("UserId")
b.HasKey("Id")
.HasName("pk_patrons");
b.HasIndex("UniquePlatformUserId")
.IsUnique()
.HasDatabaseName("ix_patrons_uniqueplatformuserid");
b.HasIndex("UserId")
.HasDatabaseName("ix_patrons_userid");
b.ToTable("patrons", (string)null);
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,55 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace NadekoBot.Migrations.PostgreSql
{
public partial class patronfix : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "pk_patrons",
table: "patrons");
migrationBuilder.AddColumn<int>(
name: "id",
table: "patrons",
type: "integer",
nullable: false,
defaultValue: 0)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddPrimaryKey(
name: "pk_patrons",
table: "patrons",
column: "id");
migrationBuilder.CreateIndex(
name: "ix_patrons_userid",
table: "patrons",
column: "userid");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "pk_patrons",
table: "patrons");
migrationBuilder.DropIndex(
name: "ix_patrons_userid",
table: "patrons");
migrationBuilder.DropColumn(
name: "id",
table: "patrons");
migrationBuilder.AddPrimaryKey(
name: "pk_patrons",
table: "patrons",
column: "userid");
}
}
}

View File

@@ -331,10 +331,12 @@ namespace NadekoBot.Migrations.PostgreSql
modelBuilder.Entity("NadekoBot.Db.Models.PatronUser", b =>
{
b.Property<decimal>("UserId")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("numeric(20,0)")
.HasColumnName("userid");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("AmountCents")
.HasColumnType("integer")
@@ -348,17 +350,24 @@ namespace NadekoBot.Migrations.PostgreSql
.HasColumnType("text")
.HasColumnName("uniqueplatformuserid");
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("userid");
b.Property<DateTime>("ValidThru")
.HasColumnType("timestamp without time zone")
.HasColumnName("validthru");
b.HasKey("UserId")
b.HasKey("Id")
.HasName("pk_patrons");
b.HasIndex("UniquePlatformUserId")
.IsUnique()
.HasDatabaseName("ix_patrons_uniqueplatformuserid");
b.HasIndex("UserId")
.HasDatabaseName("ix_patrons_userid");
b.ToTable("patrons", (string)null);
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,72 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Migrations
{
public partial class patronfix : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Patrons",
table: "Patrons");
migrationBuilder.AlterColumn<ulong>(
name: "UserId",
table: "Patrons",
type: "INTEGER",
nullable: false,
oldClrType: typeof(ulong),
oldType: "INTEGER")
.OldAnnotation("Sqlite:Autoincrement", true);
migrationBuilder.AddColumn<int>(
name: "Id",
table: "Patrons",
type: "INTEGER",
nullable: false,
defaultValue: 0)
.Annotation("Sqlite:Autoincrement", true);
migrationBuilder.AddPrimaryKey(
name: "PK_Patrons",
table: "Patrons",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_Patrons_UserId",
table: "Patrons",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Patrons",
table: "Patrons");
migrationBuilder.DropIndex(
name: "IX_Patrons_UserId",
table: "Patrons");
migrationBuilder.DropColumn(
name: "Id",
table: "Patrons");
migrationBuilder.AlterColumn<ulong>(
name: "UserId",
table: "Patrons",
type: "INTEGER",
nullable: false,
oldClrType: typeof(ulong),
oldType: "INTEGER")
.Annotation("Sqlite:Autoincrement", true);
migrationBuilder.AddPrimaryKey(
name: "PK_Patrons",
table: "Patrons",
column: "UserId");
}
}
}

View File

@@ -251,7 +251,7 @@ namespace NadekoBot.Migrations
modelBuilder.Entity("NadekoBot.Db.Models.PatronUser", b =>
{
b.Property<ulong>("UserId")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
@@ -264,14 +264,19 @@ namespace NadekoBot.Migrations
b.Property<string>("UniquePlatformUserId")
.HasColumnType("TEXT");
b.Property<ulong>("UserId")
.HasColumnType("INTEGER");
b.Property<DateTime>("ValidThru")
.HasColumnType("TEXT");
b.HasKey("UserId");
b.HasKey("Id");
b.HasIndex("UniquePlatformUserId")
.IsUnique();
b.HasIndex("UserId");
b.ToTable("Patrons");
});

View File

@@ -88,10 +88,6 @@ public class GameStatusEvent : ICurrencyEvent
await msg.ModifyAsync(m =>
{
m.Embed = GetEmbed(PotSize).Build();
},
new()
{
RetryMode = RetryMode.AlwaysRetry
});
}

View File

@@ -79,10 +79,6 @@ public class ReactionEvent : ICurrencyEvent
await msg.ModifyAsync(m =>
{
m.Embed = GetEmbed(PotSize).Build();
},
new()
{
RetryMode = RetryMode.AlwaysRetry
});
}

View File

@@ -74,11 +74,7 @@ public class TypingGame
var time = _options.StartTime;
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...",
options: new()
{
RetryMode = RetryMode.AlwaysRetry
});
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...");
do
{

View File

@@ -199,7 +199,7 @@ public sealed class PatronageService
}
else
{
if (dbPatron.LastCharge.Month < lastChargeUtc.Month)
if (dbPatron.LastCharge.Month < lastChargeUtc.Month || dbPatron.LastCharge.Year < lastChargeUtc.Year)
{
// user is charged again for this month
// if his sub would end in teh future, extend it by one month.

View File

@@ -23,11 +23,7 @@ public static class MessageChannelExtensions
embeds: embeds is null
? null
: embeds as Embed[] ?? embeds.ToArray(),
components: components,
options: new()
{
RetryMode = RetryMode.AlwaysRetry
});
components: components);
}
public static async Task<IUserMessage> SendAsync(

View File

@@ -23,11 +23,7 @@ public static class SocketMessageComponentExtensions
? null
: embeds as Embed[] ?? embeds.ToArray(),
components: components,
ephemeral: ephemeral,
options: new()
{
RetryMode = RetryMode.AlwaysRetry
});
ephemeral: ephemeral);
}
public static Task RespondAsync(