예제 #1
0
        private static async Task Main(string[] args)
        {
            var config = await File.ReadAllTextAsync("appsettings.json");

            props = JsonConvert.DeserializeObject <IrcClientProperties>(config);

            using (var client = new IrcClient(props.TwitchIrcUrl, props.TwitchIrcPort, props.BotUsername, props.TwitchOAuthToken, props.ChannelName))
            {
                var pinger = new Pinger(client);
                pinger.Start();

                var commandProcessor = new CommandProcessor(props.SteamWebApiKey, client);
                await commandProcessor.InitializeAsync();

                // Listen for commands and process them forever
                while (true)
                {
                    Console.WriteLine("Waiting for next message from chat server");
                    var message = client.ReadMessage();
                    Console.WriteLine($"Received message: {message}");

                    if (message.Contains("PRIVMSG"))
                    {
                        var parsedMessage = ParseMessage(message);
                        await commandProcessor.ProcessAsync(parsedMessage);
                    }
                    else if (message.StartsWith("PING"))
                    {
                        client.SendIrcMessage("PONG :tmi.twitch.tv");
                    }
                }
            }
        }
예제 #2
0
 private void Run()
 {
     while (true)
     {
         Console.WriteLine("Sending PING");
         client.SendIrcMessage("PING irc.twitch.tv");
         Thread.Sleep(TimeSpan.FromMinutes(5));
         Console.WriteLine("Sent PING");
     }
 }