-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add text event log database in debug builds
- Loading branch information
1 parent
39a5f7e
commit 5c66fe8
Showing
6 changed files
with
110 additions
and
4 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,9 @@ | ||
SELECT Timestamp, | ||
LAST(SPLIT(FIRST(SPLIT(Event._type, ', ')), '.')) AS Type, | ||
Event.Source AS Source, | ||
Event.ChatType AS ChatType, | ||
COALESCE(Event.Speaker, Event.SpeakerName) AS Speaker, | ||
Event.Text AS Text, | ||
Event | ||
FROM event | ||
ORDER BY Timestamp DESC; |
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,10 @@ | ||
namespace TextToTalk.Data.Model; | ||
|
||
public class TextEventLogEntry | ||
{ | ||
public Guid Id { get; init; } | ||
|
||
public required DateTime Timestamp { get; init; } | ||
|
||
public required object Event { get; init; } | ||
} |
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,27 @@ | ||
using LiteDB; | ||
using TextToTalk.Data.Model; | ||
|
||
namespace TextToTalk.Data.Service; | ||
|
||
public class TextEventLogCollection(ILiteDatabase db) | ||
{ | ||
private const string TextEventLogCollectionName = "event"; | ||
|
||
public void StoreEvent(TextEventLogEntry entry) | ||
{ | ||
var collection = GetTextEventLogCollection(); | ||
collection.Insert(entry); | ||
} | ||
|
||
private ILiteCollection<TextEventLogEntry> GetTextEventLogCollection() | ||
{ | ||
var collection = db.GetCollection<TextEventLogEntry>(TextEventLogCollectionName); | ||
EnsureIndices(collection); | ||
return collection; | ||
} | ||
|
||
private static void EnsureIndices(ILiteCollection<TextEventLogEntry> collection) | ||
{ | ||
collection.EnsureIndex(p => p.Timestamp); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,16 @@ | ||
namespace TextToTalk.Events; | ||
using System; | ||
using TextToTalk.Data.Model; | ||
|
||
public abstract class TextEvent; | ||
namespace TextToTalk.Events; | ||
|
||
public abstract class TextEvent | ||
{ | ||
public TextEventLogEntry ToLogEntry() | ||
{ | ||
return new TextEventLogEntry | ||
{ | ||
Event = this, | ||
Timestamp = DateTime.UtcNow, | ||
}; | ||
} | ||
} |
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,24 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Dalamud.Game.ClientState.Objects.Types; | ||
using Dalamud.Game.Text.SeStringHandling; | ||
using LiteDB; | ||
|
||
namespace TextToTalk; | ||
|
||
public class ObjectMapper | ||
{ | ||
[ModuleInitializer] | ||
internal static void Initialize() | ||
{ | ||
// Register one-way SeString mapper | ||
BsonMapper.Global.RegisterType<SeString>( | ||
serialize: value => value.TextValue, | ||
deserialize: _ => throw new NotSupportedException()); | ||
|
||
// Register one-way GameObject mapper | ||
BsonMapper.Global.RegisterType<GameObject>( | ||
serialize: value => value.Name.TextValue, | ||
deserialize: _ => throw new NotSupportedException()); | ||
} | ||
} |
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