Skip to content

Commit

Permalink
Remove useless stuff, sqlite db placement if they were on a version b…
Browse files Browse the repository at this point in the history
…efore 7 will be done manually
  • Loading branch information
SylveonDeko committed May 26, 2024
1 parent 731a36f commit d355973
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 58 deletions.
51 changes: 0 additions & 51 deletions src/Mewdeko/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ private static async Task Main(string[] args)
throw new ArgumentException("No token provided. Exiting...");
}

var clientId = ExtractClientId(credentials.Token);
var dbFilePath = BuildDbPath(clientId);

// Perform database migration
MigrateDatabase(dbFilePath);

// Setup environment variables and logging
Environment.SetEnvironmentVariable($"AFK_CACHED_{shardId}", "0");
Log.Information($"Pid: {Environment.ProcessId}");
Expand All @@ -59,49 +53,4 @@ private static int ExtractArgument(IReadOnlyList<string> args, int index, string

return arg;
}

private static string ExtractClientId(string token)
{
var tokenPart = token.Split('.')[0];
var paddingNeeded = 4 - tokenPart.Length % 4;
if (paddingNeeded > 0 && paddingNeeded < 4)
{
tokenPart = tokenPart.PadRight(tokenPart.Length + paddingNeeded, '=');
}

return Encoding.UTF8.GetString(Convert.FromBase64String(tokenPart));
}

private static string BuildDbPath(string clientId)
{
var folderPath = Environment.GetFolderPath(Environment.OSVersion.Platform == PlatformID.Unix
? Environment.SpecialFolder.UserProfile
: Environment.SpecialFolder.ApplicationData);

return Path.Combine(folderPath, Environment.OSVersion.Platform == PlatformID.Unix
? $".local/share/Mewdeko/{clientId}/data/Mewdeko.db"
: $"Mewdeko/{clientId}/data/Mewdeko.db");
}

private static void MigrateDatabase(string dbFilePath)
{
var targetPath = Path.GetDirectoryName(dbFilePath);
var sourcePath = Path.Combine(AppContext.BaseDirectory, "data", "Mewdeko.db");

if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}

if (!File.Exists(dbFilePath))
{
File.Copy(sourcePath, dbFilePath);

Log.Information("Database migrated to {DbFilePath}", dbFilePath);
}
else
{
Log.Information("Database already exists at {DbFilePath}", dbFilePath);
}
}
}
6 changes: 0 additions & 6 deletions src/Mewdeko/Services/Impl/BotCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public BotCredentials()
/// </summary>
public string ShardRunArguments { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the bot should use PostgreSQL.
/// </summary>
public bool UsePsql { get; set; }

/// <summary>
/// Gets or sets the PostgreSQL connection string.
/// </summary>
Expand Down Expand Up @@ -318,7 +313,6 @@ private void UpdateCredentials(object ae, FileSystemEventArgs _)
OwnerIds = data.GetSection("OwnerIds").GetChildren().Select(c => ulong.Parse(c.Value))
.ToImmutableArray();
GoogleApiKey = data[nameof(GoogleApiKey)];
UsePsql = bool.Parse(data[nameof(UsePsql)] ?? "false");
PsqlConnectionString = data[nameof(PsqlConnectionString)];
CsrfToken = data[nameof(CsrfToken)];
MigrateToPsql = bool.Parse(data[nameof(MigrateToPsql)] ?? "false");
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/credentials_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"ShardRunArguments": "",
"BotListToken": null,
"VotesUrl": null,
"UsePsql": false,
"PsqlConnectionString": "Server=ServerIp;Database=DatabaseName;Port=PsqlPort;UID=PsqlUser;Password=UserPassword",
"CoinmarketcapApiKey": null,
"DebugGuildId": 843489716674494475,
Expand Down

0 comments on commit d355973

Please sign in to comment.