Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Connect(string name, string token, int amountOfClients, string strOfChannels)
- {
- List<string>[] channels = StringTo2DArray(strOfChannels, amountOfClients);
- var credentials = new ConnectionCredentials(name, token);
- TwitchClient[] clients = new TwitchClient[amountOfClients];
- for (int i = 0; i < amountOfClients; i++)
- {
- int j = i;
- clients[i] = new TwitchClient(protocol: TwitchLib.Client.Enums.ClientProtocol.TCP);
- clients[i].OnMessageReceived += ShowAllMessages;
- clients[i].OnConnected += (sender, e) => JoinChannels(sender, e, channels[j]);
- clients[i].Initialize(credentials);
- clients[i].Connect();
- }
- }
- private static List<string>[] StringTo2DArray(string str, int num)
- {
- List<string>[] res = new List<string>[num];
- for (int k = 0; k < res.Length; k++)
- {
- res[k] = new List<string>();
- }
- var splitted = str.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x));
- int i = 0;
- foreach (var item in splitted)
- {
- res[i].Add(item);
- if (i == num - 1)
- {
- i = 0;
- }
- else
- {
- i++;
- }
- }
- return res;
- }
- private static void JoinChannels(object sender, OnConnectedArgs e, List<string> channels)
- {
- foreach (var item in channels)
- {
- ((TwitchClient)sender).JoinChannel(item);
- }
- }
- private static void ShowAllMessages(object sender, OnMessageReceivedArgs e)
- {
- Console.WriteLine($"{DateTime.Now} ({e.ChatMessage.Channel})/ {e.ChatMessage.Username}: {e.ChatMessage.Message}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement