mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 08:34:27 -05:00 
			
		
		
		
	* feature: Added .stickyroles command, untested
* ci: possible fix
This commit is contained in:
		@@ -60,6 +60,8 @@ public abstract class NadekoContext : DbContext
 | 
			
		||||
    public DbSet<PatronQuota> PatronQuotas { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    public DbSet<StreamOnlineMessage> StreamOnlineMessages { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    public DbSet<StickyRole> StickyRoles { get; set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    #region Mandatory Provider-Specific Values
 | 
			
		||||
@@ -481,6 +483,16 @@ public abstract class NadekoContext : DbContext
 | 
			
		||||
            .IsUnique());
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
        
 | 
			
		||||
        #region Sticky Roles
 | 
			
		||||
        
 | 
			
		||||
        modelBuilder.Entity<StickyRole>(sr => sr.HasIndex(x => new
 | 
			
		||||
        {
 | 
			
		||||
            x.GuildId,
 | 
			
		||||
            x.UserId
 | 
			
		||||
        }).IsUnique());
 | 
			
		||||
        
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#if DEBUG
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3828
									
								
								src/NadekoBot/Migrations/Mysql/20240423153724_sticky-roles.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										3828
									
								
								src/NadekoBot/Migrations/Mysql/20240423153724_sticky-roles.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.EntityFrameworkCore.Metadata;
 | 
			
		||||
using Microsoft.EntityFrameworkCore.Migrations;
 | 
			
		||||
 | 
			
		||||
#nullable disable
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Db.Migrations.Mysql
 | 
			
		||||
{
 | 
			
		||||
    /// <inheritdoc />
 | 
			
		||||
    public partial class stickyroles : Migration
 | 
			
		||||
    {
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        protected override void Up(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            migrationBuilder.AddColumn<bool>(
 | 
			
		||||
                name: "stickyroles",
 | 
			
		||||
                table: "guildconfigs",
 | 
			
		||||
                type: "tinyint(1)",
 | 
			
		||||
                nullable: false,
 | 
			
		||||
                defaultValue: false);
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.CreateTable(
 | 
			
		||||
                name: "stickyroles",
 | 
			
		||||
                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),
 | 
			
		||||
                    roleids = table.Column<string>(type: "longtext", nullable: false)
 | 
			
		||||
                        .Annotation("MySql:CharSet", "utf8mb4"),
 | 
			
		||||
                    userid = table.Column<ulong>(type: "bigint unsigned", nullable: false),
 | 
			
		||||
                    dateadded = table.Column<DateTime>(type: "datetime(6)", nullable: true)
 | 
			
		||||
                },
 | 
			
		||||
                constraints: table =>
 | 
			
		||||
                {
 | 
			
		||||
                    table.PrimaryKey("pk_stickyroles", x => x.id);
 | 
			
		||||
                })
 | 
			
		||||
                .Annotation("MySql:CharSet", "utf8mb4");
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.CreateIndex(
 | 
			
		||||
                name: "ix_stickyroles_guildid_userid",
 | 
			
		||||
                table: "stickyroles",
 | 
			
		||||
                columns: new[] { "guildid", "userid" },
 | 
			
		||||
                unique: true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            migrationBuilder.DropTable(
 | 
			
		||||
                name: "stickyroles");
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.DropColumn(
 | 
			
		||||
                name: "stickyroles",
 | 
			
		||||
                table: "guildconfigs");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -983,6 +983,10 @@ namespace NadekoBot.Db.Migrations.Mysql
 | 
			
		||||
                        .HasColumnType("tinyint(1)")
 | 
			
		||||
                        .HasColumnName("senddmgreetmessage");
 | 
			
		||||
 | 
			
		||||
                    b.Property<bool>("StickyRoles")
 | 
			
		||||
                        .HasColumnType("tinyint(1)")
 | 
			
		||||
                        .HasColumnName("stickyroles");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("TimeZoneId")
 | 
			
		||||
                        .HasColumnType("longtext")
 | 
			
		||||
                        .HasColumnName("timezoneid");
 | 
			
		||||
@@ -2124,6 +2128,42 @@ namespace NadekoBot.Db.Migrations.Mysql
 | 
			
		||||
                    b.ToTable("slowmodeignoreduser", (string)null);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            modelBuilder.Entity("Nadeko.Bot.Db.Models.StickyRole", b =>
 | 
			
		||||
                {
 | 
			
		||||
                    b.Property<int>("Id")
 | 
			
		||||
                        .ValueGeneratedOnAdd()
 | 
			
		||||
                        .HasColumnType("int")
 | 
			
		||||
                        .HasColumnName("id");
 | 
			
		||||
 | 
			
		||||
                    MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
 | 
			
		||||
 | 
			
		||||
                    b.Property<DateTime?>("DateAdded")
 | 
			
		||||
                        .HasColumnType("datetime(6)")
 | 
			
		||||
                        .HasColumnName("dateadded");
 | 
			
		||||
 | 
			
		||||
                    b.Property<ulong>("GuildId")
 | 
			
		||||
                        .HasColumnType("bigint unsigned")
 | 
			
		||||
                        .HasColumnName("guildid");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("RoleIds")
 | 
			
		||||
                        .IsRequired()
 | 
			
		||||
                        .HasColumnType("longtext")
 | 
			
		||||
                        .HasColumnName("roleids");
 | 
			
		||||
 | 
			
		||||
                    b.Property<ulong>("UserId")
 | 
			
		||||
                        .HasColumnType("bigint unsigned")
 | 
			
		||||
                        .HasColumnName("userid");
 | 
			
		||||
 | 
			
		||||
                    b.HasKey("Id")
 | 
			
		||||
                        .HasName("pk_stickyroles");
 | 
			
		||||
 | 
			
		||||
                    b.HasIndex("GuildId", "UserId")
 | 
			
		||||
                        .IsUnique()
 | 
			
		||||
                        .HasDatabaseName("ix_stickyroles_guildid_userid");
 | 
			
		||||
 | 
			
		||||
                    b.ToTable("stickyroles", (string)null);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            modelBuilder.Entity("Nadeko.Bot.Db.Models.StreamRoleBlacklistedUser", b =>
 | 
			
		||||
                {
 | 
			
		||||
                    b.Property<int>("Id")
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3825
									
								
								src/NadekoBot/Migrations/Postgresql/20240423153717_sticky-roles.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										3825
									
								
								src/NadekoBot/Migrations/Postgresql/20240423153717_sticky-roles.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.EntityFrameworkCore.Migrations;
 | 
			
		||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
 | 
			
		||||
 | 
			
		||||
#nullable disable
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Db.Migrations
 | 
			
		||||
{
 | 
			
		||||
    /// <inheritdoc />
 | 
			
		||||
    public partial class stickyroles : Migration
 | 
			
		||||
    {
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        protected override void Up(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            migrationBuilder.AddColumn<bool>(
 | 
			
		||||
                name: "stickyroles",
 | 
			
		||||
                table: "guildconfigs",
 | 
			
		||||
                type: "boolean",
 | 
			
		||||
                nullable: false,
 | 
			
		||||
                defaultValue: false);
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.CreateTable(
 | 
			
		||||
                name: "stickyroles",
 | 
			
		||||
                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),
 | 
			
		||||
                    roleids = table.Column<string>(type: "text", nullable: false),
 | 
			
		||||
                    userid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
 | 
			
		||||
                    dateadded = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
 | 
			
		||||
                },
 | 
			
		||||
                constraints: table =>
 | 
			
		||||
                {
 | 
			
		||||
                    table.PrimaryKey("pk_stickyroles", x => x.id);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.CreateIndex(
 | 
			
		||||
                name: "ix_stickyroles_guildid_userid",
 | 
			
		||||
                table: "stickyroles",
 | 
			
		||||
                columns: new[] { "guildid", "userid" },
 | 
			
		||||
                unique: true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            migrationBuilder.DropTable(
 | 
			
		||||
                name: "stickyroles");
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.DropColumn(
 | 
			
		||||
                name: "stickyroles",
 | 
			
		||||
                table: "guildconfigs");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -983,6 +983,10 @@ namespace NadekoBot.Db.Migrations
 | 
			
		||||
                        .HasColumnType("boolean")
 | 
			
		||||
                        .HasColumnName("senddmgreetmessage");
 | 
			
		||||
 | 
			
		||||
                    b.Property<bool>("StickyRoles")
 | 
			
		||||
                        .HasColumnType("boolean")
 | 
			
		||||
                        .HasColumnName("stickyroles");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("TimeZoneId")
 | 
			
		||||
                        .HasColumnType("text")
 | 
			
		||||
                        .HasColumnName("timezoneid");
 | 
			
		||||
@@ -2124,6 +2128,42 @@ namespace NadekoBot.Db.Migrations
 | 
			
		||||
                    b.ToTable("slowmodeignoreduser", (string)null);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            modelBuilder.Entity("Nadeko.Bot.Db.Models.StickyRole", b =>
 | 
			
		||||
                {
 | 
			
		||||
                    b.Property<int>("Id")
 | 
			
		||||
                        .ValueGeneratedOnAdd()
 | 
			
		||||
                        .HasColumnType("integer")
 | 
			
		||||
                        .HasColumnName("id");
 | 
			
		||||
 | 
			
		||||
                    NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
 | 
			
		||||
 | 
			
		||||
                    b.Property<DateTime?>("DateAdded")
 | 
			
		||||
                        .HasColumnType("timestamp without time zone")
 | 
			
		||||
                        .HasColumnName("dateadded");
 | 
			
		||||
 | 
			
		||||
                    b.Property<decimal>("GuildId")
 | 
			
		||||
                        .HasColumnType("numeric(20,0)")
 | 
			
		||||
                        .HasColumnName("guildid");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("RoleIds")
 | 
			
		||||
                        .IsRequired()
 | 
			
		||||
                        .HasColumnType("text")
 | 
			
		||||
                        .HasColumnName("roleids");
 | 
			
		||||
 | 
			
		||||
                    b.Property<decimal>("UserId")
 | 
			
		||||
                        .HasColumnType("numeric(20,0)")
 | 
			
		||||
                        .HasColumnName("userid");
 | 
			
		||||
 | 
			
		||||
                    b.HasKey("Id")
 | 
			
		||||
                        .HasName("pk_stickyroles");
 | 
			
		||||
 | 
			
		||||
                    b.HasIndex("GuildId", "UserId")
 | 
			
		||||
                        .IsUnique()
 | 
			
		||||
                        .HasDatabaseName("ix_stickyroles_guildid_userid");
 | 
			
		||||
 | 
			
		||||
                    b.ToTable("stickyroles", (string)null);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            modelBuilder.Entity("Nadeko.Bot.Db.Models.StreamRoleBlacklistedUser", b =>
 | 
			
		||||
                {
 | 
			
		||||
                    b.Property<int>("Id")
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2947
									
								
								src/NadekoBot/Migrations/Sqlite/20240423153708_sticky-roles.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										2947
									
								
								src/NadekoBot/Migrations/Sqlite/20240423153708_sticky-roles.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.EntityFrameworkCore.Migrations;
 | 
			
		||||
 | 
			
		||||
#nullable disable
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Db.Migrations.Sqlite
 | 
			
		||||
{
 | 
			
		||||
    /// <inheritdoc />
 | 
			
		||||
    public partial class stickyroles : Migration
 | 
			
		||||
    {
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        protected override void Up(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            migrationBuilder.AddColumn<bool>(
 | 
			
		||||
                name: "StickyRoles",
 | 
			
		||||
                table: "GuildConfigs",
 | 
			
		||||
                type: "INTEGER",
 | 
			
		||||
                nullable: false,
 | 
			
		||||
                defaultValue: false);
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.CreateTable(
 | 
			
		||||
                name: "StickyRoles",
 | 
			
		||||
                columns: table => new
 | 
			
		||||
                {
 | 
			
		||||
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
 | 
			
		||||
                        .Annotation("Sqlite:Autoincrement", true),
 | 
			
		||||
                    GuildId = table.Column<ulong>(type: "INTEGER", nullable: false),
 | 
			
		||||
                    RoleIds = table.Column<string>(type: "TEXT", nullable: false),
 | 
			
		||||
                    UserId = table.Column<ulong>(type: "INTEGER", nullable: false),
 | 
			
		||||
                    DateAdded = table.Column<DateTime>(type: "TEXT", nullable: true)
 | 
			
		||||
                },
 | 
			
		||||
                constraints: table =>
 | 
			
		||||
                {
 | 
			
		||||
                    table.PrimaryKey("PK_StickyRoles", x => x.Id);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.CreateIndex(
 | 
			
		||||
                name: "IX_StickyRoles_GuildId_UserId",
 | 
			
		||||
                table: "StickyRoles",
 | 
			
		||||
                columns: new[] { "GuildId", "UserId" },
 | 
			
		||||
                unique: true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            migrationBuilder.DropTable(
 | 
			
		||||
                name: "StickyRoles");
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.DropColumn(
 | 
			
		||||
                name: "StickyRoles",
 | 
			
		||||
                table: "GuildConfigs");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -729,6 +729,9 @@ namespace NadekoBot.Db.Migrations.Sqlite
 | 
			
		||||
                    b.Property<bool>("SendDmGreetMessage")
 | 
			
		||||
                        .HasColumnType("INTEGER");
 | 
			
		||||
 | 
			
		||||
                    b.Property<bool>("StickyRoles")
 | 
			
		||||
                        .HasColumnType("INTEGER");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("TimeZoneId")
 | 
			
		||||
                        .HasColumnType("TEXT");
 | 
			
		||||
 | 
			
		||||
@@ -1577,6 +1580,33 @@ namespace NadekoBot.Db.Migrations.Sqlite
 | 
			
		||||
                    b.ToTable("SlowmodeIgnoredUser");
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            modelBuilder.Entity("Nadeko.Bot.Db.Models.StickyRole", b =>
 | 
			
		||||
                {
 | 
			
		||||
                    b.Property<int>("Id")
 | 
			
		||||
                        .ValueGeneratedOnAdd()
 | 
			
		||||
                        .HasColumnType("INTEGER");
 | 
			
		||||
 | 
			
		||||
                    b.Property<DateTime?>("DateAdded")
 | 
			
		||||
                        .HasColumnType("TEXT");
 | 
			
		||||
 | 
			
		||||
                    b.Property<ulong>("GuildId")
 | 
			
		||||
                        .HasColumnType("INTEGER");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("RoleIds")
 | 
			
		||||
                        .IsRequired()
 | 
			
		||||
                        .HasColumnType("TEXT");
 | 
			
		||||
 | 
			
		||||
                    b.Property<ulong>("UserId")
 | 
			
		||||
                        .HasColumnType("INTEGER");
 | 
			
		||||
 | 
			
		||||
                    b.HasKey("Id");
 | 
			
		||||
 | 
			
		||||
                    b.HasIndex("GuildId", "UserId")
 | 
			
		||||
                        .IsUnique();
 | 
			
		||||
 | 
			
		||||
                    b.ToTable("StickyRoles");
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            modelBuilder.Entity("Nadeko.Bot.Db.Models.StreamRoleBlacklistedUser", b =>
 | 
			
		||||
                {
 | 
			
		||||
                    b.Property<int>("Id")
 | 
			
		||||
 
 | 
			
		||||
@@ -2382,7 +2382,11 @@ clubrename:
 | 
			
		||||
  args:
 | 
			
		||||
    - "New cool club name"
 | 
			
		||||
cacheusers:
 | 
			
		||||
  desc: Caches users of a Discord server and saves them to the database.
 | 
			
		||||
  desc: "Caches users of a Discord server and saves them to the database."
 | 
			
		||||
  args:
 | 
			
		||||
    - ""
 | 
			
		||||
    - "serverId"
 | 
			
		||||
    - "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:
 | 
			
		||||
    - ""
 | 
			
		||||
@@ -1064,5 +1064,7 @@
 | 
			
		||||
  "thread_created": "Thread Created",
 | 
			
		||||
  "supported_languages": "Supported Languages",
 | 
			
		||||
  "cache_users_pending": "Updating users, please wait...",
 | 
			
		||||
  "cache_users_done": "{0} users were added and {1} users were updated."
 | 
			
		||||
  "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."
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								src/NadekoBot/migrate.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/NadekoBot/migrate.ps1
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
if ($args.Length -eq 0) {
 | 
			
		||||
    Write-Host "Please provide a migration name." -ForegroundColor Red
 | 
			
		||||
}
 | 
			
		||||
else {
 | 
			
		||||
    $migrationName = $args[0]
 | 
			
		||||
    dotnet ef migrations add $migrationName -c SqliteContext
 | 
			
		||||
    dotnet ef migrations add $migrationName -c PostgreSqlContext
 | 
			
		||||
    dotnet ef migrations add $migrationName -c MysqlContext
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user