Started work on giveaways, not completed

This commit is contained in:
Kwoth
2024-04-24 16:31:51 +00:00
parent 08d8da25cd
commit 59b9742c19
25 changed files with 11667 additions and 11 deletions

View File

@@ -8,7 +8,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- `.shopadd command` You can now sell commands in the shop. The command will execute as if you were the one running it when someone buys it
- type `.h .shopadd` for more info
-
- `.stickyroles` Users leaving the server will have their roles saved to the database and reapplied if they rejoin within 30 days.
## [4.3.22] - 23.04.2023

View File

@@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.263" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta17" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0009" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />

View File

@@ -0,0 +1,12 @@
namespace NadekoBot.Db.Models;
public sealed class GiveawayModel
{
public int Id { get; set; }
public ulong GuildId { get; set; }
public ulong MessageId { get; set; }
public string Message { get; set; }
public IList<GiveawayUser> Participants { get; set; } = new List<GiveawayUser>();
public DateTime EndsAt { get; set; }
}

View File

@@ -0,0 +1,9 @@
namespace NadekoBot.Db.Models;
public sealed class GiveawayUser
{
public int Id { get; set; }
public int GiveawayId { get; set; }
public ulong UserId { get; set; }
public string Name { get; set; }
}

View File

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cgiveaway/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -189,7 +189,7 @@ public partial class Administration
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
[BotPerm(GuildPerm.Administrator)]
[BotPerm(GuildPerm.ManageRoles)]
public async Task StickyRoles()
{
var newState = await _stickyRoleSvc.ToggleStickyRoles(ctx.Guild.Id);

View File

@@ -79,7 +79,7 @@ public sealed class StickyRolesService : INService, IReadyExecutor
{
GuildId = guildId,
UserId = userId,
RoleIds = string.Join(',', guRoles.Select(x => x.Id.ToString())),
RoleIds = string.Join(',', guRoles.Where(x => !x.IsEveryone && !x.IsManaged).Select(x => x.Id.ToString())),
DateAdded = DateTime.UtcNow
});
}

View File

@@ -0,0 +1,114 @@
namespace NadekoBot.Modules.Utility;
public partial class Utility
{
[Name("Giveaways")]
[Group("ga")]
public partial class GiveawayCommands : NadekoModule<GiveawayService>
{
[Cmd]
[UserPerm(GuildPerm.ManageMessages)]
[BotPerm(ChannelPerm.ManageMessages | ChannelPerm.AddReactions)]
public async Task GiveawayStart(TimeSpan duration, [Leftover] string message)
{
if (duration > TimeSpan.FromDays(30))
{
await ReplyErrorLocalizedAsync(strs.giveaway_duration_invalid);
return;
}
var eb = _eb.Create(ctx)
.WithPendingColor()
.WithTitle(GetText(strs.giveaway_starting))
.WithDescription(message);
var startingMsg = await ctx.Channel.EmbedAsync(eb);
var maybeId =
await _service.StartGiveawayAsync(ctx.Guild.Id, ctx.Channel.Id, startingMsg.Id, duration, message);
if (maybeId is not int id)
{
await startingMsg.DeleteAsync();
await ReplyErrorLocalizedAsync(strs.giveaway_max_amount_reached);
return;
}
eb
.WithTitle(GetText(strs.giveaway_started))
.WithFooter($"id: {new kwum(id).ToString()}");
await startingMsg.AddReactionAsync(new Emoji(GiveawayService.GiveawayEmoji));
await startingMsg.ModifyAsync(x => x.Embed = eb.Build());
}
[Cmd]
[UserPerm(GuildPerm.ManageMessages)]
public async Task GiveawayEnd(kwum id)
{
var (giveaway, winner) = await _service.EndGiveawayAsync(ctx.Guild.Id, id);
if (winner is null || giveaway is null)
return;
var eb = _eb.Create(ctx)
.WithOkColor()
.WithTitle(GetText(strs.giveaway_ended))
.WithDescription(giveaway.Message)
.AddField(GetText(strs.winner),
$"""
{winner.Name}
<@{winner.UserId}>
{Format.Code(winner.UserId.ToString())}
""",
true);
await ctx.Channel.EmbedAsync(eb);
}
[Cmd]
[UserPerm(GuildPerm.ManageMessages)]
public async Task GiveawayReroll(kwum id)
{
}
[Cmd]
[UserPerm(GuildPerm.ManageMessages)]
public async Task GiveawayCancel(kwum id)
{
var success = await _service.CancelGiveawayAsync(ctx.Guild.Id, id);
if (!success)
{
await ReplyConfirmLocalizedAsync(strs.giveaway_not_found);
return;
}
await ReplyConfirmLocalizedAsync(strs.giveaway_cancelled);
}
[Cmd]
[UserPerm(GuildPerm.ManageMessages)]
public async Task GiveawayList()
{
var giveaways = await _service.GetGiveawaysAsync(ctx.Guild.Id);
if (!giveaways.Any())
{
await ReplyErrorLocalizedAsync(strs.no_givaways);
return;
}
var eb = _eb.Create(ctx)
.WithOkColor();
foreach (var g in giveaways)
{
eb.AddField($"id: {new kwum(g.Id)}", g.Message, true);
}
await ctx.Channel.EmbedAsync(eb);
}
}
}

