From 40978c123d7849bd1756fa849339d708c1cde085 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 15 Oct 2016 14:12:35 +0200 Subject: [PATCH] Clash of clans works perfectly now, updated some strings and usages for it too --- .../Migrations/20161015102407_coc.Designer.cs | 777 ++++++++++++++++++ .../Migrations/20161015102407_coc.cs | 24 + .../NadekoSqliteContextModelSnapshot.cs | 2 + .../Modules/ClashOfClans/ClashOfClans.cs | 79 +- .../Modules/ClashOfClans/Extensions.cs | 38 +- .../Resources/CommandStrings.Designer.cs | 12 +- src/NadekoBot/Resources/CommandStrings.resx | 12 +- .../Services/Database/Models/ClashCaller.cs | 1 + .../Impl/ClashOfClansRepository.cs | 4 +- 9 files changed, 887 insertions(+), 62 deletions(-) create mode 100644 src/NadekoBot/Migrations/20161015102407_coc.Designer.cs create mode 100644 src/NadekoBot/Migrations/20161015102407_coc.cs diff --git a/src/NadekoBot/Migrations/20161015102407_coc.Designer.cs b/src/NadekoBot/Migrations/20161015102407_coc.Designer.cs new file mode 100644 index 00000000..f05d500c --- /dev/null +++ b/src/NadekoBot/Migrations/20161015102407_coc.Designer.cs @@ -0,0 +1,777 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using NadekoBot.Services.Database.Impl; + +namespace NadekoBot.Migrations +{ + [DbContext(typeof(NadekoSqliteContext))] + [Migration("20161015102407_coc")] + partial class coc + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.0-rtm-21431"); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + 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("BufferSize"); + + b.Property("CurrencyGenerationChance"); + + b.Property("CurrencyGenerationCooldown"); + + b.Property("CurrencyName"); + + b.Property("CurrencyPluralName"); + + b.Property("CurrencySign"); + + b.Property("DMHelpString"); + + b.Property("ForwardMessages"); + + b.Property("ForwardToAllOwners"); + + b.Property("HelpString"); + + b.Property("MigrationVersion"); + + b.Property("RemindMessageFormat"); + + b.Property("RotatingStatuses"); + + 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("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("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.CommandCooldown", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CommandName"); + + b.Property("GuildConfigId"); + + b.Property("Seconds"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("CommandCooldown"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + 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("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("Reason"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.ToTable("CurrencyTransactions"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CustomReaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + 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.Donator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + 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("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("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("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("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("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("AutoDeleteGreetMessages"); + + b.Property("AutoDeleteGreetMessagesTimer"); + + b.Property("AutoDeleteSelfAssignedRoleMessages"); + + b.Property("ByeMessageChannelId"); + + b.Property("ChannelByeMessageText"); + + b.Property("ChannelGreetMessageText"); + + 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("LogSettingId"); + + b.Property("PermissionRole"); + + b.Property("RootPermissionId"); + + b.Property("SendChannelByeMessage"); + + b.Property("SendChannelGreetMessage"); + + b.Property("SendDmGreetMessage"); + + b.Property("VerbosePermissions"); + + b.Property("VoicePlusTextEnabled"); + + b.HasKey("Id"); + + b.HasIndex("GuildId") + .IsUnique(); + + b.HasIndex("LogSettingId"); + + b.HasIndex("RootPermissionId"); + + b.ToTable("GuildConfigs"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + 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("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("ChannelDestroyed"); + + b.Property("ChannelId"); + + b.Property("ChannelUpdated"); + + b.Property("IsLogging"); + + b.Property("LogUserPresence"); + + b.Property("LogVoicePresence"); + + b.Property("MessageDeleted"); + + b.Property("MessageUpdated"); + + b.Property("UserBanned"); + + b.Property("UserJoined"); + + b.Property("UserLeft"); + + b.Property("UserPresenceChannelId"); + + b.Property("UserUnbanned"); + + b.Property("UserUpdated"); + + 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("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("Name"); + + b.HasKey("Id"); + + b.ToTable("MusicPlaylists"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + 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.PlayingStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + 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("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("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("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("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.Repeater", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("GuildId"); + + b.Property("Interval"); + + b.Property("Message"); + + b.HasKey("Id"); + + b.HasIndex("ChannelId") + .IsUnique(); + + b.ToTable("Repeaters"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GuildId"); + + b.Property("RoleId"); + + b.HasKey("Id"); + + b.HasIndex("GuildId", "RoleId") + .IsUnique(); + + b.ToTable("SelfAssignableRoles"); + }); + + 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.CommandCooldown", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("CommandCooldowns") + .HasForeignKey("GuildConfigId"); + }); + + 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.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.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.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"); + }); + } + } +} diff --git a/src/NadekoBot/Migrations/20161015102407_coc.cs b/src/NadekoBot/Migrations/20161015102407_coc.cs new file mode 100644 index 00000000..e1d42e8c --- /dev/null +++ b/src/NadekoBot/Migrations/20161015102407_coc.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace NadekoBot.Migrations +{ + public partial class coc : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "SequenceNumber", + table: "ClashCallers", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "SequenceNumber", + table: "ClashCallers"); + } + } +} diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 148c0cdc..be1f7786 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -80,6 +80,8 @@ namespace NadekoBot.Migrations b.Property("ClashWarId"); + b.Property("SequenceNumber"); + b.Property("Stars"); b.Property("TimeAdded"); diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index ae5fc69a..1f084c4c 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -21,23 +21,21 @@ namespace NadekoBot.Modules.ClashOfClans static ClashOfClans() { - //using (var uow = DbHandler.UnitOfWork()) - //{ - // ClashWars = new ConcurrentDictionary>( - // uow.ClashOfClans - // .GetAllWars() - // .Select(cw => { - // if (cw == null || cw.Bases == null) - // return null; - // cw.Channel = NadekoBot.Client.GetGuild(cw.GuildId) - // ?.GetTextChannel(cw.ChannelId); - // cw.Bases.Capacity = cw.Size; - // return cw; - // }) - // .Where(cw => cw?.Channel != null) - // .GroupBy(cw => cw.GuildId) - // .ToDictionary(g => g.Key, g => g.ToList())); - //} + using (var uow = DbHandler.UnitOfWork()) + { + ClashWars = new ConcurrentDictionary>( + uow.ClashOfClans + .GetAllWars() + .Select(cw => + { + cw.Channel = NadekoBot.Client.GetGuild(cw.GuildId) + ?.GetTextChannel(cw.ChannelId); + return cw; + }) + .Where(cw => cw?.Channel != null) + .GroupBy(cw => cw.GuildId) + .ToDictionary(g => g.Key, g => g.ToList())); + } } public ClashOfClans(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client) { @@ -46,9 +44,9 @@ namespace NadekoBot.Modules.ClashOfClans private static async Task CheckWar(TimeSpan callExpire, ClashWar war) { var Bases = war.Bases; - for (var i = 0; i < Bases.Capacity; i++) + for (var i = 0; i < Bases.Count; i++) { - if (Bases[i] == null) continue; + if (Bases[i].CallUser == null) continue; if (!Bases[i].BaseDestroyed && DateTime.UtcNow - Bases[i].TimeAdded >= callExpire) { Bases[i] = null; @@ -84,7 +82,6 @@ namespace NadekoBot.Modules.ClashOfClans var cw = await CreateWar(enemyClan, size, channel.Guild.Id, umsg.Channel.Id); - //cw.Start(); wars.Add(cw); await channel.SendMessageAsync($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false); @@ -191,26 +188,26 @@ namespace NadekoBot.Modules.ClashOfClans [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task ClaimFinish1(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null) + public async Task ClaimFinish1(IUserMessage umsg, int number, int baseNumber = 0) { var channel = (ITextChannel)umsg.Channel; - await FinishClaim(umsg, number, baseNumber, other_name, 1); + await FinishClaim(umsg, number, baseNumber - 1, 1); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task ClaimFinish2(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null) + public async Task ClaimFinish2(IUserMessage umsg, int number, int baseNumber = 0) { var channel = (ITextChannel)umsg.Channel; - await FinishClaim(umsg, number, baseNumber, other_name, 2); + await FinishClaim(umsg, number, baseNumber - 1, 2); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task ClaimFinish(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name = null) + public async Task ClaimFinish(IUserMessage umsg, int number, int baseNumber = 0) { var channel = (ITextChannel)umsg.Channel; - await FinishClaim(umsg, number, baseNumber, other_name); + await FinishClaim(umsg, number, baseNumber - 1); } [NadekoCommand, Usage, Description, Aliases] @@ -263,7 +260,7 @@ namespace NadekoBot.Modules.ClashOfClans } } - private async Task FinishClaim(IUserMessage umsg, int number, int baseNumber, [Remainder] string other_name, int stars = 3) + private async Task FinishClaim(IUserMessage umsg, int number, int baseNumber, int stars = 3) { var channel = (ITextChannel)umsg.Channel; var warInfo = GetWarInfo(umsg, number); @@ -272,17 +269,19 @@ namespace NadekoBot.Modules.ClashOfClans await channel.SendMessageAsync("💢🔰 **That war does not exist.**").ConfigureAwait(false); return; } - var usr = - string.IsNullOrWhiteSpace(other_name) ? - umsg.Author.Username : - other_name; - var war = warInfo.Item1[warInfo.Item2]; try { - var baseNum = war.FinishClaim(usr, stars); - SaveWar(war); - await channel.SendMessageAsync($"❗🔰{umsg.Author.Mention} **DESTROYED** a base #{baseNum + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false); + if (baseNumber == -1) + { + baseNumber = war.FinishClaim(umsg.Author.Username, stars); + SaveWar(war); + } + else + { + war.FinishClaim(baseNumber, stars); + } + await channel.SendMessageAsync($"❗🔰{umsg.Author.Mention} **DESTROYED** a base #{baseNumber + 1} in a war against {war.ShortPrint()}").ConfigureAwait(false); } catch (Exception ex) { @@ -324,6 +323,16 @@ namespace NadekoBot.Modules.ClashOfClans Channel = NadekoBot.Client.GetGuild(serverId) ?.GetTextChannel(channelId) }; + cw.Bases.Capacity = size; + for (int i = 0; i < size; i++) + { + cw.Bases.Add(new ClashCaller() + { + CallUser = null, + SequenceNumber = i, + }); + } + Console.WriteLine(cw.Bases.Capacity); uow.ClashOfClans.Add(cw); await uow.CompleteAsync(); return cw; diff --git a/src/NadekoBot/Modules/ClashOfClans/Extensions.cs b/src/NadekoBot/Modules/ClashOfClans/Extensions.cs index b367f0a6..d2103edd 100644 --- a/src/NadekoBot/Modules/ClashOfClans/Extensions.cs +++ b/src/NadekoBot/Modules/ClashOfClans/Extensions.cs @@ -30,21 +30,20 @@ namespace NadekoBot.Modules.ClashOfClans public static void Call(this ClashWar cw, string u, int baseNumber) { - if (baseNumber < 0 || baseNumber >= cw.Bases.Capacity) + if (baseNumber < 0 || baseNumber >= cw.Bases.Count) throw new ArgumentException("Invalid base number"); - if (cw.Bases[baseNumber] != null) + if (cw.Bases[baseNumber].CallUser != null) throw new ArgumentException("That base is already claimed."); - for (var i = 0; i < cw.Bases.Capacity; i++) + for (var i = 0; i < cw.Bases.Count; i++) { if (cw.Bases[i]?.BaseDestroyed == false && cw.Bases[i]?.CallUser == u) throw new ArgumentException($"@{u} You already claimed base #{i + 1}. You can't claim a new one."); } - cw.Bases[baseNumber] = new ClashCaller() { - CallUser = u.Trim(), - TimeAdded = DateTime.UtcNow, - BaseDestroyed = false - }; + var cc = cw.Bases[baseNumber]; + cc.CallUser = u.Trim(); + cc.TimeAdded = DateTime.UtcNow; + cc.BaseDestroyed = false; } public static void Start(this ClashWar cw) @@ -56,7 +55,7 @@ namespace NadekoBot.Modules.ClashOfClans //Started = true; cw.WarState = StateOfWar.Started; cw.StartedAt = DateTime.UtcNow; - foreach (var b in cw.Bases.Where(b => b != null)) + foreach (var b in cw.Bases.Where(b => b.CallUser != null)) { b.ResetTime(); } @@ -65,10 +64,10 @@ namespace NadekoBot.Modules.ClashOfClans public static int Uncall(this ClashWar cw, string user) { user = user.Trim(); - for (var i = 0; i < cw.Bases.Capacity; i++) + for (var i = 0; i < cw.Bases.Count; i++) { if (cw.Bases[i]?.CallUser != user) continue; - cw.Bases[i] = null; + cw.Bases[i].CallUser = null; return i; } throw new InvalidOperationException("You are not participating in that war."); @@ -85,9 +84,9 @@ namespace NadekoBot.Modules.ClashOfClans if (cw.WarState == StateOfWar.Created) sb.AppendLine("`not started`"); var twoHours = new TimeSpan(2, 0, 0); - for (var i = 0; i < cw.Bases.Capacity; i++) + for (var i = 0; i < cw.Bases.Count; i++) { - if (cw.Bases[i] == null) + if (cw.Bases[i].CallUser == null) { sb.AppendLine($"`{i + 1}.` ❌*unclaimed*"); } @@ -111,7 +110,7 @@ namespace NadekoBot.Modules.ClashOfClans public static int FinishClaim(this ClashWar cw, string user, int stars = 3) { user = user.Trim(); - for (var i = 0; i < cw.Bases.Capacity; i++) + for (var i = 0; i < cw.Bases.Count; i++) { if (cw.Bases[i]?.BaseDestroyed != false || cw.Bases[i]?.CallUser != user) continue; cw.Bases[i].BaseDestroyed = true; @@ -120,5 +119,16 @@ namespace NadekoBot.Modules.ClashOfClans } throw new InvalidOperationException($"@{user} You are either not participating in that war, or you already destroyed a base."); } + + public static void FinishClaim(this ClashWar cw, int index, int stars = 3) + { + if (index < 0 || index > cw.Bases.Count) + throw new ArgumentOutOfRangeException(nameof(index)); + var toFinish = cw.Bases[index]; + if (toFinish.BaseDestroyed != false) throw new InvalidOperationException("That base is already destroyed."); + if (toFinish.CallUser == null) throw new InvalidOperationException("That base is unclaimed."); + toFinish.BaseDestroyed = true; + toFinish.Stars = stars; + } } } \ No newline at end of file diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 73f71499..787a437f 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -1338,7 +1338,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Finish your claim with 3 stars if you destroyed a base. First argument is the war number, optional second argument finishes for someone else.. + /// Looks up a localized string similar to Finish your claim with 3 stars if you destroyed a base. First argument is the war number, optional second argument is a base number if you want to finish for someone else.. /// public static string claimfinish_desc { get { @@ -1347,7 +1347,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `,cf 1 Someone`. + /// Looks up a localized string similar to `,cf 1` or `,cf 1 5`. /// public static string claimfinish_usage { get { @@ -1365,7 +1365,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Finish your claim with 1 star if you destroyed a base. First argument is the war number, optional second argument finishes for someone else.. + /// Looks up a localized string similar to Finish your claim with 1 star if you destroyed a base. First argument is the war number, optional second argument is a base number if you want to finish for someone else.. /// public static string claimfinish1_desc { get { @@ -1374,7 +1374,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `,cf1 2 SomeGirl`. + /// Looks up a localized string similar to `,cf1 1` or `,cf1 1 5`. /// public static string claimfinish1_usage { get { @@ -1392,7 +1392,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Finish your claim with 2 stars if you destroyed a base. First argument is the war number, optional second argument finishes for someone else.. + /// Looks up a localized string similar to Finish your claim with 2 stars if you destroyed a base. First argument is the war number, optional second argument is a base number if you want to finish for someone else.. /// public static string claimfinish2_desc { get { @@ -1401,7 +1401,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `,cf2 1 SomeGuy`. + /// Looks up a localized string similar to `,cf2 1` or `,cf2 1 5`. /// public static string claimfinish2_usage { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 42cce386..55d78219 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2362,28 +2362,28 @@ claimfinish cf - Finish your claim with 3 stars if you destroyed a base. First argument is the war number, optional second argument finishes for someone else. + Finish your claim with 3 stars if you destroyed a base. First argument is the war number, optional second argument is a base number if you want to finish for someone else. - `,cf 1 Someone` + `,cf 1` or `,cf 1 5` claimfinish2 cf2 - Finish your claim with 2 stars if you destroyed a base. First argument is the war number, optional second argument finishes for someone else. + Finish your claim with 2 stars if you destroyed a base. First argument is the war number, optional second argument is a base number if you want to finish for someone else. - `,cf2 1 SomeGuy` + `,cf2 1` or `,cf2 1 5` claimfinish1 cf1 - Finish your claim with 1 star if you destroyed a base. First argument is the war number, optional second argument finishes for someone else. + Finish your claim with 1 star if you destroyed a base. First argument is the war number, optional second argument is a base number if you want to finish for someone else. - `,cf1 2 SomeGirl` + `,cf1 1` or `,cf1 1 5` unclaim ucall uc diff --git a/src/NadekoBot/Services/Database/Models/ClashCaller.cs b/src/NadekoBot/Services/Database/Models/ClashCaller.cs index 2f875049..719ef9ee 100644 --- a/src/NadekoBot/Services/Database/Models/ClashCaller.cs +++ b/src/NadekoBot/Services/Database/Models/ClashCaller.cs @@ -9,6 +9,7 @@ namespace NadekoBot.Services.Database.Models { public class ClashCaller : DbEntity { + public int? SequenceNumber { get; set; } = null; public string CallUser { get; set; } public DateTime TimeAdded { get; set; } diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs index 78b2aaf3..bbe12205 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/ClashOfClansRepository.cs @@ -16,8 +16,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl public IEnumerable GetAllWars() { - return _set.Include(cw => cw.Bases) + var toReturn = _set.Include(cw => cw.Bases) .ToList(); + toReturn.ForEach(cw => cw.Bases = cw.Bases.Where(w => w.SequenceNumber != null).OrderBy(w => w.SequenceNumber).ToList()); + return toReturn; } } }