Skip to content

Commit

Permalink
added format
Browse files Browse the repository at this point in the history
  • Loading branch information
outerwinnie committed Aug 31, 2024
1 parent fbfacdf commit 06a5090
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ static async Task Main(string[] args)
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(channelIdStr) || string.IsNullOrEmpty(_fileId) || string.IsNullOrEmpty(_credentialsPath) || string.IsNullOrEmpty(postTimeStr))
{
Console.WriteLine("Environment variables are not set correctly.");
Console.WriteLine($"DISCORD_BOT_TOKEN: {(string.IsNullOrEmpty(token) ? "Not set" : "Set")}");
Console.WriteLine($"DISCORD_CHANNEL_ID: {(string.IsNullOrEmpty(channelIdStr) ? "Not set" : "Set")}");
Console.WriteLine($"GOOGLE_DRIVE_FILE_ID: {(string.IsNullOrEmpty(_fileId) ? "Not set" : "Set")}");
Console.WriteLine($"GOOGLE_CREDENTIALS_PATH: {(string.IsNullOrEmpty(_credentialsPath) ? "Not set" : "Set")}");
Console.WriteLine($"POST_TIME: {(string.IsNullOrEmpty(postTimeStr) ? "Not set" : "Set")}");
return;
}

Expand Down Expand Up @@ -92,15 +87,17 @@ private static async Task OnReady()
{
var records = csv.GetRecords<YourRecordClass>().ToList();

// Filter records with at least 8 reactions, including those without images
_messages = records.Where(record => record.total_reactions >= 8).Select(record =>
{
if (!string.IsNullOrWhiteSpace(record.image_url))
{
return $"{record.message}\n{record.image_url.Trim()}";
}
return record.message;
}).ToList();
// Filter records with at least 8 reactions
_messages = records.Where(record => record.total_reactions >= 8)
.Select(record =>
{
string result = $"{record.name}: {record.message}\n{record.message_link.Trim()}";
if (!string.IsNullOrWhiteSpace(record.image_url))
{
result += $"\n{record.image_url.Trim()}";
}
return result;
}).ToList();
}

Console.WriteLine("Filtered messages read from CSV:");
Expand Down Expand Up @@ -211,8 +208,10 @@ private static async Task PostRandomMessage()
// Define a class that matches the CSV structure
public class YourRecordClass
{
public string name { get; set; }
public string message { get; set; }
public string image_url { get; set; }
public string message_link { get; set; }
public string has_spoilers { get; set; }
public int total_reactions { get; set; }
}
Expand Down

0 comments on commit 06a5090

Please sign in to comment.