· 8 years ago · Feb 05, 2017, 11:32 PM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using TwitchLib;
7using TwitchLib.Models.Client;
8using Windows.Data.Xml.Dom;
9using Windows.UI.Notifications;
10
11namespace MyTwitchBot
12{
13 class Program
14 {
15 private static TwitchClient _client;
16 const string _CHANNEL = "StreamerHouse";
17 static void Main(string[] args)
18 {
19 const string _USERNAME = "NotProSamHDx";
20 const string _PASSWORD = "NOT_FOR_YOU";
21 const string _OAUTH_TOKEN = "NOT_FOR_YOU";
22 //adam13531
23 _client = new TwitchClient(new ConnectionCredentials(_USERNAME,_OAUTH_TOKEN),_CHANNEL);
24
25 _client.Connect();
26
27 _client.OnConnected += _client_OnConnected;
28 _client.OnJoinedChannel += _client_OnJoinedChannel;
29 _client.OnMessageReceived += _client_OnMessageReceived;
30
31
32
33 Console.ReadLine();
34 }
35
36 private static void _client_OnMessageReceived(object sender, TwitchLib.Events.Client.OnMessageReceivedArgs e)
37 {
38 string message = e.ChatMessage.Message;
39
40 if (message.ToLower().IndexOf("kappa") != -1)
41 {
42 string user = e.ChatMessage.DisplayName;
43
44 //Send a toast notification
45 SendNotification(user, message);
46 }
47 }
48
49 private static void SendNotification(string user, string message)
50 {
51 // Get a toast XML template
52 XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
53
54 // Fill in the text elements
55 XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
56 for (int i = 0; i < stringElements.Length; i++)
57 {
58 stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
59 }
60
61 // Specify the absolute path to an image
62 //String imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
63 //XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
64 //imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;
65
66 // Create the toast and attach event listeners
67 ToastNotification toast = new ToastNotification(toastXml);
68 toast.Activated += ToastActivated;
69 toast.Dismissed += ToastDismissed;
70 toast.Failed += ToastFailed;
71
72 // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
73 ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
74 }
75
76 private static void _client_OnJoinedChannel(object sender, TwitchLib.Events.Client.OnJoinedChannelArgs e)
77 {
78 Console.ForegroundColor = ConsoleColor.Green;
79 Console.WriteLine($"Connected to Channel: {e.Channel}");
80 }
81
82 private static void _client_OnConnected(object sender, TwitchLib.Events.Client.OnConnectedArgs e)
83 {
84 _client.JoinChannel(_CHANNEL);
85 Console.ForegroundColor = ConsoleColor.Green;
86 Console.WriteLine("Connected to Twitch :D");
87 }
88 }
89}