-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTwitchClient.cs
More file actions
55 lines (44 loc) · 1.61 KB
/
TwitchClient.cs
File metadata and controls
55 lines (44 loc) · 1.61 KB
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
using System.IO;
using System.Net.Sockets;
namespace twitchBot
{
public class TwitchClient
{
private string username;
private string password;
private string channelName;
private TcpClient tcpClient;
private StreamReader reader;
private StreamWriter writer;
public TwitchClient(string host, int port, string user, string pwd, string channel)
{
username = user;
password = pwd;
channelName = channel;
tcpClient = new TcpClient(host, port);
reader = new StreamReader(tcpClient.GetStream());
writer = new StreamWriter(tcpClient.GetStream());
writer.WriteLine($"PASS {password}");
writer.WriteLine($"NICK {username}");
writer.WriteLine($"USER {username} 8 * :{username}");
writer.WriteLine($"JOIN #{channelName}");
//SendChatMessages("Me acordaram. To aqui, pronto! Como posso ajuda-los?");
SendChatMessages("Hi there");
writer.Flush();
}
public string ReadChatMessage() => reader.ReadLine();
public void SendIrcMessages(string message)
{
writer.WriteLine(message);
writer.Flush();
}
public void SendChatMessages(string message)
{
// server to client
writer.WriteLine($":{username}!{username}@{username}.tmi.twitch.tv PRIVMSG #{channelName} :{message}");
writer.Flush();
// < client to server
//writer.WriteLine($"PRIVMSG #{channelName} : {message}");
}
}
}