Files
TentacleBot/Program.cs
Garret Patti a794e387f3
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 16s
add memory
2026-07-11 10:06:48 -04:00

70 lines
2.1 KiB
C#

using Discord;
using Discord.WebSocket;
using Discord.Interactions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TentacleBot.Services;
using TentacleBot.Services.Memory;
using TentacleBot.Services.Tools;
using TentacleBot.Commands;
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var discordConfig = new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.All,
LogLevel = LogSeverity.Info,
UseInteractionSnowflakeDate = false,
};
var client = new DiscordSocketClient(discordConfig);
var services = new ServiceCollection()
.AddLogging(builder => builder.AddConsole())
.AddSingleton<IConfiguration>(configuration)
.AddSingleton(client)
.AddSingleton(new InteractionService(client, new InteractionServiceConfig
{
LogLevel = LogSeverity.Info,
UseCompiledLambda = true,
}))
.AddSingleton<BotService>()
.AddSingleton<LlmService>()
.AddHttpClient()
.AddSingleton<PalworldApiService>();
// Initialize memory database
var dbPath = configuration["Memory:DatabasePath"] ?? "data/tentaclebot.db";
var dbInit = new DatabaseInitializer(dbPath);
dbInit.Initialize();
services.AddSingleton(dbInit);
services.AddSingleton<MemoryStore>();
services.AddSingleton<ToolRegistry>();
services.AddSingleton<MemoryTools>();
var serviceProvider = services.BuildServiceProvider();
var botService = serviceProvider.GetRequiredService<BotService>();
var interactionService = serviceProvider.GetRequiredService<InteractionService>();
// Register memory tools
var toolRegistry = serviceProvider.GetRequiredService<ToolRegistry>();
var memoryTools = serviceProvider.GetRequiredService<MemoryTools>();
memoryTools.RegisterAll(toolRegistry);
// Register command modules
await interactionService.AddModulesAsync(
typeof(Program).Assembly,
serviceProvider);
// Initialize the bot
await botService.InitializeAsync();
// Keep the bot running
await Task.Delay(Timeout.Infinite);