Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/DevChatter.Bot/BotConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using DevChatter.Bot.Core.Events;
using DevChatter.Bot.Infra.Twitch;

namespace DevChatter.Bot
{
public class BotConfiguration
{
public string DatabaseConnectionString { get; set; }
public TwitchClientSettings TwitchClientSettings { get; set; }
public CommandHandlerSettings CommandHandlerSettings { get; set; }
}
}
8 changes: 3 additions & 5 deletions src/DevChatter.Bot/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using DevChatter.Bot.Core;
using DevChatter.Bot.Core.Events;
using DevChatter.Bot.Infra.Twitch;
using DevChatter.Bot.Startup;

namespace DevChatter.Bot
Expand All @@ -11,10 +9,10 @@ internal class Program
private static void Main(string[] args)
{
Console.WriteLine("Initializing the Bot...");

(string connectionString, TwitchClientSettings clientSettings, CommandHandlerSettings commandHandlerSettings) = SetUpConfig.InitializeConfiguration();

BotMain botMain = SetUpBot.NewBot(clientSettings, commandHandlerSettings, connectionString);
var botConfiguration = SetUpConfig.InitializeConfiguration();

BotMain botMain = SetUpBot.NewBot(botConfiguration);
WaitForCommands(botMain);
}

Expand Down
7 changes: 4 additions & 3 deletions src/DevChatter.Bot/Startup/SetUpBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ namespace DevChatter.Bot.Startup
{
public static class SetUpBot
{
public static BotMain NewBot(TwitchClientSettings twitchSettings, CommandHandlerSettings commandHandlerSettings, string connectionString)
public static BotMain NewBot(BotConfiguration botConfiguration)
{
var twitchSettings = botConfiguration.TwitchClientSettings;
var twitchApi = new TwitchAPI(twitchSettings.TwitchClientId);
var twitchChatClient = new TwitchChatClient(twitchSettings, twitchApi);
var chatClients = new List<IChatClient>
Expand All @@ -28,7 +29,7 @@ public static BotMain NewBot(TwitchClientSettings twitchSettings, CommandHandler
var twitchFollowerService = new TwitchFollowerService(twitchApi, twitchSettings);
var twitchPlatform = new StreamingPlatform(twitchChatClient, twitchFollowerService, new TwitchStreamingInfoService(twitchApi, twitchSettings));

IRepository repository = SetUpDatabase.SetUpRepository(connectionString);
IRepository repository = SetUpDatabase.SetUpRepository(botConfiguration.DatabaseConnectionString);

var chatUserCollection = new ChatUserCollection(repository);
var currencyGenerator = new CurrencyGenerator(chatClients, chatUserCollection);
Expand Down Expand Up @@ -58,7 +59,7 @@ public static BotMain NewBot(TwitchClientSettings twitchSettings, CommandHandler
allCommands.Add(new HangmanCommand(hangmanGame));
allCommands.Add(new RockPaperScissorsCommand(rockPaperScissorsGame));

var commandUsageTracker = new CommandUsageTracker(commandHandlerSettings);
var commandUsageTracker = new CommandUsageTracker(botConfiguration.CommandHandlerSettings);
var commandHandler = new CommandHandler(commandUsageTracker, chatClients, allCommands);
var subscriberHandler = new SubscriberHandler(chatClients);

Expand Down
8 changes: 3 additions & 5 deletions src/DevChatter.Bot/Startup/SetUpConfig.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using DevChatter.Bot.Core.Events;
using DevChatter.Bot.Infra.Twitch;
using Microsoft.Extensions.Configuration;

namespace DevChatter.Bot.Startup
{
public static class SetUpConfig
{
public static (string, TwitchClientSettings, CommandHandlerSettings) InitializeConfiguration()
public static BotConfiguration InitializeConfiguration()
{
Console.WriteLine("Initializing configuration...");

Expand All @@ -17,8 +15,8 @@ public static (string, TwitchClientSettings, CommandHandlerSettings) InitializeC
builder.AddUserSecrets<Program>(); // TODO: Only do this in development

IConfigurationRoot configuration = builder.Build();

return (configuration.GetConnectionString("DevChatterBotDb"), configuration.Get<TwitchClientSettings>(), configuration.Get<CommandHandlerSettings>());
return configuration.Get<BotConfiguration>();
}
}
}
20 changes: 12 additions & 8 deletions src/DevChatter.Bot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"TwitchUsername": "secret",
"TwitchUserID": "secret",
"TwitchOAuth": "secret",
"TwitchChannel": "secret",
"TwitchClientId": "secret",
"GlobalCommandCooldown": "2.5",
"ConnectionStrings": {
"DevChatterBotDb": "Server=(localdb)\\mssqllocaldb;Database=DevChatterBot;Trusted_Connection=True;MultipleActiveResultSets=true"
"DatabaseConnectionString": "Server=(localdb)\\mssqllocaldb;Database=DevChatterBot;Trusted_Connection=True;MultipleActiveResultSets=true",

"TwitchClientSettings": {
"TwitchUsername": "secret",
"TwitchUserID": "secret",
"TwitchOAuth": "secret",
"TwitchChannel": "secret",
"TwitchClientId": "secret"
},

"CommandHandlerSettings": {
"GlobalCommandCooldown": "2.5"
}
}