View File

@@ -0,0 +1,209 @@
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility;
public sealed class GiveawayService : INService, IReadyExecutor
{
public static string GiveawayEmoji = "🎉";
private readonly DbService _db;
private readonly IBotCredentials _creds;
private readonly DiscordSocketClient _client;
private GiveawayModel[] _shardGiveaways;
private readonly NadekoRandom _rng;
public GiveawayService(DbService db, IBotCredentials creds, DiscordSocketClient client)
{
_db = db;
_creds = creds;
_client = client;
_rng = new NadekoRandom();
_client.ReactionAdded += OnReactionAdded;
_client.ReactionRemoved += OnReactionRemoved;
}
private async Task OnReactionRemoved(Cacheable<IUserMessage, ulong> msg,
Cacheable<IMessageChannel, ulong> arg2,
SocketReaction r)
{
if (!r.User.IsSpecified)
return;
var user = r.User.Value;
if (user.IsBot || user.IsWebhook)
return;
if (r.Emote is Emoji e && e.Name == GiveawayEmoji)
{
await LeaveGivawayAsync(msg.Id, user.Id);
}
}
private async Task OnReactionAdded(Cacheable<IUserMessage, ulong> msg, Cacheable<IMessageChannel, ulong> ch,
SocketReaction r)
{
if (!r.User.IsSpecified)
return;
var user = r.User.Value;
if (user.IsBot || user.IsWebhook)
return;
var textChannel = ch.Value as ITextChannel;
if (textChannel is null)
return;
if (r.Emote is Emoji e && e.Name == GiveawayEmoji)
{
await JoinGivawayAsync(msg.Id, user.Id, user.Username);
}
}
public async Task OnReadyAsync()
{
// load giveaways for this shard from the database
await using var ctx = _db.GetDbContext();
_shardGiveaways = await ctx
.GetTable<GiveawayModel>()
.Where(x => Linq2DbExpressions.GuildOnShard(x.GuildId, _creds.TotalShards, _client.ShardId))
.ToArrayAsync();
}
public async Task<int?> StartGiveawayAsync(ulong guildId, ulong channelId, ulong messageId, TimeSpan duration,
string message)
{
await using var ctx = _db.GetDbContext();
// first check if there are more than 5 giveaways
var count = await ctx
.GetTable<GiveawayModel>()
.CountAsync(x => x.GuildId == guildId);
if (count >= 5)
return null;
var endsAt = DateTime.UtcNow + duration;
var output = await ctx.GetTable<GiveawayModel>()
.InsertWithOutputAsync(() => new GiveawayModel
{
GuildId = guildId,
MessageId = messageId,
Message = message,
EndsAt = endsAt,
});
return output.Id;
}
public async Task<(GiveawayModel? giveaway, GiveawayUser? winner)> EndGiveawayAsync(ulong guildId, int id)
{
await using var ctx = _db.GetDbContext();
var giveaway = await ctx
.GetTable<GiveawayModel>()
.Where(x => x.GuildId == guildId && x.Id == id)
.LoadWith(x => x.Participants)
.FirstOrDefaultAsyncLinqToDB();
if (giveaway is null)
return default;
await ctx
.GetTable<GiveawayModel>()
.Where(x => x.Id == id)
.DeleteAsync();
if (giveaway.Participants.Count == 0)
return default;
if (giveaway.Participants.Count == 1)
return (giveaway, giveaway.Participants[0]);
return (giveaway, giveaway.Participants[_rng.Next(0, giveaway.Participants.Count - 1)]);
}
public async Task RerollGiveawayAsync(ulong guildId, int id)
{
}
public async Task<bool> CancelGiveawayAsync(ulong guildId, int id)
{
await using var ctx = _db.GetDbContext();
var count = await ctx
.GetTable<GiveawayModel>()
.Where(x => x.GuildId == guildId && x.Id == id)
.DeleteAsync();
// todo clear cache
return count > 0;
}
public async Task<IReadOnlyCollection<GiveawayModel>> GetGiveawaysAsync(ulong guildId)
{
await using var ctx = _db.GetDbContext();
return await ctx
.GetTable<GiveawayModel>()
.Where(x => x.GuildId == guildId)
.ToListAsync();
}
public async Task<bool> JoinGivawayAsync(ulong messageId, ulong userId, string userName)
{
await using var ctx = _db.GetDbContext();
var giveaway = await ctx
.GetTable<GiveawayModel>()
.Where(x => x.MessageId == messageId)
.FirstOrDefaultAsyncLinqToDB();
if (giveaway is null)
return false;
// add the user to the database
await ctx.GetTable<GiveawayUser>()
.InsertAsync(
() => new GiveawayUser()
{
UserId = userId,
GiveawayId = giveaway.Id,
Name = userName,
}
);
return true;
}
public async Task<bool> LeaveGivawayAsync(ulong messageId, ulong userId)
{
await using var ctx = _db.GetDbContext();
var giveaway = await ctx
.GetTable<GiveawayModel>()
.Where(x => x.MessageId == messageId)
.FirstOrDefaultAsyncLinqToDB();
if (giveaway is null)
return false;
await ctx
.GetTable<GiveawayUser>()
.Where(x => x.UserId == userId && x.GiveawayId == giveaway.Id)
.DeleteAsync();
return true;
}
}

