mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 23:31:13 -05:00
fix some issues with chat search feature
This commit is contained in:
@ -13,7 +13,6 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
{
|
||||
private const int ZScoreRange = 3;
|
||||
private const int RankIconDivisions = 24;
|
||||
private const int MaxMessages = 100;
|
||||
|
||||
public class LogParams
|
||||
{
|
||||
@ -127,70 +126,5 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// todo: lets abstract this out to a generic buildable query
|
||||
/// this is just a dirty PoC
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatSearchQuery ParseSearchInfo(this string query, int count, int offset)
|
||||
{
|
||||
string[] filters = query.Split('|');
|
||||
var searchRequest = new ChatSearchQuery
|
||||
{
|
||||
Filter = query,
|
||||
Count = count,
|
||||
Offset = offset
|
||||
};
|
||||
|
||||
// sanity checks
|
||||
searchRequest.Count = Math.Min(searchRequest.Count, MaxMessages);
|
||||
searchRequest.Count = Math.Max(searchRequest.Count, 0);
|
||||
searchRequest.Offset = Math.Max(searchRequest.Offset, 0);
|
||||
|
||||
if (filters.Length > 1)
|
||||
{
|
||||
if (filters[0].ToLower() != "chat")
|
||||
{
|
||||
throw new ArgumentException("Query is not compatible with chat");
|
||||
}
|
||||
|
||||
foreach (string filter in filters.Skip(1))
|
||||
{
|
||||
string[] args = filter.Split(' ');
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string recombinedArgs = string.Join(' ', args.Skip(1));
|
||||
switch (args[0].ToLower())
|
||||
{
|
||||
case "before":
|
||||
searchRequest.SentBefore = DateTime.Parse(recombinedArgs);
|
||||
break;
|
||||
case "after":
|
||||
searchRequest.SentAfter = DateTime.Parse(recombinedArgs);
|
||||
break;
|
||||
case "server":
|
||||
searchRequest.ServerId = args[1];
|
||||
break;
|
||||
case "client":
|
||||
searchRequest.ClientId = int.Parse(args[1]);
|
||||
break;
|
||||
case "contains":
|
||||
searchRequest.MessageContains = string.Join(' ', args.Skip(1));
|
||||
break;
|
||||
case "sort":
|
||||
searchRequest.Direction = Enum.Parse<SortDirection>(args[1], ignoreCase: true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return searchRequest;
|
||||
}
|
||||
|
||||
throw new ArgumentException("No filters specified for chat search");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user