Server shops added. $shop, $buy, $shopadd, $shoprm and $shoplistadd added

This commit is contained in:
Kwoth 2017-04-08 05:06:52 +02:00
commit e8bfb869b3
12 changed files with 2656 additions and 89 deletions

View File

@ -0,0 +1,128 @@
using NadekoBot.Services.Database.Models;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace NadekoBot.DataStructures
{
public class IndexedCollection<T> : IList<T> where T : IIndexed
{
public List<T> Source { get; }
private readonly object _locker = new object();
public IndexedCollection(IEnumerable<T> source)
{
lock (_locker)
{
Source = source.OrderBy(x => x.Index).ToList();
for (var i = 0; i < Source.Count; i++)
{
if (Source[i].Index != i)
Source[i].Index = i;
}
}
}
public static implicit operator List<T>(IndexedCollection<T> x) =>
x.Source;
public IEnumerator<T> GetEnumerator() =>
Source.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() =>
Source.GetEnumerator();
public void Add(T item)
{
lock (_locker)
{
item.Index = Source.Count;
Source.Add(item);
}
}
public virtual void Clear()
{
lock (_locker)
{
Source.Clear();
}
}
public bool Contains(T item)
{
lock (_locker)
{
return Source.Contains(item);
}
}
public void CopyTo(T[] array, int arrayIndex)
{
lock (_locker)
{
Source.CopyTo(array, arrayIndex);
}
}
public virtual bool Remove(T item)
{
bool removed;
lock (_locker)
{
if (removed = Source.Remove(item))
{
for (int i = 0; i < Source.Count; i++)
{
// hm, no idea how ef works, so I don't want to set if it's not changed,
// maybe it will try to update db?
// But most likely it just compares old to new values, meh.
if (Source[i].Index != i)
Source[i].Index = i;
}
}
}
return removed;
}
public int Count => Source.Count;
public bool IsReadOnly => false;
public int IndexOf(T item) => item.Index;
public virtual void Insert(int index, T item)
{
lock (_locker)
{
Source.Insert(index, item);
for (int i = index; i < Source.Count; i++)
{
Source[i].Index = i;
}
}
}
public virtual void RemoveAt(int index)
{
lock (_locker)
{
Source.RemoveAt(index);
for (int i = index; i < Source.Count; i++)
{
Source[i].Index = i;
}
}
}
public virtual T this[int index] {
get { return Source[index]; }
set {
lock (_locker)
{
value.Index = index;
Source[index] = value;
}
}
}
}
}

View File

