mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 12:32:03 -04:00
Initial commit
This commit is contained in:
36
KfChatDotNetKickBot/Helpers.cs
Normal file
36
KfChatDotNetKickBot/Helpers.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using NLog;
|
||||
|
||||
namespace KfChatDotNetKickBot;
|
||||
|
||||
public static class Helpers
|
||||
{
|
||||
// This ended up being pretty useless as it turns out Firefox doesn't store session cookies in cookies.sqlite
|
||||
// But I'll leave it here in case it becomes useful one day
|
||||
public static async Task<string?> GetXfToken(string cookieName, string cookieDomain, string containerPath)
|
||||
{
|
||||
var logger = LogManager.GetCurrentClassLogger();
|
||||
await using var connection = new SqliteConnection($"Data Source={containerPath}");
|
||||
|
||||
await connection.OpenAsync();
|
||||
logger.Debug($"Opened {containerPath}");
|
||||
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT value FROM moz_cookies WHERE host = $host AND name = $name ORDER BY creationTime DESC LIMIT 1";
|
||||
command.Parameters.AddWithValue("$host", cookieDomain);
|
||||
command.Parameters.AddWithValue("$name", cookieName);
|
||||
logger.Debug("Created command");
|
||||
logger.Debug(command.CommandText);
|
||||
|
||||
await using var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
logger.Debug("Reading first row, which will be immediately returned anyway");
|
||||
return reader.GetString(0);
|
||||
}
|
||||
|
||||
logger.Error("Fucked up while retrieving cookie. Cookie doesn't exist?");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user