diff --git a/src/NadekoBot/DataStructures/IndexedCollection.cs b/src/NadekoBot/DataStructures/IndexedCollection.cs new file mode 100644 index 00000000..72b4f343 --- /dev/null +++ b/src/NadekoBot/DataStructures/IndexedCollection.cs @@ -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 : IList where T : IIndexed + { + public List Source { get; } + private readonly object _locker = new object(); + + public IndexedCollection(IEnumerable 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(IndexedCollection x) => + x.Source; + + public IEnumerator 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; + } + } + } + } + +} diff --git a/src/NadekoBot/DataStructures/PermissionsCollection.cs b/src/NadekoBot/DataStructures/PermissionsCollection.cs index e7963e64..484c4f9d 100644 --- a/src/NadekoBot/DataStructures/PermissionsCollection.cs +++ b/src/NadekoBot/DataStructures/PermissionsCollection.cs @@ -6,132 +6,67 @@ using NadekoBot.Services.Database.Models; namespace NadekoBot.DataStructures { - public class PermissionsCollection : IList where T : IIndexed + public class PermissionsCollection : IndexedCollection where T : IIndexed { - public List Source { get; } - private readonly object _locker = new object(); - - public PermissionsCollection(IEnumerable source) + private readonly object _localLocker = new object(); + public PermissionsCollection(IEnumerable 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(PermissionsCollection x) => x.Source; - public IEnumerator 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; } } } diff --git a/src/NadekoBot/Migrations/20170405161814_flower-shop.Designer.cs b/src/NadekoBot/Migrations/20170405161814_flower-shop.Designer.cs new file mode 100644 index 00000000..5acf9f8e --- /dev/null +++ b/src/NadekoBot/Migrations/20170405161814_flower-shop.Designer.cs @@ -0,0 +1,1518 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using NadekoBot.Services.Database; +using NadekoBot.Services.Database.Models; +using NadekoBot.Modules.Music.Classes; + +namespace NadekoBot.Migrations +{ + [DbContext(typeof(NadekoContext))] + [Migration("20170405161814_flower-shop")] + partial class flowershop + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.0-rtm-22752"); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.AntiRaidSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Action"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Seconds"); + + b.Property("UserThreshold"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId") + .IsUnique(); + + b.ToTable("AntiRaidSetting"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.AntiSpamIgnore", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AntiSpamSettingId"); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.HasKey("Id"); + + b.HasIndex("AntiSpamSettingId"); + + b.ToTable("AntiSpamIgnore"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.AntiSpamSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Action"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("MessageThreshold"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId") + .IsUnique(); + + b.ToTable("AntiSpamSetting"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("DateAdded"); + + b.Property("ItemId"); + + b.Property("Type"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("BlacklistItem"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BetflipMultiplier"); + + b.Property("Betroll100Multiplier"); + + b.Property("Betroll67Multiplier"); + + b.Property("Betroll91Multiplier"); + + b.Property("BufferSize"); + + b.Property("CurrencyDropAmount"); + + b.Property("CurrencyGenerationChance"); + + b.Property("CurrencyGenerationCooldown"); + + b.Property("CurrencyName"); + + b.Property("CurrencyPluralName"); + + b.Property("CurrencySign"); + + b.Property("DMHelpString"); + + b.Property("DateAdded"); + + b.Property("ErrorColor"); + + b.Property("ForwardMessages"); + + b.Property("ForwardToAllOwners"); + + b.Property("HelpString"); + + b.Property("Locale"); + + b.Property("MigrationVersion"); + + b.Property("MinimumBetAmount"); + + b.Property("OkColor"); + + b.Property("RemindMessageFormat"); + + b.Property("RotatingStatuses"); + + b.Property("TriviaCurrencyReward"); + + b.HasKey("Id"); + + b.ToTable("BotConfig"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BaseDestroyed"); + + b.Property("CallUser"); + + b.Property("ClashWarId"); + + b.Property("DateAdded"); + + b.Property("SequenceNumber"); + + b.Property("Stars"); + + b.Property("TimeAdded"); + + b.HasKey("Id"); + + b.HasIndex("ClashWarId"); + + b.ToTable("ClashCallers"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashWar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("EnemyClan"); + + b.Property("GuildId"); + + b.Property("Size"); + + b.Property("StartedAt"); + + b.Property("WarState"); + + b.HasKey("Id"); + + b.ToTable("ClashOfClans"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandAlias", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Mapping"); + + b.Property("Trigger"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("CommandAlias"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandCooldown", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CommandName"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Seconds"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("CommandCooldown"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandPrice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("CommandName"); + + b.Property("DateAdded"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.HasIndex("Price") + .IsUnique(); + + b.ToTable("CommandPrice"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("InternalTrigger"); + + b.Property("Modifier"); + + b.Property("UnitType"); + + b.HasKey("Id"); + + b.ToTable("ConversionUnits"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("DateAdded"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Currency"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CurrencyTransaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("DateAdded"); + + b.Property("Reason"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.ToTable("CurrencyTransactions"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CustomReaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AutoDeleteTrigger"); + + b.Property("DateAdded"); + + b.Property("DmResponse"); + + b.Property("GuildId"); + + b.Property("IsRegex"); + + b.Property("OwnerOnly"); + + b.Property("Response"); + + b.Property("Trigger"); + + b.HasKey("Id"); + + b.ToTable("CustomReactions"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.DiscordUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AvatarId"); + + b.Property("DateAdded"); + + b.Property("Discriminator"); + + b.Property("UserId"); + + b.Property("Username"); + + b.HasKey("Id"); + + b.HasAlternateKey("UserId"); + + b.ToTable("DiscordUser"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("DateAdded"); + + b.Property("Name"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Donators"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("DateAdded"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("EightBallResponses"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FilterChannelId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("GuildConfigId1"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.HasIndex("GuildConfigId1"); + + b.ToTable("FilterChannelId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FilteredWord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Word"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("FilteredWord"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("GuildId"); + + b.Property("Type"); + + b.Property("Username"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("FollowedStream"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GCChannelId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("GCChannelId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AutoAssignRoleId"); + + b.Property("AutoDeleteByeMessages"); + + b.Property("AutoDeleteByeMessagesTimer"); + + b.Property("AutoDeleteGreetMessages"); + + b.Property("AutoDeleteGreetMessagesTimer"); + + b.Property("AutoDeleteSelfAssignedRoleMessages"); + + b.Property("ByeMessageChannelId"); + + b.Property("ChannelByeMessageText"); + + b.Property("ChannelGreetMessageText"); + + b.Property("CleverbotEnabled"); + + b.Property("DateAdded"); + + b.Property("DefaultMusicVolume"); + + b.Property("DeleteMessageOnCommand"); + + b.Property("DmGreetMessageText"); + + b.Property("ExclusiveSelfAssignedRoles"); + + b.Property("FilterInvites"); + + b.Property("FilterWords"); + + b.Property("GreetMessageChannelId"); + + b.Property("GuildId"); + + b.Property("Locale"); + + b.Property("LogSettingId"); + + b.Property("MuteRoleName"); + + b.Property("PermissionRole"); + + b.Property("RootPermissionId"); + + b.Property("SendChannelByeMessage"); + + b.Property("SendChannelGreetMessage"); + + b.Property("SendDmGreetMessage"); + + b.Property("TimeZoneId"); + + b.Property("VerbosePermissions"); + + b.Property("VoicePlusTextEnabled"); + + b.Property("WarningsInitialized"); + + b.HasKey("Id"); + + b.HasIndex("GuildId") + .IsUnique(); + + b.HasIndex("LogSettingId"); + + b.HasIndex("RootPermissionId"); + + b.ToTable("GuildConfigs"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildRepeater", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("GuildId"); + + b.Property("Interval"); + + b.Property("Message"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("GuildRepeater"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("LogSettingId"); + + b.HasKey("Id"); + + b.HasIndex("LogSettingId"); + + b.ToTable("IgnoredLogChannels"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("LogSettingId"); + + b.HasKey("Id"); + + b.HasIndex("LogSettingId"); + + b.ToTable("IgnoredVoicePresenceCHannels"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelCreated"); + + b.Property("ChannelCreatedId"); + + b.Property("ChannelDestroyed"); + + b.Property("ChannelDestroyedId"); + + b.Property("ChannelId"); + + b.Property("ChannelUpdated"); + + b.Property("ChannelUpdatedId"); + + b.Property("DateAdded"); + + b.Property("IsLogging"); + + b.Property("LogOtherId"); + + b.Property("LogUserPresence"); + + b.Property("LogUserPresenceId"); + + b.Property("LogVoicePresence"); + + b.Property("LogVoicePresenceId"); + + b.Property("LogVoicePresenceTTSId"); + + b.Property("MessageDeleted"); + + b.Property("MessageDeletedId"); + + b.Property("MessageUpdated"); + + b.Property("MessageUpdatedId"); + + b.Property("UserBanned"); + + b.Property("UserBannedId"); + + b.Property("UserJoined"); + + b.Property("UserJoinedId"); + + b.Property("UserLeft"); + + b.Property("UserLeftId"); + + b.Property("UserMutedId"); + + b.Property("UserPresenceChannelId"); + + b.Property("UserUnbanned"); + + b.Property("UserUnbannedId"); + + b.Property("UserUpdated"); + + b.Property("UserUpdatedId"); + + b.Property("VoicePresenceChannelId"); + + b.HasKey("Id"); + + b.ToTable("LogSettings"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("DateAdded"); + + b.Property("ModuleName"); + + b.Property("Prefix"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("ModulePrefixes"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.MusicPlaylist", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Author"); + + b.Property("AuthorId"); + + b.Property("DateAdded"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("MusicPlaylists"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.MutedUserId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("MutedUserId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("NextId"); + + b.Property("PrimaryTarget"); + + b.Property("PrimaryTargetId"); + + b.Property("SecondaryTarget"); + + b.Property("SecondaryTargetName"); + + b.Property("State"); + + b.HasKey("Id"); + + b.HasIndex("NextId") + .IsUnique(); + + b.ToTable("Permission"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permissionv2", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Index"); + + b.Property("PrimaryTarget"); + + b.Property("PrimaryTargetId"); + + b.Property("SecondaryTarget"); + + b.Property("SecondaryTargetName"); + + b.Property("State"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("Permissionv2"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("DateAdded"); + + b.Property("Status"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("PlayingStatus"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlaylistSong", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("MusicPlaylistId"); + + b.Property("Provider"); + + b.Property("ProviderType"); + + b.Property("Query"); + + b.Property("Title"); + + b.Property("Uri"); + + b.HasKey("Id"); + + b.HasIndex("MusicPlaylistId"); + + b.ToTable("PlaylistSong"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("AuthorName") + .IsRequired(); + + b.Property("DateAdded"); + + b.Property("GuildId"); + + b.Property("Keyword") + .IsRequired(); + + b.Property("Text") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("Quotes"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("DateAdded"); + + b.Property("Icon"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("RaceAnimals"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("DateAdded"); + + b.Property("IsPrivate"); + + b.Property("Message"); + + b.Property("ServerId"); + + b.Property("UserId"); + + b.Property("When"); + + b.HasKey("Id"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RewardedUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AmountRewardedThisMonth"); + + b.Property("DateAdded"); + + b.Property("LastReward"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("RewardedUsers"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildId"); + + b.Property("RoleId"); + + b.HasKey("Id"); + + b.HasIndex("GuildId", "RoleId") + .IsUnique(); + + b.ToTable("SelfAssignableRoles"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Index"); + + b.Property("Name"); + + b.Property("Price"); + + b.Property("RoleId"); + + b.Property("RoleName"); + + b.Property("Type"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("ShopEntry"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntryItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("ShopEntryId"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.HasIndex("ShopEntryId"); + + b.ToTable("ShopEntryItem"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("RoleId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("SlowmodeIgnoredRole"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("SlowmodeIgnoredUser"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.StartupCommand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ChannelId"); + + b.Property("ChannelName"); + + b.Property("CommandText"); + + b.Property("DateAdded"); + + b.Property("GuildId"); + + b.Property("GuildName"); + + b.Property("Index"); + + b.Property("VoiceChannelId"); + + b.Property("VoiceChannelName"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("StartupCommand"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.UnmuteTimer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("UnmuteAt"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("UnmuteTimer"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.UserPokeTypes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("UserId"); + + b.Property("type"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("PokeGame"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.VcRoleInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("RoleId"); + + b.Property("VoiceChannelId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("VcRoleInfo"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.WaifuInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AffinityId"); + + b.Property("ClaimerId"); + + b.Property("DateAdded"); + + b.Property("Price"); + + b.Property("WaifuId"); + + b.HasKey("Id"); + + b.HasIndex("AffinityId"); + + b.HasIndex("ClaimerId"); + + b.HasIndex("WaifuId") + .IsUnique(); + + b.ToTable("WaifuInfo"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.WaifuUpdate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("NewId"); + + b.Property("OldId"); + + b.Property("UpdateType"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("NewId"); + + b.HasIndex("OldId"); + + b.HasIndex("UserId"); + + b.ToTable("WaifuUpdates"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Warning", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("Forgiven"); + + b.Property("ForgivenBy"); + + b.Property("GuildId"); + + b.Property("Moderator"); + + b.Property("Reason"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.ToTable("Warnings"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.WarningPunishment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Count"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Punishment"); + + b.Property("Time"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("WarningPunishment"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.AntiRaidSetting", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig", "GuildConfig") + .WithOne("AntiRaidSetting") + .HasForeignKey("NadekoBot.Services.Database.Models.AntiRaidSetting", "GuildConfigId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.AntiSpamIgnore", b => + { + b.HasOne("NadekoBot.Services.Database.Models.AntiSpamSetting") + .WithMany("IgnoredChannels") + .HasForeignKey("AntiSpamSettingId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.AntiSpamSetting", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig", "GuildConfig") + .WithOne("AntiSpamSetting") + .HasForeignKey("NadekoBot.Services.Database.Models.AntiSpamSetting", "GuildConfigId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("Blacklist") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => + { + b.HasOne("NadekoBot.Services.Database.Models.ClashWar", "ClashWar") + .WithMany("Bases") + .HasForeignKey("ClashWarId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandAlias", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("CommandAliases") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandCooldown", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("CommandCooldowns") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandPrice", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("CommandPrices") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("EightBallResponses") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FilterChannelId", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FilterInvitesChannelIds") + .HasForeignKey("GuildConfigId"); + + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FilterWordsChannelIds") + .HasForeignKey("GuildConfigId1"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FilteredWord", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FilteredWords") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FollowedStreams") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GCChannelId", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("GenerateCurrencyChannelIds") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany() + .HasForeignKey("LogSettingId"); + + b.HasOne("NadekoBot.Services.Database.Models.Permission", "RootPermission") + .WithMany() + .HasForeignKey("RootPermissionId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildRepeater", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("GuildRepeaters") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany("IgnoredChannels") + .HasForeignKey("LogSettingId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany("IgnoredVoicePresenceChannelIds") + .HasForeignKey("LogSettingId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("ModulePrefixes") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.MutedUserId", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("MutedUsers") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.HasOne("NadekoBot.Services.Database.Models.Permission", "Next") + .WithOne("Previous") + .HasForeignKey("NadekoBot.Services.Database.Models.Permission", "NextId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permissionv2", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("Permissions") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("RotatingStatusMessages") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlaylistSong", b => + { + b.HasOne("NadekoBot.Services.Database.Models.MusicPlaylist") + .WithMany("Songs") + .HasForeignKey("MusicPlaylistId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("RaceAnimals") + .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") + .WithMany("SlowmodeIgnoredRoles") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredUser", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("SlowmodeIgnoredUsers") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.StartupCommand", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("StartupCommands") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.UnmuteTimer", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("UnmuteTimers") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.VcRoleInfo", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("VcRoleInfos") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.WaifuInfo", b => + { + b.HasOne("NadekoBot.Services.Database.Models.DiscordUser", "Affinity") + .WithMany() + .HasForeignKey("AffinityId"); + + b.HasOne("NadekoBot.Services.Database.Models.DiscordUser", "Claimer") + .WithMany() + .HasForeignKey("ClaimerId"); + + b.HasOne("NadekoBot.Services.Database.Models.DiscordUser", "Waifu") + .WithOne() + .HasForeignKey("NadekoBot.Services.Database.Models.WaifuInfo", "WaifuId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.WaifuUpdate", b => + { + b.HasOne("NadekoBot.Services.Database.Models.DiscordUser", "New") + .WithMany() + .HasForeignKey("NewId"); + + b.HasOne("NadekoBot.Services.Database.Models.DiscordUser", "Old") + .WithMany() + .HasForeignKey("OldId"); + + b.HasOne("NadekoBot.Services.Database.Models.DiscordUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.WarningPunishment", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("WarnPunishments") + .HasForeignKey("GuildConfigId"); + }); + } + } +} diff --git a/src/NadekoBot/Migrations/20170405161814_flower-shop.cs b/src/NadekoBot/Migrations/20170405161814_flower-shop.cs new file mode 100644 index 00000000..7d0cde56 --- /dev/null +++ b/src/NadekoBot/Migrations/20170405161814_flower-shop.cs @@ -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(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + AuthorId = table.Column(nullable: false), + DateAdded = table.Column(nullable: true), + GuildConfigId = table.Column(nullable: true), + Index = table.Column(nullable: false), + Name = table.Column(nullable: true), + Price = table.Column(nullable: false), + RoleId = table.Column(nullable: false), + RoleName = table.Column(nullable: true), + Type = table.Column(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(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + DateAdded = table.Column(nullable: true), + ShopEntryId = table.Column(nullable: true), + Text = table.Column(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"); + } + } +} diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 303783e4..c255ba79 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -971,6 +971,54 @@ namespace NadekoBot.Migrations b.ToTable("SelfAssignableRoles"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("DateAdded"); + + b.Property("GuildConfigId"); + + b.Property("Index"); + + b.Property("Name"); + + b.Property("Price"); + + b.Property("RoleId"); + + b.Property("RoleName"); + + b.Property("Type"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("ShopEntry"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ShopEntryItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("ShopEntryId"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.HasIndex("ShopEntryId"); + + b.ToTable("ShopEntryItem"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredRole", b => { b.Property("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") diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs b/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs new file mode 100644 index 00000000..dbb268d8 --- /dev/null +++ b/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs @@ -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 entries; + using (var uow = DbHandler.UnitOfWork()) + { + entries = new IndexedCollection(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(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().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().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(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(), + }; + using (var uow = DbHandler.UnitOfWork()) + { + var entries = new IndexedCollection(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(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(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 ""; + } + } + } +} \ No newline at end of file diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index ef52ebd4..ff0aa011 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -1031,6 +1031,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to buy. + /// + public static string buy_cmd { + get { + return ResourceManager.GetString("buy_cmd", resourceCulture); + } + } + + /// + /// 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.. + /// + public static string buy_desc { + get { + return ResourceManager.GetString("buy_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}buy 2`. + /// + public static string buy_usage { + get { + return ResourceManager.GetString("buy_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to bye. /// @@ -1716,7 +1743,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Claim patreon rewards. If you're subscribed to bot owner'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're subscribed to bot owner's patreon you can use this command to claim your rewards - assuming bot owner did setup has their patreon key.. /// public static string claimpatreonrewards_desc { get { @@ -2103,7 +2130,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}crad 44`. + /// Looks up a localized string similar to `{0}crdm 44`. /// public static string crdm_usage { get { @@ -4173,7 +4200,7 @@ namespace NadekoBot.Resources { } /// - /// 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.. /// public static string listquotes_desc { get { @@ -4182,7 +4209,7 @@ namespace NadekoBot.Resources { } /// - /// 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`. /// public static string listquotes_usage { get { @@ -5297,6 +5324,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to parewrel. + /// + public static string patreonrewardsreload_cmd { + get { + return ResourceManager.GetString("patreonrewardsreload_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Forces the update of the list of patrons who are eligible for the reward.. + /// + public static string patreonrewardsreload_desc { + get { + return ResourceManager.GetString("patreonrewardsreload_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}parewrel`. + /// + public static string patreonrewardsreload_usage { + get { + return ResourceManager.GetString("patreonrewardsreload_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to pause p. /// @@ -7511,6 +7565,114 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to shop. + /// + public static string shop_cmd { + get { + return ResourceManager.GetString("shop_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lists this server's administrators' shop. Paginated.. + /// + public static string shop_desc { + get { + return ResourceManager.GetString("shop_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}shop` or `{0}shop 2`. + /// + public static string shop_usage { + get { + return ResourceManager.GetString("shop_usage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to shopadd. + /// + public static string shopadd_cmd { + get { + return ResourceManager.GetString("shopadd_cmd", resourceCulture); + } + } + + /// + /// 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.. + /// + public static string shopadd_desc { + get { + return ResourceManager.GetString("shopadd_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}shopadd role 1000 Rich`. + /// + public static string shopadd_usage { + get { + return ResourceManager.GetString("shopadd_usage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to shoplistadd. + /// + public static string shoplistadd_cmd { + get { + return ResourceManager.GetString("shoplistadd_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Adds an item to the list of items for sale in the shop entry given the index.. + /// + public static string shoplistadd_desc { + get { + return ResourceManager.GetString("shoplistadd_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}shoplistadd 1 Uni-que-Steam-Key`. + /// + public static string shoplistadd_usage { + get { + return ResourceManager.GetString("shoplistadd_usage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to shoprem shoprm. + /// + public static string shopremove_cmd { + get { + return ResourceManager.GetString("shopremove_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removes an item from the shop by its color.. + /// + public static string shopremove_desc { + get { + return ResourceManager.GetString("shopremove_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}shoprm 1`. + /// + public static string shopremove_usage { + get { + return ResourceManager.GetString("shopremove_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to shorten. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index f65de2fa..363b09af 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -3379,7 +3379,7 @@ shopadd - Adds an item to the shop by specifying type price and name. + Adds an item to the shop by specifying type price and name. Available types are role and list. `{0}shopadd role 1000 Rich` @@ -3408,4 +3408,25 @@ `{0}rh Guests true` or `{0}rh "Space Wizards" true + + buy + + + Buys an item from the shop on a given index. If buying items, make sure that the bot can DM you. + + + `{0}buy 2` + + + shoplistadd + + + Adds an item to the list of items for sale in the shop entry given the index. + + + `{0}shoplistadd 1 Uni-que-Steam-Key` + + + `{0}shoprm 1` + \ No newline at end of file diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 1836004a..52a31610 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -2719,6 +2719,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Item. + /// + public static string gambling_item { + get { + return ResourceManager.GetString("gambling_item", resourceCulture); + } + } + /// /// Looks up a localized string similar to Leaderboard. /// @@ -2764,6 +2773,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Name. + /// + public static string gambling_name { + get { + return ResourceManager.GetString("gambling_name", resourceCulture); + } + } + /// /// Looks up a localized string similar to No more cards in the deck.. /// @@ -2800,6 +2818,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Out of stock.. + /// + public static string gambling_out_of_stock { + get { + return ResourceManager.GetString("gambling_out_of_stock", resourceCulture); + } + } + /// /// Looks up a localized string similar to page {0}. /// @@ -2845,6 +2872,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Random unique item.. + /// + public static string gambling_random_unique_item { + get { + return ResourceManager.GetString("gambling_random_unique_item", resourceCulture); + } + } + /// /// Looks up a localized string similar to You rolled {0}.. /// @@ -2863,6 +2899,141 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Shop. + /// + public static string gambling_shop { + get { + return ResourceManager.GetString("gambling_shop", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error DMing item. You've been refunded.. + /// + public static string gambling_shop_buy_error { + get { + return ResourceManager.GetString("gambling_shop_buy_error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shop item added. + /// + public static string gambling_shop_item_add { + get { + return ResourceManager.GetString("gambling_shop_item_add", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No item on that index found.. + /// + public static string gambling_shop_item_not_found { + get { + return ResourceManager.GetString("gambling_shop_item_not_found", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Item purchase successful.. + /// + public static string gambling_shop_item_purchase { + get { + return ResourceManager.GetString("gambling_shop_item_purchase", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shop item removed. + /// + public static string gambling_shop_item_rm { + get { + return ResourceManager.GetString("gambling_shop_item_rm", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to That shop entry does not support item adding.. + /// + public static string gambling_shop_item_wrong_type { + get { + return ResourceManager.GetString("gambling_shop_item_wrong_type", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Item successfully added.. + /// + public static string gambling_shop_list_item_added { + get { + return ResourceManager.GetString("gambling_shop_list_item_added", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to That item is already added.. + /// + public static string gambling_shop_list_item_not_unique { + get { + return ResourceManager.GetString("gambling_shop_list_item_not_unique", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No shop items found on this page.. + /// + public static string gambling_shop_none { + get { + return ResourceManager.GetString("gambling_shop_none", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Purchase on {0} server. + /// + public static string gambling_shop_purchase { + get { + return ResourceManager.GetString("gambling_shop_purchase", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You will get {0} role.. + /// + public static string gambling_shop_role { + get { + return ResourceManager.GetString("gambling_shop_role", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Role which is being sold no longer exists.. + /// + public static string gambling_shop_role_not_found { + get { + return ResourceManager.GetString("gambling_shop_role_not_found", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You've successfully purchased {0} role.. + /// + public static string gambling_shop_role_purchase { + get { + return ResourceManager.GetString("gambling_shop_role_purchase", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error assigning role. Your purchase has been refunded.. + /// + public static string gambling_shop_role_purchase_error { + get { + return ResourceManager.GetString("gambling_shop_role_purchase_error", resourceCulture); + } + } + /// /// Looks up a localized string similar to Bet. /// @@ -2981,6 +3152,24 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Type. + /// + public static string gambling_type { + get { + return ResourceManager.GetString("gambling_type", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} unique items left.. + /// + public static string gambling_unique_items_left { + get { + return ResourceManager.GetString("gambling_unique_items_left", resourceCulture); + } + } + /// /// Looks up a localized string similar to your affinity is already set to that waifu or you're trying to remove your affinity while not having one.. /// @@ -6124,6 +6313,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Next update in {0}. + /// + public static string utility_clpa_next_update { + get { + return ResourceManager.GetString("utility_clpa_next_update", resourceCulture); + } + } + /// /// Looks up a localized string similar to You've received {0} Thanks for supporting the project!. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index e3de1903..8b8ed781 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -2409,4 +2409,71 @@ Owner ID: {2} Set the display of guild role {0} to {1}. + + Name + + + Shop + + + Shop item added + + + No shop items found on this page. + + + You will get {0} role. + + + Type + + + Next update in {0} + Next update in 05:30 + + + Item + + + Out of stock. + + + Random unique item. + + + Error DMing item. You've been refunded. + + + No item on that index found. + + + Item purchase successful. + + + Shop item removed + + + That shop entry does not support item adding. + + + Item successfully added. + + + That item is already added. + + + Purchase on {0} server + + + Role which is being sold no longer exists. + + + You've successfully purchased {0} role. + + + Error assigning role. Your purchase has been refunded. + + + {0} unique items left. + \ No newline at end of file diff --git a/src/NadekoBot/Services/Database/Models/GuildConfig.cs b/src/NadekoBot/Services/Database/Models/GuildConfig.cs index aaf7addf..e5a2c8b6 100644 --- a/src/NadekoBot/Services/Database/Models/GuildConfig.cs +++ b/src/NadekoBot/Services/Database/Models/GuildConfig.cs @@ -76,6 +76,8 @@ namespace NadekoBot.Services.Database.Models public HashSet SlowmodeIgnoredUsers { get; set; } public HashSet SlowmodeIgnoredRoles { get; set; } + public List ShopEntries { get; set; } + //public List ProtectionIgnoredChannels { get; set; } = new List(); } diff --git a/src/NadekoBot/Services/Database/Models/ShopEntry.cs b/src/NadekoBot/Services/Database/Models/ShopEntry.cs new file mode 100644 index 00000000..aaedbe00 --- /dev/null +++ b/src/NadekoBot/Services/Database/Models/ShopEntry.cs @@ -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 Items { get; set; } = new HashSet(); + } + + 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(); + } +}