Files
SkyBot/SkyBot/Services/BotService.cs
2026-03-15 05:44:32 +00:00

40 lines
1.4 KiB
C#

using System.Collections.Concurrent;
using DotNetEnv;
using SkyBot.Helpers;
using Valour.Sdk.Client;
using Valour.Sdk.Models;
namespace SkyBot.Services
{
public static class BotService
{
public static async Task InitializeBotAsync(
ValourClient client,
ConcurrentDictionary<long, Channel> channelCache,
ConcurrentDictionary<long, bool> initalizedPlanets)
{
Env.Load();
var token = Environment.GetEnvironmentVariable("TOKEN");
if (string.IsNullOrWhiteSpace(token)) {Console.WriteLine("TOKEN not set."); return;}
var loginResult = await client.InitializeUser(token);
if (!loginResult.Success) {Console.WriteLine($"Login Failed: {loginResult.Message}"); return;}
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
await ValourUsercountHelper.UpdateUsercount();
ValourUsercountHelper.StartUpdater();
await PlanetService.InitializePlanetsAsync(client, channelCache, initalizedPlanets);
client.PlanetService.JoinedPlanetsUpdated += async () =>
{
await PlanetService.InitializePlanetsAsync(client, channelCache, initalizedPlanets);
};
client.MessageService.MessageReceived += async (message) =>
{
await Messages.Create.MessageAsync(client, channelCache, message);
};
}
}
}