@ -6,132 +6,67 @@ using NadekoBot.Services.Database.Models;
namespace NadekoBot.DataStructures
{
public class PermissionsCollection<T> : IList<T> where T : IIndexed
public class PermissionsCollection<T> : IndexedCollection<T> where T : IIndexed
{
public List<T> Source { get; }
private readonly object _locker = new object();
public PermissionsCollection(IEnumerable<T> source)
private readonly object _localLocker = new object();
public PermissionsCollection(IEnumerable<T> source) : base(source)
{
lock (_locker)
{
Source = source.OrderBy(x => x.Index).ToList();
for (var i = 0; i < Source.Count; i++)
{
if(Source[i].Index != i)
Source[i].Index = i;
}
}
}
public static implicit operator List<T>(PermissionsCollection<T> x) =>
x.Source;
public IEnumerator<T> GetEnumerator() =>
Source.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() =>
Source.GetEnumerator();
public void Add(T item)
public override void Clear()
{
lock (_locker)
{
item.Index = Source.Count;
Source.Add(item);
}
}
public void Clear()
{
lock (_locker)
lock (_localLocker)
{
var first = Source[0];
Source.Clear();
base.Clear();
Source[0] = first;
}
}
public bool Contains(T item)
{
lock (_locker)
{
return Source.Contains(item);
}
}
public void CopyTo(T[] array, int arrayIndex)
{
lock (_locker)
{
Source.CopyTo(array, arrayIndex);
}
}
public bool Remove(T item)
public override bool Remove(T item)
{
bool removed;
lock (_locker)
lock (_localLocker)
{
if(Source.IndexOf(item) == 0)
throw new ArgumentException("You can't remove first permsission (allow all)");
if (removed = Source.Remove(item))
{
for (int i = 0; i < Source.Count; i++)
{
// hm, no idea how ef works, so I don't want to set if it's not changed,
// maybe it will try to update db?
// But most likely it just compares old to new values, meh.
if (Source[i].Index != i)
Source[i].Index = i;
}
}
removed = base.Remove(item);
}
return removed;
}
public int Count => Source.Count;
public bool IsReadOnly => false;
public int IndexOf(T item) => item.Index;
public void Insert(int index, T item)
public override void Insert(int index, T item)
{
lock (_locker)
lock (_localLocker)
{
if(index == 0) // can't insert on first place. Last item is always allow all.
throw new IndexOutOfRangeException(nameof(index));
Source.Insert(index, item);
for (int i = index; i < Source.Count; i++)
{
Source[i].Index = i;
}
base.Insert(index, item);
}
}
public void RemoveAt(int index)
public override void RemoveAt(int index)
{
lock (_locker)
lock (_localLocker)
{
if(index == 0) // you can't remove first permission (allow all)
throw new IndexOutOfRangeException(nameof(index));
throw new IndexOutOfRangeException(nameof(index));
Source.RemoveAt(index);
for (int i = index; i < Source.Count; i++)
{
Source[i].Index = i;
}
base.RemoveAt(index);
}
}
public T this[int index] {
public override T this[int index] {
get { return Source[index]; }
set {
lock (_locker)
lock (_localLocker)
{
if(index == 0) // can't set first element. It's always allow all
throw new IndexOutOfRangeException(nameof(index));
value.Index = index;
Source[index] = value;
base[index] = value;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class flowershop : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ShopEntry",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
AuthorId = table.Column<ulong>(nullable: false),
DateAdded = table.Column<DateTime>(nullable: true),
GuildConfigId = table.Column<int>(nullable: true),
Index = table.Column<int>(nullable: false),
Name = table.Column<string>(nullable: true),
Price = table.Column<int>(nullable: false),
RoleId = table.Column<ulong>(nullable: false),
RoleName = table.Column<string>(nullable: true),
Type = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShopEntry", x => x.Id);
table.ForeignKey(
name: "FK_ShopEntry_GuildConfigs_GuildConfigId",
column: x => x.GuildConfigId,
principalTable: "GuildConfigs",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "ShopEntryItem",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
DateAdded = table.Column<DateTime>(nullable: true),
ShopEntryId = table.Column<int>(nullable: true),
Text = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ShopEntryItem", x => x.Id);
table.ForeignKey(
name: "FK_ShopEntryItem_ShopEntry_ShopEntryId",
column: x => x.ShopEntryId,
principalTable: "ShopEntry",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_ShopEntry_GuildConfigId",
table: "ShopEntry",
column: "GuildConfigId");
migrationBuilder.CreateIndex(
name: "IX_ShopEntryItem_ShopEntryId",
table: "ShopEntryItem",
column: "ShopEntryId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ShopEntryItem");
migrationBuilder.DropTable(
name: "ShopEntry");
}
}
}

View File

@ -971,6 +971,54 @@ namespace NadekoBot.Migrations
b.ToTable("SelfAssignableRoles");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("AuthorId");
b.Property<DateTime?>("DateAdded");
b.Property<int?>("GuildConfigId");
b.Property<int>("Index");
b.Property<string>("Name");
b.Property<int>("Price");
b.Property<ulong>("RoleId");
b.Property<string>("RoleName");
b.Property<int>("Type");
b.HasKey("Id");
b.HasIndex("GuildConfigId");
b.ToTable("ShopEntry");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntryItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime?>("DateAdded");
b.Property<int?>("ShopEntryId");
b.Property<string>("Text");
b.HasKey("Id");
b.HasIndex("ShopEntryId");
b.ToTable("ShopEntryItem");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredRole", b =>
{
b.Property<int>("Id")
@ -1377,6 +1425,20 @@ namespace NadekoBot.Migrations
.HasForeignKey("BotConfigId");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntry", b =>
{
b.HasOne("NadekoBot.Services.Database.Models.GuildConfig")
.WithMany("ShopEntries")
.HasForeignKey("GuildConfigId");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntryItem", b =>
{
b.HasOne("NadekoBot.Services.Database.Models.ShopEntry")
.WithMany("Items")
.HasForeignKey("ShopEntryId");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredRole", b =>
{
b.HasOne("NadekoBot.Services.Database.Models.GuildConfig")

View File

@ -0,0 +1,350 @@
using Discord;
using Discord.Commands;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Attributes;
using NadekoBot.DataStructures;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Gambling
{
public partial class Gambling
{
[Group]
public class FlowerShop : NadekoSubmodule
{
public enum Role
{
Role
}
public enum List
{
List
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Shop(int page = 1)
{
if (page <= 0)
return;
page -= 1;
List<ShopEntry> entries;
using (var uow = DbHandler.UnitOfWork())
{
entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries);
}
await Context.Channel.SendPaginatedConfirmAsync(page + 1, (curPage) =>
{
var theseEntries = entries.Skip((curPage - 1) * 9).Take(9);
if (!theseEntries.Any())
return new EmbedBuilder().WithErrorColor()
.WithDescription(GetText("shop_none"));
var embed = new EmbedBuilder().WithOkColor()
.WithTitle(GetText("shop", CurrencySign));
for (int i = 0; i < entries.Count; i++)
{
var entry = entries[i];
embed.AddField(efb => efb.WithName($"#{i + 1} - {entry.Price}{CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
}
return embed;
}, entries.Count / 9, true);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Buy(int index, [Remainder]string message = null)
{
index -= 1;
if (index < 0)
return;
ShopEntry entry;
using (var uow = DbHandler.UnitOfWork())
{
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set
.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items));
var entries = new IndexedCollection<ShopEntry>(config.ShopEntries);
entry = entries.ElementAtOrDefault(index);
uow.Complete();
}
if (entry == null)
{
await ReplyErrorLocalized("shop_item_not_found").ConfigureAwait(false);
return;
}
if (entry.Type == ShopEntryType.Role)
{
var guser = (IGuildUser)Context.User;
var role = Context.Guild.GetRole(entry.RoleId);
if (role == null)
{
await ReplyErrorLocalized("shop_role_not_found").ConfigureAwait(false);
return;
}
if (await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
{
try
{
await guser.AddRolesAsync(role).ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn(ex);
await CurrencyHandler.AddCurrencyAsync(Context.User.Id, $"Shop error refund", entry.Price);
await ReplyErrorLocalized("shop_role_purchase_error").ConfigureAwait(false);
return;
}
await CurrencyHandler.AddCurrencyAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", GetProfitAmount(entry.Price));
await ReplyConfirmLocalized("shop_role_purchase", Format.Bold(role.Name)).ConfigureAwait(false);
return;
}
else
{
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
return;
}
}
else if (entry.Type == ShopEntryType.List)
{
if (entry.Items.Count == 0)
{
await ReplyErrorLocalized("out_of_stock").ConfigureAwait(false);
return;
}
var item = entry.Items.ToArray()[new NadekoRandom().Next(0, entry.Items.Count)];
if (await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
{
int removed;
using (var uow = DbHandler.UnitOfWork())
{
var x = uow._context.Set<ShopEntryItem>().Remove(item);
removed = uow.Complete();
}
_log.Warn($"Removed {removed} items");
try
{
await (await Context.User.CreateDMChannelAsync())
.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithTitle(GetText("shop_purchase", Context.Guild.Name))
.AddField(efb => efb.WithName(GetText("item")).WithValue(item.Text).WithIsInline(false))
.AddField(efb => efb.WithName(GetText("price")).WithValue(entry.Price.ToString()).WithIsInline(true))
.AddField(efb => efb.WithName(GetText("name")).WithValue(entry.Name).WithIsInline(true)))
.ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync(Context.User.Id,
$"Shop error refund - {entry.Name}",
GetProfitAmount(entry.Price)).ConfigureAwait(false);
}
catch
{
using (var uow = DbHandler.UnitOfWork())
{
uow._context.Set<ShopEntryItem>().Add(item);
uow.Complete();
await CurrencyHandler.AddCurrencyAsync(Context.User.Id,
$"Shop error refund - {entry.Name}",
entry.Price,
uow).ConfigureAwait(false);
}
await ReplyErrorLocalized("shop_buy_error").ConfigureAwait(false);
return;
}
await ReplyConfirmLocalized("shop_item_purchase").ConfigureAwait(false);
}
else
{
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
return;
}
}
}
private long GetProfitAmount(int price) =>
(int)(Math.Ceiling(0.90 * price));
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
[RequireBotPermission(GuildPermission.ManageRoles)]
public async Task ShopAdd(Role _, int price, [Remainder] IRole role)
{
var entry = new ShopEntry()
{
Name = "-",
Price = price,
Type = ShopEntryType.Role,
AuthorId = Context.User.Id,
RoleId = role.Id,
RoleName = role.Name
};
using (var uow = DbHandler.UnitOfWork())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries);
entries.Add(entry);
uow.GuildConfigs.For(Context.Guild.Id, set => set).ShopEntries = entries;
uow.Complete();
}
await Context.Channel.EmbedAsync(EntryToEmbed(entry)
.WithTitle(GetText("shop_item_add")));
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
public async Task ShopAdd(List _, int price, [Remainder]string name)
{
var entry = new ShopEntry()
{
Name = name.TrimTo(100),
Price = price,
Type = ShopEntryType.List,
AuthorId = Context.User.Id,
Items = new HashSet<ShopEntryItem>(),
};
using (var uow = DbHandler.UnitOfWork())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries);
entries.Add(entry);
uow.GuildConfigs.For(Context.Guild.Id, set => set).ShopEntries = entries;
uow.Complete();
}
await Context.Channel.EmbedAsync(EntryToEmbed(entry)
.WithTitle(GetText("shop_item_add")));
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
public async Task ShopListAdd(int index, [Remainder] string itemText)
{
index -= 1;
if (index < 0)
return;
var item = new ShopEntryItem()
{
Text = itemText
};
ShopEntry entry;
bool rightType = false;
bool added = false;
using (var uow = DbHandler.UnitOfWork())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries);
entry = entries.ElementAtOrDefault(index);
if (entry != null && (rightType = (entry.Type == ShopEntryType.List)))
{
if (added = entry.Items.Add(item))
{
uow.Complete();
}
}
}
if (entry == null)
await ReplyErrorLocalized("shop_item_not_found").ConfigureAwait(false);
else if (!rightType)
await ReplyErrorLocalized("shop_item_wrong_type").ConfigureAwait(false);
else if (added == false)
await ReplyErrorLocalized("shop_list_item_not_unique").ConfigureAwait(false);
else
await ReplyConfirmLocalized("shop_list_item_added").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
public async Task ShopRemove(int index)
{
index -= 1;
if (index < 0)
return;
ShopEntry removed;
using (var uow = DbHandler.UnitOfWork())
{
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set
.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items));
var entries = new IndexedCollection<ShopEntry>(config.ShopEntries);
removed = entries.ElementAtOrDefault(index);
if (removed != null)
{
entries.Remove(removed);
config.ShopEntries = entries;
uow.Complete();
}
}
if (removed == null)
await ReplyErrorLocalized("shop_item_not_found").ConfigureAwait(false);
else
await Context.Channel.EmbedAsync(EntryToEmbed(removed)
.WithTitle(GetText("shop_item_rm")));
}
public EmbedBuilder EntryToEmbed(ShopEntry entry)
{
var embed = new EmbedBuilder().WithOkColor();
if (entry.Type == ShopEntryType.Role)
return embed.AddField(efb => efb.WithName(GetText("name")).WithValue(GetText("shop_role", Format.Bold(entry.RoleName))).WithIsInline(true))
.AddField(efb => efb.WithName(GetText("price")).WithValue(entry.Price.ToString()).WithIsInline(true))
.AddField(efb => efb.WithName(GetText("type")).WithValue(entry.Type.ToString()).WithIsInline(true));
else if (entry.Type == ShopEntryType.List)
return embed.AddField(efb => efb.WithName(GetText("name")).WithValue(entry.Name).WithIsInline(true))
.AddField(efb => efb.WithName(GetText("price")).WithValue(entry.Price.ToString()).WithIsInline(true))
.AddField(efb => efb.WithName(GetText("type")).WithValue(GetText("random_unique_item")).WithIsInline(true));
//else if (entry.Type == ShopEntryType.Infinite_List)
// return embed.AddField(efb => efb.WithName(GetText("name")).WithValue(GetText("shop_role", Format.Bold(entry.RoleName))).WithIsInline(true))
// .AddField(efb => efb.WithName(GetText("price")).WithValue(entry.Price.ToString()).WithIsInline(true))
// .AddField(efb => efb.WithName(GetText("type")).WithValue(entry.Type.ToString()).WithIsInline(true));
else return null;
}
public string EntryToString(ShopEntry entry)
{
if (entry.Type == ShopEntryType.Role)
{
return GetText("shop_role", Format.Bold(entry.RoleName));
}
else if (entry.Type == ShopEntryType.List)
{
return GetText("unique_items_left", entry.Items.Count) + "\n" + entry.Name;
}
//else if (entry.Type == ShopEntryType.Infinite_List)
//{
//}
return "";
}
}
}
}

View File

@ -1031,6 +1031,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to buy.
/// </summary>
public static string buy_cmd {
get {
return ResourceManager.GetString("buy_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Buys an item from the shop on a given index. If buying items, make sure that the bot can DM you..
/// </summary>
public static string buy_desc {
get {
return ResourceManager.GetString("buy_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}buy 2`.
/// </summary>
public static string buy_usage {
get {
return ResourceManager.GetString("buy_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to bye.
/// </summary>
@ -1716,7 +1743,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to Claim patreon rewards. If you&apos;re subscribed to bot owner&apos;s patreon you can user this command to claim your rewards - assuming bot owner did setup has their patreon key..
/// Looks up a localized string similar to Claim patreon rewards. If you&apos;re subscribed to bot owner&apos;s patreon you can use this command to claim your rewards - assuming bot owner did setup has their patreon key..
/// </summary>
public static string claimpatreonrewards_desc {
get {
@ -2103,7 +2130,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to `{0}crad 44`.
/// Looks up a localized string similar to `{0}crdm 44`.
/// </summary>
public static string crdm_usage {
get {
@ -4173,7 +4200,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to `{0}liqu` or `{0}liqu 3`.
/// Looks up a localized string similar to Lists all quotes on the server ordered alphabetically. 15 Per page..
/// </summary>
public static string listquotes_desc {
get {
@ -4182,7 +4209,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to Lists all quotes on the server ordered alphabetically. 15 Per page..
/// Looks up a localized string similar to `{0}liqu` or `{0}liqu 3`.
/// </summary>
public static string listquotes_usage {
get {
@ -5297,6 +5324,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to parewrel.
/// </summary>
public static string patreonrewardsreload_cmd {
get {
return ResourceManager.GetString("patreonrewardsreload_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Forces the update of the list of patrons who are eligible for the reward..
/// </summary>
public static string patreonrewardsreload_desc {
get {
return ResourceManager.GetString("patreonrewardsreload_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}parewrel`.
/// </summary>
public static string patreonrewardsreload_usage {
get {
return ResourceManager.GetString("patreonrewardsreload_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to pause p.
/// </summary>
@ -7511,6 +7565,114 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to shop.
/// </summary>
public static string shop_cmd {
get {
return ResourceManager.GetString("shop_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lists this server&apos;s administrators&apos; shop. Paginated..
/// </summary>
public static string shop_desc {
get {
return ResourceManager.GetString("shop_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}shop` or `{0}shop 2`.
/// </summary>
public static string shop_usage {
get {
return ResourceManager.GetString("shop_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to shopadd.
/// </summary>
public static string shopadd_cmd {
get {
return ResourceManager.GetString("shopadd_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Adds an item to the shop by specifying type price and name. Available types are role and list..
/// </summary>
public static string shopadd_desc {
get {
return ResourceManager.GetString("shopadd_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}shopadd role 1000 Rich`.
/// </summary>
public static string shopadd_usage {
get {
return ResourceManager.GetString("shopadd_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to shoplistadd.
/// </summary>
public static string shoplistadd_cmd {
get {
return ResourceManager.GetString("shoplistadd_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Adds an item to the list of items for sale in the shop entry given the index..
/// </summary>
public static string shoplistadd_desc {
get {
return ResourceManager.GetString("shoplistadd_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}shoplistadd 1 Uni-que-Steam-Key`.
/// </summary>
public static string shoplistadd_usage {
get {
return ResourceManager.GetString("shoplistadd_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to shoprem shoprm.
/// </summary>
public static string shopremove_cmd {
get {
return ResourceManager.GetString("shopremove_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Removes an item from the shop by its color..
/// </summary>
public static string shopremove_desc {
get {
return ResourceManager.GetString("shopremove_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}shoprm 1`.
/// </summary>
public static string shopremove_usage {
get {
return ResourceManager.GetString("shopremove_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to shorten.
/// </summary>

View File

@ -3379,7 +3379,7 @@
<value>shopadd</value>
</data>
<data name="shopadd_desc" xml:space="preserve">
<value>Adds an item to the shop by specifying type price and name.</value>
<value>Adds an item to the shop by specifying type price and name. Available types are role and list.</value>
</data>
<data name="shopadd_usage" xml:space="preserve">
<value>`{0}shopadd role 1000 Rich`</value>
@ -3408,4 +3408,25 @@
<data name="rolehoist_usage" xml:space="preserve">
<value>`{0}rh Guests true` or `{0}rh "Space Wizards" true</value>
</data>
<data name="buy_cmd" xml:space="preserve">
<value>buy</value>
</data>
<data name="buy_desc" xml:space="preserve">
<value>Buys an item from the shop on a given index. If buying items, make sure that the bot can DM you.</value>
</data>
<data name="buy_usage" xml:space="preserve">
<value>`{0}buy 2`</value>
</data>
<data name="shoplistadd_cmd" xml:space="preserve">
<value>shoplistadd</value>
</data>
<data name="shoplistadd_desc" xml:space="preserve">
<value>Adds an item to the list of items for sale in the shop entry given the index.</value>
</data>
<data name="shoplistadd_usage" xml:space="preserve">
<value>`{0}shoplistadd 1 Uni-que-Steam-Key`</value>
</data>
<data name="shopremove_usage" xml:space="preserve">
<value>`{0}shoprm 1`</value>
</data>
</root>

View File

@ -2719,6 +2719,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Item.
/// </summary>
public static string gambling_item {
get {
return ResourceManager.GetString("gambling_item", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Leaderboard.
/// </summary>
@ -2764,6 +2773,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Name.
/// </summary>
public static string gambling_name {
get {
return ResourceManager.GetString("gambling_name", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No more cards in the deck..
/// </summary>
@ -2800,6 +2818,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Out of stock..
/// </summary>
public static string gambling_out_of_stock {
get {
return ResourceManager.GetString("gambling_out_of_stock", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to page {0}.
/// </summary>
@ -2845,6 +2872,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Random unique item..
/// </summary>
public static string gambling_random_unique_item {
get {
return ResourceManager.GetString("gambling_random_unique_item", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You rolled {0}..
/// </summary>
@ -2863,6 +2899,141 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Shop.
/// </summary>
public static string gambling_shop {
get {
return ResourceManager.GetString("gambling_shop", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error DMing item. You&apos;ve been refunded..
/// </summary>
public static string gambling_shop_buy_error {
get {
return ResourceManager.GetString("gambling_shop_buy_error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Shop item added.
/// </summary>
public static string gambling_shop_item_add {
get {
return ResourceManager.GetString("gambling_shop_item_add", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No item on that index found..
/// </summary>
public static string gambling_shop_item_not_found {
get {
return ResourceManager.GetString("gambling_shop_item_not_found", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Item purchase successful..
/// </summary>
public static string gambling_shop_item_purchase {
get {
return ResourceManager.GetString("gambling_shop_item_purchase", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Shop item removed.
/// </summary>
public static string gambling_shop_item_rm {
get {
return ResourceManager.GetString("gambling_shop_item_rm", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to That shop entry does not support item adding..
/// </summary>
public static string gambling_shop_item_wrong_type {
get {
return ResourceManager.GetString("gambling_shop_item_wrong_type", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Item successfully added..
/// </summary>
public static string gambling_shop_list_item_added {
get {
return ResourceManager.GetString("gambling_shop_list_item_added", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to That item is already added..
/// </summary>
public static string gambling_shop_list_item_not_unique {
get {
return ResourceManager.GetString("gambling_shop_list_item_not_unique", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No shop items found on this page..
/// </summary>
public static string gambling_shop_none {
get {
return ResourceManager.GetString("gambling_shop_none", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Purchase on {0} server.
/// </summary>
public static string gambling_shop_purchase {
get {
return ResourceManager.GetString("gambling_shop_purchase", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You will get {0} role..
/// </summary>
public static string gambling_shop_role {
get {
return ResourceManager.GetString("gambling_shop_role", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Role which is being sold no longer exists..
/// </summary>
public static string gambling_shop_role_not_found {
get {
return ResourceManager.GetString("gambling_shop_role_not_found", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You&apos;ve successfully purchased {0} role..
/// </summary>
public static string gambling_shop_role_purchase {
get {
return ResourceManager.GetString("gambling_shop_role_purchase", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error assigning role. Your purchase has been refunded..
/// </summary>
public static string gambling_shop_role_purchase_error {
get {
return ResourceManager.GetString("gambling_shop_role_purchase_error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Bet.
/// </summary>
@ -2981,6 +3152,24 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Type.
/// </summary>
public static string gambling_type {
get {
return ResourceManager.GetString("gambling_type", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} unique items left..
/// </summary>
public static string gambling_unique_items_left {
get {
return ResourceManager.GetString("gambling_unique_items_left", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to your affinity is already set to that waifu or you&apos;re trying to remove your affinity while not having one..
/// </summary>
@ -6124,6 +6313,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Next update in {0}.
/// </summary>
public static string utility_clpa_next_update {
get {
return ResourceManager.GetString("utility_clpa_next_update", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You&apos;ve received {0} Thanks for supporting the project!.
/// </summary>

View File

@ -2409,4 +2409,71 @@ Owner ID: {2}</value>
<data name="administration_rh" xml:space="preserve">
<value>Set the display of guild role {0} to {1}.</value>
</data>
<data name="gambling_name" xml:space="preserve">
<value>Name</value>
</data>
<data name="gambling_shop" xml:space="preserve">
<value>Shop</value>
</data>
<data name="gambling_shop_item_add" xml:space="preserve">
<value>Shop item added</value>
</data>
<data name="gambling_shop_none" xml:space="preserve">
<value>No shop items found on this page.</value>
</data>
<data name="gambling_shop_role" xml:space="preserve">
<value>You will get {0} role.</value>
</data>
<data name="gambling_type" xml:space="preserve">
<value>Type</value>
</data>
<data name="utility_clpa_next_update" xml:space="preserve">
<value>Next update in {0}</value>
<comment>Next update in 05:30</comment>
</data>
<data name="gambling_item" xml:space="preserve">
<value>Item</value>
</data>
<data name="gambling_out_of_stock" xml:space="preserve">
<value>Out of stock.</value>
</data>
<data name="gambling_random_unique_item" xml:space="preserve">
<value>Random unique item.</value>
</data>
<data name="gambling_shop_buy_error" xml:space="preserve">
<value>Error DMing item. You've been refunded.</value>
</data>
<data name="gambling_shop_item_not_found" xml:space="preserve">
<value>No item on that index found.</value>
</data>
<data name="gambling_shop_item_purchase" xml:space="preserve">
<value>Item purchase successful.</value>
</data>
<data name="gambling_shop_item_rm" xml:space="preserve">
<value>Shop item removed</value>
</data>
<data name="gambling_shop_item_wrong_type" xml:space="preserve">
<value>That shop entry does not support item adding.</value>
</data>
<data name="gambling_shop_list_item_added" xml:space="preserve">
<value>Item successfully added.</value>
</data>
<data name="gambling_shop_list_item_not_unique" xml:space="preserve">
<value>That item is already added.</value>
</data>
<data name="gambling_shop_purchase" xml:space="preserve">
<value>Purchase on {0} server</value>
</data>
<data name="gambling_shop_role_not_found" xml:space="preserve">
<value>Role which is being sold no longer exists.</value>
</data>
<data name="gambling_shop_role_purchase" xml:space="preserve">
<value>You've successfully purchased {0} role.</value>
</data>
<data name="gambling_shop_role_purchase_error" xml:space="preserve">
<value>Error assigning role. Your purchase has been refunded.</value>
</data>
<data name="gambling_unique_items_left" xml:space="preserve">
<value>{0} unique items left.</value>
</data>
</root>

View File

@ -76,6 +76,8 @@ namespace NadekoBot.Services.Database.Models
public HashSet<SlowmodeIgnoredUser> SlowmodeIgnoredUsers { get; set; }
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
public List<ShopEntry> ShopEntries { get; set; }
//public List<ProtectionIgnoredChannel> ProtectionIgnoredChannels { get; set; } = new List<ProtectionIgnoredChannel>();
}

View File

@ -0,0 +1,45 @@
using System.Collections.Generic;
namespace NadekoBot.Services.Database.Models
{
public enum ShopEntryType
{
Role,
List,
//Infinite_List,
}
public class ShopEntry : DbEntity, IIndexed
{
public int Index { get; set; }
public int Price { get; set; }
public string Name { get; set; }
public ulong AuthorId { get; set; }
public ShopEntryType Type { get; set; }
//role
public string RoleName { get; set; }
public ulong RoleId { get; set; }
//list
public HashSet<ShopEntryItem> Items { get; set; } = new HashSet<ShopEntryItem>();
}
public class ShopEntryItem : DbEntity
{
public string Text { get; set; }
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
return ((ShopEntryItem)obj).Text == Text;
}
public override int GetHashCode() =>
Text.GetHashCode();
}
}