View File

@@ -24,8 +24,4 @@
<ProjectReference Include="..\Nadeko.Bot.Generators.Cloneable\Nadeko.Bot.Generators.Cloneable.csproj" OutputItemType="Analyzer" />
</ItemGroup>
<ItemGroup>
<Folder Include="_common\Db\" />
</ItemGroup>
</Project>

View File

@@ -493,6 +493,25 @@ public abstract class NadekoContext : DbContext
}).IsUnique());
#endregion
#region Giveaway
modelBuilder.Entity<GiveawayModel>()
.HasMany(x => x.Participants)
.WithOne()
.HasForeignKey(x => x.GiveawayId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GiveawayUser>(gu => gu
.HasIndex(x => new
{
x.GiveawayId,
x.UserId
})
.IsUnique());
#endregion
}
#if DEBUG

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Db.Migrations.Mysql
{
/// <inheritdoc />
public partial class giveaway : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "giveawaymodel",
columns: table => new
{
id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
guildid = table.Column<ulong>(type: "bigint unsigned", nullable: false),
messageid = table.Column<ulong>(type: "bigint unsigned", nullable: false),
message = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
endsat = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_giveawaymodel", x => x.id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "giveawayuser",
columns: table => new
{
id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
giveawayid = table.Column<int>(type: "int", nullable: false),
userid = table.Column<ulong>(type: "bigint unsigned", nullable: false),
name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("pk_giveawayuser", x => x.id);
table.ForeignKey(
name: "fk_giveawayuser_giveawaymodel_giveawayid",
column: x => x.giveawayid,
principalTable: "giveawaymodel",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "ix_giveawayuser_giveawayid_userid",
table: "giveawayuser",
columns: new[] { "giveawayid", "userid" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "giveawayuser");
migrationBuilder.DropTable(
name: "giveawaymodel");
}
}
}

View File

@@ -3073,6 +3073,70 @@ namespace NadekoBot.Db.Migrations.Mysql
b.ToTable("followedstream", (string)null);
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasColumnName("id");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("EndsAt")
.HasColumnType("datetime(6)")
.HasColumnName("endsat");
b.Property<ulong>("GuildId")
.HasColumnType("bigint unsigned")
.HasColumnName("guildid");
b.Property<string>("Message")
.IsRequired()
.HasColumnType("longtext")
.HasColumnName("message");
b.Property<ulong>("MessageId")
.HasColumnType("bigint unsigned")
.HasColumnName("messageid");
b.HasKey("Id")
.HasName("pk_giveawaymodel");
b.ToTable("giveawaymodel", (string)null);
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayUser", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasColumnName("id");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("GiveawayId")
.HasColumnType("int")
.HasColumnName("giveawayid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext")
.HasColumnName("name");
b.Property<ulong>("UserId")
.HasColumnType("bigint unsigned")
.HasColumnName("userid");
b.HasKey("Id")
.HasName("pk_giveawayuser");
b.HasIndex("GiveawayId", "UserId")
.IsUnique()
.HasDatabaseName("ix_giveawayuser_giveawayid_userid");
b.ToTable("giveawayuser", (string)null);
});
modelBuilder.Entity("NadekoBot.Db.Models.PatronQuota", b =>
{
b.Property<ulong>("UserId")
@@ -3703,6 +3767,16 @@ namespace NadekoBot.Db.Migrations.Mysql
.HasConstraintName("fk_followedstream_guildconfigs_guildconfigid");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayUser", b =>
{
b.HasOne("NadekoBot.Db.Models.GiveawayModel", null)
.WithMany("Participants")
.HasForeignKey("GiveawayId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_giveawayuser_giveawaymodel_giveawayid");
});
modelBuilder.Entity("Nadeko.Bot.Db.Models.AntiSpamSetting", b =>
{
b.Navigation("IgnoredChannels");
@@ -3819,6 +3893,11 @@ namespace NadekoBot.Db.Migrations.Mysql
b.Navigation("Members");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayModel", b =>
{
b.Navigation("Participants");
});
#pragma warning restore 612, 618
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace NadekoBot.Db.Migrations
{
/// <inheritdoc />
public partial class giveaway : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "giveawaymodel",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
guildid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
messageid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
message = table.Column<string>(type: "text", nullable: false),
endsat = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_giveawaymodel", x => x.id);
});
migrationBuilder.CreateTable(
name: "giveawayuser",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
giveawayid = table.Column<int>(type: "integer", nullable: false),
userid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_giveawayuser", x => x.id);
table.ForeignKey(
name: "fk_giveawayuser_giveawaymodel_giveawayid",
column: x => x.giveawayid,
principalTable: "giveawaymodel",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_giveawayuser_giveawayid_userid",
table: "giveawayuser",
columns: new[] { "giveawayid", "userid" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "giveawayuser");
migrationBuilder.DropTable(
name: "giveawaymodel");
}
}
}

