2
이봐 난 트 위치에 대한 채팅 로봇을 만들려하고 나는 그 일에 초보자의 종류있어이 지금까지 내 작품 : 아래C# 트 봇에 도움이 필요
에서 Form1.cs :
아래using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyTwitchChat
{
public partial class Form1 : Form
{
private string username;
private string password;
bool joined;
IRCClient ircClient;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
username = userNameTB.Text;
password = TokenBox.Text;
ircClient = new IRCClient("irc.chat.twitch.tv", 6667, username, password);
ircClient.joinChannel("deadlycursed");
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (ircClient.tcpClient.Available > 0)
{
string message = ircClient.inputStream.ReadLine();
ChatBox.Items.Add(message);
if (message.Contains("!Hallo"))
ircClient.sendChatMessage("Hi!");
}
}
}
}
IRCClient.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace MyTwitchChat
{
class IRCClient
{
private string username;
private string channel;
private string nickname = "deadlycursed";
public TcpClient tcpClient;
public StreamReader inputStream;
public StreamWriter outputStream;
public IRCClient(string ip, int port, string username, string password)
{
this.username = username;
tcpClient = new TcpClient(ip, port);
inputStream = new StreamReader(tcpClient.GetStream());
outputStream = new StreamWriter(tcpClient.GetStream());
outputStream.WriteLine("PASS " + password);
outputStream.WriteLine("NICK " + nickname);
outputStream.WriteLine("USER " + username + " 0 * :" + nickname);
outputStream.Flush();
}
public void joinChannel(string channel)
{
this.channel = channel;
outputStream.WriteLine("JOIN #" + channel);
outputStream.Flush();
}
public void sendIRCMessage(string message)
{
outputStream.WriteLine(message);
outputStream.Flush();
}
public void sendChatMessage(string message)
{
outputStream.WriteLine(":" + nickname + "!" + username + "@" + nickname + ".tmi.twitch.tv PRIVMSG #"
+ channel + ":" + message);
outputStream.Flush();
}
public string getMessage()
{
string message = inputStream.ReadLine();
return message;
}
}
}
그리고 실제로 메시지를 전송하거나 수신 할 수없는 이유를 알고 싶습니다? 때로는 독서가 제대로 작동하지 않을 때가 있습니다. 내 봇과 채팅 할 수 없습니다.