mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	Added .shopreq - Shop items can now have a role requirement in order to purchase. Added .shopbuy alias for .buy
This commit is contained in:
		@@ -24,6 +24,7 @@ public class ShopEntry : DbEntity, IIndexed
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    //list
 | 
					    //list
 | 
				
			||||||
    public HashSet<ShopEntryItem> Items { get; set; } = new();
 | 
					    public HashSet<ShopEntryItem> Items { get; set; } = new();
 | 
				
			||||||
 | 
					    public ulong? RoleRequirement { get; set; }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ShopEntryItem : DbEntity
 | 
					public class ShopEntryItem : DbEntity
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3550
									
								
								src/NadekoBot/Migrations/Mysql/20220913192520_shop-role-req.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										3550
									
								
								src/NadekoBot/Migrations/Mysql/20220913192520_shop-role-req.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					using Microsoft.EntityFrameworkCore.Migrations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#nullable disable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace NadekoBot.Migrations.Mysql
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public partial class shoprolereq : Migration
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        protected override void Up(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.AddColumn<ulong>(
 | 
				
			||||||
 | 
					                name: "rolerequirement",
 | 
				
			||||||
 | 
					                table: "shopentry",
 | 
				
			||||||
 | 
					                type: "bigint unsigned",
 | 
				
			||||||
 | 
					                nullable: true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        protected override void Down(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.DropColumn(
 | 
				
			||||||
 | 
					                name: "rolerequirement",
 | 
				
			||||||
 | 
					                table: "shopentry");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3548
									
								
								src/NadekoBot/Migrations/Mysql/MysqlContextModelSnapshot.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3548
									
								
								src/NadekoBot/Migrations/Mysql/MysqlContextModelSnapshot.cs
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										3694
									
								
								src/NadekoBot/Migrations/PostgreSql/20220913192529_shop-role-req.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										3694
									
								
								src/NadekoBot/Migrations/PostgreSql/20220913192529_shop-role-req.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					using Microsoft.EntityFrameworkCore.Migrations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#nullable disable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace NadekoBot.Migrations.PostgreSql
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public partial class shoprolereq : Migration
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        protected override void Up(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.AddColumn<decimal>(
 | 
				
			||||||
 | 
					                name: "rolerequirement",
 | 
				
			||||||
 | 
					                table: "shopentry",
 | 
				
			||||||
 | 
					                type: "numeric(20,0)",
 | 
				
			||||||
 | 
					                nullable: true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        protected override void Down(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.DropColumn(
 | 
				
			||||||
 | 
					                name: "rolerequirement",
 | 
				
			||||||
 | 
					                table: "shopentry");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										2849
									
								
								src/NadekoBot/Migrations/Sqlite/20220913190532_shop-role-req.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										2849
									
								
								src/NadekoBot/Migrations/Sqlite/20220913190532_shop-role-req.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					using Microsoft.EntityFrameworkCore.Migrations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#nullable disable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace NadekoBot.Migrations
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public partial class shoprolereq : Migration
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        protected override void Up(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.AddColumn<ulong>(
 | 
				
			||||||
 | 
					                name: "RoleRequirement",
 | 
				
			||||||
 | 
					                table: "ShopEntry",
 | 
				
			||||||
 | 
					                type: "INTEGER",
 | 
				
			||||||
 | 
					                nullable: true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        protected override void Down(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.DropColumn(
 | 
				
			||||||
 | 
					                name: "RoleRequirement",
 | 
				
			||||||
 | 
					                table: "ShopEntry");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1745,6 +1745,9 @@ namespace NadekoBot.Migrations
 | 
				
			|||||||
                    b.Property<string>("RoleName")
 | 
					                    b.Property<string>("RoleName")
 | 
				
			||||||
                        .HasColumnType("TEXT");
 | 
					                        .HasColumnType("TEXT");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<ulong?>("RoleRequirement")
 | 
				
			||||||
 | 
					                        .HasColumnType("INTEGER");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    b.Property<int>("Type")
 | 
					                    b.Property<int>("Type")
 | 
				
			||||||
                        .HasColumnType("INTEGER");
 | 
					                        .HasColumnType("INTEGER");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,4 +38,6 @@ public interface IShopService
 | 
				
			|||||||
    /// <param name="toIndex">Destination index of the entry</param>
 | 
					    /// <param name="toIndex">Destination index of the entry</param>
 | 
				
			||||||
    /// <returns>Whether swap was successful</returns>
 | 
					    /// <returns>Whether swap was successful</returns>
 | 
				
			||||||
    Task<bool> MoveEntryAsync(ulong guildId, int fromIndex, int toIndex);
 | 
					    Task<bool> MoveEntryAsync(ulong guildId, int fromIndex, int toIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Task<bool> SetItemRoleRequirementAsync(ulong guildId, int index, ulong? roleId);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -98,6 +98,23 @@ public partial class Gambling
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (entry.RoleRequirement is ulong reqRoleId)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var role = ctx.Guild.GetRole(reqRoleId);
 | 
				
			||||||
 | 
					                if (role is null)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    await ReplyErrorLocalizedAsync(strs.shop_item_req_role_not_found);
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var guser = (IGuildUser)ctx.User;
 | 
				
			||||||
 | 
					                if (!guser.RoleIds.Contains(reqRoleId))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    await ReplyErrorLocalizedAsync(strs.shop_item_req_role_unfulfilled(Format.Bold(role.ToString())));
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (entry.Type == ShopEntryType.Role)
 | 
					            if (entry.Type == ShopEntryType.Role)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var guser = (IGuildUser)ctx.User;
 | 
					                var guser = (IGuildUser)ctx.User;
 | 
				
			||||||
@@ -412,6 +429,27 @@ public partial class Gambling
 | 
				
			|||||||
                await ctx.ErrorAsync();
 | 
					                await ctx.ErrorAsync();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Cmd]
 | 
				
			||||||
 | 
					        [RequireContext(ContextType.Guild)]
 | 
				
			||||||
 | 
					        [UserPerm(GuildPerm.Administrator)]
 | 
				
			||||||
 | 
					        public async Task ShopReq(int itemIndex, [Leftover] IRole role = null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (--itemIndex < 0)
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var succ = await _service.SetItemRoleRequirementAsync(ctx.Guild.Id, itemIndex, role?.Id);
 | 
				
			||||||
 | 
					            if (!succ)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (role is null)
 | 
				
			||||||
 | 
					                await ReplyConfirmLocalizedAsync(strs.shop_item_role_no_req(itemIndex));
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                await ReplyConfirmLocalizedAsync(strs.shop_item_role_req(itemIndex + 1, role));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public IEmbedBuilder EntryToEmbed(ShopEntry entry)
 | 
					        public IEmbedBuilder EntryToEmbed(ShopEntry entry)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var embed = _eb.Create().WithOkColor();
 | 
					            var embed = _eb.Create().WithOkColor();
 | 
				
			||||||
@@ -443,11 +481,17 @@ public partial class Gambling
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public string EntryToString(ShopEntry entry)
 | 
					        public string EntryToString(ShopEntry entry)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var prepend = string.Empty;
 | 
				
			||||||
 | 
					            if (entry.RoleRequirement is not null)
 | 
				
			||||||
 | 
					                prepend = Format.Italics(GetText(strs.shop_item_requires_role($"<@&{entry.RoleRequirement}>")))
 | 
				
			||||||
 | 
					                          + Environment.NewLine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (entry.Type == ShopEntryType.Role)
 | 
					            if (entry.Type == ShopEntryType.Role)
 | 
				
			||||||
                return GetText(strs.shop_role(Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE")));
 | 
					                return prepend
 | 
				
			||||||
 | 
					                       + GetText(strs.shop_role(Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE")));
 | 
				
			||||||
            if (entry.Type == ShopEntryType.List)
 | 
					            if (entry.Type == ShopEntryType.List)
 | 
				
			||||||
                return GetText(strs.unique_items_left(entry.Items.Count)) + "\n" + entry.Name;
 | 
					                return prepend + GetText(strs.unique_items_left(entry.Items.Count)) + "\n" + entry.Name;
 | 
				
			||||||
            return "";
 | 
					            return prepend;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -94,4 +94,20 @@ public class ShopService : IShopService, INService
 | 
				
			|||||||
        await uow.SaveChangesAsync();
 | 
					        await uow.SaveChangesAsync();
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<bool> SetItemRoleRequirementAsync(ulong guildId, int index, ulong? roleId)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        await using var uow = _db.GetDbContext();
 | 
				
			||||||
 | 
					        var entries = GetEntriesInternal(uow, guildId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (index >= entries.Count)
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var entry = entries[index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        entry.RoleRequirement = roleId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await uow.SaveChangesAsync();
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1003,7 +1003,10 @@ shopswap:
 | 
				
			|||||||
shopmove:
 | 
					shopmove:
 | 
				
			||||||
  - shopmove
 | 
					  - shopmove
 | 
				
			||||||
buy:
 | 
					buy:
 | 
				
			||||||
 | 
					  - shopbuy
 | 
				
			||||||
  - buy
 | 
					  - buy
 | 
				
			||||||
 | 
					shopreq:
 | 
				
			||||||
 | 
					  - shopreq
 | 
				
			||||||
gamevoicechannel:
 | 
					gamevoicechannel:
 | 
				
			||||||
  - gamevoicechannel
 | 
					  - gamevoicechannel
 | 
				
			||||||
  - gvc
 | 
					  - gvc
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1742,6 +1742,11 @@ shopremove:
 | 
				
			|||||||
  desc: "Removes an item from the shop by its ID."
 | 
					  desc: "Removes an item from the shop by its ID."
 | 
				
			||||||
  args:
 | 
					  args:
 | 
				
			||||||
    - "1"
 | 
					    - "1"
 | 
				
			||||||
 | 
					shopreq:
 | 
				
			||||||
 | 
					  desc: "Sets a role which will be required to buy the item on the specified index. Specify only index to remove the requirement."
 | 
				
			||||||
 | 
					  args:
 | 
				
			||||||
 | 
					    - "2 Gamers"
 | 
				
			||||||
 | 
					    - "2"
 | 
				
			||||||
shopchangename:
 | 
					shopchangename:
 | 
				
			||||||
  desc: "Change the name of a shop entry at the specified index. Only works for non-role items"
 | 
					  desc: "Change the name of a shop entry at the specified index. Only works for non-role items"
 | 
				
			||||||
  args:
 | 
					  args:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -725,6 +725,11 @@
 | 
				
			|||||||
  "shop_role_already_bought": "You already bought this role.",
 | 
					  "shop_role_already_bought": "You already bought this role.",
 | 
				
			||||||
  "shop_role_purchase": "You've successfully purchased {0} role.",
 | 
					  "shop_role_purchase": "You've successfully purchased {0} role.",
 | 
				
			||||||
  "shop_role_purchase_error": "Error assigning role. Your purchase has been refunded.",
 | 
					  "shop_role_purchase_error": "Error assigning role. Your purchase has been refunded.",
 | 
				
			||||||
 | 
					  "shop_item_role_req": "Shop item #{0} will now require users to have a {1} role in order to purchase it.",
 | 
				
			||||||
 | 
					  "shop_item_req_role_unfulfilled": "You don't have the required role '{0}' in order to buy this shop item.",
 | 
				
			||||||
 | 
					  "shop_item_req_role_not_found": "The required role for this item doesn't exist anymore. Please contact server administrator.",
 | 
				
			||||||
 | 
					  "shop_item_requires_role": "Requires {0} role to purchase",
 | 
				
			||||||
 | 
					  "shop_item_role_no_req": "Shop item #{0} will no longer require a role.",
 | 
				
			||||||
  "unique_items_left": "{0} unique items left.",
 | 
					  "unique_items_left": "{0} unique items left.",
 | 
				
			||||||
  "blocked_commands": "Blocked Commands",
 | 
					  "blocked_commands": "Blocked Commands",
 | 
				
			||||||
  "blocked_modules": "Blocked Modules",
 | 
					  "blocked_modules": "Blocked Modules",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user