View File

@@ -3072,6 +3072,70 @@ namespace NadekoBot.Db.Migrations
b.ToTable("followedstream", (string)null);
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("EndsAt")
.HasColumnType("timestamp without time zone")
.HasColumnName("endsat");
b.Property<decimal>("GuildId")
.HasColumnType("numeric(20,0)")
.HasColumnName("guildid");
b.Property<string>("Message")
.IsRequired()
.HasColumnType("text")
.HasColumnName("message");
b.Property<decimal>("MessageId")
.HasColumnType("numeric(20,0)")
.HasColumnName("messageid");
b.HasKey("Id")
.HasName("pk_giveawaymodel");
b.ToTable("giveawaymodel", (string)null);
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayUser", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("GiveawayId")
.HasColumnType("integer")
.HasColumnName("giveawayid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name");
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("userid");
b.HasKey("Id")
.HasName("pk_giveawayuser");
b.HasIndex("GiveawayId", "UserId")
.IsUnique()
.HasDatabaseName("ix_giveawayuser_giveawayid_userid");
b.ToTable("giveawayuser", (string)null);
});
modelBuilder.Entity("NadekoBot.Db.Models.PatronQuota", b =>
{
b.Property<decimal>("UserId")
@@ -3700,6 +3764,16 @@ namespace NadekoBot.Db.Migrations
.HasConstraintName("fk_followedstream_guildconfigs_guildconfigid");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayUser", b =>
{
b.HasOne("NadekoBot.Db.Models.GiveawayModel", null)
.WithMany("Participants")
.HasForeignKey("GiveawayId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_giveawayuser_giveawaymodel_giveawayid");
});
modelBuilder.Entity("Nadeko.Bot.Db.Models.AntiSpamSetting", b =>
{
b.Navigation("IgnoredChannels");
@@ -3816,6 +3890,11 @@ namespace NadekoBot.Db.Migrations
b.Navigation("Members");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayModel", b =>
{
b.Navigation("Participants");
});
#pragma warning restore 612, 618
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Db.Migrations.Sqlite
{
/// <inheritdoc />
public partial class giveaway : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "GiveawayModel",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
GuildId = table.Column<ulong>(type: "INTEGER", nullable: false),
MessageId = table.Column<ulong>(type: "INTEGER", nullable: false),
Message = table.Column<string>(type: "TEXT", nullable: false),
EndsAt = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GiveawayModel", x => x.Id);
});
migrationBuilder.CreateTable(
name: "GiveawayUser",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
GiveawayId = table.Column<int>(type: "INTEGER", nullable: false),
UserId = table.Column<ulong>(type: "INTEGER", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GiveawayUser", x => x.Id);
table.ForeignKey(
name: "FK_GiveawayUser_GiveawayModel_GiveawayId",
column: x => x.GiveawayId,
principalTable: "GiveawayModel",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_GiveawayUser_GiveawayId_UserId",
table: "GiveawayUser",
columns: new[] { "GiveawayId", "UserId" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "GiveawayUser");
migrationBuilder.DropTable(
name: "GiveawayModel");
}
}
}

View File

@@ -2280,6 +2280,54 @@ namespace NadekoBot.Db.Migrations.Sqlite
b.ToTable("FollowedStream");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("EndsAt")
.HasColumnType("TEXT");
b.Property<ulong>("GuildId")
.HasColumnType("INTEGER");
b.Property<string>("Message")
.IsRequired()
.HasColumnType("TEXT");
b.Property<ulong>("MessageId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("GiveawayModel");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayUser", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GiveawayId")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<ulong>("UserId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("GiveawayId", "UserId")
.IsUnique();
b.ToTable("GiveawayUser");
});
modelBuilder.Entity("NadekoBot.Db.Models.PatronQuota", b =>
{
b.Property<ulong>("UserId")
@@ -2822,6 +2870,15 @@ namespace NadekoBot.Db.Migrations.Sqlite
.HasForeignKey("GuildConfigId");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayUser", b =>
{
b.HasOne("NadekoBot.Db.Models.GiveawayModel", null)
.WithMany("Participants")
.HasForeignKey("GiveawayId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Nadeko.Bot.Db.Models.AntiSpamSetting", b =>
{
b.Navigation("IgnoredChannels");
@@ -2938,6 +2995,11 @@ namespace NadekoBot.Db.Migrations.Sqlite
b.Navigation("Members");
});
modelBuilder.Entity("NadekoBot.Db.Models.GiveawayModel", b =>
{
b.Navigation("Participants");
});
#pragma warning restore 612, 618
}
}

View File

@@ -69,7 +69,7 @@
<PackageReference Include="SharpToken" Version="1.2.14" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta17" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-beta0009" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />

View File

@@ -1393,4 +1393,14 @@ doas:
- doas
- execas
cacheusers:
- cacheusers
- cacheusers
giveawaystart:
- start
giveawayend:
- end
giveawaycancel:
- cancel
giveawayreroll:
- reroll
giveawaylist:
- list

View File

@@ -2388,5 +2388,27 @@ cacheusers:
- "serverId"
stickyroles:
desc: "Toggles whether the bot will save the leaving users' roles, and reapply them once they re-join. The roles will be stored for up to 30 days."
args:
- ""
giveawaystart:
desc: "Starts a giveaway. Specify the duration (between 1 minute and 30 days) followed by the prize."
args:
- "12h We are giving away one copy of our latest album!"
- "15m Quick giveaway for a free course!"
- "1d Join to win 1000$!"
giveawayend:
desc: "Prematurely ends a giveaway and chooses a winner. Specify the ID of the giveaway to end."
args:
- "ab3"
giveawaycancel:
desc: "Cancels a giveaway. Specify the ID of the giveaway to cancel."
args:
- "ab3"
giveawayreroll:
desc: "Rerolls a giveaway. Specify the ID of the giveaway to reroll. The winner will not be chosen."
args:
- "cd3"
giveawaylist:
desc: "Lists all active giveaways."
args:
- ""

View File

@@ -1066,5 +1066,14 @@
"cache_users_pending": "Updating users, please wait...",
"cache_users_done": "{0} users were added and {1} users were updated.",
"sticky_roles_enabled": "Sticky roles enabled. Leaving users' roles will be restored when they rejoin the server.",
"sticky_roles_disabled": "Sticky roles disabled."
"sticky_roles_disabled": "Sticky roles disabled.",
"giveaway_duration_invalid": "Giveaway may not be shorter than 1 minute or longer than 30 days",
"giveaway_started": "Giveaway Started!",
"giveaway_max_amount_reached": "You've reached the maximum amount of giveaways you can have on this server.",
"giveaway_not_found": "Giveaway not found.",
"giveaway_ended": "Giveaway ended",
"no_givaways": "There are no active giveaways on this server.",
"giveaway_cancelled": "Giveaway cancelled.",
"giveaway_starting": "Starting giveaway...",
"winner": "Winner"
}

View File

@@ -0,0 +1,4 @@
dotnet ef migrations remove -c SqliteContext
dotnet ef migrations remove -c PostgreSqlContext -f
dotnet ef migrations remove -c MysqlContext -f