Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

汎用コマンド解釈処理部分の作成 #125

Merged
merged 50 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3316a22
汎用コマンド解釈処理の作成
ca45382 Jul 26, 2021
3d8a1fb
コマンド処理部分の作成
ca45382 Jul 26, 2021
2e98ab9
持ち越し部分をコマンドに対応
ca45382 Jul 28, 2021
f5e6dc5
CommandMapper周辺をリファクタリング
cllightz Jul 28, 2021
82a0473
コンパイルエラーを修正
ca45382 Jul 30, 2021
c64873c
キャルの綴り変更
ca45382 Jul 30, 2021
0e97437
AttackTypeを入れたときにString配列にするように対応
ca45382 Jul 30, 2021
755555d
持ち越し処理をコマンドに適用
ca45382 Jul 30, 2021
66e7b59
GetProgressDataにNullチェックを追加
ca45382 Aug 1, 2021
7ebe7af
チャンネル・メッセージのIDを返すメソッドを追加
ca45382 Aug 1, 2021
6d8b735
BossNumberにUnknownを追加
ca45382 Aug 1, 2021
2212119
PlayerDataを追加
ca45382 Aug 1, 2021
d18b929
コマンドに対応
ca45382 Aug 1, 2021
1b6aa2b
不要なusingを削除
ca45382 Aug 1, 2021
ad784f2
凸報告機能に適用
ca45382 Aug 8, 2021
9da05b1
予約をコマンドに追加
ca45382 Aug 9, 2021
21f8267
変数名の変更
ca45382 Aug 9, 2021
3606b64
TaskKillの部分を仮で追加
ca45382 Aug 10, 2021
1834602
Invokeにtry_catchを設定
ca45382 Aug 13, 2021
8fb67d3
ファイル名の変更
ca45382 Aug 14, 2021
49c441e
Enumの名称変更
ca45382 Aug 14, 2021
acc7c55
冗長な変数代入を修正
ca45382 Aug 14, 2021
d0cc363
リファクタリング
ca45382 Aug 14, 2021
888ff4a
配列にしなくていい箇所を修正
ca45382 Aug 14, 2021
96ddb7d
リファクタリング
ca45382 Aug 14, 2021
260ba7c
使用しなくなった関数を削除
ca45382 Aug 14, 2021
a0da883
リファクタリング
ca45382 Aug 14, 2021
e7d6658
エラーメッセージの修正+リファクタリング
ca45382 Aug 14, 2021
9abd6f7
6ボス以上を登録できてしまうバグを修正
ca45382 Aug 14, 2021
52850f8
予約が削除できないバグを修正
ca45382 Aug 14, 2021
d9e4b0c
さいころとTL変換器を追加
ca45382 Aug 14, 2021
eec9174
イベント表示機能を追加
ca45382 Aug 14, 2021
e3d9948
ボス番号と時間の判定の可読性を向上
ca45382 Aug 15, 2021
fc0ba36
コメントを修正
ca45382 Aug 15, 2021
90bd8d3
コード整形
ca45382 Aug 15, 2021
0d71a3e
不要な空白を削除
ca45382 Aug 15, 2021
69105b6
誤字修正
ca45382 Aug 15, 2021
1ed4c87
周回数を判定する箇所の可読性を向上
ca45382 Aug 15, 2021
da27ac2
不要なusingとリファクタリング
ca45382 Aug 15, 2021
f84ed20
return前の空行を追加
ca45382 Aug 15, 2021
43ebe30
null判定を追加
ca45382 Aug 15, 2021
f33dd54
TODOの追加 #131
ca45382 Aug 15, 2021
c306bcb
Exceptionのコメントを追加
ca45382 Aug 15, 2021
20e3633
リファクタリング
ca45382 Aug 15, 2021
b3fd9bd
IsValidDamageを追加
ca45382 Aug 15, 2021
3dd9edc
OrderByしてLastしてたのを関数化
ca45382 Aug 15, 2021
12d47a3
TODOを追加
ca45382 Aug 15, 2021
13d4d69
コード整形
ca45382 Aug 15, 2021
fb4255e
shortをushortに修正
ca45382 Aug 15, 2021
ed4d26a
タイポ修正
ca45382 Aug 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Attribute/CommandAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using PriconneBotConsoleApp.DataType;
using PriconneBotConsoleApp.Extension;

