From 3316a221c1a5f1208b53b43ac87be7db820d836e Mon Sep 17 00:00:00 2001 From: ca45382 Date: Tue, 27 Jul 2021 03:18:25 +0900 Subject: [PATCH 01/50] =?UTF-8?q?=E6=B1=8E=E7=94=A8=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89=E8=A7=A3=E9=87=88=E5=87=A6=E7=90=86=E3=81=AE?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Attribute/Command.cs | 47 ++++++++++++++ DataModel/CommandEventArgs.cs | 65 ++++++++++++++++++++ DataType/ShioriFeature/ChannelFeatureType.cs | 3 + Script/Program.cs | 15 ++--- Script/Utility/CommandMapper.cs | 62 +++++++++++++++++++ 5 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 Attribute/Command.cs create mode 100644 DataModel/CommandEventArgs.cs create mode 100644 Script/Utility/CommandMapper.cs diff --git a/Attribute/Command.cs b/Attribute/Command.cs new file mode 100644 index 00000000..ba8f6a6e --- /dev/null +++ b/Attribute/Command.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using PriconneBotConsoleApp.DataType; + +namespace PriconneBotConsoleApp.Attribute +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public class CommandAttribute : System.Attribute + { + public CommandAttribute( + int minArgumentLength = 0, + int maxArgumentLength = int.MaxValue, + string[] commandText = null, + params ChannelFeatureType[] channelFeatureType + ) + { + Names = commandText ?? new[] { string.Empty }; + ChannelTypes = channelFeatureType.Length == 0 ? new[] { ChannelFeatureType.All } : channelFeatureType; + + MinArgumentLength = minArgumentLength; + MaxArgumentLength = maxArgumentLength; + } + + /// + /// 受け取ったコマンドを格納する + /// + public IReadOnlyList Names { get; } + + /// + /// 受け取ったコマンドが発信されたチャンネル + /// + public IReadOnlyList ChannelTypes { get; } + + /// + /// 引数の長さの最小値 + /// + public int MinArgumentLength { get; } + + /// + /// 引数の長さの最大値 + /// + public int MaxArgumentLength { get; } + + public bool IsCompatibleArgumentLength(int argLength) + => (MinArgumentLength <= argLength && argLength <= MaxArgumentLength); + } +} diff --git a/DataModel/CommandEventArgs.cs b/DataModel/CommandEventArgs.cs new file mode 100644 index 00000000..d43cd341 --- /dev/null +++ b/DataModel/CommandEventArgs.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Discord.WebSocket; +using PriconneBotConsoleApp.Database; +using PriconneBotConsoleApp.DataType; +using PriconneBotConsoleApp.Extension; + +namespace PriconneBotConsoleApp.DataModel +{ + public class CommandEventArgs : EventArgs + { + public CommandEventArgs(SocketUserMessage socketUserMessage) + { + SocketUserMessage = socketUserMessage; + ChannelFeatureType = ChannelFeatureType.All; + + if (socketUserMessage.Content.Length == 0) + { + throw new ArgumentException("Content.Length が 0"); + } + + var splitContents = socketUserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); + Name = splitContents[0]; + + if (splitContents.Length > 1) + { + Arguments = splitContents.Skip(1).ToList(); + } + else + { + Arguments = Array.Empty(); + } + + var messageChannel = socketUserMessage.Channel as SocketGuildChannel; + Channel = messageChannel as SocketTextChannel; + var guild = messageChannel.Guild; + Author = socketUserMessage.Author as SocketGuildUser; + var playerData = DatabasePlayerDataController.LoadPlayerData(guild.Id, Author.Id); + Role = messageChannel.Guild.GetRole(playerData?.ClanData.ClanRoleID ?? 0); + + if (Role == null) + { + return; + } + + ClanData = DatabaseClanDataController.LoadClanData(Role); + var channelFeatureID = ClanData.ChannelData.FirstOrDefault(x => x.ChannelID == Channel.Id)?.FeatureID ?? 0; + + if (channelFeatureID != 0) + { + ChannelFeatureType = (ChannelFeatureType)channelFeatureID; + } + } + + public string Name { get; } + public ChannelFeatureType ChannelFeatureType { get; } + public IReadOnlyList Arguments { get; } + public SocketUserMessage SocketUserMessage { get; } + public ClanData ClanData { get; } + public SocketRole Role { get; } + public SocketGuildUser Author { get; } + public SocketTextChannel Channel { get; } + } +} diff --git a/DataType/ShioriFeature/ChannelFeatureType.cs b/DataType/ShioriFeature/ChannelFeatureType.cs index 5009709b..c0c9e151 100644 --- a/DataType/ShioriFeature/ChannelFeatureType.cs +++ b/DataType/ShioriFeature/ChannelFeatureType.cs @@ -5,6 +5,9 @@ public enum ChannelFeatureType : uint { Unknown = 0, + /// すべてのチャンネルで利用できるコマンドにつけられる. + All = 9999, + DeclareID = 1001, ReserveID = 1002, ReserveResultID = 1003, diff --git a/Script/Program.cs b/Script/Program.cs index 2a48a8ab..6f5abf27 100644 --- a/Script/Program.cs +++ b/Script/Program.cs @@ -27,6 +27,7 @@ public class Program public async Task MainAsync() { BotConfigManager.SetJsonConfig(ConfigPath); + CommandMapper.InitCommandCache(); m_config = new DiscordSocketConfig { @@ -59,24 +60,24 @@ public async Task MainAsync() /// /// メッセージの受信処理 /// - /// + /// /// - private async Task CommandRecieved(SocketMessage messageParam) + private async Task CommandRecieved(SocketMessage socketMessage) { - if (messageParam is not SocketUserMessage message) + if (socketMessage is not SocketUserMessage socketUserMessage) { return; } - Console.WriteLine($"{message.Channel.Name} {message.Author.Username}:{message}"); + Console.WriteLine($"{socketUserMessage.Channel.Name} {socketUserMessage.Author.Username}:{socketUserMessage}"); - if (message.Author.IsBot) + if (socketUserMessage.Author.IsBot) { return; } - var receiveMessages = new ReceiveMessageController(message); - await receiveMessages.RunMessageReceive(); + var commandEventArgs = new CommandEventArgs(socketUserMessage); + await CommandMapper.Invoke(commandEventArgs); } /// diff --git a/Script/Utility/CommandMapper.cs b/Script/Utility/CommandMapper.cs new file mode 100644 index 00000000..495f58b4 --- /dev/null +++ b/Script/Utility/CommandMapper.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using PriconneBotConsoleApp.Attribute; +using PriconneBotConsoleApp.DataModel; +using PriconneBotConsoleApp.DataType; + +namespace PriconneBotConsoleApp.Script +{ + public static class CommandMapper + { + private readonly static ConcurrentDictionary<(ChannelFeatureType, string), (CommandAttribute Info, Func Handler)> m_CommandCache = new(); + + public static void InitCommandCache() + { + var searchOption = BindingFlags.Static | BindingFlags.Public; + + foreach (var methodInfo in typeof(Commands).GetMethods(searchOption).AsEnumerable()) + { + if (methodInfo.GetCustomAttribute(false) is not CommandAttribute commandAttribute) + { + continue; + } + + foreach (var commandName in commandAttribute.Names) + { + foreach (var channelFeatureType in commandAttribute.ChannelTypes) + { + m_CommandCache[(channelFeatureType, commandName)] = (commandAttribute, (Func)Delegate.CreateDelegate(typeof(Func), methodInfo)); + } + } + } + + return; + } + + public static async Task Invoke(CommandEventArgs commandEventArgs) + { + if ((m_CommandCache.TryGetValue((commandEventArgs.ChannelFeatureType, commandEventArgs.Name), out var functionData) + || m_CommandCache.TryGetValue((ChannelFeatureType.All, commandEventArgs.Name), out functionData) + || m_CommandCache.TryGetValue((commandEventArgs.ChannelFeatureType, string.Empty), out functionData))) + { + if (functionData.Info.IsCompatibleArgumentLength(commandEventArgs.Arguments.Count)) + { + await functionData.Handler(commandEventArgs); + } + else + { + throw new ArgumentException( + $"Argument length {commandEventArgs.Arguments.Count} is incompatible; Expect : between {functionData.Info.MinArgumentLength} and {functionData.Info.MaxArgumentLength}\n{commandEventArgs.SocketUserMessage.Content}"); + } + } + else + { + throw new KeyNotFoundException($"{commandEventArgs.SocketUserMessage.Content}"); + } + } + } +} From 3d8a1fb22215fafe1a38b516f8b90e12407f7cd8 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Tue, 27 Jul 2021 03:18:43 +0900 Subject: [PATCH 02/50] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E5=87=A6=E7=90=86=E9=83=A8=E5=88=86=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Extension/EnumExtension.cs | 16 ++++++++++++++-- Script/Commands.cs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Script/Commands.cs diff --git a/Extension/EnumExtension.cs b/Extension/EnumExtension.cs index fb8abb49..f06547c4 100644 --- a/Extension/EnumExtension.cs +++ b/Extension/EnumExtension.cs @@ -1,7 +1,8 @@ -using PriconneBotConsoleApp.Attribute; -using System; +using System; using System.ComponentModel; using System.Reflection; +using PriconneBotConsoleApp.Attribute; +using PriconneBotConsoleApp.DataType; namespace PriconneBotConsoleApp.Extension { @@ -26,5 +27,16 @@ public static MultiDescriptionData GetMultiDescripion(this Enum enumValue) ShortDescription = string.Empty, Aliases = Array.Empty(), }; + + public static BossNumberType GetBossNumberType(this ChannelFeatureType channelFeatureType) + => channelFeatureType switch + { + ChannelFeatureType.ProgressBoss1ID => BossNumberType.Boss1Number, + ChannelFeatureType.ProgressBoss2ID => BossNumberType.Boss2Number, + ChannelFeatureType.ProgressBoss3ID => BossNumberType.Boss3Number, + ChannelFeatureType.ProgressBoss4ID => BossNumberType.Boss4Number, + ChannelFeatureType.ProgressBoss5ID => BossNumberType.Boss5Number, + _ => throw new ArgumentException($"Cannot cast to BossNumberType. {channelFeatureType}"), + }; } } diff --git a/Script/Commands.cs b/Script/Commands.cs new file mode 100644 index 00000000..501b74fb --- /dev/null +++ b/Script/Commands.cs @@ -0,0 +1,30 @@ +using System.Threading.Tasks; +using PriconneBotConsoleApp.Attribute; +using PriconneBotConsoleApp.DataModel; +using PriconneBotConsoleApp.DataType; +using PriconneBotConsoleApp.Extension; + +namespace PriconneBotConsoleApp.Script +{ + public static class Commands + { + [Command( + channelFeatureType: new[] { ChannelFeatureType.CarryOverID } + )] + public static async Task BattleCarryOver(CommandEventArgs commandEventArgs) + => await new BattleCarryOver(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage).RunByMessage(); + + [Command( + channelFeatureType: new[]{ + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task Progress(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage, (byte)commandEventArgs.ChannelFeatureType.GetBossNumberType()) + .RunByMessage(); + } +} From 2e98ab9080db23498d34abc7192425ed4646385c Mon Sep 17 00:00:00 2001 From: ca45382 Date: Wed, 28 Jul 2021 21:07:52 +0900 Subject: [PATCH 03/50] =?UTF-8?q?=E6=8C=81=E3=81=A1=E8=B6=8A=E3=81=97?= =?UTF-8?q?=E9=83=A8=E5=88=86=E3=82=92=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/InfomationType.cs | 4 + Script/ClanBattle/BattleCarryOver.cs | 224 ++++++++++++--------------- Script/Utility/EnumMapper.cs | 2 +- 3 files changed, 100 insertions(+), 130 deletions(-) diff --git a/DataType/InfomationType.cs b/DataType/InfomationType.cs index 7c7a52b2..9176bab6 100644 --- a/DataType/InfomationType.cs +++ b/DataType/InfomationType.cs @@ -14,5 +14,9 @@ public enum InfomationType // 凸報告関連 [Description("<@{0}>の凸報告を代理削除しました。\nこのメッセージは{1}秒後削除されます。")] DeleteInsted, + + //持ち越し関連 + [Description("持ち越しをすべて削除しました。\nこのメッセージは{0}秒後削除されます。")] + DeleteAllCarryOverData, } } diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index a6e2e8b1..41a89734 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -14,9 +14,7 @@ namespace PriconneBotConsoleApp.Script { public class BattleCarryOver { - private readonly ClanData m_ClanData; - private readonly SocketUserMessage m_UserMessage; - private readonly SocketRole m_ClanRole; + private readonly CommandEventArgs m_CommandEventArgs; private class PlayerInfo { @@ -47,165 +45,157 @@ public string GetCarryOverString() } } - public BattleCarryOver(ClanData clanData, SocketUserMessage userMessage) + public BattleCarryOver(CommandEventArgs commandEventArgs) { - m_ClanData = clanData; - m_UserMessage = userMessage; - var guild = (userMessage.Channel as SocketTextChannel)?.Guild; - m_ClanRole = guild?.GetRole(clanData.ClanRoleID); - } - - public async Task RunByMessage() - { - var messageContent = m_UserMessage.Content; - - if (messageContent.StartsWith("!")) - { - if (messageContent.StartsWith("!init")) - { - InitAllData(); - } - else if (messageContent.StartsWith("!rm")) - { - UpdateOtherPlayerData(); - } - else if (messageContent.StartsWith("!list")) - { - await SendClanCarryOverList(); - } - - } - else - { - UpdateCarryOverData(); - } + m_CommandEventArgs = commandEventArgs; } /// - /// 個人の持ち越し所持・消化報告 + /// 持ち越しを登録するか更新する. 引数は2以上 /// - private void UpdateCarryOverData() + public void UpdateCarryOverData() { - const int minCommandLength = 1; - // TODO : " "を定数化する。 - var splitMessage = m_UserMessage.Content.ZenToHan().Split(" ", StringSplitOptions.RemoveEmptyEntries); - var result = false; + var playerData = DatabasePlayerDataController + .LoadPlayerData(m_CommandEventArgs.Role, m_CommandEventArgs.SocketUserMessage.Author.Id); - if (splitMessage.Length < minCommandLength) + if (!byte.TryParse(m_CommandEventArgs.Arguments[0], out var bossNumber) + || !byte.TryParse(m_CommandEventArgs.Arguments[1], out var remainTime) + || bossNumber < CommonDefine.MinBossNumber || bossNumber > CommonDefine.MaxBossNumber + || remainTime < CommonDefine.MinBattleTime || remainTime > CommonDefine.MaxBattleTime + || playerData == null) { return; } - // TODO : 持ち越し番号をEnum化 - - if (EnumMapper.TryParse(splitMessage.First(), out var attackType) - && attackType == AttackType.CarryOver) + CarryOverData carryOverData = new() { - var userCarryOverData = CommandToCarryOverData(splitMessage); + BossNumber = bossNumber, + RemainTime = remainTime, + // TODO : " "を定数化する。 + CommentData = string.Join(" ", m_CommandEventArgs.Arguments.Skip(2)), + PlayerID = playerData.PlayerID, + }; - if (userCarryOverData == null) - { - return; - } + var databaseCarryOverList = DatabaseCarryOverController.GetCarryOverData(playerData).ToArray(); + var databaseCarryOverData = databaseCarryOverList.FirstOrDefault(x => x.BossNumber == carryOverData.BossNumber && x.RemainTime == carryOverData.RemainTime); + bool result = false; - var userID = m_UserMessage.Author.Id; - var playerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, userID); + if (databaseCarryOverData != null) + { + carryOverData.CarryOverID = databaseCarryOverData.CarryOverID; + result = DatabaseCarryOverController.UpdateCarryOverData(carryOverData); + } + else if (databaseCarryOverList.Length < CommonDefine.MaxCarryOverNumber) + { + result = DatabaseCarryOverController.CreateCarryOverData(carryOverData); + } - if (playerData == null) - { - return; - } + if (result) + { + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + } + } - var databaseCarryOverList = DatabaseCarryOverController.GetCarryOverData(playerData).ToArray(); - var databaseCarryOverData = databaseCarryOverList.FirstOrDefault(x => x.BossNumber == userCarryOverData.BossNumber && x.RemainTime == userCarryOverData.RemainTime); + /// + /// 持ち越しデータを削除する時に用いる。引数0か1。 + /// + public void DeleteCarryOverData() + { + const int defaultDeleteNumber = 1; + var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, m_CommandEventArgs.Author.Id); - if (databaseCarryOverData == null && databaseCarryOverList.Length < CommonDefine.MaxCarryOverNumber) - { - result = DatabaseCarryOverController.CreateCarryOverData(userCarryOverData); - } - else if (databaseCarryOverData != null) - { - userCarryOverData.CarryOverID = databaseCarryOverData.CarryOverID; - result = DatabaseCarryOverController.UpdateCarryOverData(userCarryOverData); - } - } - // TODO:ここの消化記述を別にまとめたい - else if (splitMessage.First() == "消化") + try { - var playerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, m_UserMessage.Author.Id); - - if (splitMessage.Length > 1 && byte.TryParse(splitMessage[1], out byte deleteNumber)) + if (byte.TryParse(m_CommandEventArgs.Arguments.ElementAtOrDefault(0), out var deleteNumber)) { - result = DeleteCarryOverData(playerData, deleteNumber); + DeletePlayerCarryOverData(playerData, deleteNumber); } else { - result = DeleteCarryOverData(playerData); + DeletePlayerCarryOverData(playerData, defaultDeleteNumber); } } - - if (result) + catch { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + return; } + + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); } - private void UpdateOtherPlayerData() + /// + /// 他人の持越しを削除する。引数は2つ必要とする。 + /// + public void DeleteOtherPlayerData() { - const int minCommandLength = 1; + SocketGuildUser targetUser; - // TODO : " "を定数化する。 - var splitMessage = m_UserMessage.Content.ZenToHan().Split(" ", StringSplitOptions.RemoveEmptyEntries); - - if (splitMessage.Length <= minCommandLength || m_UserMessage.MentionedUsers.FirstOrDefault()?.Id is not ulong userID) + if (MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out var userID) || + ulong.TryParse(m_CommandEventArgs.Arguments[0], out userID)) { - return; + targetUser = m_CommandEventArgs.Role.Guild.GetUser(userID); + } + else + { + throw new ArgumentNullException(); } // コマンドは `!rm @削除対象のユーザー 古い方から何番目か` としている。 - var deleteNumber = (splitMessage.Length > minCommandLength + 1 && byte.TryParse(splitMessage[minCommandLength + 1], out var number)) ? number : (byte)0; + if (!byte.TryParse(m_CommandEventArgs.Arguments[1], out var number) + || number > CommonDefine.MaxReportNumber || number <= 0) + { + throw new ArgumentOutOfRangeException(); + } - var playerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, userID); + var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, targetUser.Id); - if (DeleteCarryOverData(playerData, deleteNumber)) + try { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + DeletePlayerCarryOverData(playerData, number); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + } + catch (Exception e) + { + Console.WriteLine(e.Message); } } + /// + /// 持ち越しリストを表示するコマンド。引数0か1。 + /// + /// private async Task SendClanCarryOverList() { var clanCarryOverEmbed = CreateEmbedData(); - await m_UserMessage.Channel.SendMessageAsync(embed: clanCarryOverEmbed); + await m_CommandEventArgs.Channel.SendMessageAsync(embed: clanCarryOverEmbed); } - private bool DeleteCarryOverData(PlayerData playerData, byte deleteNumber = 0) + private void DeletePlayerCarryOverData(PlayerData playerData, byte deleteNumber) { var carryOverList = DatabaseCarryOverController.GetCarryOverData(playerData) .OrderBy(x => x.DateTime).ToArray(); if (carryOverList.Length == 0) { - return false; + throw new ArgumentOutOfRangeException(); } - var result = false; - if (deleteNumber > 0 && deleteNumber <= carryOverList.Length) { - result = DatabaseCarryOverController.DeleteCarryOverData(carryOverList[deleteNumber - 1]); + DatabaseCarryOverController.DeleteCarryOverData(carryOverList[deleteNumber - 1]); } else { - result = DatabaseCarryOverController.DeleteCarryOverData(carryOverList.First()); + DatabaseCarryOverController.DeleteCarryOverData(carryOverList.First()); } - - return result; } - private void InitAllData() + /// + /// 全ての持ち越しを削除する。引数は0。 + /// + public void InitAllData() { - var carryOverList = DatabaseCarryOverController.GetCarryOverData(m_ClanData); + var carryOverList = DatabaseCarryOverController.GetCarryOverData(m_CommandEventArgs.ClanData); if (!carryOverList.Any()) { @@ -213,41 +203,17 @@ private void InitAllData() } DatabaseCarryOverController.DeleteCarryOverData(carryOverList); - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); - } - - private CarryOverData CommandToCarryOverData(string[] messageData) - { - const int bossNumberColumn = 1; - const int remainTimeColumn = 2; - const int messageMinLength = 3; - - if (messageData.Length < messageMinLength || - !byte.TryParse(messageData[bossNumberColumn], out var bossNumber) || !byte.TryParse(messageData[remainTimeColumn], out var remainTime) - || bossNumber < CommonDefine.MinBossNumber || bossNumber > CommonDefine.MaxBossNumber - || remainTime < CommonDefine.MinBattleTime || remainTime > CommonDefine.MaxBattleTime) - { - return null; - } - - var playerID = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, m_UserMessage.Author.Id).PlayerID; - - return new CarryOverData() - { - BossNumber = bossNumber, - RemainTime = remainTime, - // TODO : " "を定数化する。 - CommentData = string.Join(" ", messageData.Skip(3)), - PlayerID = playerID, - }; + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync(TimeDefine.SuccessMessageDisplayTime, + string.Format(EnumMapper.ToLabel(InfomationType.DeleteAllCarryOverData), TimeDefine.SuccessMessageDisplayTime)); } // 持ち越しを表示するUIを考える private Embed CreateEmbedData() { - var carryOverArray = DatabaseCarryOverController.GetCarryOverData(m_ClanData) + var carryOverArray = DatabaseCarryOverController.GetCarryOverData(m_CommandEventArgs.ClanData) .OrderBy(x => x.DateTime); - var playerArray = DatabasePlayerDataController.LoadPlayerData(m_ClanData); + var playerArray = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); List carryOverStringList = new(); foreach (var playerData in playerArray) diff --git a/Script/Utility/EnumMapper.cs b/Script/Utility/EnumMapper.cs index 42826580..2381596e 100644 --- a/Script/Utility/EnumMapper.cs +++ b/Script/Utility/EnumMapper.cs @@ -52,7 +52,7 @@ private static string[] GetAliases(this T data) where T : Enum public static Emoji ToEmoji(this ButtonType buttonType) => new(buttonType.ToShortLabel()); - public static Emoji emoji(this ReactionType reactionType) + public static Emoji ToEmoji(this ReactionType reactionType) => new(reactionType.ToLabel()); private static DescriptionType GetDescriptionType() where T : Enum From f5e6dc5177ea70995396b2184b7d01c0be1a8f7a Mon Sep 17 00:00:00 2001 From: Jumpei Gokaya Date: Wed, 28 Jul 2021 23:41:08 +0900 Subject: [PATCH 04/50] =?UTF-8?q?CommandMapper=E5=91=A8=E8=BE=BA=E3=82=92?= =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Attribute/Command.cs | 37 ++++++++++----- DataModel/CommandEventArgs.cs | 41 ++++++---------- Extension/DictionaryExtension.cs | 43 ++++++++++++++--- Extension/EnumExtension.cs | 33 ++++++------- Extension/IEnumerableExtension.cs | 14 +++--- Script/Commands.cs | 12 +++-- Script/Utility/CommandMapper.cs | 79 +++++++++++++++++++------------ Script/Utility/EnumMapper.cs | 2 +- 8 files changed, 155 insertions(+), 106 deletions(-) diff --git a/Attribute/Command.cs b/Attribute/Command.cs index ba8f6a6e..a7dc4116 100644 --- a/Attribute/Command.cs +++ b/Attribute/Command.cs @@ -4,21 +4,32 @@ namespace PriconneBotConsoleApp.Attribute { - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method, Inherited = false)] public class CommandAttribute : System.Attribute { public CommandAttribute( + string[] names = null, int minArgumentLength = 0, int maxArgumentLength = int.MaxValue, - string[] commandText = null, - params ChannelFeatureType[] channelFeatureType - ) + params ChannelFeatureType[] compatibleChannels) { - Names = commandText ?? new[] { string.Empty }; - ChannelTypes = channelFeatureType.Length == 0 ? new[] { ChannelFeatureType.All } : channelFeatureType; - + Names = names ?? new[] { string.Empty }; MinArgumentLength = minArgumentLength; MaxArgumentLength = maxArgumentLength; + CompatibleChannels = compatibleChannels.Length == 0 ? new[] { ChannelFeatureType.All } : compatibleChannels; + } + + public CommandAttribute( + string name, + int minArgumentLength = 0, + int maxArgumentLength = int.MaxValue, + params ChannelFeatureType[] compatibleChannels) + : this( + name == null ? null : new[] { name }, + minArgumentLength, + maxArgumentLength, + compatibleChannels) + { } /// @@ -26,11 +37,6 @@ params ChannelFeatureType[] channelFeatureType /// public IReadOnlyList Names { get; } - /// - /// 受け取ったコマンドが発信されたチャンネル - /// - public IReadOnlyList ChannelTypes { get; } - /// /// 引数の長さの最小値 /// @@ -41,7 +47,12 @@ params ChannelFeatureType[] channelFeatureType /// public int MaxArgumentLength { get; } + /// + /// コマンドが対応するチャンネル + /// + public IReadOnlyList CompatibleChannels { get; } + public bool IsCompatibleArgumentLength(int argLength) - => (MinArgumentLength <= argLength && argLength <= MaxArgumentLength); + => MinArgumentLength <= argLength && argLength <= MaxArgumentLength; } } diff --git a/DataModel/CommandEventArgs.cs b/DataModel/CommandEventArgs.cs index d43cd341..989d057d 100644 --- a/DataModel/CommandEventArgs.cs +++ b/DataModel/CommandEventArgs.cs @@ -13,31 +13,20 @@ public class CommandEventArgs : EventArgs public CommandEventArgs(SocketUserMessage socketUserMessage) { SocketUserMessage = socketUserMessage; - ChannelFeatureType = ChannelFeatureType.All; - if (socketUserMessage.Content.Length == 0) + if (SocketUserMessage.Content.Length == 0) { throw new ArgumentException("Content.Length が 0"); } - var splitContents = socketUserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); + var splitContents = SocketUserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); Name = splitContents[0]; + Arguments = splitContents.Length > 1 ? splitContents.Skip(1).ToList() : Array.Empty(); + Author = SocketUserMessage.Author as SocketGuildUser; + Channel = SocketUserMessage.Channel as SocketTextChannel; - if (splitContents.Length > 1) - { - Arguments = splitContents.Skip(1).ToList(); - } - else - { - Arguments = Array.Empty(); - } - - var messageChannel = socketUserMessage.Channel as SocketGuildChannel; - Channel = messageChannel as SocketTextChannel; - var guild = messageChannel.Guild; - Author = socketUserMessage.Author as SocketGuildUser; - var playerData = DatabasePlayerDataController.LoadPlayerData(guild.Id, Author.Id); - Role = messageChannel.Guild.GetRole(playerData?.ClanData.ClanRoleID ?? 0); + var playerData = DatabasePlayerDataController.LoadPlayerData(Channel.Guild.Id, SocketUserMessage.Author.Id); + Role = Channel.Guild.GetRole(playerData?.ClanData.ClanRoleID ?? 0); if (Role == null) { @@ -45,21 +34,19 @@ public CommandEventArgs(SocketUserMessage socketUserMessage) } ClanData = DatabaseClanDataController.LoadClanData(Role); - var channelFeatureID = ClanData.ChannelData.FirstOrDefault(x => x.ChannelID == Channel.Id)?.FeatureID ?? 0; - if (channelFeatureID != 0) - { - ChannelFeatureType = (ChannelFeatureType)channelFeatureID; - } + ChannelFeatureType = + (ChannelFeatureType?)ClanData.ChannelData.FirstOrDefault(x => x.ChannelID == Channel.Id)?.FeatureID + ?? ChannelFeatureType.All; } + public SocketUserMessage SocketUserMessage { get; } public string Name { get; } - public ChannelFeatureType ChannelFeatureType { get; } public IReadOnlyList Arguments { get; } - public SocketUserMessage SocketUserMessage { get; } - public ClanData ClanData { get; } - public SocketRole Role { get; } public SocketGuildUser Author { get; } public SocketTextChannel Channel { get; } + public SocketRole Role { get; } + public ClanData ClanData { get; } + public ChannelFeatureType ChannelFeatureType { get; } } } diff --git a/Extension/DictionaryExtension.cs b/Extension/DictionaryExtension.cs index 97a43ff0..59815ad6 100644 --- a/Extension/DictionaryExtension.cs +++ b/Extension/DictionaryExtension.cs @@ -1,22 +1,51 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace PriconneBotConsoleApp.Extension { public static class DictionaryExtension { public static TValue GetValueOrInitialize( - this IDictionary dictionary, - TKey key, - Func initializer) + [NotNull] this IDictionary dictionary, + [NotNull] TKey key, + [NotNull] Func initializer) => dictionary.TryGetValue(key, out var result) ? result : dictionary[key] = initializer(); - public static void Deconstruct( - this KeyValuePair pair, - out Tkey key, - out TValue value) + /// + /// を複数のキーで検索できるようにしたバージョン + /// + /// paramsに対応するため、out引数を先に書く必要がある点に注意 + /// + /// 検索対象の辞書 + /// 検索結果 (無い場合はdefaultになる) + /// キーの候補 (前方から順に検索される) + /// 辞書のキーの型 + /// 辞書の値の型 + /// + public static bool TryGetValueMany( + [NotNull] this IDictionary dictionary, + [NotNull] out TValue value, + [NotNull] params TKey[] keys) + { + foreach (var key in keys) + { + if (dictionary.TryGetValue(key, out value)) + { + return true; + } + } + + value = default; + return false; + } + + public static void Deconstruct( + [NotNull] this KeyValuePair pair, + [NotNull] out TKey key, + [NotNull] out TValue value) => (key, value) = (pair.Key, pair.Value); } } diff --git a/Extension/EnumExtension.cs b/Extension/EnumExtension.cs index f06547c4..4a74f00b 100644 --- a/Extension/EnumExtension.cs +++ b/Extension/EnumExtension.cs @@ -8,25 +8,26 @@ namespace PriconneBotConsoleApp.Extension { public static class EnumExtension { - public static string GetDescription(this Enum type) + public static string GetDescription(this T enumValue) where T : Enum { - var descriptionAttribute = type.GetType() - .GetField(type.ToString()).GetCustomAttribute(false); + var enumString = enumValue.ToString(); - return descriptionAttribute?.Description ?? type.ToString(); + return typeof(T).GetField(enumString)?.GetCustomAttribute(false)?.Description + ?? enumString; } - public static MultiDescriptionData GetMultiDescripion(this Enum enumValue) - => enumValue.GetType() - .GetField(enumValue.ToString()) - .GetCustomAttribute(false) - ?.Data - ?? new MultiDescriptionData - { - LongDescription = enumValue.ToString(), - ShortDescription = string.Empty, - Aliases = Array.Empty(), - }; + public static MultiDescriptionData GetMultiDescription(this T enumValue) where T : Enum + { + var enumString = enumValue.ToString(); + + return typeof(T).GetField(enumString)?.GetCustomAttribute(false)?.Data + ?? new MultiDescriptionData + { + LongDescription = enumString, + ShortDescription = string.Empty, + Aliases = Array.Empty() + }; + } public static BossNumberType GetBossNumberType(this ChannelFeatureType channelFeatureType) => channelFeatureType switch @@ -36,7 +37,7 @@ public static BossNumberType GetBossNumberType(this ChannelFeatureType channelFe ChannelFeatureType.ProgressBoss3ID => BossNumberType.Boss3Number, ChannelFeatureType.ProgressBoss4ID => BossNumberType.Boss4Number, ChannelFeatureType.ProgressBoss5ID => BossNumberType.Boss5Number, - _ => throw new ArgumentException($"Cannot cast to BossNumberType. {channelFeatureType}"), + _ => throw new ArgumentException($"Cannot cast to BossNumberType. {channelFeatureType}") }; } } diff --git a/Extension/IEnumerableExtension.cs b/Extension/IEnumerableExtension.cs index d557000c..4e773070 100644 --- a/Extension/IEnumerableExtension.cs +++ b/Extension/IEnumerableExtension.cs @@ -1,19 +1,17 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics.CodeAnalysis; namespace PriconneBotConsoleApp.Extension { - public static class IEnumerableExtension + public static class EnumerableExtension { - public static void ForEach(this IEnumerable source, Action action) + public static void ForEach([NotNull] this IEnumerable source, [NotNull] Action action) { - foreach (T element in source) + foreach (var element in source) { action(element); - } + } } } -} \ No newline at end of file +} diff --git a/Script/Commands.cs b/Script/Commands.cs index 501b74fb..7270b2b0 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -8,14 +8,13 @@ namespace PriconneBotConsoleApp.Script { public static class Commands { - [Command( - channelFeatureType: new[] { ChannelFeatureType.CarryOverID } - )] + [Command(compatibleChannels: ChannelFeatureType.CarryOverID)] public static async Task BattleCarryOver(CommandEventArgs commandEventArgs) => await new BattleCarryOver(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage).RunByMessage(); [Command( - channelFeatureType: new[]{ + compatibleChannels: new[] + { ChannelFeatureType.ProgressBoss1ID, ChannelFeatureType.ProgressBoss2ID, ChannelFeatureType.ProgressBoss3ID, @@ -24,7 +23,10 @@ public static async Task BattleCarryOver(CommandEventArgs commandEventArgs) } )] public static async Task Progress(CommandEventArgs commandEventArgs) - => await new BattleProgress(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage, (byte)commandEventArgs.ChannelFeatureType.GetBossNumberType()) + => await new BattleProgress( + commandEventArgs.ClanData, + commandEventArgs.SocketUserMessage, + (byte) commandEventArgs.ChannelFeatureType.GetBossNumberType()) .RunByMessage(); } } diff --git a/Script/Utility/CommandMapper.cs b/Script/Utility/CommandMapper.cs index 495f58b4..a1500ec4 100644 --- a/Script/Utility/CommandMapper.cs +++ b/Script/Utility/CommandMapper.cs @@ -7,56 +7,77 @@ using PriconneBotConsoleApp.Attribute; using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; +using PriconneBotConsoleApp.Extension; namespace PriconneBotConsoleApp.Script { public static class CommandMapper { - private readonly static ConcurrentDictionary<(ChannelFeatureType, string), (CommandAttribute Info, Func Handler)> m_CommandCache = new(); + /// コマンドキャッシュのキーの型 + /// 対応するチャンネル + /// 対応するコマンド名 + private record CacheKey(ChannelFeatureType ChannelFeature, string Name); - public static void InitCommandCache() + /// コマンドキャッシュの要素 + private class CacheValue { - var searchOption = BindingFlags.Static | BindingFlags.Public; - - foreach (var methodInfo in typeof(Commands).GetMethods(searchOption).AsEnumerable()) + internal CacheValue(MethodInfo methodInfo) { - if (methodInfo.GetCustomAttribute(false) is not CommandAttribute commandAttribute) - { - continue; - } + Info = methodInfo.GetCustomAttribute(false); - foreach (var commandName in commandAttribute.Names) + if (Info != null) { - foreach (var channelFeatureType in commandAttribute.ChannelTypes) - { - m_CommandCache[(channelFeatureType, commandName)] = (commandAttribute, (Func)Delegate.CreateDelegate(typeof(Func), methodInfo)); - } + IsValid = true; + Handler = (Func)Delegate.CreateDelegate(typeof(Func), methodInfo); } } - return; + /// 対象のがつけられているかどうか + internal bool IsValid { get; } + + /// 対象のにつけられた + internal CommandAttribute Info { get; } + + /// 対象のの実体 + internal Func Handler { get; } } + private static ConcurrentDictionary m_CommandCache; + + public static void InitCommandCache() + => m_CommandCache = new( + typeof(Commands) + .GetMethods(BindingFlags.Static | BindingFlags.Public) + .Select(methodInfo => new CacheValue(methodInfo)) + .Where(cacheValue => cacheValue.IsValid) + .SelectMany( + valueTuple => valueTuple.Info.CompatibleChannels.SelectMany( + _ => valueTuple.Info.Names, + (channelFeature, name) => new CacheKey(channelFeature, name) + ), + (valueTuple, keyTuple) => (keyTuple, valueTuple)) + .ToDictionary(keyValueTuple => keyValueTuple.keyTuple, keyValueTuple => keyValueTuple.valueTuple) + ); + public static async Task Invoke(CommandEventArgs commandEventArgs) { - if ((m_CommandCache.TryGetValue((commandEventArgs.ChannelFeatureType, commandEventArgs.Name), out var functionData) - || m_CommandCache.TryGetValue((ChannelFeatureType.All, commandEventArgs.Name), out functionData) - || m_CommandCache.TryGetValue((commandEventArgs.ChannelFeatureType, string.Empty), out functionData))) + if (!m_CommandCache.TryGetValueMany( + out var functionData, + new(commandEventArgs.ChannelFeatureType, commandEventArgs.Name), + new(ChannelFeatureType.All, commandEventArgs.Name), + new(commandEventArgs.ChannelFeatureType, string.Empty))) { - if (functionData.Info.IsCompatibleArgumentLength(commandEventArgs.Arguments.Count)) - { - await functionData.Handler(commandEventArgs); - } - else - { - throw new ArgumentException( - $"Argument length {commandEventArgs.Arguments.Count} is incompatible; Expect : between {functionData.Info.MinArgumentLength} and {functionData.Info.MaxArgumentLength}\n{commandEventArgs.SocketUserMessage.Content}"); - } + throw new KeyNotFoundException(commandEventArgs.SocketUserMessage.Content); } - else + + if (!functionData.Info.IsCompatibleArgumentLength(commandEventArgs.Arguments.Count)) { - throw new KeyNotFoundException($"{commandEventArgs.SocketUserMessage.Content}"); + throw new ArgumentException( + $"Argument length {commandEventArgs.Arguments.Count} is incompatible; Expect : between {functionData.Info.MinArgumentLength} and {functionData.Info.MaxArgumentLength}\n{commandEventArgs.SocketUserMessage.Content}" + ); } + + await functionData.Handler(commandEventArgs); } } } diff --git a/Script/Utility/EnumMapper.cs b/Script/Utility/EnumMapper.cs index 2381596e..9831ef40 100644 --- a/Script/Utility/EnumMapper.cs +++ b/Script/Utility/EnumMapper.cs @@ -35,7 +35,7 @@ public static string ToLabel(this T data) where T : Enum }; private static MultiDescriptionData GetMultiDescriptionData(T data) where T : Enum - => m_MultiDescriptionDictionary.GetValueOrInitialize((typeof(T), data), data.GetMultiDescripion); + => m_MultiDescriptionDictionary.GetValueOrInitialize((typeof(T), data), data.GetMultiDescription); private static string ToSingleLabel(this T data) where T : Enum => m_SingleDescriptionDictionary.GetValueOrInitialize((typeof(T), data), data.GetDescription); From 82a0473dbabdf833279924a4b7aa807956e03869 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Fri, 30 Jul 2021 23:51:21 +0900 Subject: [PATCH 05/50] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=91=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Utility/EnumMapper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Script/Utility/EnumMapper.cs b/Script/Utility/EnumMapper.cs index 9831ef40..f201a348 100644 --- a/Script/Utility/EnumMapper.cs +++ b/Script/Utility/EnumMapper.cs @@ -35,10 +35,10 @@ public static string ToLabel(this T data) where T : Enum }; private static MultiDescriptionData GetMultiDescriptionData(T data) where T : Enum - => m_MultiDescriptionDictionary.GetValueOrInitialize((typeof(T), data), data.GetMultiDescription); + => m_MultiDescriptionDictionary.GetValueOrInitialize((typeof(T), data), () => data.GetMultiDescription()); private static string ToSingleLabel(this T data) where T : Enum - => m_SingleDescriptionDictionary.GetValueOrInitialize((typeof(T), data), data.GetDescription); + => m_SingleDescriptionDictionary.GetValueOrInitialize((typeof(T), data), () => data.GetDescription()); public static string ToLongLabel(this T data) where T : Enum => GetMultiDescriptionData(data).LongDescription; From c64873c696bd7343dc95df156e03ebbaf8e871ec Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 31 Jul 2021 01:27:42 +0900 Subject: [PATCH 06/50] =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E7=B6=B4=E3=82=8A=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/AttackType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataType/AttackType.cs b/DataType/AttackType.cs index 791b3bca..3e465638 100644 --- a/DataType/AttackType.cs +++ b/DataType/AttackType.cs @@ -13,7 +13,7 @@ public enum AttackType Magic, [MultiDescription("ニャル", "ニ", "n", "N")] - NewYearKyaru, + NewYearKaryl, [MultiDescription("持ち越し", "持", "-", "持越し", "持越")] CarryOver, From 0e97437953fc36340351095fd5bb91ac48d16590 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 31 Jul 2021 02:38:37 +0900 Subject: [PATCH 07/50] =?UTF-8?q?AttackType=E3=82=92=E5=85=A5=E3=82=8C?= =?UTF-8?q?=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=ABString=E9=85=8D=E5=88=97?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Attribute/Command.cs | 14 ++++++++++++++ Attribute/Description.cs | 19 +++++++++++++------ Script/Utility/EnumMapper.cs | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Attribute/Command.cs b/Attribute/Command.cs index a7dc4116..e8daea49 100644 --- a/Attribute/Command.cs +++ b/Attribute/Command.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using PriconneBotConsoleApp.DataType; +using PriconneBotConsoleApp.Extension; namespace PriconneBotConsoleApp.Attribute { @@ -32,6 +33,19 @@ public CommandAttribute( { } + public CommandAttribute( + AttackType attackType, + int minArgumentLength = 0, + int maxArgumentLength = int.MaxValue, + params ChannelFeatureType[] compatibleChannels) + : this( + attackType.GetMultiDescription().Names, + minArgumentLength, + maxArgumentLength, + compatibleChannels) + { + } + /// /// 受け取ったコマンドを格納する /// diff --git a/Attribute/Description.cs b/Attribute/Description.cs index c3772e56..737441f6 100644 --- a/Attribute/Description.cs +++ b/Attribute/Description.cs @@ -1,20 +1,27 @@ using System; +using System.Collections.Generic; +using System.Linq; namespace PriconneBotConsoleApp.Attribute { public struct MultiDescriptionData { - public string LongDescription; - public string ShortDescription; - public string[] Aliases; + public string LongDescription { get; init; } + public string ShortDescription { get; init; } + public IReadOnlyList Aliases { get; init; } + + private string[] m_Names; + + public string[] Names + => m_Names ??= Aliases.Append(LongDescription).Append(ShortDescription).ToArray(); } [AttributeUsage(AttributeTargets.Field)] public class MultiDescriptionAttribute : System.Attribute { public MultiDescriptionAttribute( - string longDescription, - string shortDescription = null, + string longDescription, + string shortDescription = null, params string[] aliases) { Data = new MultiDescriptionData @@ -26,5 +33,5 @@ public MultiDescriptionAttribute( } public MultiDescriptionData Data { get; } - } + } } diff --git a/Script/Utility/EnumMapper.cs b/Script/Utility/EnumMapper.cs index f201a348..588b2a58 100644 --- a/Script/Utility/EnumMapper.cs +++ b/Script/Utility/EnumMapper.cs @@ -46,7 +46,7 @@ public static string ToLongLabel(this T data) where T : Enum public static string ToShortLabel(this T data) where T : Enum => GetMultiDescriptionData(data).ShortDescription; - private static string[] GetAliases(this T data) where T : Enum + private static IReadOnlyList GetAliases(this T data) where T : Enum => GetMultiDescriptionData(data).Aliases; public static Emoji ToEmoji(this ButtonType buttonType) From 755555d28172ca195272e00ee518e4c8e4d1da98 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 31 Jul 2021 02:39:11 +0900 Subject: [PATCH 08/50] =?UTF-8?q?=E6=8C=81=E3=81=A1=E8=B6=8A=E3=81=97?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=AB=E9=81=A9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleCarryOver.cs | 2 +- Script/Commands.cs | 66 ++++++++++++++- Script/ReceiveMessageController.cs | 118 --------------------------- 3 files changed, 63 insertions(+), 123 deletions(-) delete mode 100644 Script/ReceiveMessageController.cs diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index 41a89734..8087b5c4 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -164,7 +164,7 @@ public void DeleteOtherPlayerData() /// 持ち越しリストを表示するコマンド。引数0か1。 /// /// - private async Task SendClanCarryOverList() + public async Task SendClanCarryOverList() { var clanCarryOverEmbed = CreateEmbedData(); await m_CommandEventArgs.Channel.SendMessageAsync(embed: clanCarryOverEmbed); diff --git a/Script/Commands.cs b/Script/Commands.cs index 7270b2b0..8006a9a2 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -8,9 +8,67 @@ namespace PriconneBotConsoleApp.Script { public static class Commands { - [Command(compatibleChannels: ChannelFeatureType.CarryOverID)] - public static async Task BattleCarryOver(CommandEventArgs commandEventArgs) - => await new BattleCarryOver(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage).RunByMessage(); + // 持ち越し関連 + [Command(AttackType.CarryOver, + 2, + compatibleChannels: ChannelFeatureType.CarryOverID + )] + public static Task UpdateCarryOverData(CommandEventArgs commandEventArgs) + { + new BattleCarryOver(commandEventArgs).UpdateCarryOverData(); + return Task.CompletedTask; + } + + [Command("消化", + 0, + 1, + compatibleChannels: ChannelFeatureType.CarryOverID + )] + public static Task DeleteCarryOverData(CommandEventArgs commandEventArgs) + { + new BattleCarryOver(commandEventArgs).DeleteCarryOverData(); + return Task.CompletedTask; + } + + [Command( "!rm" , + 0, + 2, + compatibleChannels: ChannelFeatureType.CarryOverID + )] + public static Task DeleteOtherPlayerCarryOverData(CommandEventArgs commandEventArgs) + { + if (commandEventArgs.Arguments.Count == 2) + { + new BattleCarryOver(commandEventArgs).DeleteOtherPlayerData(); + } + else + { + new BattleCarryOver(commandEventArgs).DeleteCarryOverData(); + } + + return Task.CompletedTask; + } + + [Command("!list", + 0, + 0, + compatibleChannels: ChannelFeatureType.CarryOverID + )] + public static async Task DisplayCarryOverList(CommandEventArgs commandEventArgs) + { + await new BattleCarryOver(commandEventArgs).SendClanCarryOverList(); + } + + [Command("!init", + 0, + 0, + compatibleChannels: ChannelFeatureType.CarryOverID + )] + public static Task InitAllCarryOverData(CommandEventArgs commandEventArgs) + { + new BattleCarryOver(commandEventArgs).InitAllData(); + return Task.CompletedTask; + } [Command( compatibleChannels: new[] @@ -26,7 +84,7 @@ public static async Task Progress(CommandEventArgs commandEventArgs) => await new BattleProgress( commandEventArgs.ClanData, commandEventArgs.SocketUserMessage, - (byte) commandEventArgs.ChannelFeatureType.GetBossNumberType()) + (byte)commandEventArgs.ChannelFeatureType.GetBossNumberType()) .RunByMessage(); } } diff --git a/Script/ReceiveMessageController.cs b/Script/ReceiveMessageController.cs deleted file mode 100644 index 016bffaa..00000000 --- a/Script/ReceiveMessageController.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System.Threading.Tasks; -using Discord.WebSocket; -using PriconneBotConsoleApp.DataModel; -using PriconneBotConsoleApp.Database; -using System.Linq; -using PriconneBotConsoleApp.DataType; -using PriconneBotConsoleApp.Extension; - -namespace PriconneBotConsoleApp.Script -{ - public class ReceiveMessageController - { - private readonly ClanData m_PlayerClanData; - private readonly PlayerData m_PlayerData; - private readonly SocketUserMessage m_ReceiveMessage; - - public ReceiveMessageController(SocketUserMessage message) - { - m_ReceiveMessage = message; - var messageChannel = message.Channel as SocketGuildChannel; - var guildID = messageChannel.Guild.Id; - var userID = message.Author.Id; - m_PlayerData = DatabasePlayerDataController.LoadPlayerData(guildID, userID); - - if (m_PlayerData == null) - { - return; - } - - var userRole = messageChannel.Guild.GetRole(m_PlayerData.ClanData.ClanRoleID); - - if (userRole == null) - { - return; - } - - m_PlayerClanData = DatabaseClanDataController.LoadClanData(userRole); - } - - public async Task RunMessageReceive() - { - if (m_ReceiveMessage != null) - { - await RunMessageReceive(m_ReceiveMessage); - } - } - - public async Task RunMessageReceive(SocketUserMessage message) - { - await new TimeLineConversion(message).RunByMessage(); - await new PriconneEventViewer(message).SendEventInfomationByMessage(); - await new Dice(message).Run(); - - if (m_PlayerData == null || m_PlayerClanData == null) - { - return; - } - - var messageChannelID = message.Channel.Id; - var featureID = m_PlayerClanData.ChannelData.FirstOrDefault(x => x.ChannelID == messageChannelID)?.FeatureID ?? 0; - - if (messageChannelID == m_PlayerClanData.ChannelData.GetChannelID(m_PlayerClanData.ClanID, ChannelFeatureType.ReserveID)) - { - await new BattleReservation(m_PlayerClanData, message).RunReservationCommand(); - } - - if (messageChannelID == m_PlayerClanData.ChannelData.GetChannelID(m_PlayerClanData.ClanID, ChannelFeatureType.ReserveResultID)) - { - await new BattleReservation(m_PlayerClanData, message).RunReservationResultCommand(); - } - - if (messageChannelID == m_PlayerClanData.ChannelData.GetChannelID(m_PlayerClanData.ClanID, ChannelFeatureType.TaskKillID)) - { - await new BattleTaskKill(m_PlayerClanData, message).RunByMessageCommands(); - } - - if (messageChannelID == m_PlayerClanData.ChannelData.GetChannelID(m_PlayerClanData.ClanID, ChannelFeatureType.ReportID)) - { - await new BattleReport(m_PlayerClanData, message).RunByMessage(); - } - - if (messageChannelID == m_PlayerClanData.ChannelData.GetChannelID(m_PlayerClanData.ClanID, ChannelFeatureType.CarryOverID)) - { - await new BattleCarryOver(m_PlayerClanData, message).RunByMessage(); - } - - BattleDeclaration battleDeclaration = featureID switch - { - (int)ChannelFeatureType.DeclareBoss1ID => new(m_PlayerClanData, message, BossNumberType.Boss1Number), - (int)ChannelFeatureType.DeclareBoss2ID => new(m_PlayerClanData, message, BossNumberType.Boss2Number), - (int)ChannelFeatureType.DeclareBoss3ID => new(m_PlayerClanData, message, BossNumberType.Boss3Number), - (int)ChannelFeatureType.DeclareBoss4ID => new(m_PlayerClanData, message, BossNumberType.Boss4Number), - (int)ChannelFeatureType.DeclareBoss5ID => new(m_PlayerClanData, message, BossNumberType.Boss5Number), - _ => null, - }; - - if (battleDeclaration != null) - { - await battleDeclaration.RunDeclarationCommandByMessage(); - } - - BattleProgress battleProgress = featureID switch - { - (uint)ChannelFeatureType.ProgressBoss1ID => new(m_PlayerClanData, message, (byte)BossNumberType.Boss1Number), - (uint)ChannelFeatureType.ProgressBoss2ID => new(m_PlayerClanData, message, (byte)BossNumberType.Boss2Number), - (uint)ChannelFeatureType.ProgressBoss3ID => new(m_PlayerClanData, message, (byte)BossNumberType.Boss3Number), - (uint)ChannelFeatureType.ProgressBoss4ID => new(m_PlayerClanData, message, (byte)BossNumberType.Boss4Number), - (uint)ChannelFeatureType.ProgressBoss5ID => new(m_PlayerClanData, message, (byte)BossNumberType.Boss5Number), - _ => null, - }; - - if (battleProgress != null) - { - await battleProgress.RunByMessage(); - } - } - } -} From 66e7b59f4699395d704454f0b17619da9f915c1d Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 1 Aug 2021 19:37:08 +0900 Subject: [PATCH 09/50] =?UTF-8?q?GetProgressData=E3=81=ABNull=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Shiori/DatabaseProgressController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Database/Shiori/DatabaseProgressController.cs b/Database/Shiori/DatabaseProgressController.cs index 5c13a8c7..89bb012d 100644 --- a/Database/Shiori/DatabaseProgressController.cs +++ b/Database/Shiori/DatabaseProgressController.cs @@ -23,10 +23,11 @@ public static IEnumerable GetProgressData(ClanData clanData, BossN public static IEnumerable GetProgressData(PlayerData playerData, BossNumberType bossNumber) { + var playerID = playerData?.PlayerID ?? 0; using var databaseConnector = new DatabaseConnector(); return databaseConnector.ProgressData.AsQueryable() - .Where(x => x.PlayerID == playerData.PlayerID && x.BossNumber == (byte)bossNumber && !x.DeleteFlag) + .Where(x => x.PlayerID == playerID && x.BossNumber == (byte)bossNumber && !x.DeleteFlag) .ToArray(); } From 7ebe7afbf125ca7f74e9db2dc60c1df39d2bddbe Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 1 Aug 2021 19:38:02 +0900 Subject: [PATCH 10/50] =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=B3=E3=83=8D?= =?UTF-8?q?=E3=83=AB=E3=83=BB=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=81=AEID=E3=82=92=E8=BF=94=E3=81=99=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataModel/Shiori/ClanData.cs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/DataModel/Shiori/ClanData.cs b/DataModel/Shiori/ClanData.cs index aad51050..36dafaff 100644 --- a/DataModel/Shiori/ClanData.cs +++ b/DataModel/Shiori/ClanData.cs @@ -1,4 +1,5 @@ using PriconneBotConsoleApp.DataType; +using PriconneBotConsoleApp.Extension; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -82,8 +83,30 @@ public void SetBossLap(int bossNum, int bossLap) }; } + public int GetBossLap(BossNumberType bossNumberType) + => GetBossLap((int)bossNumberType); + + public void SetBossLap(BossNumberType bossNumberType, int bossLap) + => SetBossLap((int)bossNumberType, bossLap); + + /// + /// クラン内のチャンネルIDを返す。 + /// + /// + /// + public ulong GetChannelID(ChannelFeatureType channelFeatureType) + => ChannelData?.GetChannelID(ClanID, channelFeatureType) ?? 0; + /// - /// 最も周回数を返す + /// クラン内のメッセージIDを返す。 + /// + /// + /// + public ulong GetMessageID(MessageFeatureType messageFeatureType) + => MessageData?.GetMessageID(ClanID, messageFeatureType) ?? 0; + + /// + /// 最も小さい周回数を返す /// /// public int GetMinBossLap() @@ -104,7 +127,7 @@ public byte GetNowBoss() { return (byte)BossNumberType.Boss5Number; } - if (Boss1Lap == Boss2Lap + 1 ) + if (Boss1Lap == Boss2Lap + 1) { return (byte)BossNumberType.Boss1Number; } @@ -145,5 +168,4 @@ public ushort GetNowLap() } } } - } From 6d8b735813f4195945f860d987881158d399c6f3 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 1 Aug 2021 19:38:24 +0900 Subject: [PATCH 11/50] =?UTF-8?q?BossNumber=E3=81=ABUnknown=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/BossNumberType.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/DataType/BossNumberType.cs b/DataType/BossNumberType.cs index 6ca9c3a0..b792c2b6 100644 --- a/DataType/BossNumberType.cs +++ b/DataType/BossNumberType.cs @@ -2,6 +2,7 @@ { public enum BossNumberType { + Unknown = 0, Boss1Number = 1, Boss2Number = 2, Boss3Number = 3, From 221211945ac81a336f700aacd1d7be076e60590a Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 1 Aug 2021 19:39:07 +0900 Subject: [PATCH 12/50] =?UTF-8?q?PlayerData=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataModel/CommandEventArgs.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DataModel/CommandEventArgs.cs b/DataModel/CommandEventArgs.cs index 989d057d..3d63ce05 100644 --- a/DataModel/CommandEventArgs.cs +++ b/DataModel/CommandEventArgs.cs @@ -25,8 +25,8 @@ public CommandEventArgs(SocketUserMessage socketUserMessage) Author = SocketUserMessage.Author as SocketGuildUser; Channel = SocketUserMessage.Channel as SocketTextChannel; - var playerData = DatabasePlayerDataController.LoadPlayerData(Channel.Guild.Id, SocketUserMessage.Author.Id); - Role = Channel.Guild.GetRole(playerData?.ClanData.ClanRoleID ?? 0); + PlayerData = DatabasePlayerDataController.LoadPlayerData(Channel.Guild.Id, SocketUserMessage.Author.Id); + Role = Channel.Guild.GetRole(PlayerData?.ClanData.ClanRoleID ?? 0); if (Role == null) { @@ -47,6 +47,7 @@ public CommandEventArgs(SocketUserMessage socketUserMessage) public SocketTextChannel Channel { get; } public SocketRole Role { get; } public ClanData ClanData { get; } + public PlayerData PlayerData { get; } public ChannelFeatureType ChannelFeatureType { get; } } } From d18b9298568d6c6b69172a4924ce491f64253be8 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 1 Aug 2021 19:39:20 +0900 Subject: [PATCH 13/50] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/ProgressStatus.cs | 2 +- Script/ClanBattle/BattleProgress.cs | 532 ++++++++++++---------------- Script/Commands.cs | 254 +++++++++++-- 3 files changed, 449 insertions(+), 339 deletions(-) diff --git a/DataType/ProgressStatus.cs b/DataType/ProgressStatus.cs index a1febc90..951768e1 100644 --- a/DataType/ProgressStatus.cs +++ b/DataType/ProgressStatus.cs @@ -25,6 +25,6 @@ public enum ProgressStatus : byte SOS, [Description("🏃")] - CarryOver, + Fin, } } diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index a7dd4d04..37866186 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -15,14 +15,8 @@ namespace PriconneBotConsoleApp.Script { public class BattleProgress { - private readonly SocketUserMessage m_UserMessage; - private readonly SocketRole m_UserRole; - private readonly ClanData m_UserClanData; - private readonly SocketGuild m_Guild; - private readonly byte m_BossNumber; - private readonly bool m_AllBattleFlag = true; - - private ProgressData m_UserProgressData; + private readonly CommandEventArgs m_CommandEventArgs; + private readonly BossNumberType m_BossNumberType; private class PlayerInfo { @@ -55,177 +49,161 @@ public string GetNameWithData() } } - public BattleProgress(ClanData clanData, SocketUserMessage userMessage, byte bossNumber) + public BattleProgress(CommandEventArgs commandEventArgs) { - if (clanData.RoleData == null || clanData.ChannelData == null || clanData.MessageData == null) - { - clanData = DatabaseClanDataController.LoadClanData(m_UserRole); - } - - m_BossNumber = bossNumber; - m_UserClanData = clanData; - m_UserMessage = userMessage; - m_Guild = (userMessage.Channel as SocketTextChannel)?.Guild; - m_UserRole = m_Guild?.GetRole(clanData.ClanRoleID); + m_CommandEventArgs = commandEventArgs; + m_BossNumberType = ChannelTypeToBossNumber(m_CommandEventArgs.ChannelFeatureType); } - public async Task RunByMessage() + /// + /// 進行を開始するコマンド。引数は「ボス番号」。 + /// + /// + public async Task Start() { - if (m_UserMessage.Content.StartsWith("!")) - { - if (m_UserMessage.Content.StartsWith("!init")) - { - InitializeProgressData(); - return; - } - else if (m_UserMessage.Content.StartsWith("!list")) - { - await SendClanProgressList(); - return; - } - else if (m_UserMessage.Content.StartsWith("!next")) - { - await ChangeLap(); - return; - } - else if (m_UserMessage.Content.StartsWith("!call")) - { - await CallProgress(); - return; - } - else if (m_UserMessage.Content.StartsWith("!rm")) - { - await RevertOrRevertUserData(true); - return; - } - else if (m_UserMessage.Content.StartsWith("!rv")) - { - await RevertOrRevertUserData(); - return; - } - } - else + if (!ushort.TryParse(m_CommandEventArgs.Arguments[0], out var lap) + || lap > ClanBattleDefine.MaxLapNumber || lap <= 0) { - await UpdateProgressData(); + return; } - return; + await ChangeLap(lap); } - private async Task UpdateProgressData() + public async Task SendList() { - var messageData = m_UserMessage.Content.ZenToHan().Split(" ", StringSplitOptions.RemoveEmptyEntries); - var progressUser = m_UserMessage.Author; - - if (m_UserMessage.MentionedUsers.Count() == 1) - { - progressUser = m_UserMessage.MentionedUsers.FirstOrDefault(); - } - - var progressPlayerData = DatabasePlayerDataController.LoadPlayerData(m_UserRole, progressUser.Id); - m_UserProgressData = DatabaseProgressController.GetProgressData(progressPlayerData, (BossNumberType)m_BossNumber) - .Where(x => x.Status != (byte)ProgressStatus.AttackDone || x.Status != (byte)ProgressStatus.CarryOver) - .FirstOrDefault(); + await SendClanProgressList(); + } - var successFlag = false; + public async Task NextBoss() + { + await ChangeLap(); + } - if (UpdateAttackData(messageData[0])) - { - successFlag = true; - } - else if (UpdateDamageData(messageData)) - { - successFlag = true; - } - else if (m_UserProgressData == null) - { - return false; - } - else if (m_UserProgressData.ProgressID != 0 ) + /// + /// 編成データをアップデートする。 + /// + /// + /// + public async Task UpdateAttackData(AttackType attackType) + { + if (!TryGetProgressData(out var userProgressData)) { - successFlag = UpdateStatusData(messageData); + userProgressData = new ProgressData() + { + PlayerID = m_CommandEventArgs.PlayerData.PlayerID, + BossNumber = (byte)m_BossNumberType, + BattleLap = (ushort)m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType), + }; } - if (!successFlag) + if (attackType == AttackType.CarryOver) { - return false; + userProgressData.CarryOverFlag = true; } - - if (m_UserProgressData.Status == (byte)ProgressStatus.Unknown) + else { - m_UserProgressData.Status = (byte)ProgressStatus.AttackReported; + userProgressData.AttackType = (byte)attackType; } - m_UserProgressData.BossNumber = m_BossNumber; - m_UserProgressData.BattleLap = (ushort)m_UserClanData.GetBossLap(m_BossNumber); + await UpdateProgressData(userProgressData, m_CommandEventArgs.PlayerData); + } - if (m_UserProgressData.ProgressID == 0) - { - m_UserProgressData.PlayerID = progressPlayerData.PlayerID; + /// + /// ダメージ・残り時間を抽出。 + /// + /// + /// + public async Task UpdateDamageData() + { + var progressDataFlag = false; + uint damageNumber = 0; + byte remainTimeNumber = 0; - if (DatabaseProgressController.CreateProgressData(m_UserProgressData)) + if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d+万$")) + { + if (!uint.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\d+").ToString(), out damageNumber) + || damageNumber > CommonDefine.MaxDamageValue) { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); - await SendClanProgressList(); - return true; + return; } + + progressDataFlag = true; } - else + + if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d+@\d+")) { - if (DatabaseProgressController.ModifyProgressData(m_UserProgressData)) + var damageText = Regex.Match(m_CommandEventArgs.Name, @"\d+@").ToString(); + var remainTimeText = Regex.Match(m_CommandEventArgs.Name, @"@\d+").ToString(); + + if (!uint.TryParse(Regex.Match(damageText, @"\d+").ToString(), out damageNumber) + || !byte.TryParse(Regex.Match(remainTimeText, @"\d+").ToString(), out remainTimeNumber) + || damageNumber > CommonDefine.MaxDamageValue || remainTimeNumber > CommonDefine.MaxBattleTime) { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); - await SendClanProgressList(); - return true; + return; } + + progressDataFlag = true; } - return false; - } + if (!progressDataFlag) + { + return; + } - private async Task CallProgress() - { - var messageData = m_UserMessage.Content.ZenToHan().Split(" ", StringSplitOptions.RemoveEmptyEntries); + if (!TryGetProgressData(out var userProgressData)) + { + userProgressData = new ProgressData() + { + PlayerID = m_CommandEventArgs.PlayerData.PlayerID, + BossNumber = (byte)m_BossNumberType, + BattleLap = (ushort)m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType), + }; + } - if (messageData.Length != 2 || !ushort.TryParse(messageData[1], out var lap)) + if (damageNumber == 0) { - return; + userProgressData.Status = (byte)ProgressStatus.SOS; } - await ChangeLap(lap); + userProgressData.Damage = damageNumber; + userProgressData.RemainTime = remainTimeNumber; + userProgressData.CommentData = string.Join(" ", m_CommandEventArgs.Arguments); + await UpdateProgressData(userProgressData, m_CommandEventArgs.PlayerData); } - private async Task ChangeLap(ushort lap = 0) + /// + /// 進行報告のステータス変更。引数 1か2。 + /// + /// + /// + public async Task UpdateStatusData(ProgressStatus progressStatus) { - InitializeProgressData(); - var bossLap = m_UserClanData.GetBossLap(m_BossNumber); - - if (lap == 0) - { - m_UserClanData.SetBossLap(m_BossNumber, bossLap + 1); - } - else + if (!TryGetProgressData(out var userProgressData)) { - m_UserClanData.SetBossLap(m_BossNumber, lap); + return; } - DatabaseClanDataController.UpdateClanData(m_UserClanData); - await SendClanProgressList(); - - return true; + userProgressData.Status = (byte)progressStatus; + await UpdateProgressData(userProgressData, m_CommandEventArgs.PlayerData); } - private async Task RevertOrRevertUserData(bool deleteFlag = false) + /// + /// 進行データの削除や戻しを行います。 + /// + /// + /// + public async Task RemoveOrRevertUserData(bool deleteFlag = false) { - var userData = m_UserMessage.MentionedUsers.FirstOrDefault(); + var userData = m_CommandEventArgs.SocketUserMessage.MentionedUsers.FirstOrDefault(); if (userData == null) { return; } - var playerData = DatabasePlayerDataController.LoadPlayerData(m_UserRole, userData.Id); - var playerProgressData = DatabaseProgressController.GetProgressData(playerData, (BossNumberType)m_BossNumber) + var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, userData.Id); + var playerProgressData = DatabaseProgressController.GetProgressData(playerData, m_BossNumberType) .OrderByDescending(x => x.UpdateDateTime).FirstOrDefault(); if (playerProgressData == null) @@ -247,229 +225,140 @@ private async Task RevertOrRevertUserData(bool deleteFlag = false) } /// - /// 凸報告の初期化 + /// Initコマンドが入力されたとき /// /// - private void InitializeProgressData() + public async Task InitCommand() { - var deleteData = DatabaseProgressController.GetProgressData(m_UserClanData, (BossNumberType)m_BossNumber); - - if (deleteData == null) - { - return; - } - - if (DatabaseProgressController.DeleteProgressData(deleteData)) - { - return; - } - - return; + InitializeProgressData(); + await SendClanProgressList(); } - private async Task SendClanProgressList(bool removeLastMessage = true) + private async Task UpdateProgressData(ProgressData progressData, PlayerData playerData) { - var clanProgressEmbed = CreateProgressData(); - var sendMessage = await m_UserMessage.Channel.SendMessageAsync(embed: clanProgressEmbed); - var bossNumber = 0; - if (sendMessage == null) + if (progressData.Status == (byte)ProgressStatus.Unknown) { - return; + progressData.Status = (byte)ProgressStatus.AttackReported; } - if (m_AllBattleFlag) + if (progressData.ProgressID == 0) { - bossNumber = m_BossNumber; - } - - var progressChannel = m_Guild.GetChannel(m_UserClanData.ChannelData.GetChannelID(m_UserClanData.ClanID, BossNumberToChannelType(bossNumber))) as SocketTextChannel; - var lastMessageID = m_UserClanData.MessageData.GetMessageID(m_UserClanData.ClanID, BossNumberToMessageType(bossNumber)); - DatabaseMessageDataController.UpdateMessageID(m_UserClanData, sendMessage.Id, BossNumberToMessageType(bossNumber)); - var lastMessage = progressChannel.GetCachedMessage(lastMessageID); + progressData.PlayerID = playerData.PlayerID; - if (lastMessage == null) - { - IMessage lastIMessage; - - try + if (DatabaseProgressController.CreateProgressData(progressData)) { - lastIMessage = await progressChannel.GetMessageAsync(lastMessageID); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + await SendClanProgressList(); } - catch (Exception e) + } + else + { + if (DatabaseProgressController.ModifyProgressData(progressData)) { - Console.WriteLine(e.Message); - return; + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + await SendClanProgressList(); } - - await lastIMessage.DeleteAsync(); - return; } - - await lastMessage.DeleteAsync(); - return; } - /// - /// 編成データをアップデートする。 - /// - /// - /// - private bool UpdateAttackData(string inputCommand) + private async Task ChangeLap(ushort lap = 0) { - try - { - var attackType = EnumMapper.Parse(inputCommand); - - if (m_UserProgressData == null) - { - m_UserProgressData = new ProgressData(); - } - - if (attackType == AttackType.CarryOver) - { - m_UserProgressData.CarryOverFlag = true; - } - else - { - m_UserProgressData.AttackType = (byte)attackType; - } + InitializeProgressData(); + var bossLap = m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType); - return true; + if (lap == 0) + { + m_CommandEventArgs.ClanData.SetBossLap(m_BossNumberType, bossLap + 1); } - catch + else { - return false; + m_CommandEventArgs.ClanData.SetBossLap(m_BossNumberType, lap); } + + DatabaseClanDataController.UpdateClanData(m_CommandEventArgs.ClanData); + await SendClanProgressList(); } /// - /// ダメージ・残り時間を抽出。 + /// 凸進行報告状況の初期化 /// - /// /// - private bool UpdateDamageData(string[] inputCommand) + private void InitializeProgressData() { - var damageData = inputCommand.Select(x => Regex.Match(x, @"\d+万")).Where(x => x != null).FirstOrDefault().ToString(); + var deleteData = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType); - if (damageData != "") + if (deleteData == null) { - if (!uint.TryParse(Regex.Match(damageData, @"\d+").ToString(), out uint damageNumber) - || damageNumber > CommonDefine.MaxDamageValue) - { - return false; - } - - if (m_UserProgressData == null) - { - m_UserProgressData = new ProgressData(); - } + return; + } - if (damageNumber == 0) - { - m_UserProgressData.Status = (byte)ProgressStatus.SOS; - } + DatabaseProgressController.DeleteProgressData(deleteData); + } - m_UserProgressData.Damage = damageNumber; - var dataIndex = Array.IndexOf(inputCommand, damageData); - m_UserProgressData.CommentData = string.Join(" ", inputCommand.Where((value, index) => index != dataIndex)); + private async Task SendClanProgressList(bool removeLastMessage = true) + { + var clanProgressEmbed = CreateProgressList(); + var sendMessage = await m_CommandEventArgs.Channel.SendMessageAsync(embed: clanProgressEmbed); - return true; + if (sendMessage == null) + { + return; } - var timeAndDamageData = inputCommand.Select(x => Regex.Match(x, @"\d+@\d+")).Where(x => x != null).FirstOrDefault().ToString(); + var channelIDTemp = m_CommandEventArgs.ClanData.GetChannelID(BossNumberToChannelType(m_BossNumberType)); + + var progressChannelTEMP = m_CommandEventArgs.Role.Guild.GetChannel(channelIDTemp) as SocketTextChannel; + var progressChannel = progressChannelTEMP as SocketTextChannel; + var lastMessageID = m_CommandEventArgs.ClanData.GetMessageID(BossNumberToMessageType(m_BossNumberType)); + DatabaseMessageDataController.UpdateMessageID(m_CommandEventArgs.ClanData, sendMessage.Id, BossNumberToMessageType(m_BossNumberType)); + var lastMessage = progressChannel.GetCachedMessage(lastMessageID); - if (timeAndDamageData != "") + if (lastMessage == null) { - var damageText = Regex.Match(timeAndDamageData, @"\d+@").ToString(); - var remainTimeText = Regex.Match(timeAndDamageData, @"@\d+").ToString(); + IMessage lastIMessage; - if (!uint.TryParse(Regex.Match(damageText, @"\d+").ToString(), out uint damageNumber) - || !byte.TryParse(Regex.Match(remainTimeText, @"\d+").ToString(), out byte remainTimeNumber) - || damageNumber > CommonDefine.MaxDamageValue || remainTimeNumber > CommonDefine.MaxBattleTime) + try { - return false; + lastIMessage = await progressChannel.GetMessageAsync(lastMessageID); } - - if (m_UserProgressData == null) + catch (Exception e) { - m_UserProgressData = new ProgressData(); + Console.WriteLine(e.Message); + return; } - if (damageNumber == 0) + if (removeLastMessage) { - m_UserProgressData.Status = (byte)ProgressStatus.SOS; + await lastIMessage.DeleteAsync(); } - m_UserProgressData.Damage = damageNumber; - m_UserProgressData.RemainTime = remainTimeNumber; - var dataIndex = Array.IndexOf(inputCommand, timeAndDamageData); - m_UserProgressData.CommentData = string.Join(" ", inputCommand.Where((value, index) => index != dataIndex)); - - return true; - } - - return false; - } - - /// - /// 進行報告のステータス変更。 - /// - /// - /// - private bool UpdateStatusData(string[] inputCommand) - { - if (m_UserProgressData == null) - { - return false; - } - - int maxSplitNumber = 2; - var SplitData = inputCommand[0].Split("@", maxSplitNumber, StringSplitOptions.RemoveEmptyEntries); - - var dataUpdateFlag = SplitData[0] switch - { - "atk" or "凸確定" => m_UserProgressData.Status = (byte)ProgressStatus.AttackDone, - "kari" or "仮確定" => m_UserProgressData.Status = (byte)ProgressStatus.AttackReady, - "sos" or "ziko" or "jiko" or "事故" => m_UserProgressData.Status = (byte)ProgressStatus.SOS, - "〆確定" or "fin" => m_UserProgressData.Status = (byte)ProgressStatus.CarryOver, - _ => 0, - }; - - if (dataUpdateFlag == 0) - { - return false; - } - - if (SplitData.Length == 1 || !uint.TryParse(SplitData[1], out uint damegeData)) - { - return true; + return; } - - if (m_UserProgressData.Status == (byte)ProgressStatus.CarryOver) + else { - m_UserProgressData.RemainTime = (byte)damegeData; - return true; + if (removeLastMessage) + { + await lastMessage.DeleteAsync(); + } } - m_UserProgressData.Damage = damegeData; - - return true; + return; } - private Embed CreateProgressData() + private Embed CreateProgressList() { - var clanProgressData = DatabaseProgressController.GetProgressData(m_UserClanData, (BossNumberType)m_BossNumber) + var clanProgressData = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) .OrderBy(x => x.Status).ThenByDescending(x => x.Damage).ThenBy(x => x.CreateDateTime) .ToArray(); - var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_UserClanData); + var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); var progressPlayer = clanProgressData.Select(x => new PlayerInfo( clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID), x )).ToArray(); - var bossLap = m_UserClanData.GetBossLap(m_BossNumber); + var bossLap = m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType); var bossData = RediveClanBattleData.BossDataList - .FirstOrDefault(x => x.BossNumber == m_BossNumber && x.LapNumberFrom <= bossLap && (x.LapNumberTo == -1 || x.LapNumberTo >= bossLap)); + .FirstOrDefault(x => x.BossNumber == (byte)m_BossNumberType && x.LapNumberFrom <= bossLap && (x.LapNumberTo == -1 || x.LapNumberTo >= bossLap)); var summaryStringBuilder = new StringBuilder(); // 持ち越しデータ出力 @@ -478,7 +367,7 @@ private Embed CreateProgressData() var remainAttackString = new StringBuilder(); remainAttackString.Append("残凸 "); - var reportCount = DatabaseReportDataController.GetRemainPlayerCount(m_UserClanData); + var reportCount = DatabaseReportDataController.GetRemainPlayerCount(m_CommandEventArgs.ClanData); for (int i = CommonDefine.MaxReportNumber; i >= 0; i--) { @@ -510,7 +399,7 @@ private Embed CreateProgressData() var embedBuilder = new EmbedBuilder(); embedBuilder.AddField(headerFieldBuilder); embedBuilder.AddField(embedFieldBuilder); - embedBuilder.Title = $"{m_UserClanData.GetBossLap(m_BossNumber)}周目 {m_BossNumber}ボス {bossData?.Name}"; + embedBuilder.Title = $"{m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType)}周目 {(uint)m_BossNumberType}ボス {bossData?.Name}"; embedBuilder.Footer = new EmbedFooterBuilder() { @@ -520,30 +409,61 @@ private Embed CreateProgressData() return embedBuilder.Build(); } - private MessageFeatureType BossNumberToMessageType(int bossNumber) + private ProgressData GetProgressData(PlayerData playerData = null) { - return bossNumber switch + if (playerData == null) { - (int)BossNumberType.Boss1Number => MessageFeatureType.ProgressBoss1ID, - (int)BossNumberType.Boss2Number => MessageFeatureType.ProgressBoss2ID, - (int)BossNumberType.Boss3Number => MessageFeatureType.ProgressBoss3ID, - (int)BossNumberType.Boss4Number => MessageFeatureType.ProgressBoss4ID, - (int)BossNumberType.Boss5Number => MessageFeatureType.ProgressBoss5ID, + playerData = m_CommandEventArgs.PlayerData; + } + + return DatabaseProgressController.GetProgressData(playerData, m_BossNumberType) + .Where(x => x.Status != (byte)ProgressStatus.AttackDone || x.Status != (byte)ProgressStatus.Fin) + .FirstOrDefault(); + } + + private bool TryGetProgressData(out ProgressData progressData) + { + progressData = GetProgressData(); + return progressData != null; + } + + private MessageFeatureType BossNumberToMessageType(BossNumberType bossNumberType) + { + return bossNumberType switch + { + BossNumberType.Boss1Number => MessageFeatureType.ProgressBoss1ID, + BossNumberType.Boss2Number => MessageFeatureType.ProgressBoss2ID, + BossNumberType.Boss3Number => MessageFeatureType.ProgressBoss3ID, + BossNumberType.Boss4Number => MessageFeatureType.ProgressBoss4ID, + BossNumberType.Boss5Number => MessageFeatureType.ProgressBoss5ID, _ => MessageFeatureType.ProgressID, }; } - private ChannelFeatureType BossNumberToChannelType(int bossNumber) + private ChannelFeatureType BossNumberToChannelType(BossNumberType bossNumberType) { - return bossNumber switch + return bossNumberType switch { - (int)BossNumberType.Boss1Number => ChannelFeatureType.ProgressBoss1ID, - (int)BossNumberType.Boss2Number => ChannelFeatureType.ProgressBoss2ID, - (int)BossNumberType.Boss3Number => ChannelFeatureType.ProgressBoss3ID, - (int)BossNumberType.Boss4Number => ChannelFeatureType.ProgressBoss4ID, - (int)BossNumberType.Boss5Number => ChannelFeatureType.ProgressBoss5ID, + BossNumberType.Boss1Number => ChannelFeatureType.ProgressBoss1ID, + BossNumberType.Boss2Number => ChannelFeatureType.ProgressBoss2ID, + BossNumberType.Boss3Number => ChannelFeatureType.ProgressBoss3ID, + BossNumberType.Boss4Number => ChannelFeatureType.ProgressBoss4ID, + BossNumberType.Boss5Number => ChannelFeatureType.ProgressBoss5ID, _ => ChannelFeatureType.ProgressID, }; } + + private BossNumberType ChannelTypeToBossNumber(ChannelFeatureType channelFeatureType) + { + return channelFeatureType switch + { + ChannelFeatureType.ProgressBoss1ID => BossNumberType.Boss1Number, + ChannelFeatureType.ProgressBoss2ID => BossNumberType.Boss2Number, + ChannelFeatureType.ProgressBoss3ID => BossNumberType.Boss3Number, + ChannelFeatureType.ProgressBoss4ID => BossNumberType.Boss4Number, + ChannelFeatureType.ProgressBoss5ID => BossNumberType.Boss5Number, + _ => BossNumberType.Unknown, + }; + } } } diff --git a/Script/Commands.cs b/Script/Commands.cs index 8006a9a2..dae715c3 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -9,32 +9,21 @@ namespace PriconneBotConsoleApp.Script public static class Commands { // 持ち越し関連 - [Command(AttackType.CarryOver, - 2, - compatibleChannels: ChannelFeatureType.CarryOverID - )] + [Command(AttackType.CarryOver, 2, compatibleChannels: ChannelFeatureType.CarryOverID)] public static Task UpdateCarryOverData(CommandEventArgs commandEventArgs) { new BattleCarryOver(commandEventArgs).UpdateCarryOverData(); return Task.CompletedTask; } - [Command("消化", - 0, - 1, - compatibleChannels: ChannelFeatureType.CarryOverID - )] + [Command("消化", 0, 1, compatibleChannels: ChannelFeatureType.CarryOverID)] public static Task DeleteCarryOverData(CommandEventArgs commandEventArgs) { new BattleCarryOver(commandEventArgs).DeleteCarryOverData(); return Task.CompletedTask; } - [Command( "!rm" , - 0, - 2, - compatibleChannels: ChannelFeatureType.CarryOverID - )] + [Command("!rm", 0, 2, compatibleChannels: ChannelFeatureType.CarryOverID)] public static Task DeleteOtherPlayerCarryOverData(CommandEventArgs commandEventArgs) { if (commandEventArgs.Arguments.Count == 2) @@ -45,33 +34,141 @@ public static Task DeleteOtherPlayerCarryOverData(CommandEventArgs commandEventA { new BattleCarryOver(commandEventArgs).DeleteCarryOverData(); } - + return Task.CompletedTask; } - [Command("!list", - 0, - 0, - compatibleChannels: ChannelFeatureType.CarryOverID - )] + [Command("!list", 0, 0, compatibleChannels: ChannelFeatureType.CarryOverID)] public static async Task DisplayCarryOverList(CommandEventArgs commandEventArgs) { await new BattleCarryOver(commandEventArgs).SendClanCarryOverList(); } - [Command("!init", - 0, - 0, - compatibleChannels: ChannelFeatureType.CarryOverID - )] + [Command("!init", 0, 0, compatibleChannels: ChannelFeatureType.CarryOverID)] public static Task InitAllCarryOverData(CommandEventArgs commandEventArgs) { new BattleCarryOver(commandEventArgs).InitAllData(); return Task.CompletedTask; } + // 進行関連 + [Command( + AttackType.Physics, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task AttackPhysics(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.Physics); + + [Command( + AttackType.Magic, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task AttackMagic(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.Magic); + + [Command( + AttackType.NewYearKaryl, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task AttackNewYearKaryl(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.NewYearKaryl); + + [Command( + AttackType.CarryOver, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task AttackCarryOver(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.CarryOver); + + [Command( + new[] { "kari", "仮確定" }, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task UpdateProgressStatusReady(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.AttackReady); + + [Command( + new[] { "atk", "確定" }, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task UpdateProgressStatusDone(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.AttackDone); + + [Command( + new[] { "sos", "jiko", "ziko", "事故" }, + 0, + 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task UpdateProgressSOS(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.SOS); + [Command( - compatibleChannels: new[] + new[] { "〆確定", "fin" }, + 0, + 0, + new[] { ChannelFeatureType.ProgressBoss1ID, ChannelFeatureType.ProgressBoss2ID, @@ -80,11 +177,104 @@ public static Task InitAllCarryOverData(CommandEventArgs commandEventArgs) ChannelFeatureType.ProgressBoss5ID, } )] - public static async Task Progress(CommandEventArgs commandEventArgs) - => await new BattleProgress( - commandEventArgs.ClanData, - commandEventArgs.SocketUserMessage, - (byte)commandEventArgs.ChannelFeatureType.GetBossNumberType()) - .RunByMessage(); + public static async Task UpdateProgressFin(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.Fin); + + [Command( + "!init", 0, 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task InitProgressData(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).InitCommand(); + + [Command( + "!call", 1, 1, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task CallProgress(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).Start(); + + [Command( + "!list", 0, 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task DisplayList(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).SendList(); + + [Command( + "!rm", 1, 1, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task RemoveProgressData(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).RemoveOrRevertUserData(true); + + [Command( + "!rv", 1, 1, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task RevertProgressData(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).RemoveOrRevertUserData(); + + [Command( + "!next", 0, 0, + new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task NextProgressBoss(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).NextBoss(); + + [Command( + compatibleChannels: new[] + { + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID, + } + )] + public static async Task UpdateProgressDamage(CommandEventArgs commandEventArgs) + => await new BattleProgress(commandEventArgs).UpdateDamageData(); } } From 1b6aa2bd7b92840ece948e43a5ad5eb2cbf2d048 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 1 Aug 2021 19:44:04 +0900 Subject: [PATCH 14/50] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAusing=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/ProgressStatus.cs | 7 +------ Script/Commands.cs | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/DataType/ProgressStatus.cs b/DataType/ProgressStatus.cs index 951768e1..c3132e94 100644 --- a/DataType/ProgressStatus.cs +++ b/DataType/ProgressStatus.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; namespace PriconneBotConsoleApp.DataType { diff --git a/Script/Commands.cs b/Script/Commands.cs index dae715c3..bf7ce0a4 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -2,7 +2,6 @@ using PriconneBotConsoleApp.Attribute; using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; -using PriconneBotConsoleApp.Extension; namespace PriconneBotConsoleApp.Script { From ad784f25881b1b4434834a045213e4a59a4f8946 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 8 Aug 2021 14:33:41 +0900 Subject: [PATCH 15/50] =?UTF-8?q?=E5=87=B8=E5=A0=B1=E5=91=8A=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=81=AB=E9=81=A9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleProgress.cs | 1 - Script/ClanBattle/BattleReport.cs | 168 +++++++++------------------- Script/Commands.cs | 32 ++++++ 3 files changed, 87 insertions(+), 114 deletions(-) diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 37866186..324dc040 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -9,7 +9,6 @@ using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; using PriconneBotConsoleApp.Define; -using PriconneBotConsoleApp.Extension; namespace PriconneBotConsoleApp.Script { diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 9f48755f..6a5723dc 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -4,7 +4,6 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Discord; -using Discord.WebSocket; using PriconneBotConsoleApp.Database; using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; @@ -15,10 +14,7 @@ namespace PriconneBotConsoleApp.Script { public class BattleReport { - private readonly ClanData m_ClanData; - private readonly SocketUserMessage m_UserMessage; - private readonly SocketRole m_ClanRole; - private readonly SocketGuild m_Guild; + private readonly CommandEventArgs m_CommandEventArgs; private class PlayerInfo { @@ -48,71 +44,55 @@ public string GetNameWithReport() } } - public BattleReport(ClanData clanData, SocketUserMessage userMessage) + public BattleReport(CommandEventArgs commandEventArgs) { - m_ClanData = clanData; - m_UserMessage = userMessage; - m_Guild = (userMessage.Channel as SocketTextChannel)?.Guild; - m_ClanRole = m_Guild?.GetRole(clanData.ClanRoleID); + m_CommandEventArgs = commandEventArgs; } - public async Task RunByMessage() + /// + /// 個人の凸報告 + /// + public void RegisterReportData() { - if (m_UserMessage.Content.StartsWith("!")) + var reportData = new ReportData(); + + if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d\D{1,3}")) { - if (m_UserMessage.Content.StartsWith("!add")) - { - RegisterOtherUserReportData(); - } - else if (m_UserMessage.Content.StartsWith("!list")) - { - await SendClanAttackList(); - } - else if (m_UserMessage.Content.StartsWith("!rm")) - { - DeleteReportData(); - } - else if (m_UserMessage.Content.StartsWith("!init")) + var bossNumber = int.Parse(Regex.Match(m_CommandEventArgs.Name, @"\d").Value); + + if (!EnumMapper.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\D{1,3}").Value, out var attackType) + || attackType == AttackType.Unknown || attackType == AttackType.CarryOver) { - DeleteAllClanReport(); + return; } - } - else - { - RegisterReportData(); - } - } - /// - /// 個人の凸報告 - /// - private void RegisterReportData() - { - var playerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, m_UserMessage.Author.Id); + reportData.AttackType = (byte)attackType; + reportData.BossNumber = (byte)bossNumber; + } - if (playerData == null) + if (reportData.BossNumber < CommonDefine.MinBossNumber || reportData.BossNumber > CommonDefine.MaxBossNumber) { return; } - var reportData = StringToReportData(m_UserMessage.Content.ZenToHan(), playerData.PlayerID); + reportData.PlayerID = m_CommandEventArgs.PlayerData.PlayerID; if (reportData == null) { return; } - var userReportedData = DatabaseReportDataController.GetReportData(playerData); + var userReportedData = DatabaseReportDataController.GetReportData(m_CommandEventArgs.PlayerData); if (userReportedData.Count() >= CommonDefine.MaxReportNumber) { - _ = m_UserMessage.Channel.SendTimedMessageAsync(TimeDefine.ErrorMessageDisplayTime, ErrorType.UpperLimitReport.ToLabel()); + _ = m_CommandEventArgs.SocketUserMessage.Channel.SendTimedMessageAsync(TimeDefine.ErrorMessageDisplayTime, ErrorType.UpperLimitReport.ToLabel()); return; } if (DatabaseReportDataController.CreateReportData(reportData)) { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); } return; @@ -121,18 +101,17 @@ private void RegisterReportData() /// /// 個人の最新の凸報告を削除する。 /// - private void DeleteReportData() + public void DeleteReportData() { - var splitContent = m_UserMessage.Content.ZenToHan().Split(" ", StringSplitOptions.RemoveEmptyEntries); var playerData = new PlayerData(); - if (splitContent.Length == 2 - && ulong.TryParse(Regex.Match(splitContent[1], @"\d+").Value, out ulong registerUserID)) + if (m_CommandEventArgs.Arguments.Count == 1 + && ulong.TryParse(Regex.Match(m_CommandEventArgs.Arguments[0], @"\d+").Value, out ulong registerUserID)) { - playerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, registerUserID); + playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, registerUserID); } else { - playerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, m_UserMessage.Author.Id); + playerData = m_CommandEventArgs.PlayerData; } if (playerData == null) @@ -140,17 +119,16 @@ private void DeleteReportData() return; } - var recentReportData = DatabaseReportDataController.GetReportData(playerData) - .OrderBy(x => x.DateTime).ToList(); - var removeData = recentReportData.Last(); + var removeData = DatabaseReportDataController.GetReportData(playerData) + .OrderBy(x => x.DateTime).Last(); if (DatabaseReportDataController.DeleteReportData(removeData)) { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); - if (playerData.UserID != m_UserMessage.Author.Id) + if (playerData.UserID != m_CommandEventArgs.User.Id) { - _ = m_UserMessage.Channel.SendTimedMessageAsync(TimeDefine.SuccessMessageDisplayTime, + _ = m_CommandEventArgs.SocketUserMessage.Channel.SendTimedMessageAsync(TimeDefine.SuccessMessageDisplayTime, string.Format(InfomationType.DeleteInsted.ToLabel(), playerData.UserID, TimeDefine.SuccessMessageDisplayTime)); } } @@ -159,60 +137,57 @@ private void DeleteReportData() /// /// 代理報告用 /// - private void RegisterOtherUserReportData() + public void RegisterOtherUserReportData() { - var splitContent = m_UserMessage.Content.ZenToHan().Split(" ", StringSplitOptions.RemoveEmptyEntries); - - if (splitContent.Length != CommonDefine.MaxReportNumber) + if ((!ulong.TryParse(m_CommandEventArgs.Arguments[0], out var registerUserID) + && !MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out registerUserID)) + || !byte.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) + || bossNumber > CommonDefine.MaxBossNumber || bossNumber < CommonDefine.MinBossNumber + || !EnumMapper.TryParse(m_CommandEventArgs.Arguments[2], out var attackType)) { return; } - if (!ulong.TryParse(Regex.Match(splitContent[1], @"\d+").Value, out ulong registerUserID)) - { - return; - } - - var registerPlayerData = DatabasePlayerDataController.LoadPlayerData(m_ClanRole, registerUserID); + var registerPlayerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, registerUserID); if (registerPlayerData == null) { return; } - var reportData = StringToReportData(splitContent[2], registerPlayerData.PlayerID); - - if (reportData == null) + var reportData = new ReportData() { - return; - } + AttackType = (byte)attackType, + BossNumber = bossNumber, + PlayerID = registerUserID, + }; var userReportedData = DatabaseReportDataController.GetReportData(registerPlayerData); if (userReportedData.Count() >= CommonDefine.MaxReportNumber) { - _ = m_UserMessage.Channel.SendTimedMessageAsync(TimeDefine.ErrorMessageDisplayTime, ErrorType.UpperLimitReport.ToLabel()); + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync(TimeDefine.ErrorMessageDisplayTime, ErrorType.UpperLimitReport.ToLabel()); return; } if (DatabaseReportDataController.CreateReportData(reportData)) { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(EnumMapper.ToEmoji(ReactionType.Success)); } return; - } /// /// クランの凸報告を削除 /// - private void DeleteAllClanReport() + public void DeleteAllClanReport() { - var clanReportData = DatabaseReportDataController.GetReportData(m_ClanData); + var clanReportData = DatabaseReportDataController.GetReportData(m_CommandEventArgs.ClanData); if (DatabaseReportDataController.DeleteReportData(clanReportData)) { - _ = m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(EnumMapper.ToEmoji(ReactionType.Success)); + } } @@ -220,43 +195,10 @@ private void DeleteAllClanReport() /// 凸報告データ送信用 /// /// - private async Task SendClanAttackList() + public async Task SendClanAttackList() { var clanAttackEmbed = CreateClanReportData(); - await m_UserMessage.Channel.SendMessageAsync(embed: clanAttackEmbed); - } - - /// - /// メッセージ情報から報告データに変換する。 - /// - /// メッセージ内容 - /// - private ReportData StringToReportData(string messageContent, ulong playerID) - { - var userReportData = new ReportData(); - - if (Regex.IsMatch(messageContent, @"\d\D{1,3}")) - { - var bossNumber = int.Parse(Regex.Match(messageContent, @"\d").Value); - - if (!EnumMapper.TryParse(Regex.Match(messageContent, @"\D{1,3}").Value, out var attackType) - || attackType == AttackType.Unknown || attackType == AttackType.CarryOver) - { - return null; - } - - userReportData.AttackType = (byte)attackType; - userReportData.BossNumber = (byte)bossNumber; - } - - if (userReportData.BossNumber < CommonDefine.MinBossNumber || userReportData.BossNumber > CommonDefine.MaxBossNumber) - { - return null; - } - - userReportData.PlayerID = playerID; - - return userReportData; + await m_CommandEventArgs.SocketUserMessage.Channel.SendMessageAsync(embed: clanAttackEmbed); } /// @@ -267,8 +209,8 @@ private Embed CreateClanReportData() { var embedBuilder = new EmbedBuilder(); - var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_ClanData); - var reportDataList = DatabaseReportDataController.GetReportData(m_ClanData); + var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); + var reportDataList = DatabaseReportDataController.GetReportData(m_CommandEventArgs.ClanData); var playerInfoList = clanPlayerDataList.Select(x => new PlayerInfo( x.PlayerID, diff --git a/Script/Commands.cs b/Script/Commands.cs index bf7ce0a4..be2c8252 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -275,5 +275,37 @@ public static async Task NextProgressBoss(CommandEventArgs commandEventArgs) )] public static async Task UpdateProgressDamage(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateDamageData(); + + [Command("!list", 0, 0, ChannelFeatureType.ReportID)] + public static async Task ListReport(CommandEventArgs commandEventArgs) + => await new BattleReport(commandEventArgs).SendClanAttackList(); + + [Command("!rm", 0, 1, ChannelFeatureType.ReportID)] + public static Task RemovePlayerReportData(CommandEventArgs commandEventArgs) + { + new BattleReport(commandEventArgs).DeleteReportData(); + return Task.CompletedTask; + } + + [Command("!add", 3, 3, ChannelFeatureType.ReportID)] + public static Task RegisterOtherPlayerReportData(CommandEventArgs commandEventArgs) + { + new BattleReport(commandEventArgs).RegisterOtherUserReportData(); + return Task.CompletedTask; + } + + [Command("!init", 0, 0, ChannelFeatureType.ReportID)] + public static Task InitReportData(CommandEventArgs commandEventArgs) + { + new BattleReport(commandEventArgs).DeleteAllClanReport(); + return Task.CompletedTask; + } + + [Command(minArgumentLength: 0, maxArgumentLength: 0, compatibleChannels: ChannelFeatureType.ReportID)] + public static Task RegisterReportData(CommandEventArgs commandEventArgs) + { + new BattleReport(commandEventArgs).RegisterReportData(); + return Task.CompletedTask; + } } } From 9da05b1774e83d8f538832eeedbf6550863651be Mon Sep 17 00:00:00 2001 From: ca45382 Date: Mon, 9 Aug 2021 20:02:26 +0900 Subject: [PATCH 16/50] =?UTF-8?q?=E4=BA=88=E7=B4=84=E3=82=92=E3=82=B3?= =?UTF-8?q?=E3=83=9E=E3=83=B3=E3=83=89=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/WarningType.cs | 15 + .../Shiori/DatabaseReservationController.cs | 72 ++-- Define/TimeDefine.cs | 1 + Script/ClanBattle/BattleDeclaration.cs | 16 +- Script/ClanBattle/BattleReservation.cs | 370 +++--------------- Script/ClanBattle/BattleReservationSummary.cs | 155 ++++++++ Script/ClanBattle/UpdateDate.cs | 2 +- Script/Commands.cs | 63 +++ Script/ReceiveInteractionController.cs | 7 +- 9 files changed, 332 insertions(+), 369 deletions(-) create mode 100644 DataType/WarningType.cs create mode 100644 Script/ClanBattle/BattleReservationSummary.cs diff --git a/DataType/WarningType.cs b/DataType/WarningType.cs new file mode 100644 index 00000000..0ced3198 --- /dev/null +++ b/DataType/WarningType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PriconneBotConsoleApp.DataType +{ + public enum WarningType + { + [Description("コメントが長いので切り取られました。\n 問題がある場合は予約削除をして再度予約してください。") ] + LongComment, + } +} diff --git a/Database/Shiori/DatabaseReservationController.cs b/Database/Shiori/DatabaseReservationController.cs index f644d435..5e09cb5f 100644 --- a/Database/Shiori/DatabaseReservationController.cs +++ b/Database/Shiori/DatabaseReservationController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Microsoft.EntityFrameworkCore; using PriconneBotConsoleApp.DataModel; @@ -35,17 +36,15 @@ public static List LoadReservationData(ClanData clanData) public static List LoadReservationData(PlayerData playerData) { - if (playerData == null) + if (playerData == null|| playerData.PlayerID == 0) { return null; } using var databaseConnector = new DatabaseConnector(); - var playerID = LoadPlayerID(databaseConnector.PlayerData, playerData); - return databaseConnector.ReservationData.AsQueryable() - .Where(b => b.PlayerID == playerID && !b.DeleteFlag) + .Where(b => b.PlayerID == playerData.PlayerID && !b.DeleteFlag) .OrderBy(o => o.BattleLap).ThenBy(d => d.BossNumber) .ToList(); } @@ -96,28 +95,24 @@ public static List LoadBossLapReservationData(ClanData clanData /// public static void CreateReservationData(ReservationData reservationData) { - var playerData = reservationData.PlayerData; - using var databaseConnector = new DatabaseConnector(); - var transaction = databaseConnector.Database.BeginTransaction(); - var playerID = LoadPlayerID(databaseConnector.PlayerData, playerData); - - if (playerID == 0) + if (reservationData.PlayerID == 0) { - transaction.Rollback(); return; } - databaseConnector.ReservationData.Add( - new ReservationData() - { - PlayerID = playerID, - BattleLap = reservationData.BattleLap, - BossNumber = reservationData.BossNumber, - CommentData = reservationData.CommentData - }); + using var databaseConnector = new DatabaseConnector(); + var transaction = databaseConnector.Database.BeginTransaction(); - databaseConnector.SaveChanges(); - transaction.Commit(); + databaseConnector.ReservationData.Add(reservationData); + try + { + databaseConnector.SaveChanges(); + transaction.Commit(); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } } /// @@ -126,30 +121,21 @@ public static void CreateReservationData(ReservationData reservationData) /// public static void UpdateReservationData(ReservationData reservationData) { - var playerData = reservationData.PlayerData; using var databaseConnector = new DatabaseConnector(); var transaction = databaseConnector.Database.BeginTransaction(); - var playerID = LoadPlayerID(databaseConnector.PlayerData, playerData); + var updateData = databaseConnector.ReservationData + .FirstOrDefault(x => x.ReserveID == reservationData.ReserveID); - if (playerID == 0) + try { - transaction.Rollback(); - return; + updateData.CommentData = reservationData.CommentData; + databaseConnector.SaveChanges(); + transaction.Commit(); } - - var updateData = databaseConnector.ReservationData - .FirstOrDefault(d => d.PlayerID == playerID && d.BattleLap == reservationData.BattleLap - && d.BossNumber == reservationData.BossNumber && !d.DeleteFlag); - - if (updateData == null) + catch { transaction.Rollback(); - return; } - - updateData.CommentData = reservationData.CommentData; - databaseConnector.SaveChanges(); - transaction.Commit(); } public static void DeleteReservationData(ReservationData reservationData) @@ -176,15 +162,5 @@ public static void DeleteReservationData(IEnumerable reservatio databaseConnector.SaveChanges(); transaction.Commit(); } - - private static ulong LoadPlayerID(IQueryable queryable, PlayerData playerData) - { - return queryable - .Include(b => b.ClanData) - .FirstOrDefault(b => b.ClanData.ServerID == playerData.ClanData.ServerID - && b.ClanData.ClanRoleID == playerData.ClanData.ClanRoleID - && b.UserID == playerData.UserID) - ?.PlayerID ?? 0; - } } } diff --git a/Define/TimeDefine.cs b/Define/TimeDefine.cs index 0fcb6dc1..8bb0a977 100644 --- a/Define/TimeDefine.cs +++ b/Define/TimeDefine.cs @@ -8,6 +8,7 @@ public static class TimeDefine public readonly static TimeSpan DailyRefreshTime = new(5, 0, 30); public readonly static TimeSpan ErrorMessageDisplayTime = new(0, 0, 5); + public readonly static TimeSpan WarningMessageDisplayTime = new(0, 0, 20); public readonly static TimeSpan SuccessMessageDisplayTime = new(0, 0, 30); } } diff --git a/Script/ClanBattle/BattleDeclaration.cs b/Script/ClanBattle/BattleDeclaration.cs index 7d72d56e..582bc32f 100644 --- a/Script/ClanBattle/BattleDeclaration.cs +++ b/Script/ClanBattle/BattleDeclaration.cs @@ -80,9 +80,9 @@ public async Task RunDeclarationCommandByMessage() if (m_UserMessage.Content.StartsWith("!call")) { await DeclarationCallCommand(); - var battleReservation = new BattleReservation(m_UserRole); - battleReservation.DeleteUnusedData(m_BossNumber); - await battleReservation.UpdateSystemMessage(); + var battleReservationSummary = new BattleReservationSummary(m_UserRole); + battleReservationSummary.DeleteUnusedData(m_BossNumber); + await battleReservationSummary.UpdateMessage(); } } @@ -119,7 +119,7 @@ public async Task RunByInteraction() case ButtonType.SubdueBoss: await NextBossCommand(); - await new BattleReservation(m_UserRole).UpdateSystemMessage(); + await new BattleReservationSummary(m_UserRole).UpdateMessage(); return; case ButtonType.CancelBattle: @@ -128,7 +128,7 @@ public async Task RunByInteraction() } await UpdateDeclarationBotMessage(); - await new BattleReservation(m_UserRole).UpdateSystemMessage(); + await new BattleReservationSummary(m_UserRole).UpdateMessage(); } /// @@ -307,9 +307,9 @@ private async Task NextBossCommand() m_UserClanData.SetBossLap(m_BossNumber, nextBattleLap); DatabaseClanDataController.UpdateClanData(m_UserClanData); - var battleReservation = new BattleReservation(m_UserRole); - battleReservation.DeleteUnusedData(m_BossNumber); - await Task.WhenAll(SendDeclarationBotMessage(), battleReservation.UpdateSystemMessage()); + var battleReservationSummary = new BattleReservationSummary(m_UserRole); + battleReservationSummary.DeleteUnusedData(m_BossNumber); + await Task.WhenAll(SendDeclarationBotMessage(), battleReservationSummary.UpdateMessage()); } /// diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index 32bbaf87..b477bc63 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -1,17 +1,15 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Reflection; -using System.ComponentModel; using Discord; using Discord.WebSocket; +using PriconneBotConsoleApp.Database; using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; -using PriconneBotConsoleApp.Database; -using PriconneBotConsoleApp.Extension; -using System.Collections.Generic; using PriconneBotConsoleApp.Define; +using PriconneBotConsoleApp.Extension; namespace PriconneBotConsoleApp.Script { @@ -19,232 +17,87 @@ public class BattleReservation { private const int MaxCommentLength = 30; - private readonly ClanData m_UserClanData; - private readonly SocketRole m_UserRole; - private readonly SocketUserMessage m_UserMessage; - private readonly SocketInteraction m_UserInteraction; - - private BattleReservation( - ClanData userClanData, - ISocketMessageChannel channel, - SocketUserMessage userMessage = null, - SocketInteraction userInterction = null) - { - m_UserClanData = userClanData; - m_UserRole = (channel as SocketGuildChannel)?.Guild.GetRole(m_UserClanData.ClanRoleID); - m_UserMessage = userMessage; - m_UserInteraction = userInterction; - } + private readonly CommandEventArgs m_CommandEventArgs; - public BattleReservation(ClanData userClanData, SocketUserMessage message) - : this(userClanData, message.Channel, userMessage: message) + public BattleReservation(CommandEventArgs commandEventArgs) { + m_CommandEventArgs = commandEventArgs; } - public BattleReservation(ClanData userClanData, SocketInteraction interaction) - : this(userClanData, interaction.Channel, userInterction: interaction) - { - } - - public BattleReservation(SocketRole userRole) + /// + /// 個人の予約一覧を表示する。引数は無し。 + /// + public void PlayerReserveList() { - m_UserRole = userRole; - m_UserClanData = DatabaseClanDataController.LoadClanData(userRole); + _ = m_CommandEventArgs.Channel.SendMessageAsync( + CreateUserReservationDataMessage(m_CommandEventArgs.PlayerData)); } - public async Task RunReservationCommand() + public void RegisterReserveData() { - var userMessage = m_UserMessage; - - if (userMessage == null) + if (!IsReservationAllowTime()) { + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync( + TimeDefine.ErrorMessageDisplayTime, + string.Format(ErrorType.OutOfReservationTime.ToLabel(), + $"{m_CommandEventArgs.ClanData.ReservationStartTime.Hours}:00", + $"{m_CommandEventArgs.ClanData.ReservationEndTime.Hours}:00") + ); return; } - var messageContents = userMessage.Content; - - if (messageContents.StartsWith("予約")) - { - switch (messageContents) - { - case "予約": - case "予約確認": - case "予約状況": - Console.WriteLine("予約確認"); - await userMessage.Channel.SendMessageAsync(CreateUserReservationDataMessage()); - return; - } - - if (!IsReservationAllowTime()) - { - await SendErrorMessage(ErrorType.OutOfReservationTime, - $"{m_UserClanData.ReservationStartTime.Hours}:00", $"{m_UserClanData.ReservationEndTime.Hours}:00"); - return; - } - - var reservationData = MessageToReservationData(); - - if (reservationData is null) - { - await SendErrorMessage(ErrorType.FailedReservation); - return; - } - - var allowReservationLap = m_UserClanData.ReservationLap == 0 - ? ClanBattleDefine.MaxLapNumber : (m_UserClanData.ReservationLap + m_UserClanData.GetMinBossLap()); - - if (reservationData.BattleLap > allowReservationLap) - { - await SendErrorMessage(ErrorType.OutOfReservationBossLaps, allowReservationLap.ToString()); - return; - } - - RegisterReservationData(reservationData); - await SuccessAddEmoji(); - await UpdateSystemMessage(); - - if (m_UserClanData.GetBossLap(reservationData.BossNumber) == reservationData.BattleLap) - { - await new BattleDeclaration(m_UserRole, (BossNumberType)reservationData.BossNumber).UpdateDeclarationBotMessage(); - } - } - else if (messageContents.StartsWith("削除")) - { - var deleteReservationData = MessageToReservationData(); - - if (deleteReservationData is null) - { - // await FailedToRegisterMessage(); - return; - } + var reservationData = MessageToReservationData(); - if (DeleteUserReservationData(deleteReservationData)) - { - await SuccessAddEmoji(); - await UpdateSystemMessage(); - } - } - else if (messageContents.StartsWith("!rm")) - { - var userReservationData = MessageToUserReservationData(); - - if (userReservationData == null || !DeleteUserReservationData(userReservationData)) - { - return; - } - - await SuccessAddEmoji(); - await UpdateSystemMessage(); - - if (m_UserClanData.GetBossLap(userReservationData.BossNumber) == userReservationData.BattleLap) - { - await new BattleDeclaration(m_UserRole, (BossNumberType)userReservationData.BossNumber).UpdateDeclarationBotMessage(); - } - } - } - - - public async Task RunReservationResultCommand() - { - if (m_UserMessage.Content.StartsWith("!start")) - { - await SendSystemMessage(); - } - } - - public async Task RunResultInteraction() - { - if (m_UserInteraction == null) + if (reservationData is null) { + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync( + TimeDefine.ErrorMessageDisplayTime, + ErrorType.FailedReservation.ToLabel() + ); return; } - var messageComponent = (SocketMessageComponent)m_UserInteraction; + var allowReservationLap = m_CommandEventArgs.ClanData.ReservationLap == 0 + ? ClanBattleDefine.MaxLapNumber : (m_CommandEventArgs.ClanData.ReservationLap + m_CommandEventArgs.ClanData.GetMinBossLap()); - if (!Enum.TryParse(messageComponent.Data.CustomId, out var buttonType)) + if (reservationData.BattleLap > allowReservationLap) { + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync( + TimeDefine.ErrorMessageDisplayTime, + string.Format(ErrorType.OutOfReservationBossLaps.ToLabel(), allowReservationLap.ToString()) + ); return; } - switch (buttonType) - { - case ButtonType.Reload: - await UpdateSystemMessage(); - break; - } - } + RegisterReservationData(reservationData); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); + _ = new BattleReservationSummary(m_CommandEventArgs.Role, m_CommandEventArgs.ClanData).UpdateMessage(); - /// - /// 凸予約一覧チャンネルにメッセージを送信する。 - /// - /// - public async Task SendSystemMessage() - { - var embedData = CreateAllReservationDataMessage(); - var componentData = CreateSystemMessageComponent(); - var reservationResultChannelID = m_UserClanData.ChannelData - .GetChannelID(m_UserClanData.ClanID, ChannelFeatureType.ReserveResultID); - - if (reservationResultChannelID == 0) + if (m_CommandEventArgs.ClanData.GetBossLap(reservationData.BossNumber) == reservationData.BattleLap) { - return; + _ = new BattleDeclaration(m_CommandEventArgs.Role, (BossNumberType)reservationData.BossNumber).UpdateDeclarationBotMessage(); } - - var resultChannel = m_UserRole.Guild - .GetTextChannel(reservationResultChannelID); - - var sendedMessageData = await resultChannel.SendMessageAsync(embed: embedData, component: componentData); - DatabaseMessageDataController.UpdateMessageID(m_UserClanData, sendedMessageData.Id, MessageFeatureType.ReserveResultID); } - public async Task UpdateSystemMessage() + public void DeleteReserveData() { - var reservationMessageID = m_UserClanData.MessageData - .GetMessageID(m_UserClanData.ClanID, MessageFeatureType.ReserveResultID); - var reservationResultChannelID = m_UserClanData.ChannelData - .GetChannelID(m_UserClanData.ClanID, ChannelFeatureType.ReserveResultID); + var deleteReservationData = MessageToReservationData(); - if (reservationResultChannelID == 0 || reservationMessageID == 0) + if (deleteReservationData is null) { return; } - var guildChannel = m_UserRole.Guild - .GetChannel(reservationResultChannelID) as SocketTextChannel; - var socketMessage = guildChannel.GetCachedMessage(reservationMessageID); - - if (socketMessage == null || !(socketMessage is SocketUserMessage)) + if (DeleteUserReservationData(deleteReservationData)) { - var message = await guildChannel.GetMessageAsync(reservationMessageID); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); + _ = new BattleReservationSummary(m_CommandEventArgs.Role, m_CommandEventArgs.ClanData).UpdateMessage(); - if (message != null) + if (m_CommandEventArgs.ClanData.GetBossLap(deleteReservationData.BossNumber) == deleteReservationData.BattleLap) { - await guildChannel.DeleteMessageAsync(message); - await SendSystemMessage(); + _ = new BattleDeclaration(m_CommandEventArgs.Role, (BossNumberType)deleteReservationData.BossNumber).UpdateDeclarationBotMessage(); } - - return; } - - var serverMessage = socketMessage as SocketUserMessage; - var embedData = CreateAllReservationDataMessage(); - await serverMessage.ModifyAsync(x => x.Embed = embedData); - } - - public void DeleteUnusedData(byte bossNumber) - { - var clanReservationData = DatabaseReservationController.LoadReservationData(m_UserClanData, bossNumber); - var bossLap = m_UserClanData.GetBossLap(bossNumber); - var deleteData = clanReservationData.Where(x => x.BattleLap < bossLap); - DatabaseReservationController.DeleteReservationData(deleteData); - } - - private MessageComponent CreateSystemMessageComponent() - { - ComponentBuilder componentBuilder = new(); - componentBuilder.WithButton( - ButtonType.Reload.ToLongLabel(), ButtonType.Reload.ToString(), ButtonStyle.Secondary, ButtonType.Reload.ToEmoji()); - return componentBuilder.Build(); } /// @@ -255,80 +108,47 @@ private MessageComponent CreateSystemMessageComponent() /// private ReservationData MessageToReservationData() { - var splitMessageContent = m_UserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); - - if (splitMessageContent.Length < 3 - || !(byte.TryParse(splitMessageContent[1], out byte battleLap) && battleLap > 0) - || !(byte.TryParse(splitMessageContent[2], out byte bossNumber) && bossNumber <= CommonDefine.MaxBossNumber && bossNumber >= CommonDefine.MinBossNumber) - || battleLap < m_UserClanData.GetBossLap(bossNumber)) + if (!Enum.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) + || !(byte.TryParse(m_CommandEventArgs.Arguments[0], out var battleLap) && battleLap > m_CommandEventArgs.ClanData.GetBossLap(bossNumber))) { return null; } - var commentData = string.Join(' ', splitMessageContent.Skip(3)); + + var commentData = string.Join(' ', m_CommandEventArgs.Arguments.Skip(2)); if (commentData.Length > MaxCommentLength) { commentData = commentData.Substring(0, MaxCommentLength); - m_UserMessage.Channel.SendMessageAsync($"コメントが長いので切り取られました。\n 問題がある場合は予約削除をして再度予約してください。"); + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync(TimeDefine.WarningMessageDisplayTime, WarningType.LongComment.ToLabel()); } return new ReservationData() { - PlayerData = new PlayerData - { - ClanData = m_UserClanData, - UserID = m_UserMessage.Author.Id, - }, + PlayerID = m_CommandEventArgs.PlayerData.PlayerID, BattleLap = battleLap, - BossNumber = bossNumber, + BossNumber = (byte)bossNumber, CommentData = commentData, }; } private void RegisterReservationData(ReservationData reservationData) { - var allSqlReservationData = DatabaseReservationController.LoadReservationData(reservationData.PlayerData); + var allSqlReservationData = DatabaseReservationController.LoadReservationData(m_CommandEventArgs.PlayerData); - var doesExistReservationData = allSqlReservationData - .Any(x => x.BossNumber == reservationData.BossNumber && x.BattleLap == reservationData.BattleLap); + var DatabaseReservationData = allSqlReservationData + .FirstOrDefault(x => x.BossNumber == reservationData.BossNumber && x.BattleLap == reservationData.BattleLap); - if (!doesExistReservationData) + if (DatabaseReservationData == null) { DatabaseReservationController.CreateReservationData(reservationData); } else { + reservationData.ReserveID = DatabaseReservationData.ReserveID; DatabaseReservationController.UpdateReservationData(reservationData); } } - /// - /// 個人が予約しているデータの取得 - /// - /// - private ReservationData MessageToUserReservationData() - { - var splitMessageContent = m_UserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); - - if (splitMessageContent.Length != 4 - || !ulong.TryParse(splitMessageContent[1], out ulong userID) - || !(byte.TryParse(splitMessageContent[2], out byte battleLap) && battleLap > 0) - || !(byte.TryParse(splitMessageContent[3], out byte bossNumber) && bossNumber <= CommonDefine.MaxBossNumber && bossNumber >= CommonDefine.MinBossNumber)) - { - return null; - } - - var playerData = DatabasePlayerDataController.LoadPlayerData(m_UserRole, userID); - - if (playerData == null) - { - return null; - } - - return DatabaseReservationController.LoadReservationData(playerData) - .FirstOrDefault(d => d.BattleLap == battleLap && d.BossNumber == bossNumber); - } - private bool DeleteUserReservationData(ReservationData reservationData) { var userReservationDataList = DatabaseReservationController.LoadReservationData(reservationData.PlayerData); @@ -347,11 +167,6 @@ private bool DeleteUserReservationData(ReservationData reservationData) return true; } - private string CreateUserReservationDataMessage() - => CreateUserReservationDataMessage( - DatabasePlayerDataController.LoadPlayerData(m_UserRole, m_UserMessage.Author.Id) - ); - private string CreateUserReservationDataMessage(PlayerData playerData) { var reservationDataSet = DatabaseReservationController.LoadReservationData(playerData); @@ -377,82 +192,19 @@ private string CreateUserReservationDataMessage(PlayerData playerData) return messageData.ToString(); } - /// - /// 予約メッセージを作成する - /// - /// - /// - private Embed CreateAllReservationDataMessage() - { - var reservationDataSet = DatabaseReservationController.LoadReservationData(m_UserClanData); - List> reservationDataList = new(); - - for (var i = 0; i < CommonDefine.MaxBossNumber; i++) - { - reservationDataList.Add(new List()); - } - - reservationDataSet.ForEach(x => reservationDataList[x.BossNumber - 1].Add(x)); - EmbedBuilder embedBuilder = new(); - - for (var i = 0; i < CommonDefine.MaxBossNumber; i++) - { - EmbedFieldBuilder fieldBuilder = new(); - - if (!reservationDataList[i].Any()) - { - // 何かの空白代入して空行を生成している。 - fieldBuilder.Value = "\n\u200b"; - } - else - { - StringBuilder messageData = new(); - messageData.AppendLine("```python"); - reservationDataList[i].ForEach(x => messageData.AppendLine($"{x.BattleLap,2}周目 {x.PlayerData.GuildUserName} {x.CommentData}")); - messageData.AppendLine("```"); - fieldBuilder.Value = messageData.ToString(); - } - - fieldBuilder.Name = $"{i + 1}ボス({reservationDataList[i].Count}件)"; - embedBuilder.AddField(fieldBuilder); - } - - embedBuilder.Title = $"現在の予約状況:計{reservationDataSet.Count}件"; - - return embedBuilder.Build(); - } - - private async Task SendErrorMessage(ErrorType type, params string[] parameters) - { - var descriptionString = type.GetDescription(); - var sendMessage = string.Empty; - if (descriptionString == null) - { - sendMessage = type.ToString(); - } - else - { - sendMessage = string.Format(descriptionString, parameters); - } - await m_UserMessage.Channel.SendMessageAsync(sendMessage); - } - - private async Task SuccessAddEmoji() - => await m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.GetDescription())); - /// /// 予約できる時間かどうか判断する。 /// /// private bool IsReservationAllowTime() { - if (m_UserClanData == null) + if (m_CommandEventArgs.ClanData == null) { return false; } - var startTime = m_UserClanData.ReservationStartTime; - var endTime = m_UserClanData.ReservationEndTime; + var startTime = m_CommandEventArgs.ClanData.ReservationStartTime; + var endTime = m_CommandEventArgs.ClanData.ReservationEndTime; var nowTime = DateTime.Now.TimeOfDay; if (startTime.Hours == 0 && endTime.Hours == 0) diff --git a/Script/ClanBattle/BattleReservationSummary.cs b/Script/ClanBattle/BattleReservationSummary.cs new file mode 100644 index 00000000..1b0e1874 --- /dev/null +++ b/Script/ClanBattle/BattleReservationSummary.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord; +using Discord.WebSocket; +using PriconneBotConsoleApp.Database; +using PriconneBotConsoleApp.DataModel; +using PriconneBotConsoleApp.DataType; +using PriconneBotConsoleApp.Define; + +namespace PriconneBotConsoleApp.Script +{ + public class BattleReservationSummary + { + private readonly ClanData m_ClanData; + private readonly SocketRole m_Role; + private readonly SocketTextChannel m_SocketTextChannel; + + public BattleReservationSummary(SocketRole role, ClanData clanData = null) + { + m_Role = role; + if (clanData == null) + { + m_ClanData = DatabaseClanDataController.LoadClanData(m_Role); + } + else + { + m_ClanData = clanData; + } + m_SocketTextChannel = m_Role.Guild.GetChannel(m_ClanData.GetChannelID(ChannelFeatureType.ReserveResultID)) + as SocketTextChannel; + } + + public async Task RunInteraction(SocketInteraction socketInteraction) + { + var messageComponent = (SocketMessageComponent)socketInteraction; + + if (!Enum.TryParse(messageComponent.Data.CustomId, out var buttonType)) + { + return; + } + + switch (buttonType) + { + case ButtonType.Reload: + await UpdateMessage(); + break; + } + } + + /// + /// 凸予約一覧チャンネルにメッセージを送信する。 + /// + /// + public async Task SendMessage() + { + var embedData = CreateEmbed(); + var componentData = CreateComponent(); + var sendedMessageData = await m_SocketTextChannel.SendMessageAsync(embed: embedData, component: componentData); + DatabaseMessageDataController.UpdateMessageID(m_ClanData, sendedMessageData.Id, MessageFeatureType.ReserveResultID); + } + + public async Task UpdateMessage() + { + if (m_SocketTextChannel == null) + { + return; + } + + var reservationMessageID = m_ClanData.GetMessageID(MessageFeatureType.ReserveResultID); + var cachedMessage = m_SocketTextChannel.GetCachedMessage(reservationMessageID); + var embedData = CreateEmbed(); + var componentData = CreateComponent(); + + if (cachedMessage is SocketUserMessage serverMessage) + { + await serverMessage.ModifyAsync(x => x.Embed = embedData); + } + else + { + var message = await m_SocketTextChannel.GetMessageAsync(reservationMessageID); + await SendMessage(); + + if (message != null) + { + await m_SocketTextChannel.DeleteMessageAsync(message); + } + } + } + + public void DeleteUnusedData(byte bossNumber) + { + var clanReservationData = DatabaseReservationController.LoadReservationData(m_ClanData, bossNumber); + var bossLap = m_ClanData.GetBossLap(bossNumber); + var deleteData = clanReservationData.Where(x => x.BattleLap < bossLap); + DatabaseReservationController.DeleteReservationData(deleteData); + } + + /// + /// 予約メッセージを作成する + /// + /// + /// + private Embed CreateEmbed() + { + var reservationDataSet = DatabaseReservationController.LoadReservationData(m_ClanData); + List> reservationDataList = new(); + + for (var i = 0; i < CommonDefine.MaxBossNumber; i++) + { + reservationDataList.Add(new List()); + } + + reservationDataSet.ForEach(x => reservationDataList[x.BossNumber - 1].Add(x)); + EmbedBuilder embedBuilder = new(); + + for (var i = 0; i < CommonDefine.MaxBossNumber; i++) + { + EmbedFieldBuilder fieldBuilder = new(); + + if (!reservationDataList[i].Any()) + { + // 何かの空白代入して空行を生成している。 + fieldBuilder.Value = "\n\u200b"; + } + else + { + StringBuilder messageData = new(); + messageData.AppendLine("```python"); + reservationDataList[i].ForEach(x => messageData.AppendLine($"{x.BattleLap,2}周目 {x.PlayerData.GuildUserName} {x.CommentData}")); + messageData.AppendLine("```"); + fieldBuilder.Value = messageData.ToString(); + } + + fieldBuilder.Name = $"{i + 1}ボス({reservationDataList[i].Count}件)"; + embedBuilder.AddField(fieldBuilder); + } + + embedBuilder.Title = $"現在の予約状況:計{reservationDataSet.Count}件"; + + return embedBuilder.Build(); + } + + private MessageComponent CreateComponent() + { + ComponentBuilder componentBuilder = new(); + componentBuilder.WithButton( + ButtonType.Reload.ToLongLabel(), ButtonType.Reload.ToString(), ButtonStyle.Secondary, ButtonType.Reload.ToEmoji()); + return componentBuilder.Build(); + } + + } +} diff --git a/Script/ClanBattle/UpdateDate.cs b/Script/ClanBattle/UpdateDate.cs index da5b09ef..190f3dbb 100644 --- a/Script/ClanBattle/UpdateDate.cs +++ b/Script/ClanBattle/UpdateDate.cs @@ -55,7 +55,7 @@ public async Task DeleteYesterdayData() } taskList.Add(new BattleTaskKill(clanRole).SyncTaskKillData()); - taskList.Add(new BattleReservation(clanRole).UpdateSystemMessage()); + taskList.Add(new BattleReservationSummary(clanRole).UpdateMessage()); for (int i = 0; i < CommonDefine.MaxBossNumber; i++) { diff --git a/Script/Commands.cs b/Script/Commands.cs index be2c8252..d91b10b0 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -307,5 +307,68 @@ public static Task RegisterReportData(CommandEventArgs commandEventArgs) new BattleReport(commandEventArgs).RegisterReportData(); return Task.CompletedTask; } + + [Command("予約", 0, compatibleChannels: ChannelFeatureType.ReserveID)] + public static Task ReservationCommand(CommandEventArgs commandEventArgs) + { + BattleReservation battleReservation = new(commandEventArgs); + + if (commandEventArgs.Arguments.Count == 0) + { + battleReservation.PlayerReserveList(); + } + else + { + battleReservation.RegisterReserveData(); + } + + return Task.CompletedTask; + } + + [Command(new[] { "予約一覧, 予約確認, 予約状況, !list" }, 0, 0, ChannelFeatureType.ReserveID)] + public static Task ListReservation(CommandEventArgs commandEventArgs) + { + new BattleReservation(commandEventArgs).PlayerReserveList(); + return Task.CompletedTask; + } + + [Command(new[] { "削除", "!rm" }, 2, 2, ChannelFeatureType.ReserveID)] + public static Task DeleteReserveData(CommandEventArgs commandEventArgs) + { + new BattleReservation(commandEventArgs).DeleteReserveData(); + return Task.CompletedTask; + } + + [Command("!start", 0, 0, ChannelFeatureType.ReserveResultID)] + public static async Task SendReserveSummary(CommandEventArgs commandEventArgs) + => await new BattleReservationSummary(commandEventArgs.Role, commandEventArgs.ClanData).SendMessage(); + + [Command(compatibleChannels: new[] + { + ChannelFeatureType.DeclareBoss1ID, + ChannelFeatureType.DeclareBoss2ID, + ChannelFeatureType.DeclareBoss3ID, + ChannelFeatureType.DeclareBoss4ID, + ChannelFeatureType.DeclareBoss5ID, + })] + public static async Task StartDeclare(CommandEventArgs commandEventArgs) + { + var BossNumber = commandEventArgs.ChannelFeatureType switch + { + ChannelFeatureType.DeclareBoss1ID => BossNumberType.Boss1Number, + ChannelFeatureType.DeclareBoss2ID => BossNumberType.Boss2Number, + ChannelFeatureType.DeclareBoss3ID => BossNumberType.Boss3Number, + ChannelFeatureType.DeclareBoss4ID => BossNumberType.Boss4Number, + ChannelFeatureType.DeclareBoss5ID => BossNumberType.Boss5Number, + _ => BossNumberType.Unknown, + }; + + if (BossNumber == BossNumberType.Unknown) + { + return; + } + + await new BattleDeclaration(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage, BossNumber).RunDeclarationCommandByMessage(); + } } } diff --git a/Script/ReceiveInteractionController.cs b/Script/ReceiveInteractionController.cs index f29da2a2..80289aa8 100644 --- a/Script/ReceiveInteractionController.cs +++ b/Script/ReceiveInteractionController.cs @@ -13,6 +13,7 @@ public class ReceiveInteractionController private readonly SocketTextChannel m_TextChannel; private readonly PlayerData m_PlayerData; private readonly ClanData m_ClanData; + private readonly SocketRole m_Role; public ReceiveInteractionController(SocketInteraction interaction) { @@ -25,8 +26,8 @@ public ReceiveInteractionController(SocketInteraction interaction) return; } - var playerRole = m_TextChannel.Guild.GetRole(m_PlayerData.ClanData.ClanRoleID); - m_ClanData = DatabaseClanDataController.LoadClanData(playerRole); + m_Role = m_TextChannel.Guild.GetRole(m_PlayerData.ClanData.ClanRoleID); + m_ClanData = DatabaseClanDataController.LoadClanData(m_Role); } public async Task Run() @@ -42,7 +43,7 @@ public async Task Run() if (channelFeatureID == (int)ChannelFeatureType.ReserveResultID) { - await new BattleReservation(m_ClanData, m_Interaction).RunResultInteraction(); + await new BattleReservationSummary(m_Role, m_ClanData).RunInteraction(m_Interaction); } BattleDeclaration battleDeclaration = channelFeatureID switch From 21f8267b9539b9561680e7c1ac713acfc1027b6a Mon Sep 17 00:00:00 2001 From: ca45382 Date: Mon, 9 Aug 2021 21:46:03 +0900 Subject: [PATCH 17/50] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=90=8D=E3=81=AE?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataModel/CommandEventArgs.cs | 4 ++-- Script/ClanBattle/BattleCarryOver.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DataModel/CommandEventArgs.cs b/DataModel/CommandEventArgs.cs index 3d63ce05..bff83fed 100644 --- a/DataModel/CommandEventArgs.cs +++ b/DataModel/CommandEventArgs.cs @@ -22,7 +22,7 @@ public CommandEventArgs(SocketUserMessage socketUserMessage) var splitContents = SocketUserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); Name = splitContents[0]; Arguments = splitContents.Length > 1 ? splitContents.Skip(1).ToList() : Array.Empty(); - Author = SocketUserMessage.Author as SocketGuildUser; + User = SocketUserMessage.Author as SocketGuildUser; Channel = SocketUserMessage.Channel as SocketTextChannel; PlayerData = DatabasePlayerDataController.LoadPlayerData(Channel.Guild.Id, SocketUserMessage.Author.Id); @@ -43,7 +43,7 @@ public CommandEventArgs(SocketUserMessage socketUserMessage) public SocketUserMessage SocketUserMessage { get; } public string Name { get; } public IReadOnlyList Arguments { get; } - public SocketGuildUser Author { get; } + public SocketGuildUser User { get; } public SocketTextChannel Channel { get; } public SocketRole Role { get; } public ClanData ClanData { get; } diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index 8087b5c4..a7a53879 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -102,7 +102,7 @@ public void UpdateCarryOverData() public void DeleteCarryOverData() { const int defaultDeleteNumber = 1; - var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, m_CommandEventArgs.Author.Id); + var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, m_CommandEventArgs.User.Id); try { From 3606b6411fd3fed5a40bb9b45b21ec21b3cacbe6 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Tue, 10 Aug 2021 20:06:37 +0900 Subject: [PATCH 18/50] =?UTF-8?q?TaskKill=E3=81=AE=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=82=92=E4=BB=AE=E3=81=A7=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleTaskKill.cs | 2 +- Script/Commands.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Script/ClanBattle/BattleTaskKill.cs b/Script/ClanBattle/BattleTaskKill.cs index 1eba12a9..361a6144 100644 --- a/Script/ClanBattle/BattleTaskKill.cs +++ b/Script/ClanBattle/BattleTaskKill.cs @@ -153,6 +153,6 @@ private async Task SyncTaskKillRole() } private async Task SuccessAddEmoji() - => await m_UserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + => await m_UserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); } } diff --git a/Script/Commands.cs b/Script/Commands.cs index d91b10b0..a2e324d4 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -370,5 +370,9 @@ public static async Task StartDeclare(CommandEventArgs commandEventArgs) await new BattleDeclaration(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage, BossNumber).RunDeclarationCommandByMessage(); } + + [Command(compatibleChannels: ChannelFeatureType.TaskKillID)] + public static async Task StartTaskkill(CommandEventArgs commandEventArgs) + => await new BattleTaskKill(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage).RunByMessageCommands(); } } From 18346020a3f4687fc95d7f71f590347be522acae Mon Sep 17 00:00:00 2001 From: ca45382 Date: Fri, 13 Aug 2021 13:11:36 +0900 Subject: [PATCH 19/50] =?UTF-8?q?Invoke=E3=81=ABtry=5Fcatch=E3=82=92?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Script/Program.cs b/Script/Program.cs index 6f5abf27..0188a2cc 100644 --- a/Script/Program.cs +++ b/Script/Program.cs @@ -77,7 +77,15 @@ private async Task CommandRecieved(SocketMessage socketMessage) } var commandEventArgs = new CommandEventArgs(socketUserMessage); - await CommandMapper.Invoke(commandEventArgs); + + try + { + await CommandMapper.Invoke(commandEventArgs); + } + catch + { + + } } /// From 8fb67d3a73d7fc63f97537841412dd9d4c515728 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 17:10:36 +0900 Subject: [PATCH 20/50] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E5=90=8D=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Attribute/{Command.cs => CommandAttribute.cs} | 0 Attribute/{Description.cs => MultiDescriptionAttribute.cs} | 0 Extension/{IEnumerableExtension.cs => EnumerableExtension.cs} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Attribute/{Command.cs => CommandAttribute.cs} (100%) rename Attribute/{Description.cs => MultiDescriptionAttribute.cs} (100%) rename Extension/{IEnumerableExtension.cs => EnumerableExtension.cs} (100%) diff --git a/Attribute/Command.cs b/Attribute/CommandAttribute.cs similarity index 100% rename from Attribute/Command.cs rename to Attribute/CommandAttribute.cs diff --git a/Attribute/Description.cs b/Attribute/MultiDescriptionAttribute.cs similarity index 100% rename from Attribute/Description.cs rename to Attribute/MultiDescriptionAttribute.cs diff --git a/Extension/IEnumerableExtension.cs b/Extension/EnumerableExtension.cs similarity index 100% rename from Extension/IEnumerableExtension.cs rename to Extension/EnumerableExtension.cs From 49c441e14daf4ff97fa5f735eae2fd098d9f94e6 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 17:14:10 +0900 Subject: [PATCH 21/50] =?UTF-8?q?Enum=E3=81=AE=E5=90=8D=E7=A7=B0=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/ProgressStatus.cs | 2 +- DataType/WarningType.cs | 2 +- Script/ClanBattle/BattleProgress.cs | 2 +- Script/ClanBattle/BattleReservation.cs | 2 +- Script/Commands.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DataType/ProgressStatus.cs b/DataType/ProgressStatus.cs index c3132e94..6f0a8e79 100644 --- a/DataType/ProgressStatus.cs +++ b/DataType/ProgressStatus.cs @@ -20,6 +20,6 @@ public enum ProgressStatus : byte SOS, [Description("🏃")] - Fin, + SubdueBoss, } } diff --git a/DataType/WarningType.cs b/DataType/WarningType.cs index 0ced3198..8cc0c060 100644 --- a/DataType/WarningType.cs +++ b/DataType/WarningType.cs @@ -10,6 +10,6 @@ namespace PriconneBotConsoleApp.DataType public enum WarningType { [Description("コメントが長いので切り取られました。\n 問題がある場合は予約削除をして再度予約してください。") ] - LongComment, + TooLongComment, } } diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 324dc040..f50b7fb3 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -416,7 +416,7 @@ private ProgressData GetProgressData(PlayerData playerData = null) } return DatabaseProgressController.GetProgressData(playerData, m_BossNumberType) - .Where(x => x.Status != (byte)ProgressStatus.AttackDone || x.Status != (byte)ProgressStatus.Fin) + .Where(x => x.Status != (byte)ProgressStatus.AttackDone || x.Status != (byte)ProgressStatus.SubdueBoss) .FirstOrDefault(); } diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index b477bc63..0a10a352 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -119,7 +119,7 @@ private ReservationData MessageToReservationData() if (commentData.Length > MaxCommentLength) { commentData = commentData.Substring(0, MaxCommentLength); - _ = m_CommandEventArgs.Channel.SendTimedMessageAsync(TimeDefine.WarningMessageDisplayTime, WarningType.LongComment.ToLabel()); + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync(TimeDefine.WarningMessageDisplayTime, WarningType.TooLongComment.ToLabel()); } return new ReservationData() diff --git a/Script/Commands.cs b/Script/Commands.cs index a2e324d4..30cf44b3 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -177,7 +177,7 @@ public static async Task UpdateProgressSOS(CommandEventArgs commandEventArgs) } )] public static async Task UpdateProgressFin(CommandEventArgs commandEventArgs) - => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.Fin); + => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.SubdueBoss); [Command( "!init", 0, 0, From acc7c5514066ec9fdf3f5e89ab94653fc21084e4 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 17:15:53 +0900 Subject: [PATCH 22/50] =?UTF-8?q?=E5=86=97=E9=95=B7=E3=81=AA=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E4=BB=A3=E5=85=A5=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Program.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Script/Program.cs b/Script/Program.cs index 0188a2cc..7a2a925a 100644 --- a/Script/Program.cs +++ b/Script/Program.cs @@ -76,15 +76,12 @@ private async Task CommandRecieved(SocketMessage socketMessage) return; } - var commandEventArgs = new CommandEventArgs(socketUserMessage); - try { - await CommandMapper.Invoke(commandEventArgs); + await CommandMapper.Invoke(new CommandEventArgs(socketUserMessage)); } catch { - } } From d0cc363772afc7d598d920c9944b4c0e0a663978 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 17:26:36 +0900 Subject: [PATCH 23/50] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleReservationSummary.cs | 23 ++++++++++--------- Script/ReceiveInteractionController.cs | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Script/ClanBattle/BattleReservationSummary.cs b/Script/ClanBattle/BattleReservationSummary.cs index 1b0e1874..e7992299 100644 --- a/Script/ClanBattle/BattleReservationSummary.cs +++ b/Script/ClanBattle/BattleReservationSummary.cs @@ -21,6 +21,7 @@ public class BattleReservationSummary public BattleReservationSummary(SocketRole role, ClanData clanData = null) { m_Role = role; + if (clanData == null) { m_ClanData = DatabaseClanDataController.LoadClanData(m_Role); @@ -29,24 +30,20 @@ public BattleReservationSummary(SocketRole role, ClanData clanData = null) { m_ClanData = clanData; } - m_SocketTextChannel = m_Role.Guild.GetChannel(m_ClanData.GetChannelID(ChannelFeatureType.ReserveResultID)) - as SocketTextChannel; + + m_SocketTextChannel = m_Role.Guild.GetChannel(m_ClanData.GetChannelID(ChannelFeatureType.ReserveResultID)) as SocketTextChannel; } - public async Task RunInteraction(SocketInteraction socketInteraction) + public async Task RunInteraction(SocketMessageComponent messageComponent) { - var messageComponent = (SocketMessageComponent)socketInteraction; - if (!Enum.TryParse(messageComponent.Data.CustomId, out var buttonType)) { return; } - switch (buttonType) + if(buttonType == ButtonType.Reload) { - case ButtonType.Reload: - await UpdateMessage(); - break; + await UpdateMessage(); } } @@ -147,9 +144,13 @@ private MessageComponent CreateComponent() { ComponentBuilder componentBuilder = new(); componentBuilder.WithButton( - ButtonType.Reload.ToLongLabel(), ButtonType.Reload.ToString(), ButtonStyle.Secondary, ButtonType.Reload.ToEmoji()); + ButtonType.Reload.ToLongLabel(), + ButtonType.Reload.ToString(), + ButtonStyle.Secondary, + ButtonType.Reload.ToEmoji() + ); + return componentBuilder.Build(); } - } } diff --git a/Script/ReceiveInteractionController.cs b/Script/ReceiveInteractionController.cs index 80289aa8..810535c0 100644 --- a/Script/ReceiveInteractionController.cs +++ b/Script/ReceiveInteractionController.cs @@ -43,7 +43,7 @@ public async Task Run() if (channelFeatureID == (int)ChannelFeatureType.ReserveResultID) { - await new BattleReservationSummary(m_Role, m_ClanData).RunInteraction(m_Interaction); + await new BattleReservationSummary(m_Role, m_ClanData).RunInteraction(m_Interaction as SocketMessageComponent); } BattleDeclaration battleDeclaration = channelFeatureID switch From 888ff4a6d26b0b112664bde5ef0dcf676e995859 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 17:26:57 +0900 Subject: [PATCH 24/50] =?UTF-8?q?=E9=85=8D=E5=88=97=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=A6=E3=81=84=E3=81=84=E7=AE=87=E6=89=80?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Commands.cs | 190 ++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 116 deletions(-) diff --git a/Script/Commands.cs b/Script/Commands.cs index 30cf44b3..10a07a8d 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -55,14 +55,11 @@ public static Task InitAllCarryOverData(CommandEventArgs commandEventArgs) AttackType.Physics, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task AttackPhysics(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.Physics); @@ -71,14 +68,11 @@ public static async Task AttackPhysics(CommandEventArgs commandEventArgs) AttackType.Magic, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task AttackMagic(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.Magic); @@ -87,14 +81,11 @@ public static async Task AttackMagic(CommandEventArgs commandEventArgs) AttackType.NewYearKaryl, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task AttackNewYearKaryl(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.NewYearKaryl); @@ -103,14 +94,11 @@ public static async Task AttackNewYearKaryl(CommandEventArgs commandEventArgs) AttackType.CarryOver, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task AttackCarryOver(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateAttackData(AttackType.CarryOver); @@ -119,14 +107,11 @@ public static async Task AttackCarryOver(CommandEventArgs commandEventArgs) new[] { "kari", "仮確定" }, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task UpdateProgressStatusReady(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.AttackReady); @@ -135,14 +120,11 @@ public static async Task UpdateProgressStatusReady(CommandEventArgs commandEvent new[] { "atk", "確定" }, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task UpdateProgressStatusDone(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.AttackDone); @@ -151,14 +133,11 @@ public static async Task UpdateProgressStatusDone(CommandEventArgs commandEventA new[] { "sos", "jiko", "ziko", "事故" }, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task UpdateProgressSOS(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.SOS); @@ -167,98 +146,77 @@ public static async Task UpdateProgressSOS(CommandEventArgs commandEventArgs) new[] { "〆確定", "fin" }, 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task UpdateProgressFin(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).UpdateStatusData(ProgressStatus.SubdueBoss); [Command( "!init", 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task InitProgressData(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).InitCommand(); [Command( - "!call", 1, 1, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + "!call", 1, 1, + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task CallProgress(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).Start(); [Command( - "!list", 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + "!list", 0, 0, + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task DisplayList(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).SendList(); [Command( - "!rm", 1, 1, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + "!rm", 1, 1, + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task RemoveProgressData(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).RemoveOrRevertUserData(true); [Command( - "!rv", 1, 1, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + "!rv", 1, 1, + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task RevertProgressData(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).RemoveOrRevertUserData(); [Command( "!next", 0, 0, - new[] - { - ChannelFeatureType.ProgressBoss1ID, - ChannelFeatureType.ProgressBoss2ID, - ChannelFeatureType.ProgressBoss3ID, - ChannelFeatureType.ProgressBoss4ID, - ChannelFeatureType.ProgressBoss5ID, - } + ChannelFeatureType.ProgressBoss1ID, + ChannelFeatureType.ProgressBoss2ID, + ChannelFeatureType.ProgressBoss3ID, + ChannelFeatureType.ProgressBoss4ID, + ChannelFeatureType.ProgressBoss5ID )] public static async Task NextProgressBoss(CommandEventArgs commandEventArgs) => await new BattleProgress(commandEventArgs).NextBoss(); From 96ddb7d94b9e6e61d03389ce80bc28cbc4527531 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 19:11:31 +0900 Subject: [PATCH 25/50] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataModel/CommandEventArgs.cs | 1 - .../Shiori/DatabaseReservationController.cs | 5 +- Script/ClanBattle/BattleCarryOver.cs | 46 ++++++++----------- Script/ClanBattle/BattleReport.cs | 12 ++--- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/DataModel/CommandEventArgs.cs b/DataModel/CommandEventArgs.cs index bff83fed..8d046ced 100644 --- a/DataModel/CommandEventArgs.cs +++ b/DataModel/CommandEventArgs.cs @@ -24,7 +24,6 @@ public CommandEventArgs(SocketUserMessage socketUserMessage) Arguments = splitContents.Length > 1 ? splitContents.Skip(1).ToList() : Array.Empty(); User = SocketUserMessage.Author as SocketGuildUser; Channel = SocketUserMessage.Channel as SocketTextChannel; - PlayerData = DatabasePlayerDataController.LoadPlayerData(Channel.Guild.Id, SocketUserMessage.Author.Id); Role = Channel.Guild.GetRole(PlayerData?.ClanData.ClanRoleID ?? 0); diff --git a/Database/Shiori/DatabaseReservationController.cs b/Database/Shiori/DatabaseReservationController.cs index 5e09cb5f..d0731038 100644 --- a/Database/Shiori/DatabaseReservationController.cs +++ b/Database/Shiori/DatabaseReservationController.cs @@ -104,6 +104,7 @@ public static void CreateReservationData(ReservationData reservationData) var transaction = databaseConnector.Database.BeginTransaction(); databaseConnector.ReservationData.Add(reservationData); + try { databaseConnector.SaveChanges(); @@ -123,8 +124,7 @@ public static void UpdateReservationData(ReservationData reservationData) { using var databaseConnector = new DatabaseConnector(); var transaction = databaseConnector.Database.BeginTransaction(); - var updateData = databaseConnector.ReservationData - .FirstOrDefault(x => x.ReserveID == reservationData.ReserveID); + var updateData = databaseConnector.ReservationData.FirstOrDefault(x => x.ReserveID == reservationData.ReserveID); try { @@ -148,7 +148,6 @@ public static void DeleteReservationData(IEnumerable reservatio foreach (var reservationData in reservationDataSet) { - var updateData = databaseConnector.ReservationData.AsQueryable() .FirstOrDefault(d => d.PlayerID == reservationData.PlayerID && d.BossNumber == reservationData.BossNumber && d.BattleLap == reservationData.BattleLap && !d.DeleteFlag); diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index a7a53879..aeb19197 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -78,7 +78,7 @@ public void UpdateCarryOverData() var databaseCarryOverList = DatabaseCarryOverController.GetCarryOverData(playerData).ToArray(); var databaseCarryOverData = databaseCarryOverList.FirstOrDefault(x => x.BossNumber == carryOverData.BossNumber && x.RemainTime == carryOverData.RemainTime); - bool result = false; + var result = false; if (databaseCarryOverData != null) { @@ -92,7 +92,7 @@ public void UpdateCarryOverData() if (result) { - _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); } } @@ -128,21 +128,15 @@ public void DeleteCarryOverData() /// public void DeleteOtherPlayerData() { - SocketGuildUser targetUser; - - if (MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out var userID) || - ulong.TryParse(m_CommandEventArgs.Arguments[0], out userID)) - { - targetUser = m_CommandEventArgs.Role.Guild.GetUser(userID); - } - else - { - throw new ArgumentNullException(); - } + var targetUser = MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out var userID) + || ulong.TryParse(m_CommandEventArgs.Arguments[0], out userID) + ? m_CommandEventArgs.Role.Guild.GetUser(userID) + : throw new ArgumentNullException(); // コマンドは `!rm @削除対象のユーザー 古い方から何番目か` としている。 if (!byte.TryParse(m_CommandEventArgs.Arguments[1], out var number) - || number > CommonDefine.MaxReportNumber || number <= 0) + || number <= 0 + || CommonDefine.MaxReportNumber < number) { throw new ArgumentOutOfRangeException(); } @@ -152,7 +146,7 @@ public void DeleteOtherPlayerData() try { DeletePlayerCarryOverData(playerData, number); - _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); } catch (Exception e) { @@ -173,21 +167,15 @@ public async Task SendClanCarryOverList() private void DeletePlayerCarryOverData(PlayerData playerData, byte deleteNumber) { var carryOverList = DatabaseCarryOverController.GetCarryOverData(playerData) - .OrderBy(x => x.DateTime).ToArray(); + .OrderBy(x => x.DateTime) + .ToArray(); if (carryOverList.Length == 0) { throw new ArgumentOutOfRangeException(); } - if (deleteNumber > 0 && deleteNumber <= carryOverList.Length) - { - DatabaseCarryOverController.DeleteCarryOverData(carryOverList[deleteNumber - 1]); - } - else - { - DatabaseCarryOverController.DeleteCarryOverData(carryOverList.First()); - } + DatabaseCarryOverController.DeleteCarryOverData(carryOverList[(deleteNumber > 0 && deleteNumber <= carryOverList.Length) ? deleteNumber - 1 : 0]); } /// @@ -203,9 +191,12 @@ public void InitAllData() } DatabaseCarryOverController.DeleteCarryOverData(carryOverList); - _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); - _ = m_CommandEventArgs.Channel.SendTimedMessageAsync(TimeDefine.SuccessMessageDisplayTime, - string.Format(EnumMapper.ToLabel(InfomationType.DeleteAllCarryOverData), TimeDefine.SuccessMessageDisplayTime)); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); + + _ = m_CommandEventArgs.Channel.SendTimedMessageAsync( + TimeDefine.SuccessMessageDisplayTime, + string.Format(EnumMapper.ToLabel(InfomationType.DeleteAllCarryOverData), TimeDefine.SuccessMessageDisplayTime) + ); } // 持ち越しを表示するUIを考える @@ -213,6 +204,7 @@ private Embed CreateEmbedData() { var carryOverArray = DatabaseCarryOverController.GetCarryOverData(m_CommandEventArgs.ClanData) .OrderBy(x => x.DateTime); + var playerArray = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); List carryOverStringList = new(); diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 6a5723dc..07603716 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -45,9 +45,7 @@ public string GetNameWithReport() } public BattleReport(CommandEventArgs commandEventArgs) - { - m_CommandEventArgs = commandEventArgs; - } + => m_CommandEventArgs = commandEventArgs; /// /// 個人の凸報告 @@ -61,7 +59,8 @@ public void RegisterReportData() var bossNumber = int.Parse(Regex.Match(m_CommandEventArgs.Name, @"\d").Value); if (!EnumMapper.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\D{1,3}").Value, out var attackType) - || attackType == AttackType.Unknown || attackType == AttackType.CarryOver) + || attackType == AttackType.Unknown + || attackType == AttackType.CarryOver) { return; } @@ -92,7 +91,7 @@ public void RegisterReportData() if (DatabaseReportDataController.CreateReportData(reportData)) { - _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(new Emoji(ReactionType.Success.ToLabel())); + _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(ReactionType.Success.ToEmoji()); } return; @@ -104,6 +103,7 @@ public void RegisterReportData() public void DeleteReportData() { var playerData = new PlayerData(); + if (m_CommandEventArgs.Arguments.Count == 1 && ulong.TryParse(Regex.Match(m_CommandEventArgs.Arguments[0], @"\d+").Value, out ulong registerUserID)) { @@ -155,7 +155,7 @@ public void RegisterOtherUserReportData() return; } - var reportData = new ReportData() + var reportData = new ReportData { AttackType = (byte)attackType, BossNumber = bossNumber, From 260ba7c60999c41d540839ac8ea7c3be61552f90 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 19:11:40 +0900 Subject: [PATCH 26/50] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=9F=E9=96=A2=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataModel/Shiori/ClanData.cs | 56 ------------------------------------ 1 file changed, 56 deletions(-) diff --git a/DataModel/Shiori/ClanData.cs b/DataModel/Shiori/ClanData.cs index 36dafaff..e2465059 100644 --- a/DataModel/Shiori/ClanData.cs +++ b/DataModel/Shiori/ClanData.cs @@ -111,61 +111,5 @@ public ulong GetMessageID(MessageFeatureType messageFeatureType) /// public int GetMinBossLap() => Enumerable.Min(new int[] { Boss1Lap, Boss2Lap, Boss3Lap, Boss4Lap, Boss5Lap }); - - /// - /// 5つのボスデータから今のボスに変換。来月削除。 - /// - /// - /// - [Obsolete] - public byte GetNowBoss() - { - if (Boss1Lap == Boss2Lap - && Boss2Lap == Boss3Lap - && Boss3Lap == Boss4Lap - && Boss4Lap == Boss5Lap) - { - return (byte)BossNumberType.Boss5Number; - } - if (Boss1Lap == Boss2Lap + 1) - { - return (byte)BossNumberType.Boss1Number; - } - else if (Boss2Lap == Boss3Lap + 1) - { - return (byte)BossNumberType.Boss2Number; - } - else if (Boss3Lap == Boss4Lap + 1) - { - return (byte)BossNumberType.Boss3Number; - } - else if (Boss4Lap == Boss5Lap + 1) - { - return (byte)BossNumberType.Boss4Number; - } - - return 0; - } - - /// - /// 5つのボスデータから今のLapに変換。来月削除。 - /// - /// - /// - [Obsolete] - public ushort GetNowLap() - { - if (Boss1Lap == Boss2Lap - && Boss2Lap == Boss3Lap - && Boss3Lap == Boss4Lap - && Boss4Lap == Boss5Lap) - { - return Boss5Lap; - } - else - { - return Boss1Lap; - } - } } } From a0da8833fb76e4949f81d00717dcc76ef28d5ad8 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 20:11:42 +0900 Subject: [PATCH 27/50] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleProgress.cs | 73 +++++++++++------------------ Script/ClanBattle/BattleReport.cs | 4 +- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index f50b7fb3..bb986211 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -70,14 +71,10 @@ public async Task Start() } public async Task SendList() - { - await SendClanProgressList(); - } + => await SendClanProgressList(); public async Task NextBoss() - { - await ChangeLap(); - } + => await ChangeLap(); /// /// 編成データをアップデートする。 @@ -88,7 +85,7 @@ public async Task UpdateAttackData(AttackType attackType) { if (!TryGetProgressData(out var userProgressData)) { - userProgressData = new ProgressData() + userProgressData = new ProgressData { PlayerID = m_CommandEventArgs.PlayerData.PlayerID, BossNumber = (byte)m_BossNumberType, @@ -202,6 +199,7 @@ public async Task RemoveOrRevertUserData(bool deleteFlag = false) } var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, userData.Id); + var playerProgressData = DatabaseProgressController.GetProgressData(playerData, m_BossNumberType) .OrderByDescending(x => x.UpdateDateTime).FirstOrDefault(); @@ -285,14 +283,10 @@ private async Task ChangeLap(ushort lap = 0) /// private void InitializeProgressData() { - var deleteData = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType); - - if (deleteData == null) + if(DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) is { } deleteData) { - return; + DatabaseProgressController.DeleteProgressData(deleteData); } - - DatabaseProgressController.DeleteProgressData(deleteData); } private async Task SendClanProgressList(bool removeLastMessage = true) @@ -306,55 +300,44 @@ private async Task SendClanProgressList(bool removeLastMessage = true) } var channelIDTemp = m_CommandEventArgs.ClanData.GetChannelID(BossNumberToChannelType(m_BossNumberType)); - - var progressChannelTEMP = m_CommandEventArgs.Role.Guild.GetChannel(channelIDTemp) as SocketTextChannel; - var progressChannel = progressChannelTEMP as SocketTextChannel; + var progressChannel = m_CommandEventArgs.Role.Guild.GetChannel(channelIDTemp) as SocketTextChannel; var lastMessageID = m_CommandEventArgs.ClanData.GetMessageID(BossNumberToMessageType(m_BossNumberType)); DatabaseMessageDataController.UpdateMessageID(m_CommandEventArgs.ClanData, sendMessage.Id, BossNumberToMessageType(m_BossNumberType)); - var lastMessage = progressChannel.GetCachedMessage(lastMessageID); + var cachedMessage = progressChannel.GetCachedMessage(lastMessageID); - if (lastMessage == null) + if (cachedMessage == null) { - IMessage lastIMessage; - try { - lastIMessage = await progressChannel.GetMessageAsync(lastMessageID); + var message = await progressChannel.GetMessageAsync(lastMessageID); + + if (removeLastMessage) + { + await message.DeleteAsync(); + } } catch (Exception e) { Console.WriteLine(e.Message); - return; - } - - if (removeLastMessage) - { - await lastIMessage.DeleteAsync(); } - - return; } - else + else if (removeLastMessage) { - if (removeLastMessage) - { - await lastMessage.DeleteAsync(); - } + await cachedMessage.DeleteAsync(); } - - return; } private Embed CreateProgressList() { + var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); var clanProgressData = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) .OrderBy(x => x.Status).ThenByDescending(x => x.Damage).ThenBy(x => x.CreateDateTime) .ToArray(); - var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); - var progressPlayer = clanProgressData.Select(x => new PlayerInfo( - clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID), - x - )).ToArray(); + + var progressPlayer = clanProgressData.Select(x => + new PlayerInfo(clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID),x)) + .ToArray(); + var bossLap = m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType); var bossData = RediveClanBattleData.BossDataList .FirstOrDefault(x => x.BossNumber == (byte)m_BossNumberType && x.LapNumberFrom <= bossLap && (x.LapNumberTo == -1 || x.LapNumberTo >= bossLap)); @@ -372,13 +355,13 @@ private Embed CreateProgressList() { remainAttackString.Append((i == 0 ? "完凸:" : i + "凸:") + reportCount[i] + "人 "); } + summaryStringBuilder.AppendLine(remainAttackString.ToString()); // ボスのHPをここに入力(万表示) var bossHP = bossData?.HP / CommonDefine.DisplayDamageUnit ?? 0; var sumAttackDoneHP = progressPlayer.Where(x => x.ProgressData.Status == (byte)ProgressStatus.AttackDone).Select(x => (int)x.ProgressData.Damage).Sum(); var sumAttackReadyHP = progressPlayer.Where(x => x.ProgressData.Status == (byte)ProgressStatus.AttackReady).Select(x => (int)x.ProgressData.Damage).Sum(); - summaryStringBuilder.AppendLine("現在HP " + (bossHP - sumAttackDoneHP) + "万 / " + bossHP + "万"); summaryStringBuilder.AppendLine("仮確HP " + (bossHP - sumAttackReadyHP - sumAttackDoneHP) + "万 / " + bossHP + "万"); @@ -389,6 +372,7 @@ private Embed CreateProgressList() }; var reportMessage = string.Join("\n", progressPlayer.Select(x => x.GetNameWithData()).ToArray()); + var embedFieldBuilder = new EmbedFieldBuilder() { Name = "参加者", @@ -421,10 +405,7 @@ private ProgressData GetProgressData(PlayerData playerData = null) } private bool TryGetProgressData(out ProgressData progressData) - { - progressData = GetProgressData(); - return progressData != null; - } + => (progressData = GetProgressData()) != null; private MessageFeatureType BossNumberToMessageType(BossNumberType bossNumberType) { diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 07603716..49d52034 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -59,7 +59,7 @@ public void RegisterReportData() var bossNumber = int.Parse(Regex.Match(m_CommandEventArgs.Name, @"\d").Value); if (!EnumMapper.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\D{1,3}").Value, out var attackType) - || attackType == AttackType.Unknown + || attackType == AttackType.Unknown || attackType == AttackType.CarryOver) { return; @@ -184,10 +184,10 @@ public void RegisterOtherUserReportData() public void DeleteAllClanReport() { var clanReportData = DatabaseReportDataController.GetReportData(m_CommandEventArgs.ClanData); + if (DatabaseReportDataController.DeleteReportData(clanReportData)) { _ = m_CommandEventArgs.SocketUserMessage.AddReactionAsync(EnumMapper.ToEmoji(ReactionType.Success)); - } } From e7d6658f93b2746ff357737ebc877829d3c412be Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 20:14:45 +0900 Subject: [PATCH 28/50] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?+=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA?= =?UTF-8?q?=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/ErrorType.cs | 2 +- Script/ClanBattle/BattleReservation.cs | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/DataType/ErrorType.cs b/DataType/ErrorType.cs index 2027cb0c..467a8ccb 100644 --- a/DataType/ErrorType.cs +++ b/DataType/ErrorType.cs @@ -12,7 +12,7 @@ public enum ErrorType //予約関連 [Description("予約に失敗しました。")] FailedReservation, - [Description("予約できません。予約可能時間は{0}~{1}です。")] + [Description("予約できません。予約可能時間は{0}:00~{1}:00です。")] OutOfReservationTime, [Description("コメントが長いので切り取られました。\n 問題がある場合は予約削除をして再度予約してください。")] TooLongComment, diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index 0a10a352..f7e0115d 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -20,18 +20,13 @@ public class BattleReservation private readonly CommandEventArgs m_CommandEventArgs; public BattleReservation(CommandEventArgs commandEventArgs) - { - m_CommandEventArgs = commandEventArgs; - } + => m_CommandEventArgs = commandEventArgs; /// /// 個人の予約一覧を表示する。引数は無し。 /// public void PlayerReserveList() - { - _ = m_CommandEventArgs.Channel.SendMessageAsync( - CreateUserReservationDataMessage(m_CommandEventArgs.PlayerData)); - } + => m_CommandEventArgs.Channel.SendMessageAsync(CreateUserReservationDataMessage(m_CommandEventArgs.PlayerData)); public void RegisterReserveData() { @@ -40,8 +35,8 @@ public void RegisterReserveData() _ = m_CommandEventArgs.Channel.SendTimedMessageAsync( TimeDefine.ErrorMessageDisplayTime, string.Format(ErrorType.OutOfReservationTime.ToLabel(), - $"{m_CommandEventArgs.ClanData.ReservationStartTime.Hours}:00", - $"{m_CommandEventArgs.ClanData.ReservationEndTime.Hours}:00") + $"{m_CommandEventArgs.ClanData.ReservationStartTime.Hours}", + $"{m_CommandEventArgs.ClanData.ReservationEndTime.Hours}") ); return; } @@ -58,7 +53,8 @@ public void RegisterReserveData() } var allowReservationLap = m_CommandEventArgs.ClanData.ReservationLap == 0 - ? ClanBattleDefine.MaxLapNumber : (m_CommandEventArgs.ClanData.ReservationLap + m_CommandEventArgs.ClanData.GetMinBossLap()); + ? ClanBattleDefine.MaxLapNumber + : (m_CommandEventArgs.ClanData.ReservationLap + m_CommandEventArgs.ClanData.GetMinBossLap()); if (reservationData.BattleLap > allowReservationLap) { From 9abd6f75179aa517bc979162fdc702bda59abd07 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sat, 14 Aug 2021 23:36:22 +0900 Subject: [PATCH 29/50] =?UTF-8?q?6=E3=83=9C=E3=82=B9=E4=BB=A5=E4=B8=8A?= =?UTF-8?q?=E3=82=92=E7=99=BB=E9=8C=B2=E3=81=A7=E3=81=8D=E3=81=A6=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=86=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleReservation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index f7e0115d..4860563d 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -104,7 +104,7 @@ public void DeleteReserveData() /// private ReservationData MessageToReservationData() { - if (!Enum.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) + if (!(byte.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) && CommonDefine.MinBossNumber<= bossNumber && bossNumber <= CommonDefine.MaxBossNumber ) || !(byte.TryParse(m_CommandEventArgs.Arguments[0], out var battleLap) && battleLap > m_CommandEventArgs.ClanData.GetBossLap(bossNumber))) { return null; From 52850f803582b5d757b977d171aba6fd5252c8ea Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 00:07:37 +0900 Subject: [PATCH 30/50] =?UTF-8?q?=E4=BA=88=E7=B4=84=E3=81=8C=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleReservation.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index 4860563d..7402360d 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -79,7 +79,7 @@ public void DeleteReserveData() { var deleteReservationData = MessageToReservationData(); - if (deleteReservationData is null) + if (deleteReservationData == null) { return; } @@ -122,7 +122,7 @@ private ReservationData MessageToReservationData() { PlayerID = m_CommandEventArgs.PlayerData.PlayerID, BattleLap = battleLap, - BossNumber = (byte)bossNumber, + BossNumber = bossNumber, CommentData = commentData, }; } @@ -147,7 +147,7 @@ private void RegisterReservationData(ReservationData reservationData) private bool DeleteUserReservationData(ReservationData reservationData) { - var userReservationDataList = DatabaseReservationController.LoadReservationData(reservationData.PlayerData); + var userReservationDataList = DatabaseReservationController.LoadReservationData(m_CommandEventArgs.PlayerData); var sqlReservationData = userReservationDataList .Where(x => x.BossNumber == reservationData.BossNumber && x.BattleLap == reservationData.BattleLap) From d9e4b0c15968c333c1be0f8420b9a80710c9037f Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 00:22:57 +0900 Subject: [PATCH 31/50] =?UTF-8?q?=E3=81=95=E3=81=84=E3=81=93=E3=82=8D?= =?UTF-8?q?=E3=81=A8TL=E5=A4=89=E6=8F=9B=E5=99=A8=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Commands.cs | 8 +++++++ Script/Utility/Dice.cs | 25 +++++++------------- Script/Utility/TimeLineConversion.cs | 35 +++++++++++----------------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/Script/Commands.cs b/Script/Commands.cs index 10a07a8d..ac321e74 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -332,5 +332,13 @@ public static async Task StartDeclare(CommandEventArgs commandEventArgs) [Command(compatibleChannels: ChannelFeatureType.TaskKillID)] public static async Task StartTaskkill(CommandEventArgs commandEventArgs) => await new BattleTaskKill(commandEventArgs.ClanData, commandEventArgs.SocketUserMessage).RunByMessageCommands(); + + [Command("!dice", 0, 1)] + public static async Task Dice(CommandEventArgs commandEventArgs) + => await new Dice(commandEventArgs).Run(); + + [Command("!tl", 2, 2)] + public static async Task TimeLineConversion(CommandEventArgs commandEventArgs) + => await new TimeLineConversion(commandEventArgs).RunByMessage(); } } diff --git a/Script/Utility/Dice.cs b/Script/Utility/Dice.cs index c92640d2..6e28c5e5 100644 --- a/Script/Utility/Dice.cs +++ b/Script/Utility/Dice.cs @@ -1,38 +1,29 @@ -using Discord.WebSocket; -using PriconneBotConsoleApp.Define; -using PriconneBotConsoleApp.Extension; -using System; +using System; using System.Threading.Tasks; +using PriconneBotConsoleApp.DataModel; +using PriconneBotConsoleApp.Define; namespace PriconneBotConsoleApp.Script { public class Dice { - private SocketMessage m_UserMessage; + private CommandEventArgs m_CommandEventArgs; - public Dice(SocketMessage message) - { - m_UserMessage = message; - } + public Dice(CommandEventArgs commandEventArgs) + => m_CommandEventArgs = commandEventArgs; public async Task Run() { - var splitMessage = m_UserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries); var diceMax = UtilityDefine.DefaultMaxDiceNumber; - if (splitMessage.Length == 0 || splitMessage[0] != "!dice") - { - return; - } - - if (splitMessage.Length == 2 && int.TryParse(splitMessage[1], out var number)) + if (m_CommandEventArgs.Arguments.Count == 1 && int.TryParse(m_CommandEventArgs.Arguments[0], out var number)) { diceMax = number; } var diceResult = new Random().Next(UtilityDefine.DefaultMinDiceNumber, diceMax); var sendMessage = $"{diceResult}"; - await m_UserMessage.Channel.SendMessageAsync(sendMessage); + await m_CommandEventArgs.Channel.SendMessageAsync(sendMessage); } } } diff --git a/Script/Utility/TimeLineConversion.cs b/Script/Utility/TimeLineConversion.cs index 4e0ee822..5dc5ec07 100644 --- a/Script/Utility/TimeLineConversion.cs +++ b/Script/Utility/TimeLineConversion.cs @@ -1,17 +1,17 @@ using System; -using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Discord; using Discord.WebSocket; +using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.Define; namespace PriconneBotConsoleApp.Script { public class TimeLineConversion { - private IMessage m_userMessage; + private CommandEventArgs m_CommandEventArgs; private class ConvertData { @@ -22,19 +22,12 @@ private class ConvertData public IMessage Message = null; } - public TimeLineConversion(IMessage message) - { - m_userMessage = message; - } + public TimeLineConversion(CommandEventArgs commandEventArgs) + => m_CommandEventArgs = commandEventArgs; public async Task RunByMessage() { - if (m_userMessage == null || !m_userMessage.Content.StartsWith("!tl")) - { - return; - } - - var messageData = await LoadTimeLineMessage(m_userMessage); + var messageData = await LoadTimeLineMessage(); if (messageData == null) { @@ -42,9 +35,7 @@ public async Task RunByMessage() } var convertMessage = ConversionMessage(messageData.Message.Content, messageData.Time); - var userChannelData = m_userMessage.Channel as ISocketMessageChannel; - await userChannelData.SendMessageAsync(convertMessage); - return; + await m_CommandEventArgs.Channel.SendMessageAsync(convertMessage); } /// @@ -53,11 +44,12 @@ public async Task RunByMessage() /// /// /// - private async Task LoadTimeLineMessage(IMessage message) + private async Task LoadTimeLineMessage() { - var splitMessageContent = message.Content.Split( new[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries); - if (splitMessageContent.Length != 3 || !int.TryParse(splitMessageContent[2], out int timeData) || timeData < CommonDefine.MinBattleTime || timeData > CommonDefine.MaxBattleTime ) + if (!int.TryParse(m_CommandEventArgs.Arguments[1], out int timeData) + || timeData < CommonDefine.MinBattleTime + || CommonDefine.MaxBattleTime < timeData ) { return null; } @@ -67,10 +59,10 @@ private async Task LoadTimeLineMessage(IMessage message) Time = timeData, }; - var uriData = new Uri(splitMessageContent[1]); + var uriData = new Uri(m_CommandEventArgs.Arguments[0]); var discordID = uriData.Segments; - if (discordID.Count() != 5) + if (discordID.Length != 5) { return null; } @@ -79,8 +71,7 @@ private async Task LoadTimeLineMessage(IMessage message) convertData.MessageChannelID = discordID[3].Replace("/", ""); convertData.MessageID = discordID[4]; - var userChannelData = message.Channel as SocketGuildChannel; - var timeLineChannelData = userChannelData.Guild.GetChannel(ulong.Parse(convertData.MessageChannelID)) as SocketTextChannel; + var timeLineChannelData = m_CommandEventArgs.Role.Guild.GetChannel(ulong.Parse(convertData.MessageChannelID)) as SocketTextChannel; convertData.Message = await timeLineChannelData.GetMessageAsync(ulong.Parse(convertData.MessageID)); if (convertData.Message == null) From eec9174098e3b31f5206795dec225f1532924ab9 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 04:54:22 +0900 Subject: [PATCH 32/50] =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Commands.cs | 4 ++++ Script/Utility/PriconneEventViewer.cs | 16 +++++----------- Script/Utility/TimeLineConversion.cs | 2 -- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Script/Commands.cs b/Script/Commands.cs index ac321e74..6a8418ec 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -340,5 +340,9 @@ public static async Task Dice(CommandEventArgs commandEventArgs) [Command("!tl", 2, 2)] public static async Task TimeLineConversion(CommandEventArgs commandEventArgs) => await new TimeLineConversion(commandEventArgs).RunByMessage(); + + [Command("!today", 0, 0)] + public static async Task EventInfomation(CommandEventArgs commandEventArgs) + => await new PriconneEventViewer(commandEventArgs).SendEventInfomationByMessage(); } } diff --git a/Script/Utility/PriconneEventViewer.cs b/Script/Utility/PriconneEventViewer.cs index 1ec68142..18185241 100644 --- a/Script/Utility/PriconneEventViewer.cs +++ b/Script/Utility/PriconneEventViewer.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Discord; using PriconneBotConsoleApp.Database; +using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; using PriconneBotConsoleApp.Extension; @@ -11,21 +12,14 @@ namespace PriconneBotConsoleApp.Script { public class PriconneEventViewer { - private IMessage m_UserMessage; - public PriconneEventViewer(IMessage message) - { - m_UserMessage = message; - } + private CommandEventArgs m_CommandEventArgs; + public PriconneEventViewer(CommandEventArgs commandEventArgs) + => m_CommandEventArgs = commandEventArgs; public async Task SendEventInfomationByMessage() { - if (m_UserMessage.Content != "!today") - { - return; - } - var eventString = EventString(); - await m_UserMessage.Channel.SendMessageAsync(text: eventString) ; + await m_CommandEventArgs.Channel.SendMessageAsync(text: eventString) ; } public string EventString() diff --git a/Script/Utility/TimeLineConversion.cs b/Script/Utility/TimeLineConversion.cs index 5dc5ec07..9621d904 100644 --- a/Script/Utility/TimeLineConversion.cs +++ b/Script/Utility/TimeLineConversion.cs @@ -148,8 +148,6 @@ private string ConversionMessage(string messageData, int timeData) { afterLineMessageContent = afterLineMessageContent.Replace(matchTimeData.Value, $"{afterSeconds:D2}{matchTimeData.Groups[2]}"); } - - } sendMessageContent.AppendLine(afterLineMessageContent); From e3d994892274cf6f40e46d35d80297c46f5cf433 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:11:22 +0900 Subject: [PATCH 33/50] =?UTF-8?q?=E3=83=9C=E3=82=B9=E7=95=AA=E5=8F=B7?= =?UTF-8?q?=E3=81=A8=E6=99=82=E9=96=93=E3=81=AE=E5=88=A4=E5=AE=9A=E3=81=AE?= =?UTF-8?q?=E5=8F=AF=E8=AA=AD=E6=80=A7=E3=82=92=E5=90=91=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Shiori/DatabaseReservationController.cs | 4 ++-- Define/CommonDefine.cs | 6 ++++++ Script/ClanBattle/BattleCarryOver.cs | 4 ++-- Script/ClanBattle/BattleProgress.cs | 3 ++- Script/ClanBattle/BattleReport.cs | 6 +++--- Script/ClanBattle/BattleReservation.cs | 6 ++++-- Script/Utility/TimeLineConversion.cs | 6 ++---- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Database/Shiori/DatabaseReservationController.cs b/Database/Shiori/DatabaseReservationController.cs index d0731038..f6424f1d 100644 --- a/Database/Shiori/DatabaseReservationController.cs +++ b/Database/Shiori/DatabaseReservationController.cs @@ -51,7 +51,7 @@ public static List LoadReservationData(PlayerData playerData) public static IEnumerable LoadReservationData(ClanData clanData, int bossNumber) { - if (bossNumber < CommonDefine.MinBossNumber || bossNumber > CommonDefine.MaxBossNumber) + if (!CommonDefine.IsValidBossNumber(bossNumber)) { return null; } @@ -66,7 +66,7 @@ public static IEnumerable LoadReservationData(ClanData clanData public static List LoadBossLapReservationData(ClanData clanData, int bossNumber) { - if (bossNumber < CommonDefine.MinBossNumber || bossNumber > CommonDefine.MaxBossNumber) + if (!CommonDefine.IsValidBossNumber(bossNumber)) { return null; } diff --git a/Define/CommonDefine.cs b/Define/CommonDefine.cs index 5c9dac39..0f8dddfc 100644 --- a/Define/CommonDefine.cs +++ b/Define/CommonDefine.cs @@ -19,5 +19,11 @@ public static class CommonDefine public const int MaxDamageValue = 999999; public const int DisplayDamageUnit = 10000; + + public static bool IsValidBossNumber(int value) + => MinBossNumber <= value && value <= MaxBossNumber; + + public static bool IsValidBattleTime(int value) + => MinBattleTime <= value && value <= MaxBattleTime; } } diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index aeb19197..23641cb2 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -60,8 +60,8 @@ public void UpdateCarryOverData() if (!byte.TryParse(m_CommandEventArgs.Arguments[0], out var bossNumber) || !byte.TryParse(m_CommandEventArgs.Arguments[1], out var remainTime) - || bossNumber < CommonDefine.MinBossNumber || bossNumber > CommonDefine.MaxBossNumber - || remainTime < CommonDefine.MinBattleTime || remainTime > CommonDefine.MaxBattleTime + || !CommonDefine.IsValidBossNumber(bossNumber) + || !CommonDefine.IsValidBattleTime(remainTime) || playerData == null) { return; diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index bb986211..80b487b9 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -134,7 +134,8 @@ public async Task UpdateDamageData() if (!uint.TryParse(Regex.Match(damageText, @"\d+").ToString(), out damageNumber) || !byte.TryParse(Regex.Match(remainTimeText, @"\d+").ToString(), out remainTimeNumber) - || damageNumber > CommonDefine.MaxDamageValue || remainTimeNumber > CommonDefine.MaxBattleTime) + || damageNumber > CommonDefine.MaxDamageValue + || remainTimeNumber > CommonDefine.MaxBattleTime) { return; } diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 49d52034..6e7d86d3 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -69,7 +69,7 @@ public void RegisterReportData() reportData.BossNumber = (byte)bossNumber; } - if (reportData.BossNumber < CommonDefine.MinBossNumber || reportData.BossNumber > CommonDefine.MaxBossNumber) + if (!CommonDefine.IsValidBossNumber(reportData.BossNumber)) { return; } @@ -140,9 +140,9 @@ public void DeleteReportData() public void RegisterOtherUserReportData() { if ((!ulong.TryParse(m_CommandEventArgs.Arguments[0], out var registerUserID) - && !MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out registerUserID)) + && !MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out registerUserID)) || !byte.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) - || bossNumber > CommonDefine.MaxBossNumber || bossNumber < CommonDefine.MinBossNumber + || !CommonDefine.IsValidBossNumber(bossNumber) || !EnumMapper.TryParse(m_CommandEventArgs.Arguments[2], out var attackType)) { return; diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index 7402360d..3a501b8f 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -104,8 +104,10 @@ public void DeleteReserveData() /// private ReservationData MessageToReservationData() { - if (!(byte.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) && CommonDefine.MinBossNumber<= bossNumber && bossNumber <= CommonDefine.MaxBossNumber ) - || !(byte.TryParse(m_CommandEventArgs.Arguments[0], out var battleLap) && battleLap > m_CommandEventArgs.ClanData.GetBossLap(bossNumber))) + if (!byte.TryParse(m_CommandEventArgs.Arguments[1], out var bossNumber) + || !byte.TryParse(m_CommandEventArgs.Arguments[0], out var battleLap) + || !CommonDefine.IsValidBossNumber(bossNumber) + || !CommonDefine.IsValidBattleTime(battleLap)) { return null; } diff --git a/Script/Utility/TimeLineConversion.cs b/Script/Utility/TimeLineConversion.cs index 9621d904..f70b73c3 100644 --- a/Script/Utility/TimeLineConversion.cs +++ b/Script/Utility/TimeLineConversion.cs @@ -46,10 +46,8 @@ public async Task RunByMessage() /// private async Task LoadTimeLineMessage() { - - if (!int.TryParse(m_CommandEventArgs.Arguments[1], out int timeData) - || timeData < CommonDefine.MinBattleTime - || CommonDefine.MaxBattleTime < timeData ) + if (!int.TryParse(m_CommandEventArgs.Arguments[1], out int timeData) + || !CommonDefine.IsValidBattleTime(timeData)) { return null; } From fc0ba36ac218089efc45640e36bcda8e98fbcb68 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:14:29 +0900 Subject: [PATCH 34/50] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleReservationSummary.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Script/ClanBattle/BattleReservationSummary.cs b/Script/ClanBattle/BattleReservationSummary.cs index e7992299..a5afd4b8 100644 --- a/Script/ClanBattle/BattleReservationSummary.cs +++ b/Script/ClanBattle/BattleReservationSummary.cs @@ -119,7 +119,7 @@ private Embed CreateEmbed() if (!reservationDataList[i].Any()) { - // 何かの空白代入して空行を生成している。 + // 空行を保つためのゼロ幅空白(\u200b)を挿入している。 fieldBuilder.Value = "\n\u200b"; } else From 90bd8d3df8d4123290dc276ab2100110030c270e Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:15:39 +0900 Subject: [PATCH 35/50] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E6=95=B4?= =?UTF-8?q?=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleReservationSummary.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Script/ClanBattle/BattleReservationSummary.cs b/Script/ClanBattle/BattleReservationSummary.cs index a5afd4b8..d298bc23 100644 --- a/Script/ClanBattle/BattleReservationSummary.cs +++ b/Script/ClanBattle/BattleReservationSummary.cs @@ -41,7 +41,7 @@ public async Task RunInteraction(SocketMessageComponent messageComponent) return; } - if(buttonType == ButtonType.Reload) + if (buttonType == ButtonType.Reload) { await UpdateMessage(); } From 0d71a3e8a4e073065aa4aca7f34ee4c829950239 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:17:32 +0900 Subject: [PATCH 36/50] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Script/Program.cs b/Script/Program.cs index 7a2a925a..cb6afe84 100644 --- a/Script/Program.cs +++ b/Script/Program.cs @@ -80,7 +80,7 @@ private async Task CommandRecieved(SocketMessage socketMessage) { await CommandMapper.Invoke(new CommandEventArgs(socketUserMessage)); } - catch + catch { } } From 69105b6d96480f1d640584fc2ff7298f4e44da5f Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:20:35 +0900 Subject: [PATCH 37/50] =?UTF-8?q?=E8=AA=A4=E5=AD=97=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/InfomationType.cs | 2 +- Script/ClanBattle/BattleReport.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DataType/InfomationType.cs b/DataType/InfomationType.cs index 9176bab6..29e4dbd1 100644 --- a/DataType/InfomationType.cs +++ b/DataType/InfomationType.cs @@ -13,7 +13,7 @@ public enum InfomationType // 凸報告関連 [Description("<@{0}>の凸報告を代理削除しました。\nこのメッセージは{1}秒後削除されます。")] - DeleteInsted, + DeleteInstead, //持ち越し関連 [Description("持ち越しをすべて削除しました。\nこのメッセージは{0}秒後削除されます。")] diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 6e7d86d3..2a96d0b7 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -129,7 +129,7 @@ public void DeleteReportData() if (playerData.UserID != m_CommandEventArgs.User.Id) { _ = m_CommandEventArgs.SocketUserMessage.Channel.SendTimedMessageAsync(TimeDefine.SuccessMessageDisplayTime, - string.Format(InfomationType.DeleteInsted.ToLabel(), playerData.UserID, TimeDefine.SuccessMessageDisplayTime)); + string.Format(InfomationType.DeleteInstead.ToLabel(), playerData.UserID, TimeDefine.SuccessMessageDisplayTime)); } } } From 1ed4c878733f4207b810133a37766dcca8ccf350 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:29:20 +0900 Subject: [PATCH 38/50] =?UTF-8?q?=E5=91=A8=E5=9B=9E=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E3=81=99=E3=82=8B=E7=AE=87=E6=89=80=E3=81=AE?= =?UTF-8?q?=E5=8F=AF=E8=AA=AD=E6=80=A7=E3=82=92=E5=90=91=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Define/ClanBattleDefine.cs | 3 +++ Script/ClanBattle/BattleProgress.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Define/ClanBattleDefine.cs b/Define/ClanBattleDefine.cs index 84e6af72..49ae222b 100644 --- a/Define/ClanBattleDefine.cs +++ b/Define/ClanBattleDefine.cs @@ -3,5 +3,8 @@ public static class ClanBattleDefine { public const short MaxLapNumber = 250; + + public static bool IsValidLapNumber(int value) + => 0 <= value && value <= MaxLapNumber; } } diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 80b487b9..37b25f95 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -62,7 +62,7 @@ public BattleProgress(CommandEventArgs commandEventArgs) public async Task Start() { if (!ushort.TryParse(m_CommandEventArgs.Arguments[0], out var lap) - || lap > ClanBattleDefine.MaxLapNumber || lap <= 0) + || !ClanBattleDefine.IsValidLapNumber(lap)) { return; } From da27ac2a86660d0b0c4bf02f1c8bfb48e0da1155 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:44:42 +0900 Subject: [PATCH 39/50] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAusing=E3=81=A8?= =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleProgress.cs | 1 - Script/ClanBattle/BattleReservation.cs | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 37b25f95..43cf4e08 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index 3a501b8f..10854f16 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; -using Discord; -using Discord.WebSocket; using PriconneBotConsoleApp.Database; using PriconneBotConsoleApp.DataModel; using PriconneBotConsoleApp.DataType; @@ -36,8 +32,10 @@ public void RegisterReserveData() TimeDefine.ErrorMessageDisplayTime, string.Format(ErrorType.OutOfReservationTime.ToLabel(), $"{m_CommandEventArgs.ClanData.ReservationStartTime.Hours}", - $"{m_CommandEventArgs.ClanData.ReservationEndTime.Hours}") - ); + $"{m_CommandEventArgs.ClanData.ReservationEndTime.Hours}" + ) + ); + return; } From f84ed2066be282d2c4ee80c719057f3793111037 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:50:13 +0900 Subject: [PATCH 40/50] =?UTF-8?q?return=E5=89=8D=E3=81=AE=E7=A9=BA?= =?UTF-8?q?=E8=A1=8C=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleReservation.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Script/ClanBattle/BattleReservation.cs b/Script/ClanBattle/BattleReservation.cs index 10854f16..38fc4a27 100644 --- a/Script/ClanBattle/BattleReservation.cs +++ b/Script/ClanBattle/BattleReservation.cs @@ -47,6 +47,7 @@ public void RegisterReserveData() TimeDefine.ErrorMessageDisplayTime, ErrorType.FailedReservation.ToLabel() ); + return; } @@ -60,6 +61,7 @@ public void RegisterReserveData() TimeDefine.ErrorMessageDisplayTime, string.Format(ErrorType.OutOfReservationBossLaps.ToLabel(), allowReservationLap.ToString()) ); + return; } From 43ebe30801bbada0ff203e832b8b0e22410e16c3 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:50:23 +0900 Subject: [PATCH 41/50] =?UTF-8?q?null=E5=88=A4=E5=AE=9A=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ReceiveInteractionController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Script/ReceiveInteractionController.cs b/Script/ReceiveInteractionController.cs index 810535c0..24f59a64 100644 --- a/Script/ReceiveInteractionController.cs +++ b/Script/ReceiveInteractionController.cs @@ -41,9 +41,10 @@ public async Task Run() .FirstOrDefault(x => x.ChannelID == m_TextChannel.Id) ?.FeatureID ?? 0; - if (channelFeatureID == (int)ChannelFeatureType.ReserveResultID) + if (channelFeatureID == (int)ChannelFeatureType.ReserveResultID + && m_Interaction is SocketMessageComponent socketMessageComponent) { - await new BattleReservationSummary(m_Role, m_ClanData).RunInteraction(m_Interaction as SocketMessageComponent); + await new BattleReservationSummary(m_Role, m_ClanData).RunInteraction(socketMessageComponent); } BattleDeclaration battleDeclaration = channelFeatureID switch From f33dd549ce32532ddad819fd7397a40611de426d Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 20:55:32 +0900 Subject: [PATCH 42/50] =?UTF-8?q?TODO=E3=81=AE=E8=BF=BD=E5=8A=A0=20#131?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleProgress.cs | 2 ++ Script/ClanBattle/BattleReport.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 43cf4e08..23ad67ae 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -115,6 +115,7 @@ public async Task UpdateDamageData() uint damageNumber = 0; byte remainTimeNumber = 0; + // TODO : 冗長なRegexの高速化 #131 if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d+万$")) { if (!uint.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\d+").ToString(), out damageNumber) @@ -126,6 +127,7 @@ public async Task UpdateDamageData() progressDataFlag = true; } + // TODO : 冗長なRegexの高速化 #131 if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d+@\d+")) { var damageText = Regex.Match(m_CommandEventArgs.Name, @"\d+@").ToString(); diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 2a96d0b7..534ce391 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -54,6 +54,7 @@ public void RegisterReportData() { var reportData = new ReportData(); + // TODO : 冗長なRegexの高速化 #131 if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d\D{1,3}")) { var bossNumber = int.Parse(Regex.Match(m_CommandEventArgs.Name, @"\d").Value); From c306bcb87c9430f484f817e3bbd72ad5fe565770 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 21:02:34 +0900 Subject: [PATCH 43/50] =?UTF-8?q?Exception=E3=81=AE=E3=82=B3=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleCarryOver.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index 23641cb2..aad266e8 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -131,14 +131,14 @@ public void DeleteOtherPlayerData() var targetUser = MentionUtils.TryParseUser(m_CommandEventArgs.Arguments[0], out var userID) || ulong.TryParse(m_CommandEventArgs.Arguments[0], out userID) ? m_CommandEventArgs.Role.Guild.GetUser(userID) - : throw new ArgumentNullException(); + : throw new ArgumentNullException("ユーザー情報がありません。"); // コマンドは `!rm @削除対象のユーザー 古い方から何番目か` としている。 if (!byte.TryParse(m_CommandEventArgs.Arguments[1], out var number) || number <= 0 || CommonDefine.MaxReportNumber < number) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException("持ち越しがありません。"); } var playerData = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.Role, targetUser.Id); @@ -172,7 +172,7 @@ private void DeletePlayerCarryOverData(PlayerData playerData, byte deleteNumber) if (carryOverList.Length == 0) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException("持ち越しがありません。"); } DatabaseCarryOverController.DeleteCarryOverData(carryOverList[(deleteNumber > 0 && deleteNumber <= carryOverList.Length) ? deleteNumber - 1 : 0]); From 20e363314242e668213b5b1a73592c9170bdaeb8 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 21:10:17 +0900 Subject: [PATCH 44/50] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleProgress.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 23ad67ae..319a5ca4 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -37,7 +37,7 @@ public string GetNameWithData() return string.Join( halfSizeWhitespace, - ((ProgressStatus) ProgressData.Status).ToLabel(), + ((ProgressStatus)ProgressData.Status).ToLabel(), ProgressData.CarryOverFlag ? "持" : fullSizeWhitespace, $"{ProgressData.Damage,6}@{ProgressData.RemainTime:D2}", ((AttackType)ProgressData.AttackType).ToShortLabel(), @@ -285,7 +285,7 @@ private async Task ChangeLap(ushort lap = 0) /// private void InitializeProgressData() { - if(DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) is { } deleteData) + if (DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) is { } deleteData) { DatabaseProgressController.DeleteProgressData(deleteData); } @@ -332,15 +332,18 @@ private async Task SendClanProgressList(bool removeLastMessage = true) private Embed CreateProgressList() { var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); + var clanProgressData = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) - .OrderBy(x => x.Status).ThenByDescending(x => x.Damage).ThenBy(x => x.CreateDateTime) + .OrderBy(x => x.Status) + .ThenByDescending(x => x.Damage) + .ThenBy(x => x.CreateDateTime) .ToArray(); - var progressPlayer = clanProgressData.Select(x => - new PlayerInfo(clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID),x)) + var progressPlayer = clanProgressData.Select(x => new PlayerInfo(clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID), x)) .ToArray(); var bossLap = m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType); + var bossData = RediveClanBattleData.BossDataList .FirstOrDefault(x => x.BossNumber == (byte)m_BossNumberType && x.LapNumberFrom <= bossLap && (x.LapNumberTo == -1 || x.LapNumberTo >= bossLap)); From b3fd9bdd1fa7905504db9a52ee65d9c174ea0efc Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 21:13:54 +0900 Subject: [PATCH 45/50] =?UTF-8?q?IsValidDamage=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Define/CommonDefine.cs | 3 +++ Script/ClanBattle/BattleProgress.cs | 18 ++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Define/CommonDefine.cs b/Define/CommonDefine.cs index 0f8dddfc..43cb2641 100644 --- a/Define/CommonDefine.cs +++ b/Define/CommonDefine.cs @@ -25,5 +25,8 @@ public static bool IsValidBossNumber(int value) public static bool IsValidBattleTime(int value) => MinBattleTime <= value && value <= MaxBattleTime; + + public static bool IsValidDamageValue(int value) + => 0 <= value && value <= MaxDamageValue; } } diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 319a5ca4..3f2b47ad 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -112,14 +112,14 @@ public async Task UpdateAttackData(AttackType attackType) public async Task UpdateDamageData() { var progressDataFlag = false; - uint damageNumber = 0; + int damageNumber = 0; byte remainTimeNumber = 0; // TODO : 冗長なRegexの高速化 #131 if (Regex.IsMatch(m_CommandEventArgs.Name, @"\d+万$")) { - if (!uint.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\d+").ToString(), out damageNumber) - || damageNumber > CommonDefine.MaxDamageValue) + if (!int.TryParse(Regex.Match(m_CommandEventArgs.Name, @"\d+").ToString(), out damageNumber) + || CommonDefine.IsValidDamageValue(damageNumber)) { return; } @@ -133,9 +133,9 @@ public async Task UpdateDamageData() var damageText = Regex.Match(m_CommandEventArgs.Name, @"\d+@").ToString(); var remainTimeText = Regex.Match(m_CommandEventArgs.Name, @"@\d+").ToString(); - if (!uint.TryParse(Regex.Match(damageText, @"\d+").ToString(), out damageNumber) + if (!int.TryParse(Regex.Match(damageText, @"\d+").ToString(), out damageNumber) || !byte.TryParse(Regex.Match(remainTimeText, @"\d+").ToString(), out remainTimeNumber) - || damageNumber > CommonDefine.MaxDamageValue + || CommonDefine.IsValidDamageValue(damageNumber) || remainTimeNumber > CommonDefine.MaxBattleTime) { return; @@ -164,7 +164,7 @@ public async Task UpdateDamageData() userProgressData.Status = (byte)ProgressStatus.SOS; } - userProgressData.Damage = damageNumber; + userProgressData.Damage = (uint)damageNumber; userProgressData.RemainTime = remainTimeNumber; userProgressData.CommentData = string.Join(" ", m_CommandEventArgs.Arguments); await UpdateProgressData(userProgressData, m_CommandEventArgs.PlayerData); @@ -333,13 +333,11 @@ private Embed CreateProgressList() { var clanPlayerDataList = DatabasePlayerDataController.LoadPlayerData(m_CommandEventArgs.ClanData); - var clanProgressData = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) + var progressPlayer = DatabaseProgressController.GetProgressData(m_CommandEventArgs.ClanData, m_BossNumberType) .OrderBy(x => x.Status) .ThenByDescending(x => x.Damage) .ThenBy(x => x.CreateDateTime) - .ToArray(); - - var progressPlayer = clanProgressData.Select(x => new PlayerInfo(clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID), x)) + .Select(x => new PlayerInfo(clanPlayerDataList.FirstOrDefault(y => y.PlayerID == x.PlayerID), x)) .ToArray(); var bossLap = m_CommandEventArgs.ClanData.GetBossLap(m_BossNumberType); From 3dd9edcc6c0b6edd89bdeb11d606e0dbd7676cbf Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 21:57:32 +0900 Subject: [PATCH 46/50] =?UTF-8?q?OrderBy=E3=81=97=E3=81=A6Last=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=9F=E3=81=AE=E3=82=92=E9=96=A2=E6=95=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Extension/EnumerableExtension.cs | 22 ++++++++++++++++++++++ Script/ClanBattle/BattleReport.cs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Extension/EnumerableExtension.cs b/Extension/EnumerableExtension.cs index 4e773070..bfa4920f 100644 --- a/Extension/EnumerableExtension.cs +++ b/Extension/EnumerableExtension.cs @@ -13,5 +13,27 @@ public static void ForEach([NotNull] this IEnumerable source, [NotNull] Ac action(element); } } + + public static TSource MaxBy([NotNull] this IEnumerable source, [NotNull] Func func) + where TValue : IComparable + { + var firstFlag = true; + TValue maxValue = default; + TSource maxSource = default; + + foreach (var element in source) + { + var value = func(element); + + if (firstFlag || value.CompareTo(maxValue) > 0) + { + maxValue = value; + maxSource = element; + firstFlag = false; + } + } + + return maxSource; + } } } diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 534ce391..4092ed0f 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -121,7 +121,7 @@ public void DeleteReportData() } var removeData = DatabaseReportDataController.GetReportData(playerData) - .OrderBy(x => x.DateTime).Last(); + .MaxBy(x => x.DateTime); if (DatabaseReportDataController.DeleteReportData(removeData)) { From 12d47a3f651e2da2b9bada38e833e4f892839f28 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 21:58:30 +0900 Subject: [PATCH 47/50] =?UTF-8?q?TODO=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/ClanBattle/BattleProgress.cs | 1 + Script/ClanBattle/BattleReservationSummary.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Script/ClanBattle/BattleProgress.cs b/Script/ClanBattle/BattleProgress.cs index 3f2b47ad..ff184f50 100644 --- a/Script/ClanBattle/BattleProgress.cs +++ b/Script/ClanBattle/BattleProgress.cs @@ -111,6 +111,7 @@ public async Task UpdateAttackData(AttackType attackType) /// public async Task UpdateDamageData() { + // TODO : progressDataFlagでやりくりしているのが非常に見にくいので修正したい var progressDataFlag = false; int damageNumber = 0; byte remainTimeNumber = 0; diff --git a/Script/ClanBattle/BattleReservationSummary.cs b/Script/ClanBattle/BattleReservationSummary.cs index d298bc23..bba2321d 100644 --- a/Script/ClanBattle/BattleReservationSummary.cs +++ b/Script/ClanBattle/BattleReservationSummary.cs @@ -105,6 +105,7 @@ private Embed CreateEmbed() var reservationDataSet = DatabaseReservationController.LoadReservationData(m_ClanData); List> reservationDataList = new(); + // TODO : Linqで行けそうな気がする for (var i = 0; i < CommonDefine.MaxBossNumber; i++) { reservationDataList.Add(new List()); From 13d4d69605989607fff36cbe766e31f6e3193540 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 22:03:10 +0900 Subject: [PATCH 48/50] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E6=95=B4?= =?UTF-8?q?=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/ErrorType.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DataType/ErrorType.cs b/DataType/ErrorType.cs index 467a8ccb..2c80f6dc 100644 --- a/DataType/ErrorType.cs +++ b/DataType/ErrorType.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.ComponentModel; +using System.ComponentModel; namespace PriconneBotConsoleApp.DataType { @@ -12,10 +9,13 @@ public enum ErrorType //予約関連 [Description("予約に失敗しました。")] FailedReservation, + [Description("予約できません。予約可能時間は{0}:00~{1}:00です。")] OutOfReservationTime, + [Description("コメントが長いので切り取られました。\n 問題がある場合は予約削除をして再度予約してください。")] TooLongComment, + [Description("予約できません。予約は{0}周目まで可能です。")] OutOfReservationBossLaps, From fb4255eb741285648d6a17930266ca6af5d2b50d Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 22:05:42 +0900 Subject: [PATCH 49/50] =?UTF-8?q?short=E3=82=92ushort=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Define/ClanBattleDefine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Define/ClanBattleDefine.cs b/Define/ClanBattleDefine.cs index 49ae222b..701edba8 100644 --- a/Define/ClanBattleDefine.cs +++ b/Define/ClanBattleDefine.cs @@ -2,7 +2,7 @@ { public static class ClanBattleDefine { - public const short MaxLapNumber = 250; + public const ushort MaxLapNumber = 250; public static bool IsValidLapNumber(int value) => 0 <= value && value <= MaxLapNumber; From ed4d26ad38b40fb7afedef79544e45dfc806a956 Mon Sep 17 00:00:00 2001 From: ca45382 Date: Sun, 15 Aug 2021 22:14:11 +0900 Subject: [PATCH 50/50] =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=9D=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataType/{InfomationType.cs => InformationType.cs} | 2 +- Script/ClanBattle/BattleCarryOver.cs | 2 +- Script/ClanBattle/BattleReport.cs | 2 +- Script/Commands.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename DataType/{InfomationType.cs => InformationType.cs} (94%) diff --git a/DataType/InfomationType.cs b/DataType/InformationType.cs similarity index 94% rename from DataType/InfomationType.cs rename to DataType/InformationType.cs index 29e4dbd1..6ffecbb7 100644 --- a/DataType/InfomationType.cs +++ b/DataType/InformationType.cs @@ -7,7 +7,7 @@ namespace PriconneBotConsoleApp.DataType { - public enum InfomationType + public enum InformationType { Unknown, diff --git a/Script/ClanBattle/BattleCarryOver.cs b/Script/ClanBattle/BattleCarryOver.cs index aad266e8..38797a00 100644 --- a/Script/ClanBattle/BattleCarryOver.cs +++ b/Script/ClanBattle/BattleCarryOver.cs @@ -195,7 +195,7 @@ public void InitAllData() _ = m_CommandEventArgs.Channel.SendTimedMessageAsync( TimeDefine.SuccessMessageDisplayTime, - string.Format(EnumMapper.ToLabel(InfomationType.DeleteAllCarryOverData), TimeDefine.SuccessMessageDisplayTime) + string.Format(EnumMapper.ToLabel(InformationType.DeleteAllCarryOverData), TimeDefine.SuccessMessageDisplayTime) ); } diff --git a/Script/ClanBattle/BattleReport.cs b/Script/ClanBattle/BattleReport.cs index 4092ed0f..082d6862 100644 --- a/Script/ClanBattle/BattleReport.cs +++ b/Script/ClanBattle/BattleReport.cs @@ -130,7 +130,7 @@ public void DeleteReportData() if (playerData.UserID != m_CommandEventArgs.User.Id) { _ = m_CommandEventArgs.SocketUserMessage.Channel.SendTimedMessageAsync(TimeDefine.SuccessMessageDisplayTime, - string.Format(InfomationType.DeleteInstead.ToLabel(), playerData.UserID, TimeDefine.SuccessMessageDisplayTime)); + string.Format(InformationType.DeleteInstead.ToLabel(), playerData.UserID, TimeDefine.SuccessMessageDisplayTime)); } } } diff --git a/Script/Commands.cs b/Script/Commands.cs index 6a8418ec..3f6ac1a4 100644 --- a/Script/Commands.cs +++ b/Script/Commands.cs @@ -342,7 +342,7 @@ public static async Task TimeLineConversion(CommandEventArgs commandEventArgs) => await new TimeLineConversion(commandEventArgs).RunByMessage(); [Command("!today", 0, 0)] - public static async Task EventInfomation(CommandEventArgs commandEventArgs) + public static async Task EventInformation(CommandEventArgs commandEventArgs) => await new PriconneEventViewer(commandEventArgs).SendEventInfomationByMessage(); } }