static void Main(string[] args) { IConfiguration Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .AddCommandLine(args) .Build(); var twitchSettings = new TwitchSettings { Channel = Configuration["TwitchSettings:Channel"], BotName = Configuration["TwitchSettings:BotName"], AccessToken = Configuration["TwitchSettings:AccessToken"] }; var bot = new Bot(twitchSettings); Console.ReadLine(); }
public Bot(TwitchSettings twitchSettings) { var credential = new ConnectionCredentials(twitchSettings.BotName, twitchSettings.AccessToken); var clientOptions = new ClientOptions { MessagesAllowedInPeriod = 100, ThrottlingPeriod = TimeSpan.FromSeconds(30) }; var customClient = new WebSocketClient(clientOptions); client = new TwitchClient(customClient); client.Initialize(credential, twitchSettings.Channel); client.OnLog += Client_OnLog; client.OnJoinedChannel += Client_OnJoinedChannel; client.OnMessageReceived += Client_OnMessageReceived; client.OnWhisperReceived += Client_OnWhisperReceived; client.OnNewSubscriber += Client_OnNewSubscriber; client.OnConnected += Client_OnConnected; client.Connect(); }