namespace PriconneBotConsoleApp.Attribute
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public class CommandAttribute : System.Attribute
{
public CommandAttribute(
string[] names = null,
int minArgumentLength = 0,
int maxArgumentLength = int.MaxValue,
params ChannelFeatureType[] compatibleChannels)
{
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)
{
}

public CommandAttribute(
AttackType attackType,
int minArgumentLength = 0,
int maxArgumentLength = int.MaxValue,
params ChannelFeatureType[] compatibleChannels)
: this(
attackType.GetMultiDescription().Names,
minArgumentLength,
maxArgumentLength,
compatibleChannels)
{
}

/// <summary>
/// 受け取ったコマンドを格納する
/// </summary>
public IReadOnlyList<string> Names { get; }

/// <summary>
/// 引数の長さの最小値
/// </summary>
public int MinArgumentLength { get; }

/// <summary>
/// 引数の長さの最大値
/// </summary>
public int MaxArgumentLength { get; }

/// <summary>
/// コマンドが対応するチャンネル
/// </summary>
public IReadOnlyList<ChannelFeatureType> CompatibleChannels { get; }

public bool IsCompatibleArgumentLength(int argLength)
=> MinArgumentLength <= argLength && argLength <= MaxArgumentLength;
}
}
Original file line number Diff line number Diff line change
@@ -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<string> 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
Expand All @@ -26,5 +33,5 @@ public MultiDescriptionAttribute(
}

public MultiDescriptionData Data { get; }
}
}
}
52 changes: 52 additions & 0 deletions DataModel/CommandEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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;

if (SocketUserMessage.Content.Length == 0)
{
throw new ArgumentException("Content.Length が 0");
}

var splitContents = SocketUserMessage.Content.ZenToHan().Split(' ', StringSplitOptions.RemoveEmptyEntries);
Name = splitContents[0];
Arguments = splitContents.Length > 1 ? splitContents.Skip(1).ToList() : Array.Empty<string>();
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);

if (Role == null)
{
return;
}

ClanData = DatabaseClanDataController.LoadClanData(Role);

ChannelFeatureType =
(ChannelFeatureType?)ClanData.ChannelData.FirstOrDefault(x => x.ChannelID == Channel.Id)?.FeatureID
?? ChannelFeatureType.All;
}

public SocketUserMessage SocketUserMessage { get; }
public string Name { get; }
public IReadOnlyList<string> Arguments { get; }
public SocketGuildUser User { get; }
public SocketTextChannel Channel { get; }
public SocketRole Role { get; }
public ClanData ClanData { get; }
public PlayerData PlayerData { get; }
public ChannelFeatureType ChannelFeatureType { get; }
}
}
70 changes: 18 additions & 52 deletions DataModel/Shiori/ClanData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PriconneBotConsoleApp.DataType;
using PriconneBotConsoleApp.Extension;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
Expand Down Expand Up @@ -82,68 +83,33 @@ 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);

/// <summary>
/// 最も周回数を返す
/// クラン内のチャンネルIDを返す。
/// </summary>
/// <param name="channelFeatureType"></param>
/// <returns></returns>
public int GetMinBossLap()
=> Enumerable.Min(new int[] { Boss1Lap, Boss2Lap, Boss3Lap, Boss4Lap, Boss5Lap });
public ulong GetChannelID(ChannelFeatureType channelFeatureType)
=> ChannelData?.GetChannelID(ClanID, channelFeatureType) ?? 0;

