Guest User

Untitled

a guest
Feb 11th, 2018
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.07 KB | None | 0 0
  1. ircClient.cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.IO;
  10.  
  11. namespace twitchbot
  12. {
  13.  
  14.     class ircClient
  15.     {
  16.         private string userName;
  17.         private string channel;
  18.  
  19.         private TcpClient tcpClient;
  20.         private StreamReader inputStream;
  21.         private StreamWriter outputStream;
  22.         public ircClient(String ip, int port, string userName, string password)
  23.         {
  24.             this.userName = userName;
  25.  
  26.             tcpClient = new TcpClient(ip, port);
  27.             inputStream = new StreamReader(tcpClient.GetStream());
  28.             outputStream = new StreamWriter(tcpClient.GetStream());
  29.  
  30.             outputStream.WriteLine("PASS " + password);
  31.             outputStream.WriteLine("Nick " + userName);
  32.             outputStream.WriteLine("USER " + userName + " 8 * : " + userName);
  33.             outputStream.Flush();
  34.  
  35.         }
  36.         public void joinRoom(string channel)
  37.         {
  38.             this.channel = channel;
  39.             outputStream.WriteLine("JOIN #" + channel);
  40.             outputStream.Flush();
  41.         }
  42.         public void sendIrcMessage(string message)
  43.         {
  44.             outputStream.WriteLine(message);
  45.             outputStream.Flush();
  46.         }
  47.  
  48.         public void sendChatMessage(string message)
  49.         {
  50.             sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" +  channel + " :" + message);
  51.         }
  52.         public string readMessage()
  53.         {
  54.             string message = inputStream.ReadLine();
  55.            
  56.             return message;
  57.         }
  58.     }
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. Program.cs
  68.  
  69. using System;
  70. using System.Collections.Generic;
  71. using System.Diagnostics;
  72. using System.IO;
  73. using System.Linq;
  74. using System.Text;
  75. using System.Threading;
  76. using System.Threading.Tasks;
  77. using System.Windows;
  78. using WMPRichPreviewLauncher;
  79. using WMPLib;
  80.  
  81.  
  82. namespace twitchbot
  83. {
  84.     class Program
  85.     {
  86.  
  87.         static void Main(string[] args)
  88.         {
  89.            
  90.             System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"C:\\Users\\VPSwede\\Desktop\\Dankmemes\\Sounds\\song.wav");
  91.             ircClient irc = new ircClient("irc.twitch.tv", 6667, "vpswedebot", "oauth");
  92.             irc.joinRoom("vpswede");
  93.             while(true)
  94.             {
  95.                 string message = irc.readMessage();
  96.                 if (message.Contains("PING :tmi.twitch.tv"))
  97.                 {
  98.                    
  99.                     Console.WriteLine(message);
  100.                     irc.sendIrcMessage("PONG tmi.twitch.tv\r\n");
  101.  
  102.                 }
  103.                
  104.                 if (message.Contains("string"))
  105.                 {
  106.                     //somecode
  107.                 }
  108.                 else if (message.Contains("string"))
  109.                 {
  110.                    //somecode
  111.                 }
  112.                
  113.                 else
  114.                 {
  115.                     Console.WriteLine(message);
  116.                 }
  117.             }
  118.         }
  119.  
  120.     }
  121. }
Add Comment
Please, Sign In to add comment