-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from ca45382/feature/command-interpret
汎用コマンド解釈処理部分の作成
- Loading branch information
Showing
37 changed files
with
1,426 additions
and
1,255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
{ | ||
public enum BossNumberType | ||
{ | ||
Unknown = 0, | ||
Boss1Number = 1, | ||
Boss2Number = 2, | ||
Boss3Number = 3, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.