/// <summary>
/// 5つのボスデータから今のボスに変換。来月削除
/// クラン内のメッセージIDを返す
/// </summary>
/// <param name="clanData"></param>
/// <param name="messageFeatureType"></param>
/// <returns></returns>
[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;
}
public ulong GetMessageID(MessageFeatureType messageFeatureType)
=> MessageData?.GetMessageID(ClanID, messageFeatureType) ?? 0;

/// <summary>
/// 5つのボスデータから今のLapに変換。来月削除。
/// 最も小さい周回数を返す
/// </summary>
/// <param name="clanData"></param>
/// <returns></returns>
[Obsolete]
public ushort GetNowLap()
{
if (Boss1Lap == Boss2Lap
&& Boss2Lap == Boss3Lap
&& Boss3Lap == Boss4Lap
&& Boss4Lap == Boss5Lap)
{
return Boss5Lap;
}
else
{
return Boss1Lap;
}
}
public int GetMinBossLap()
=> Enumerable.Min(new int[] { Boss1Lap, Boss2Lap, Boss3Lap, Boss4Lap, Boss5Lap });
}

}
2 changes: 1 addition & 1 deletion DataType/AttackType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum AttackType
Magic,

[MultiDescription("ニャル", "ニ", "n", "N")]
NewYearKyaru,
NewYearKaryl,

[MultiDescription("持ち越し", "持", "-", "持越し", "持越")]
CarryOver,
Expand Down
1 change: 1 addition & 0 deletions DataType/BossNumberType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum BossNumberType
{
Unknown = 0,
Boss1Number = 1,
Boss2Number = 2,
Boss3Number = 3,
Expand Down
10 changes: 5 additions & 5 deletions DataType/ErrorType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.ComponentModel;

namespace PriconneBotConsoleApp.DataType
{
Expand All @@ -12,10 +9,13 @@ public enum ErrorType
//予約関連
[Description("予約に失敗しました。")]
FailedReservation,
[Description("予約できません。予約可能時間は{0}~{1}です。")]

[Description("予約できません。予約可能時間は{0}:00~{1}:00です。")]
OutOfReservationTime,
ca45382 marked this conversation as resolved.
Show resolved Hide resolved

[Description("コメントが長いので切り取られました。\n 問題がある場合は予約削除をして再度予約してください。")]
TooLongComment,

[Description("予約できません。予約は{0}周目まで可能です。")]
OutOfReservationBossLaps,

Expand Down
6 changes: 5 additions & 1 deletion DataType/InfomationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public enum InfomationType

// 凸報告関連
[Description("<@{0}>の凸報告を代理削除しました。\nこのメッセージは{1}秒後削除されます。")]
DeleteInsted,
DeleteInstead,

//持ち越し関連
[Description("持ち越しをすべて削除しました。\nこのメッセージは{0}秒後削除されます。")]
DeleteAllCarryOverData,
}
}
9 changes: 2 additions & 7 deletions DataType/ProgressStatus.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -25,6 +20,6 @@ public enum ProgressStatus : byte
SOS,

[Description("🏃")]
CarryOver,
SubdueBoss,
}
}
3 changes: 3 additions & 0 deletions DataType/ShioriFeature/ChannelFeatureType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public enum ChannelFeatureType : uint
{
Unknown = 0,

/// <summary>すべてのチャンネルで利用できるコマンドにつけられる.</summary>
All = 9999,

DeclareID = 1001,
ReserveID = 1002,
ReserveResultID = 1003,
Expand Down
15 changes: 15 additions & 0 deletions DataType/WarningType.cs
Original file line number Diff line number Diff line change
@@ -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 問題がある場合は予約削除をして再度予約してください。") ]
TooLongComment,
}
}
3 changes: 2 additions & 1 deletion Database/Shiori/DatabaseProgressController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public static IEnumerable<ProgressData> GetProgressData(ClanData clanData, BossN

public static IEnumerable<ProgressData> 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();
}

Expand Down
Loading