-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIrcClient.cs
58 lines (47 loc) · 1.58 KB
/
IrcClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.IO;
using System.Net.Sockets;
namespace Diamond_Chat_Bot
{
public class IrcClient
{
private string userName;
private string channel;
private TcpClient tcpClient;
private StreamReader inputStream;
private StreamWriter outputStream;
public IrcClient(string ip, int port, string userName, string password, string channel)
{
this.userName = userName;
this.channel = channel;
tcpClient = new TcpClient(ip, port);
inputStream = new StreamReader(tcpClient.GetStream());
outputStream = new StreamWriter(tcpClient.GetStream());
outputStream.WriteLine($"PASS {password}");
outputStream.WriteLine($"NICK {userName}");
outputStream.WriteLine($"USER {userName} 8 * :{userName}");
outputStream.WriteLine($"JOIN #{channel}");
outputStream.Flush();
}
public void SendIrcMessage(string message)
{
try
{
outputStream.WriteLine(message);
outputStream.Flush();
}
catch { }
}
public string ReadMessage()
{
try
{
return inputStream.ReadLine();
}
catch { return "Error"; }
}
public void SendChatMessage(string message)
{
SendIrcMessage($":{userName}!{userName}@{userName}.tmi.twitch.tv PRIVMSG #{channel} :{message}");
}
}
}