Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Net;
- using System.Net.Sockets;
- using System.IO;
- using TwitchLib;
- using TwitchLib.Models.Client;
- using System.Data.SQLite;
- namespace TwitchBot
- {
- public partial class Bot : Form
- {
- TwitchClient Client;
- ConnectionCredentials Credentials;
- string USER, PASS, CHANNEL, STATUS;
- List<string> Viewers = new List<string>();
- public Bot()
- {
- InitializeComponent();
- }
- void Setup()
- {
- if (!string.IsNullOrEmpty(UsernameTextBox.Text) && !string.IsNullOrEmpty(PasswordTextBox.Text) && !string.IsNullOrEmpty(ChannelTextBox.Text))
- {
- USER = UsernameTextBox.Text;
- PASS = PasswordTextBox.Text;
- CHANNEL = ChannelTextBox.Text;
- Credentials = new ConnectionCredentials(USER, PASS);
- if (Client == null) { Client = new TwitchClient(Credentials, CHANNEL, '!'); }
- if (!Client.IsConnected)
- {
- // Setup all event handlers
- Client.OnJoinedChannel += Client_OnJoinedChannel;
- Client.OnMessageSent += Client_OnMessageSent;
- Client.OnMessageReceived += Client_OnMessageReceived;
- // Connect the client
- Client.Connect();
- // Change status identifier
- STATUS = "Status: Connected...";
- StatusLabel.Text = STATUS;
- }
- }
- }
- void UpdateViewersText()
- {
- ViewersTextBox.Invoke((MethodInvoker)delegate
- {
- foreach (string v in Viewers)
- {
- ViewersTextBox.AppendText(v);
- }
- });
- }
- private void Client_OnJoinedChannel(object sender, TwitchLib.Events.Client.OnJoinedChannelArgs e)
- {
- OutputTextBox.Invoke((MethodInvoker)delegate
- {
- OutputTextBox.Text = "Joined Twitch Chat, LordeJerry!\n";
- });
- }
- private void Client_OnMessageReceived(object sender, TwitchLib.Events.Client.OnMessageReceivedArgs e)
- {
- OutputTextBox.Invoke((MethodInvoker)delegate
- {
- OutputTextBox.AppendText("[{e.ChatMessage.UserType}] {e.ChatMessage.DisplayName}: {e.ChatMessage.Message}\n");
- });
- ChatTextBox.Invoke((MethodInvoker)delegate
- {
- OutputTextBox.AppendText("[{e.ChatMessage.UserType}] {e.ChatMessage.DisplayName}: {e.ChatMessage.Message}\n");
- });
- }
- private void UsernameTextBox_TextChanged(object sender, EventArgs e)
- {
- }
- private void SendChatMessageButton_Click(object sender, EventArgs e)
- {
- Client.SendMessage(SendChatMessageTextBox.Text);
- SendChatMessageTextBox.Text = string.Empty;
- }
- private void Client_OnMessageSent(object sender, TwitchLib.Events.Client.OnMessageSentArgs e)
- {
- OutputTextBox.Invoke((MethodInvoker)delegate
- {
- OutputTextBox.AppendText("[{e.SentMessage.UserType}] {USER}: {e.SentMessage.Message}\n");
- });
- ChatTextBox.Invoke((MethodInvoker)delegate
- {
- ChatTextBox.AppendText("[{e.SentMessage.UserType}] {USER}: {e.SentMessage.Message}\n");
- });
- }
- private void ConnectButton_Click(object sender, EventArgs e)
- {
- STATUS = "Status: Connecting...";
- StatusLabel.Text = STATUS;
- Setup();
- }
- private void Bot_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement