static void Main(string[] args) { IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, Identifiant.PSEUDO, Identifiant.OAUTHKEY); irc.joinRoom("ducmirack"); while (true) { Message message = Message.Parse(irc.readMessage()); if (message is ServerMessage) { ServerMessage my_message = message as ServerMessage; //traitement pour un serverMessage } if (message is ChatMessage) { ChatMessage my_message = message as ChatMessage; //traitement pour un chatMessage } if (message != null) { Console.WriteLine(message.ToString()); //irc.sendIrcMessage("salut"); } } }
static void Main(string[] args) { bool.TryParse(ConfigurationManager.AppSettings["testmode"], out _testMode); string password = ConfigurationManager.AppSettings["oauth"]; //password from www.twitchapps.com/tmi //include the "oauth:" portion irc = new IrcClient("irc.twitch.tv", 6667, "mrsheila", password); //join channel irc.JoinRoom("voxdavis"); CommandManager.AddCommand("!hype", "Used to generate hype!", (message) => { return "HYPE HYPE HYPE!!!!"; }); CommandManager.AddCommand("!name", "Used to generate a random name. Give a username afterwards to assign it to someone.", (message) => { Regex r = new Regex(@"!name @[\w_\-]+"); NameGenerator ng = new NameGenerator(); if (r.IsMatch(message)) { string u = message.Substring(7); return u + "'s new name is " + ng.GetName(); } else { return ng.GetName(); } }); CommandManager.AddCommand("!source", "Gets a link to the source code!", (message) => { return @"https://github.com/AronDavis/TwitchBot"; }); if (_testMode) { while (true) { string message = irc.readMessage(); if (message == null || message.Length == 0) continue; if (message[0] == '!') { handleCommand("TestUser", message); } } } else { while (true) { string message = irc.readMessage(); if (message == null || message.Length == 0) continue; Console.WriteLine(message); if (message.IndexOf("!") >= 0) handleChatMessage(message); else if (message.StartsWith("PING")) irc.sendIrcMessage("PONG"); } } }
public static void RunBot() { IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, "meleeonlybot", @"C:\Users\nicho\source\repos\MeleeOnlyBot\oauth.txt"); MessageHandler messageHandler = new MessageHandler(irc); irc.joinRoom("umber__"); while (true) { messageHandler.Message(irc.readMessage()); } }
private void getMessage() { serverStream = irc.tcpClient.GetStream(); int buffsize = 0; byte[] inStream = new byte[10025]; buffsize = irc.tcpClient.ReceiveBufferSize; while (true) { try { readData = irc.readMessage(); msg(); } catch (Exception) { } } }
//takes oauth password from twitch static void Main(string[] args) { IrcClient irc = new IrcClient("irc.twitch.tv", 6667, "nightlurk", "oauth:p9znoj3v2mm3niyxd42o6n4ae5zmgs"); irc.joinRoom("nightlurk"); Mod mod = new Mod(); Random rand = new Random(); while (true) { string message = irc.readMessage(); string curUser = irc.getUserName(message); // if (message != "") // irc.sendChatMessage(message); if (message.Contains("!banRoulette")) { int random = rand.Next(); string result; if (random % 6 == 0) { result = "RIP"; mod.timeout(curUser, irc); } else { result = "nothing happens."; } irc.sendChatMessage(curUser + " spins the barrel and shoots ... 1 second later and " + result); } mod.containsBannedWord(message, curUser, irc); } //end of while } //end of main
static void Main(string[] args) { restrt: Console.WriteLine("Welcome to the Pok" + '\u00E9' + "bot console application!"); Console.WriteLine("**Make sure to connect your bot via the LoginInfo.txt file**"); Console.WriteLine("The bot works in chat and on the console (!pokedex not required for console)\n"); //start a new thread to find any keyboard input Thread t = new Thread(readKeyboard); t.Start(); Thread.Sleep(1); //Scan "LoginInfo.txt "file for user login info string channelMain = "", passMain = "", channel = ""; string targetFile = Directory.GetCurrentDirectory() + @"\LoginInfo.txt"; StreamReader file = new StreamReader(targetFile, true); for (int i = 0; i < 3; i++) { if (i == 0) { channelMain = file.ReadLine(); } if (i == 1) { passMain = file.ReadLine(); } if (i == 2) { channel = file.ReadLine(); } } file.Close(); refresh: //jump to here if null message is received from stream DateTime lastMessage = DateTime.Now; //Used to delay messages to counter bans GC.Collect(); //Connect to twitch irc server with login info IrcClient irc = new IrcClient("irc.twitch.tv", 6667, channelMain, passMain); irc.joinRoom(channel); //Infinite loop to check any keyboard or stream input while (true) { bool enter = false; bool advance = false; //Used to know if a picture was updated string message = irc.readMessage(); //Restart program if boolean value changes mid-loop if (restart == true) { restart = false; t.Join(); Console.Clear(); goto restrt; } //Now check for any irc messages and respond appropriately if (message == null) { //Caught this stupid guy giving me problems! //Console.Clear(); //Console.WriteLine("We hit a null message"); GC.Collect(); goto refresh; } if (message.Contains("!pokedex add")) { irc.sendChatMessage("Adding name to database..."); lastMessage = DateTime.Now; addName(message, lastMessage);//add name to data base enter = true; } if ((message.Contains("!pokedex") || message.Contains("!pdx")) && enter == false) { lastMessage = DateTime.Now; advance = updatePic(message, lastMessage);//update pokemon.png if pokemon is found if (advance == false) { advance = checkNames(message); //Look for a nickname and update } if (advance == true) { irc.sendChatMessage("Pok" + '\u00E9' + "dex updated"); //Let chat know we found the nickname } } GC.Collect(); } }
static void Main(string[] args) { bool.TryParse(ConfigurationManager.AppSettings["testmode"], out _testMode); string password = ConfigurationManager.AppSettings["oauth"]; //password from www.twitchapps.com/tmi //include the "oauth:" portion irc = new IrcClient("irc.twitch.tv", 6667, "mrsheila", password); //join channel irc.JoinRoom("voxdavis"); CommandManager.AddCommand("!hype", "Used to generate hype!", (message) => { return("HYPE HYPE HYPE!!!!"); }); CommandManager.AddCommand("!name", "Used to generate a random name. Give a username afterwards to assign it to someone.", (message) => { Regex r = new Regex(@"!name @[\w_\-]+"); NameGenerator ng = new NameGenerator(); if (r.IsMatch(message)) { string u = message.Substring(7); return(u + "'s new name is " + ng.GetName()); } else { return(ng.GetName()); } }); CommandManager.AddCommand("!source", "Gets a link to the source code!", (message) => { return(@"https://github.com/AronDavis/TwitchBot"); }); if (_testMode) { while (true) { string message = irc.readMessage(); if (message == null || message.Length == 0) { continue; } if (message[0] == '!') { handleCommand("TestUser", message); } } } else { while (true) { string message = irc.readMessage(); if (message == null || message.Length == 0) { continue; } Console.WriteLine(message); if (message.IndexOf("!") >= 0) { handleChatMessage(message); } else if (message.StartsWith("PING")) { irc.sendIrcMessage("PONG"); } } } }