public IrcMessenger() { var server = Config.Get("Irc.Server"); var nick = Config.Get("Irc.Nick", Config.Get("Name", "gambot")); var user = Config.Get("Irc.User", nick); var password = Config.Get("Irc.Password"); var ssl = Config.GetBool("Irc.Ssl"); client = new IrcClient(server, new IrcUser(nick, user, password), ssl); client.SetHandler("372", (c, m) => { }); // Ignore MOTD client.PrivateMessageRecieved += (sender, args) => { if (MessageReceived != null) { var message = new IrcMessage(args.PrivateMessage); MessageReceived(this, new MessageEventArgs { Message = message, Addressed = (!args.PrivateMessage .IsChannelMessage || String.Equals(message.To, nick, StringComparison .CurrentCultureIgnoreCase)) }); } }; client.ConnectAsync(); }
static void Main(string[] argArray) { InitClasses(); if (argArray.Any()) _nickServAuth = argArray[0]; //set the command prefix to $ if debug mode _commandPrefix = string.IsNullOrEmpty(_nickServAuth) ? "$" : "!"; DevMode = string.IsNullOrEmpty(_nickServAuth); Client = (!string.IsNullOrEmpty(_nickServAuth)) ? new IrcClient(Config.Host, new IrcUser(Config.Nickname, Config.Username)) : new IrcClient(Config.Host, new IrcUser(Config.NickTest, Config.UserTest)); Client.NetworkError += OnNetworkError; Client.ConnectionComplete += OnConnectionComplete; Client.UserMessageRecieved += OnUserMessageReceived; Client.ChannelMessageRecieved += OnChannelMessageReceived; Client.UserJoinedChannel += OnUserJoinedChannel; AnnounceTimer = new Timer(); AnnounceTimer.Elapsed += OnTimedEvent; if (string.IsNullOrEmpty(_nickServAuth)) { Utils.Log("Warning, nick serv authentication password is empty."); } Utils.Log("Connecting to IRC..."); Client.ConnectAsync(); Console.ReadLine(); }
private void runIrc() { client = new IrcClient("irc.twitch.tv", new IrcUser(Settings.username, Settings.username, Settings.oauth)); client.ConnectionComplete += (s, e) => client.JoinChannel("#" + Settings.username); client.ConnectionComplete += (s, e) => Invoke((MethodInvoker)(() => label2.Text = "Connected")); client.ConnectionComplete += (s, e) => Invoke((MethodInvoker)(() => label2.Location = new System.Drawing.Point(25, 127))); client.ChannelMessageRecieved += (s, e) => //holy shit the wrong spelling of received { //var channel = client.Channels[0]; string message = e.IrcMessage.RawMessage; message = message.Substring(1); string user = message.Substring(0, message.IndexOf("!")); message = message.Substring(message.IndexOf(":") + 1); if (!sessionUsers.ContainsKey(user)) { sessionUsers.Add(user, new double[] { int.Parse(DateTime.Now.ToString("MMddHHmm")), 1 }); Console.WriteLine(sessionUsers[user].ToString()); } else { sessionUsers[user] = new double[] { sessionUsers[user][0], sessionUsers[user][1] + 1 }; } Invoke((MethodInvoker)(() => ChatWindow.AppendText(user + ": " + message + "\n"))); }; client.ConnectAsync(); }
static void Main(string[] args) { var client = new IrcClient("irc.freenode.net", new IrcUser("ChatSharp", "ChatSharp")); client.NetworkError += (s, e) => Console.WriteLine("Error: " + e.SocketError); client.RawMessageRecieved += (s, e) => Console.WriteLine("<< {0}", e.Message); client.RawMessageSent += (s, e) => Console.WriteLine(">> {0}", e.Message); client.UserMessageRecieved += (s, e) => { if (e.PrivateMessage.Message.StartsWith(".join ")) client.Channels.Join(e.PrivateMessage.Message.Substring(6)); else if (e.PrivateMessage.Message.StartsWith(".list ")) { var channel = client.Channels[e.PrivateMessage.Message.Substring(6)]; var list = channel.Users.Select(u => u.Nick).Aggregate((a, b) => a + "," + b); client.SendMessage(list, e.PrivateMessage.User.Nick); } else if (e.PrivateMessage.Message.StartsWith(".whois ")) client.WhoIs(e.PrivateMessage.Message.Substring(7), null); else if (e.PrivateMessage.Message.StartsWith(".raw ")) client.SendRawMessage(e.PrivateMessage.Message.Substring(5)); else if (e.PrivateMessage.Message.StartsWith(".mode ")) { var parts = e.PrivateMessage.Message.Split(' '); client.ChangeMode(parts[1], parts[2]); } }; client.ChannelMessageRecieved += (s, e) => { Console.WriteLine("<{0}> {1}", e.PrivateMessage.User.Nick, e.PrivateMessage.Message); }; client.ConnectAsync(); while (true) ; }
private static void Main(){ var ircUser = new IrcUser(Conf.Nick, Conf.User); var client = new IrcClient(Conf.Server, ircUser); var ChatBot = new BotAgent(); ChatBot.Initialise(); client.ConnectionComplete += (s, e) => { foreach (string chan in Conf.Channels) client.JoinChannel(chan); }; client.ChannelMessageRecieved += (s, e) => { var source = e.PrivateMessage.Source; var channel = client.Channels[source]; var message = e.PrivateMessage.Message; var urls = URLTitle.GetURLs(message); if (urls.Count != 0){ var responseTitle = URLTitle.GetTitle(urls[0]); channel.SendMessage(responseTitle); } else{ var query = ChatBot.Query(message); var response = ChatBot.Reply(query); Log(message, response.Output, Conf.Nick, source); channel.SendMessage(response.Output); } }; client.NetworkError += (s, e) => Console.WriteLine("Error: {0}", e.SocketError); client.ConnectAsync(); while (true); }
internal IrcChannel(IrcClient client, string name) { Client = client; Users = new UserCollection(); UsersByMode = new Dictionary<char, UserCollection>(); Name = name; }
public DarkChat() { loadConfig(); DarkLog.Debug(String.Format("[DarkChat] initialized version {0}", PLUGIN_VER)); ircUser = new IrcUser(settings.Nick, settings.Ident, settings.NickServ, settings.RealName); ircClient = new IrcClient(settings.Server, ircUser); }
public static void SendNotice(IrcClient client, string message, params string[] destinations) { const string illegalCharacters = "\r\n\0"; if (!destinations.Any()) throw new InvalidOperationException("Message must have at least one target."); if (illegalCharacters.Any(message.Contains)) throw new ArgumentException("Illegal characters are present in message.", "message"); var to = string.Join(",", destinations); client.SendRawMessage("NOTICE {0} :{1}", to, message); }
// Start the bot public IRCBot() { // Load the settings if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/settings.json")) settings = Utils.Load<Settings>(); else Utils.Save(ref settings); // Load the words if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/words.json")) words = Utils.Load<Words>(); else Utils.Save(ref words); // Load the seen_tells' if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/seen_tell.json")) seenTell = Utils.Load<Seen_Tell>(); else Utils.Save(ref seenTell); /* // Load the aliase if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/alias.json")) alias = Utils.Load<Alias>(); else Utils.Save(ref alias); */ // Create the randomizer BaseUtils.random = new Random(); // Startup BaseUtils.LogSpecial(settings.name + " - a friendly IRC bot!"); // Connection client = new IrcClient(settings.host, new IrcUser(settings.name, settings.name)); client.ConnectionComplete += (s, e) => { client.SendMessage("identify " + settings.pw, new[] { "NickServ" }); settings.channels.ForEach(c => client.JoinChannel(c)); }; client.ChannelMessageRecieved += Client_ChannelMessageRecieved; client.UserKicked += Client_UserKicked; //client.NickChanged += Client_NickChanged; client.ConnectAsync(); AppDomain.CurrentDomain.ProcessExit += (s, e) => { client.Quit(); BaseUtils.Writer().WriteLine("[Stop] ============ " + DateTime.UtcNow.ToShortDateString() + " " + DateTime.UtcNow.ToLongTimeString() + " ============"); BaseUtils.Writer().Close(); }; // Stop GC GC.KeepAlive(this); }
internal PrivateMessage(IrcClient client, IrcMessage message, ServerInfo serverInfo) { Source = message.Parameters[0]; Message = message.Parameters[1]; User = client.Users.GetOrAdd(message.Prefix); if (serverInfo.ChannelTypes.Any(c => Source.StartsWith(c.ToString()))) IsChannelMessage = true; else Source = User.Nick; }
internal IrcChannel(IrcClient client, string name) { Client = client; Users = new UserCollection(); Operators = new UserCollection(); Voiced = new UserCollection(); Bans = new MaskCollection(); Exceptions = new MaskCollection(); Quiets = new MaskCollection(); Invites = new MaskCollection(); Name = name; }
static void Main(string[] args) { var client = new IrcClient("irc.freenode.net", new IrcUser("ChatSharp", "ChatSharp")); client.NetworkError += (s, e) => Console.WriteLine("Error: " + e.SocketError); client.RawMessageRecieved += (s, e) => Console.WriteLine("<< {0}", e.Message); client.RawMessageSent += (s, e) => Console.WriteLine(">> {0}", e.Message); client.UserMessageRecieved += (s, e) => { if (e.PrivateMessage.Message.StartsWith(".join ")) client.Channels.Join(e.PrivateMessage.Message.Substring(6)); else if (e.PrivateMessage.Message.StartsWith(".list ")) { var channel = client.Channels[e.PrivateMessage.Message.Substring(6)]; var list = channel.Users.Select(u => u.Nick).Aggregate((a, b) => a + "," + b); client.SendMessage(list, e.PrivateMessage.User.Nick); } else if (e.PrivateMessage.Message.StartsWith(".whois ")) client.WhoIs(e.PrivateMessage.Message.Substring(7), null); else if (e.PrivateMessage.Message.StartsWith(".raw ")) client.SendRawMessage(e.PrivateMessage.Message.Substring(5)); else if (e.PrivateMessage.Message.StartsWith(".mode ")) { var parts = e.PrivateMessage.Message.Split(' '); client.ChangeMode(parts[1], parts[2]); } else if (e.PrivateMessage.Message.StartsWith(".topic ")) { string messageArgs = e.PrivateMessage.Message.Substring(7); if (messageArgs.Contains(" ")) { string channel = messageArgs.Substring(0, messageArgs.IndexOf(" ")); string topic = messageArgs.Substring(messageArgs.IndexOf(" ") + 1); client.Channels[channel].SetTopic(topic); } else { string channel = messageArgs.Substring(messageArgs.IndexOf("#")); client.GetTopic(channel); } } }; client.ChannelMessageRecieved += (s, e) => { Console.WriteLine("<{0}> {1}", e.PrivateMessage.User.Nick, e.PrivateMessage.Message); }; client.ChannelTopicReceived += (s, e) => { Console.WriteLine("Received topic for channel {0}: {1}", e.Channel.Name, e.Topic); }; client.ConnectAsync(); while (true) ; }
public IrcClientAdapter(string serverAddress, string nick, string user) { _client = new IrcClient(serverAddress, new IrcUser(nick, user)); _client.ConnectionComplete += (s, e) => ConnectionComplete(s, e); _client.RawMessageSent += (s, e) => RawMessageSent(s, e); _client.RawMessageRecieved += (s, e) => RawMessageReceived(s, e); _client.PrivateMessageRecieved += delegate(object s, ChatSharp.Events.PrivateMessageEventArgs e) { var msg = e.PrivateMessage; PrivateMessageReceived(s, new PrivateMessageEventArgs(msg.IsChannelMessage, msg.Source, msg.User.Nick, msg.Message)); }; }
/// <summary> /// Here we run the command and evaluate the parameters /// </summary> public override void RunCommand(IrcClient client, ProtoIrcMessage message) { if (message.Source != "#principia") { QIRC.SendMessage(client, "This command can only be used in #principia.", message.User, message.Source); return; } if (!File.Exists(Constants.Paths.settings + "principia.txt")) File.Create(Constants.Paths.settings + "principia.txt"); String[] builds = File.ReadAllLines(Constants.Paths.settings + "principia.txt"); if (builds.Count(s => s.StartsWith("Win64:")) == 1) QIRC.SendMessage(client, builds.First(s => s.StartsWith("Win64: ")).Remove(0, "Win64: ".Length), message.User, message.Source, true); else QIRC.SendMessage(client, "There seems to be no build for Win64!", message.User, message.Source, true); }
public void Connect(string u, string c, string server, string p) { User = new IrcUser(u, u); Client = new IrcClient(server + ":" + p, User); Client.ConnectionComplete += (s, e) => { Client.JoinChannel(c); }; Client.MOTDRecieved += (s, e) => { this.DisplayMessage(new CompositeType("MOTD", e.MOTD)); }; Client.ConnectAsync(); }
static void Main(string[] args) { var client = new IrcClient("irc.freenode.net", new IrcUser("ChatSharp", "ChatSharp")); client.NetworkError += (s, e) => Console.WriteLine("Error: " + e.SocketError); client.RawMessageRecieved += (s, e) => Console.WriteLine("<< {0}", e.Message); client.RawMessageSent += (s, e) => Console.WriteLine(">> {0}", e.Message); client.UserMessageRecieved += (s, e) => { if (e.PrivateMessage.Message.StartsWith(".join ")) client.Channels.Join(e.PrivateMessage.Message.Substring(6)); else if (e.PrivateMessage.Message.StartsWith(".list ")) { var channel = client.Channels[e.PrivateMessage.Message.Substring(6)]; var list = channel.Users.Select(u => u.Nick).Aggregate((a, b) => a + "," + b); client.SendMessage(list, e.PrivateMessage.User.Nick); } else if (e.PrivateMessage.Message.StartsWith(".whois ")) client.WhoIs(e.PrivateMessage.Message.Substring(7), null); else if (e.PrivateMessage.Message.StartsWith(".raw ")) client.SendRawMessage(e.PrivateMessage.Message.Substring(5)); else if (e.PrivateMessage.Message.StartsWith(".bans ")) { client.GetBanList(e.PrivateMessage.Message.Substring(6), bans => { client.SendMessage(string.Join(",", bans.Select(b => string.Format("{0} by {1} at {2}", b.Value, b.Creator, b.CreationTime) ).ToArray()), e.PrivateMessage.User.Nick); }); } else if (e.PrivateMessage.Message.StartsWith(".exceptions ")) { client.GetExceptionList(e.PrivateMessage.Message.Substring(12), exceptions => { client.SendMessage(string.Join(",", exceptions.Select(ex => string.Format("{0} by {1} at {2}", ex.Value, ex.Creator, ex.CreationTime) ).ToArray()), e.PrivateMessage.User.Nick); }); } }; client.ChannelMessageRecieved += (s, e) => { Console.WriteLine("<{0}> {1}", e.PrivateMessage.User.Nick, e.PrivateMessage.Message); }; client.ConnectAsync(); while (true) ; }
public MainTwitch(MainGame game, Voting voting) { this.game = game; this.voting = voting; AddActions(); IrcClient client = new IrcClient(Host, new IrcUser(Username, Username, Password)); client.ConnectionComplete += (s, e) => client.JoinChannel(Channel); client.PrivateMessageRecieved += (s, e) => { ParseMessage(e.PrivateMessage.User.RealName, e.PrivateMessage.Message); }; client.ConnectAsync(); }
/// <summary> /// Here we run the command and evaluate the parameters /// </summary> public override void RunCommand(IrcClient client, ProtoIrcMessage message) { if (!message.IsChannelMessage) return; if (client.Channels[message.Source].Users.Contains("teabot")) { String[] words = Words.words.Split('\n'); Boolean noTea = new Random().Next(0, 100) == 1; Func<String, Boolean> predicate = s => s.Contains("te") || s.Contains("ti") || s.Contains("ty"); String[] select = words.Where(s => noTea ? !predicate(s) : predicate(s)).ToArray(); String word = select[new Random().Next(0, select.Length)]; QIRC.SendMessage(client, "teabot: " + word, message.User, message.Source, true); } else { QIRC.SendMessage(client, "No teabot!", message.User, message.Source); } }
/// <summary> /// Be sure that this is only called AFTER you join a channel! /// </summary> /// <param name="path"></param> public void LoadDatabase(IrcClient client) { if (File.Exists(Environment.CurrentDirectory + Path.DirectorySeparatorChar + "seen_database.json")) { JsonSerializer js = new JsonSerializer(); js.Formatting = Formatting.Indented; using (StreamReader sr = new StreamReader(Environment.CurrentDirectory + Path.DirectorySeparatorChar + "seen_database.json")) { using (JsonReader jsr = new JsonTextReader(sr)) { List<IrcUserAndSeen> des; des = js.Deserialize<List<IrcUserAndSeen>>(jsr); UsersSeenDatabase = des; } } } else Console.WriteLine("No database"); }
public MainWindow() { InitializeComponent(); titleBar.MouseLeftButtonDown += (o, e) => DragMove(); AddServerMessage("Connecting..."); log.ItemsSource = messages[currentChannel]; client = new IrcClient(SERVER, new IrcUser(USERNAME, USERNAME)); channels.ItemsSource = channelNames; client.NoticeRecieved += NoticeReceived; client.MOTDPartRecieved += MotdPartReceived; client.ConnectionComplete += ConnectionComplete; client.UserJoinedChannel += UserJoinedChannel; client.ChannelMessageRecieved += ChannelMessageReceived; client.ConnectAsync(); }
public void Create(string server, string nick, string password, int port, bool ssl, bool nickserv) { _server = server; _nick = nick; _password = password; _port = port; _ssl = ssl; _nickserv = nickserv; if (!string.IsNullOrEmpty(password) || nickserv) { _client = new ChatSharp.IrcClient(String.Format("{0}:{1}", server, port), new IrcUser(nick, nick), ssl); } else { _client = new ChatSharp.IrcClient(String.Format("{0}:{1}", server, port), new IrcUser(nick, nick, password), ssl); } _client.RawMessageRecieved += _client_RawMessageRecieved; _client.OnDisconnected += _client_OnDisconnected; _client.UnhandledException += _client_UnhandledException; }
static void Main(string[] args) { var settings = Properties.Settings.Default; ircClient = new IrcClient(settings.IrcServer, new IrcUser(settings.IrcNick, settings.IrcNick)); ircClient.ConnectionComplete += (s, e) => ircClient.JoinChannel(settings.IrcChannel); ircClient.ConnectAsync(); Uri baseAddress = new Uri("net.pipe://localhost"); using (ServiceHost host = new ServiceHost(typeof(Program), baseAddress)) { host.AddServiceEndpoint(typeof(IBotService), new NetNamedPipeBinding(), "BotService"); host.Open(); Console.WriteLine("TfsBot {0} started...", Application.ProductVersion); Console.WriteLine("Press <Enter> to stop the bot."); Console.ReadLine(); host.Close(); } ircClient.Quit("Shutdown..."); }
internal PrivateMessage(IrcClient client, IrcMessage message, ServerInfo serverInfo) { Source = message.Parameters[0]; Message = message.Parameters[1]; User = client.Users.GetOrAdd(message.Prefix); if (serverInfo.ChannelTypes == null) { IsChannelMessage = true; return; } if (serverInfo.ChannelTypes.Any(c => Source.StartsWith(c.ToString()))) { IsChannelMessage = true; } else { Source = User.Nick; } }
internal PrivateMessage(IrcClient client, IrcMessage message, ServerInfo serverInfo) { Source = message.Parameters[0]; Message = message.Parameters[1]; User = client.Users.GetOrAdd(message.Prefix); char[] channelTypes = serverInfo.ChannelTypes; if (channelTypes == null) { channelTypes = new[] { '#' }; // Assume this is twitch } if (channelTypes.Any(c => Source.StartsWith(c.ToString()))) { IsChannelMessage = true; if (client.Channels.Contains(Source)) { Channel = client.Channels[Source]; } } else { Source = User.Nick; } }
static void Main() { var client = new IrcClient("irc.esper.net:5555", new IrcUser("EdgeTest", "EdgeTest")); client.ConnectionComplete += (s, e) => client.JoinChannel("#otegamers"); client.NetworkError += (s, e) => Console.WriteLine("Error: " + e.SocketError); client.RawMessageRecieved += (s, e) => Console.WriteLine("RAWRCV {0}", e.Message); client.RawMessageSent += (s, e) => Console.WriteLine("RAWSNT {0}", e.Message); client.ChannelMessageRecieved += (s, e) => Console.WriteLine("<{0}> {1}", e.PrivateMessage.User.Nick, e.PrivateMessage.Message); client.UserJoinedChannel += (sender, args) => { if (Debug && EdgeData.Developers.Any(str => str.Equals(args.User.Nick))) { EdgeUtils.SendNotice(client, String.Format(EdgeData.JoinMessage, args.User.Nick), args.User.Nick); } }; client.ConnectAsync(); while (true) { } }
internal IrcChannel(IrcClient client, string name) { Client = client; Name = name; Users = new UserPoolView(client.Users.Where(u => u.Channels.Contains(this))); }
internal UserPool(IrcClient client) { Client = client; Users = new List <IrcUser>(); }
private static void ircCommands(string command, IrcUser sender, IrcClient reciever) { command = command.TrimStart(ProgramSettings.settings.Prefix); //simply removes the prefix if (command.StartsWith("quit")) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower() == sender.Nick.ToLower()) { Shutdown(); } } } if (command.StartsWith("help") || command.StartsWith("info")) { client.SendRawMessage("PRIVMSG {0} :Hi! I'm a bot! The current prefix is {1}. You can get a list of my commands with {1}commands!", client.Channels[0].Name, ProgramSettings.settings.Prefix); } if (command.StartsWith("commands")) { client.SendRawMessage("PRIVMSG {0} :Hi {1}! I'm sending you a list of my commands!", client.Channels[0].Name, sender.Nick); client.SendRawMessage("PRIVMSG {0} :Here is a list of my commands!", sender.Nick); client.SendRawMessage("PRIVMSG {0} :quit, help, info, commands, roll, slap, trivia", sender.Nick); client.SendRawMessage("PRIVMSG {0} :If you have any command suggestions, feel free to ping my owner, Blank!", sender.Nick); } if (command.StartsWith("roll")) { string[] splitcommand = command.Split(new char[] { ' ', 'd' }, 3); if (splitcommand.Length > 1){ string secondnumber; int secondDice = 0; if (splitcommand[1].Contains("blunt")) { client.SendRawMessage("PRIVMSG {0} :Hey {1}, pass the weed!", client.Channels[0].Name, sender.Nick); return; } if (command.Contains("d")) { try{ secondnumber = splitcommand[2].ToLower(); secondDice = Convert.ToInt32(secondnumber); } catch { client.SendRawMessage("PRIVMSG {0} :{1}, make sure you type in a # or #d#!", client.Channels[0].Name, sender.Nick); return; } } try { string number = splitcommand[1].ToLower(); float diceroll = Convert.ToSingle(number); if (diceroll > 999) { client.SendRawMessage("PRIVMSG {0} :I don't have that many dice!", client.Channels[0].Name); } else if (diceroll <= 0) { client.SendRawMessage("PRIVMSG {0} :I can't roll negative dice!", client.Channels[0].Name); } else { if (secondDice > 0) { float nextValue = random.Next(1, secondDice); // Returns a random number from 0-99 float finaloutcome = (1 + nextValue) * diceroll; string finaloutcometxt = Convert.ToString(finaloutcome); client.SendRawMessage("PRIVMSG {0} :You rolled a {1}", client.Channels[0].Name, finaloutcometxt); } else if (secondDice <= 0) { float nextValue = random.Next(1, 7); // Returns a random number from 0-99 float finaloutcome = (1 + nextValue) * diceroll; string finaloutcometxt = Convert.ToString(finaloutcome); client.SendRawMessage("PRIVMSG {0} :You rolled a {1}", client.Channels[0].Name, finaloutcometxt); } else { float nextValue = random.Next(1, 7); // Returns a random number from 0-99 float finaloutcome = (1 + nextValue) * diceroll; string finaloutcometxt = Convert.ToString(finaloutcome); client.SendRawMessage("PRIVMSG {0} :You rolled a {1}", client.Channels[0].Name, finaloutcometxt); } } } catch { client.SendRawMessage("PRIVMSG {0} :I can't roll that!", client.Channels[0].Name); } } } if (command.StartsWith("slap")) { string[] splitcommand = command.Split(new char[] { ' ' }, 2); if (splitcommand.Length > 1) { if (splitcommand[1] != client.User.Nick) { client.SendRawMessage("PRIVMSG {0} :" + "\x01" + "ACTION was commanded by {1} to slap {2} with a giant fishbot, and does so.\x01", client.Channels[0].Name, sender.Nick, splitcommand[1]); } } } /* if (command.StartsWith("join")) { string[] splitcommand = command.Split(new char[] { ' ' }, 2); if (splitcommand.Length > 1){ client.SendRawMessage("JOIN {0}", splitcommand[1]); } }*/ if (command.StartsWith("setprefix")) { string[] splitcommand = command.Split(new char[] { ' ' }, 2); foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower() == sender.Nick.ToLower()) { if (splitcommand.Length > 1) { if (splitcommand[1] == "/") { client.SendRawMessage("PRIVMSG {0} :Ahahahaha I don't think so, smart ass.", client.Channels[0].Name); return; } try { char newPrefix = char.Parse(splitcommand[1]); ProgramSettings.settings.Prefix = newPrefix; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nWARNING! Prefix changed to " + newPrefix + "!"); Console.ForegroundColor = ConsoleColor.Gray; client.SendRawMessage("PRIVMSG {0} :NOTICE : Prefix changed to {1}!", client.Channels[0].Name, newPrefix); return; } catch (Exception ex) { client.SendRawMessage("PRIVMSG {0} :The prefix must be a single character!", client.Channels[0].Name); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR : "+ ex +"\n"); Console.ForegroundColor = ConsoleColor.Gray; } } else { client.SendRawMessage("PRIVMSG {0} :The prefix must be a single character!", client.Channels[0].Name); } } } } if (command.StartsWith("trivia")) { string[] splitcommand = command.Split(new char[] { ' ' }, 2); currentQuestion = 1; if (splitcommand.Length >= 1) { if (triviaToggle == true) { if (splitcommand.Length > 1) { if (splitcommand[1].Contains("end")) { client.SendRawMessage("PRIVMSG {0} :{1} TOGGLED TRIVIA OFF!", client.Channels[0].Name, sender.Nick); triviaToggle = false; timer.Enabled = false; return; } else if (triviaToggle == false && !splitcommand[1].Contains("end")) { client.SendRawMessage("PRIVMSG {0} :{1}, Trivia isn't toggled.", client.Channels[0].Name, sender.Nick); return; } } } if (triviaToggle == false) { try { bool result = Int32.TryParse(splitcommand[1], out ttlquestions); if (result) { Console.WriteLine("\nConverted '{0}' to {1}.", splitcommand[1], ttlquestions); client.SendRawMessage("PRIVMSG {0} :TRIVIA HAS BEEN TOGGLED! If you know the answer, respond with '-A answer'!", client.Channels[0].Name); } triviaQuestion(); } catch { //Nothing } } } } if (triviaToggle == true && triviaTimer > 0) { if (command.StartsWith("A")) { string[] splitcommand2 = command.Split(new char[] { ' ' }, 2); string input = splitcommand2[1]; if (input.Equals(Trivia.thisanswer, StringComparison.CurrentCultureIgnoreCase)) { client.SendRawMessage("PRIVMSG {0} :{1} Got the answer correct! ({2})", client.Channels[0].Name, sender.Nick, Trivia.thisanswer); timer.Enabled = false; if (currentQuestion < ttlquestions) { currentQuestion += 1; triviaQuestion(); } else { timer.Interval = 1; triviaToggle = false; client.SendRawMessage("PRIVMSG {0} :THAT'S THE END OF THE LIST FOLKS! TRIVIA IS OVER!", client.Channels[0].Name); return; } } } } else if (triviaTimer <= 0 && triviaToggle == true) { triviaTimer = 0; client.SendRawMessage("PRIVMSG {0} :TIME IS UP! THE CORRECT ANSWER IS ({1})", client.Channels[0].Name, Trivia.thisanswer); triviaToggle = false; } if (command.StartsWith("reverse")) { string[] splitcommand = command.Split(new char[] { ' ' }, 2); char[] charArray = splitcommand[1].ToCharArray(); Array.Reverse(charArray); String reverse = new String(charArray); string returntext = reverse; client.SendRawMessage("PRIVMSG {0} :{1}", client.Channels[0].Name, returntext); } }
private static void RunBot(string nick, string server, string channel) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("\nConnecting to " + ProgramSettings.settings.LastJoinedServer + " on port 6667...."); Console.ForegroundColor = ConsoleColor.White; client = new IrcClient(ProgramSettings.settings.LastJoinedServer, new IrcUser(ProgramSettings.settings.LastUsedNick, "RetaSharp", "V54swg3!", "RetaReta")); client.NetworkError += (s, e) => Console.WriteLine("Error: " + e.SocketError); client.ConnectionComplete += (s, e) => { Console.ForegroundColor = ConsoleColor.Green; Console.Write("\nConnected! Joining " + ProgramSettings.settings.LastJoinedChannel + "..."); Console.ForegroundColor = ConsoleColor.White; client.JoinChannel(ProgramSettings.settings.LastJoinedChannel); Console.ForegroundColor = ConsoleColor.Green; Console.Write("\nSuccessfully joined " + ProgramSettings.settings.LastJoinedChannel + "\n"); Console.ForegroundColor = ConsoleColor.White; }; client.ConnectAsync(); InputThread.Start(); client.NoticeRecieved += (s, e) => { Console.WriteLine("\nNOTICE FROM {0}: {1}", e.Source, e.Notice.ToString()); }; client.ChannelMessageRecieved += (s, e) => { var channels = client.Channels[e.PrivateMessage.Source]; Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("{0} - {1}: {2}", e.PrivateMessage.Source, e.PrivateMessage.User, e.PrivateMessage.Message); //just output the stuff boss Console.ForegroundColor = ConsoleColor.White; if (e.PrivateMessage.Message.StartsWith(ProgramSettings.settings.Prefix.ToString())) { ircCommands(e.PrivateMessage.Message, e.PrivateMessage.User, client); } else if (e.PrivateMessage.Message.Contains(client.User.Nick)) { if (e.PrivateMessage.Message.Contains("help")) { char commandpre = ProgramSettings.settings.Prefix; client.SendRawMessage("PRIVMSG {0} :Hi! I'm a bot! The current prefix is {1}. You can get a list of my commands with {1}commands!", client.Channels[0].Name, commandpre); } if (e.PrivateMessage.Message.Contains("Hello".ToLower()) || e.PrivateMessage.Message.Contains("Hi".ToLower()) || e.PrivateMessage.Message.Contains("Hey".ToLower()) || e.PrivateMessage.Message.Contains("Howdy".ToLower()) || e.PrivateMessage.Message.Contains("Hola".ToLower()) || e.PrivateMessage.Message.Contains("Bonjour".ToLower())) { client.SendRawMessage("PRIVMSG {0} :Hello there!", client.Channels[0].Name); } if (e.PrivateMessage.Message.Contains("time")) { string time = DateTime.Now.ToString("h:mm:ss tt"); client.SendRawMessage("PRIVMSG {0} :The time is currently {1} UTC-8 (PST).", client.Channels[0].Name, time); } if (e.PrivateMessage.Message.Contains("how") && e.PrivateMessage.Message.Contains("are") || e.PrivateMessage.Message.Contains("you")) { int feels = random.Next(0,6); string imfeeling = feeling[feels]; client.SendRawMessage("PRIVMSG {0} :{1}.", client.Channels[0].Name, imfeeling); } if (e.PrivateMessage.Message.Contains("hug") || e.PrivateMessage.Message.Contains("hugs")) { client.SendRawMessage("PRIVMSG {0} :" + "\x01" + "ACTION hugs {1} back.\x01", client.Channels[0].Name, e.PrivateMessage.User.Nick); } if (e.PrivateMessage.Message.Contains("kiss") || e.PrivateMessage.Message.Contains("kisses") || e.PrivateMessage.Message.Contains("makes out")) { client.SendRawMessage("PRIVMSG {0} :" + "\x01" + "ACTION pushes {1} away.\x01", client.Channels[0].Name, e.PrivateMessage.User.Nick); client.SendRawMessage("PRIVMSG {0} :Uhm...no kissing me, {1}.", client.Channels[0].Name, e.PrivateMessage.User.Nick); } if (e.PrivateMessage.Message.Contains("sex") || e.PrivateMessage.Message.Contains("f**k") || e.PrivateMessage.Message.Contains("f***s") || e.PrivateMessage.Message.Contains("humps") || e.PrivateMessage.Message.Contains("rapes") || e.PrivateMessage.Message.Contains("inappropriate") && e.PrivateMessage.Message.Contains("place") || e.PrivateMessage.Message.Contains("places")) { client.SendRawMessage("PRIVMSG {0} :" + "\x01" + "ACTION punches {1}.\x01", client.Channels[0].Name, e.PrivateMessage.User.Nick); client.SendRawMessage("PRIVMSG {0} :DON'T TOUCH ME, {1}!", client.Channels[0].Name, e.PrivateMessage.User.Nick.ToUpper()); try { client.SendRawMessage("PRIVMSG CHANSERV :op"); try { client.KickUser(client.Channels[0].Name, e.PrivateMessage.User.Nick, "EXPLOIT!"); } catch { client.SendRawMessage("PRIVMSG {0} :IF ONLY I COULD KICK YOU...!", client.Channels[0].Name); } client.SendRawMessage("PRIVMSG CHANSERV :deop"); } catch { client.SendRawMessage("PRIVMSG {0} :I NEED AN ADMIN!", client.Channels[0].Name); } } if (e.PrivateMessage.Message.Contains("joke")) { Jokes.Joke(); client.SendRawMessage("PRIVMSG {0} :{1}", client.Channels[0].Name, Jokes.thisjoke); Console.WriteLine("The joke was " + Jokes.randJoke); } } else { if (e.PrivateMessage.Message.Contains("http://") || e.PrivateMessage.Message.Contains("https://") || e.PrivateMessage.Message.Contains("www.") || e.PrivateMessage.Message.Contains(".com") || e.PrivateMessage.Message.Contains(".net") || e.PrivateMessage.Message.Contains(".org") || e.PrivateMessage.Message.Contains(".ca") || e.PrivateMessage.Message.Contains(".us") || e.PrivateMessage.Message.Contains(".io") || e.PrivateMessage.Message.Contains(".mx") && !e.PrivateMessage.Message.Contains("dnp")) { try { string privatemessage = e.PrivateMessage.Message; WebClient x = new WebClient(); client.SendRawMessage("NOTICE {0} :{0} Hold on, grabbing link title...", e.PrivateMessage.User.Nick); string url = e.PrivateMessage.Message.Substring(e.PrivateMessage.Message.LastIndexOf("http://")); string[] cleaned = url.Split(new char[] { ' ' }, 2); if (e.PrivateMessage.Message.Contains(".xxx") || e.PrivateMessage.Message.Contains("p**n")) { client.SendRawMessage("PRIVMSG {0} :Thanks for posting p**n here, {1}", client.Channels[0].Name, e.PrivateMessage.User.Nick); return; } string source = x.DownloadString(cleaned[0]); string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value; client.SendRawMessage("PRIVMSG {0} :{3} submitted a link : [ {1} ] - {2}.", client.Channels[0].Name, title, cleaned[0], e.PrivateMessage.User.Nick); } catch { //Do nothing. } } } }; while (true) ; //just keeps everything going }
private void StartIrc() { var user = new IrcUser(""); if (Properties.Settings.Default.nickserv == string.Empty) user = new IrcUser("twitchplaysagame", "twitchplaysagame"); else user = new IrcUser(Properties.Settings.Default.user, Properties.Settings.Default.user); client = new IrcClient(Properties.Settings.Default.server, user); client.NetworkError += (s, e) => WriteConsole("Error: " + e.SocketError); client.ChannelMessageRecieved += (s, e) => { ParseInput(e.PrivateMessage.User.Nick + ":" + e.PrivateMessage.Message); }; client.ConnectionComplete += (s, e) => { client.SendRawMessage("PRIVMSG {0} :{1}", "nickserv", "identify " + Properties.Settings.Default.nickserv); client.Channels.Join(Properties.Settings.Default.room); WriteConsole("Connected"); }; client.ConnectAsync(); this.WriteConsole("Starting irc service"); started = true; buttonStart.Text = "Stop"; }
internal ChannelCollection(IrcClient client) { Channels = new List <IrcChannel>(); Client = client; }
/// <summary> /// Here we run the command and evaluate the parameters /// </summary> public override void RunCommand(IrcClient client, ProtoIrcMessage message) { QIRC.SendMessage(client, "Win32 is no longer supported. Please use the x64 build, available through !win64, or get a new bird.", message.User, message.Source, true); }
internal IrcChannel(IrcClient client, string name) { Client = client; Users = new UserCollection(); Name = name; }
/// <summary> /// Here we run the command and evaluate the parameters /// </summary> public override void RunCommand(IrcClient client, ProtoIrcMessage message) { String msg = message.Message; if (StartsWithParam("add", message.Message)) { String type = StripParam("add", ref msg); if (type == "wpn") { if (weapons.Contains(msg)) QIRC.SendMessage(client, "Weapon already added!", message.User, message.Source); else { weapons.Add(msg); QIRC.SendMessage(client, "Weapon added!", message.User, message.Source); } } else if (type == "adj") { if (adjectives.Contains(msg)) QIRC.SendMessage(client, "Adjective already added!", message.User, message.Source); else { adjectives.Add(msg); QIRC.SendMessage(client, "Adjective added!", message.User, message.Source); } } else { QIRC.SendMessage(client, "Invalid type", message.User, message.Source); } return; } if (StartsWithParam("remove", message.Message)) { String type = StripParam("remove", ref msg); if (type == "wpn") { if (!weapons.Contains(msg)) QIRC.SendMessage(client, "Weapon doesn't exist!", message.User, message.Source); else { weapons.Remove(msg); QIRC.SendMessage(client, "Weapon removed!", message.User, message.Source); } } else if (type == "adj") { if (!adjectives.Contains(msg)) QIRC.SendMessage(client, "Adjective doesn't exist!", message.User, message.Source); else { adjectives.Remove(msg); QIRC.SendMessage(client, "Adjective removed!", message.User, message.Source); } } else { QIRC.SendMessage(client, "Invalid type", message.User, message.Source); } return; } if (StartsWithParam("stats", message.Message)) { Int32 weaponsnum = weapons.Count; Int32 adjsnum = adjectives.Count; Int64 combospossible = (weaponsnum) + (weaponsnum * adjsnum) + (4 * weaponsnum * weaponsnum * adjsnum) + (weaponsnum * adjsnum * adjsnum) + (4 * weaponsnum * weaponsnum * adjsnum * adjsnum); QIRC.SendMessage(client, $"Total weapons: {weaponsnum}. Total adjectives: {adjsnum}. Total possible combinations: {combospossible}.", message.User, message.Source); return; } Random r = new Random(); String name = String.IsNullOrWhiteSpace(message.Message) ? message.User : message.Message; String weapon = weapons[r.Next(0, weapons.Count)]; String adjective = adjectives[r.Next(0, adjectives.Count)]; Int32 extraweapon = r.Next(0, 20); // roll a d20; if it comes up 1-4, do something silly with an extra weapon entry. if (extraweapon == 1) // weapon/weapon hybrid weapon += "/" + weapons[r.Next(0, weapons.Count)] + " hybrid"; if (extraweapon == 2) // weapon with a weapon attachment { String wpn2 = weapons[r.Next(0, weapons.Count)]; if (new[] {"a", "e", "i", "o", "u"}.Contains(wpn2.ToLower().Substring(0, 1)) && wpn2.ToLower().Substring(0, 2) != "eu") weapon += " with an "; else weapon += " with a "; weapon += wpn2 + " attachment"; } if (extraweapon == 3) // weapon-like weapon { String wpn2 = weapons[r.Next(0, weapons.Count)]; if (!wpn2.Contains(" ")) weapon = wpn2 + "-like " + weapon; } if (extraweapon == 4) // weapon which strongly/vaguely resembles a weapon { String wpn2 = weapons[r.Next(0, weapons.Count)]; if (r.Next(0, 2) == 0) // pick strong/vague resemblance with a coin toss { if (new[] {"a", "e", "i", "o", "u"}.Contains(wpn2.ToLower().Substring(0, 1)) && wpn2.ToLower().Substring(0, 2) != "eu") weapon += " which vaguely resembles an " + wpn2; else weapon += " which vaguely resembles a " + wpn2; } else { if (new[] {"a", "e", "i", "o", "u"}.Contains(wpn2.ToLower().Substring(0, 1)) && wpn2.ToLower().Substring(0, 2) != "eu") weapon += " which strongly resembles an " + wpn2; else weapon += " which strongly resembles a " + wpn2; } } if (r.Next(0, 11) == 4) // roll a d10, if it comes up 4, give up on adjectives and return a plain old weapon. adjective = ""; // why 4? I don't know, go ask a psychologist. (And I dont know too) else { if (!adjective.EndsWith(">")) adjective += " "; else adjective = adjective.Substring(0, adjective.Length - 1); if (r.Next(0, 6) == 3) // roll a d5, if it comes up 3, use more adjectives! I do realize that this is actually a d6 because of that 0... { String extraadj = adjectives[r.Next(0, adjectives.Count)]; // ...but I don't really care, to be honest. if (!extraadj.EndsWith(">")) extraadj += " "; else extraadj = adjective.Substring(0, adjective.Length - 1); if (adjective.Length > 3) // more stuff. mostly a/an detection. { if (adjective.EndsWith(" a ") && new[] {"a", "e", "i", "o", "u"}.Contains(extraadj.ToLower().Substring(0, 1)) && extraadj.ToLower().Substring(0, 2) != "eu") adjective = adjective.Substring(0, adjective.Length - 1) + "n "; } adjective += extraadj; } } if (adjective.Length > 3) // more stuff. mostly a/an detection. { if (adjective.EndsWith(" a ") && new[] {"a", "e", "i", "o", "u"}.Contains(weapon.ToLower().Substring(0, 1)) && weapon.ToLower().Substring(0, 2) != "eu") adjective = adjective.Substring(0, adjective.Length - 1) + "n "; } weapon = adjective + weapon; if (new[] {"a", "e", "i", "o", "u"}.Contains(weapon.ToLower().Substring(0, 1)) && weapon.ToLower().Substring(0, 2) != "eu") weapon = "an " + weapon; else weapon = "a " + weapon; QIRC.SendAction(client, $"gives {name} {weapon}", message.Source); }
internal ChannelCollection(IrcClient client) : this() { Client = client; }
/// <summary> /// Interprets commands /// </summary> /// <param name="command">The full message</param> /// <param name="sender">The full sender</param> /// <param name="recipient">The full recipient</param> private static void InterpretCommand(string command, IrcUser sender, IrcClient client) { command = command.TrimStart(ProgramSettings.settings.CommandPrefix); //simply removes the prefix if (command.StartsWith ("slap")) { if (ProgramSettings.settings.SlapEnabled) { string[] splitCommand = command.Split (new char[] { ' ' }, 2); if (splitCommand.Length > 1) { var listCopy = UsersList; bool foundUser = false; try { foreach (IrcUserAndSeen user in listCopy) { if (user.User.Nick.ToLower () == splitCommand [1].ToLower ().Trim ()) { if (user.User.Nick == client.User.Nick) client.SendRawMessage ("PRIVMSG {0} :What'd I do? :(", client.Channels [0].Name); else client.SendRawMessage ("PRIVMSG {0} :" + "\x01" + "ACTION slaps {1} with a giant fish.\x01", client.Channels [0].Name, user.User.Nick); foundUser = true; break; } } if (!foundUser) client.SendRawMessage ("PRIVMSG {0} :User not found!"); } catch{} } else client.SendRawMessage ("PRIVMSG {0} :Slap who?", client.Channels [0].Name); } } if (command.StartsWith("removeuser")) { string[] split = command.Split(new char[]{' '}, 2); Console.ForegroundColor = ConsoleColor.Yellow; if (split.Length > 1) { bool removed = false; for(int i = 0; i < ProgramSettings.settings.UsersAllowedToDisable.Count; i++) { if (ProgramSettings.settings.UsersAllowedToDisable[i] == split[1].ToLower()) { ProgramSettings.settings.UsersAllowedToDisable.RemoveAt(i); removed = true; } } if (removed) { Console.WriteLine("Removed user \"{0}\" successfully!", split[1].ToLower()); client.SendRawMessage("PRIVMSG {0} :Removed user \"{1}\" successfully!", client.Channels[0].Name, split[1].ToLower()); } else { Console.WriteLine("User doesn't exist!"); client.SendRawMessage("PRIVMSG {0} :That user never existed in the database!", client.Channels[0].Name); } } else { Console.WriteLine("Remove who?"); } Console.ForegroundColor = ConsoleColor.White; } if (command.StartsWith("adduser")) { string[] split = command.Split(new char[]{' '}, 2); Console.ForegroundColor = ConsoleColor.Yellow; if (split.Length > 1) { ProgramSettings.settings.UsersAllowedToDisable.Add(split[1].ToLower()); Console.WriteLine("Added user \"{0}\" to the VIP list", split[1].ToLower()); client.SendRawMessage("PRIVMSG {0} :Added user \"{1}\" to the VIP list.?", client.Channels[0].Name, split[1].ToLower()); } else { Console.WriteLine("Who?"); client.SendRawMessage("PRIVMSG {0} :Add who?", client.Channels[0].Name); } Console.ForegroundColor = ConsoleColor.White; } if (command.StartsWith("disableseen")) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower() == sender.Nick.ToLower()) { ProgramSettings.settings.SeenEnabled = false; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Seen Command Disabled"); Console.ForegroundColor = ConsoleColor.White; client.SendRawMessage ("PRIVMSG {0} :Disabled seen command!", client.Channels[0].Name); } } } if (command.StartsWith("enableseen")) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower() == sender.Nick.ToLower()) { ProgramSettings.settings.SeenEnabled = true; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Seen Command Enabled"); Console.ForegroundColor = ConsoleColor.White; client.SendRawMessage ("PRIVMSG {0} :Enabled seen command!", client.Channels[0].Name); } } } if (command.StartsWith ("enableurlparse")) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower () == sender.Nick.ToLower ()) { ProgramSettings.settings.UrlParsingEnabled = true; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("URL Parsing Enabled"); Console.ForegroundColor = ConsoleColor.White; client.SendRawMessage ("PRIVMSG {0} :Enabling URL parsing!", client.Channels[0].Name); } } } if (command.StartsWith ("disableurlparse")) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower () == sender.Nick.ToLower ()) { ProgramSettings.settings.UrlParsingEnabled = false; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("URL Parsing Disabled"); Console.ForegroundColor = ConsoleColor.White; client.SendRawMessage ("PRIVMSG {0} :Disabling URL parsing!", client.Channels[0].Name); } } } if (command.StartsWith ("nick") || command.StartsWith ("name")) { string[] splitCommand = command.Split (new char[]{ ' ' }, 2); if (splitCommand.Length > 1) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if (user.ToLower () == sender.Nick.ToLower ()) { string cleanNick = CleanInput (splitCommand [1]); client.Nick (cleanNick); ProgramSettings.settings.LastUsedNick = client.User.Nick; } } } } if(command.StartsWith("motto") || command.StartsWith("slogan")) { client.SendRawMessage("PRIVMSG {0} :Luigibot does what Reta don't \u00a9", client.Channels[0].Name); } if(command.StartsWith("version")) { #if __MONOCS__ client.SendRawMessage("PRIVMSG {0} :Luigibot v{1} - http://www.github.com/Luigifan/Luigibot - Running under Mono", client.Channels[0].Name, ProgramVersion.ToString()); #else client.SendRawMessage("PRIVMSG {0} :Luigibot v{1} - http://www.github.com/Luigifan/Luigibot", client.Channels[0].Name, ProgramVersion.ToString()); #endif } if(command.StartsWith("changeprefix")) { string[] splitCommand = command.Split(new char[] { ' ' }, 2); if (splitCommand.Length > 1) { foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if(user.ToLower() == sender.Nick.ToLower()) { if (splitCommand[1].Length == 1) { if (splitCommand[1] == "/") { client.SendRawMessage("PRIVMSG {0} :oi u cheeky c**t ill bash ur ead in i swear on me mum", client.Channels[0].Name); return; } try { char newPrefix = char.Parse(splitCommand[1]); ProgramSettings.settings.CommandPrefix = newPrefix; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Command prefix changed to '{0}' successfully!", newPrefix.ToString()); Console.ForegroundColor = ConsoleColor.White; client.SendRawMessage("PRIVMSG {0} :Command prefix changed to '{1}' successfully!", client.Channels[0].Name, newPrefix.ToString()); return; } catch (Exception ex) { client.SendRawMessage("PRIVMSG {0} :Uh-oh! Luigibot encountered an error. Email Luigifan @ [email protected]", client.Channels[0].Name); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("UH OH BIG ERROR\nUH OH BIG ERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(ex.Message + "\n"); } } else { client.SendRawMessage("PRIVMSG {0} :The prefix must be a single character!", client.Channels[0].Name); } } } } else client.SendRawMessage("PRIVMSG {0} :What character will prefix my commands?", client.Channels[0].Name); } if(command.StartsWith("kick")) { //0: command //1: user //2: reason string[] splitCommand = command.Split(new char[] { ' ' }, 3); foreach (string user in ProgramSettings.settings.UsersAllowedToDisable) { if(user.ToLower() == sender.Nick.ToLower()) { try { if (splitCommand.Length > 2) { client.KickUser(client.Channels[0].Name, splitCommand[1], splitCommand[2]); } else client.KickUser(client.Channels[0].Name, splitCommand[1]); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: {0}", ex.Message); Console.ForegroundColor = ConsoleColor.White; } } } } if(command.StartsWith("getmodes")) { client.SendMessage("Modes: " + client.User.Mode, client.Channels[0].Name); } if (command.StartsWith ("ann")) { string[] splitCommand = command.Split (new char[]{ ' ' }, 2); if (splitCommand.Length > 1) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { if (splitCommand [1] == "test") { if (ProgramSettings.settings.WelcomeMessage.Contains ("/me")) { client.SendAction (String.Format (ProgramSettings.settings.WelcomeMessage.Substring (4), sender.Nick), client.Channels [0].Name); } else { client.SendRawMessage ("PRIVMSG {0} :{1}", client.Channels [0].Name, String.Format (ProgramSettings.settings.WelcomeMessage, sender.Nick)); } } else { if(splitCommand[1].Contains("{") && splitCommand[1].Contains("}")) { string[] tester = splitCommand[1].Split(new char[] { '{', '}' }, 3); foreach(string x in tester) { int xf = -1; bool parsed = false; try { xf = int.Parse(x.ToString()); parsed = true; } catch{parsed = false;} if (parsed) { if (xf > 0 || xf < 0) { client.SendRawMessage("PRIVMSG {0} :ERROR: Index numbers can't be bigger than 0 or less than 0. MUST BE 0!", client.Channels[0].Name); return; } } } } ProgramSettings.settings.WelcomeMessage = splitCommand [1]; client.SendRawMessage ("PRIVMSG {0} :Welcome message set!", client.Channels [0].Name); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("New welcome message set: " + splitCommand [1]); Console.ForegroundColor = ConsoleColor.White; } } } } else { client.SendRawMessage ("PRIVMSG {0} :What message do I set?", client.Channels[0].Name); } } if (command.StartsWith ("enableslap")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ProgramSettings.settings.SlapEnabled = true; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Enabling slap"); Console.ForegroundColor = ConsoleColor.White; break; } } } if (command.StartsWith ("enablewelcome")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ProgramSettings.settings.WelcomeUserEnabled = true; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Enabling welcome messages"); Console.ForegroundColor = ConsoleColor.White; break; } } } if (command.StartsWith ("disablewelcome")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ProgramSettings.settings.WelcomeUserEnabled = false; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Disabling welcome messages"); Console.ForegroundColor = ConsoleColor.White; break; } } } if (command.StartsWith ("disableslap")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ProgramSettings.settings.SlapEnabled = false; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Disabling slap"); Console.ForegroundColor = ConsoleColor.White; break; } } } if (command.StartsWith ("eightball") || command.StartsWith ("8ball") || command.StartsWith ("fortune")) { if (ProgramSettings.settings.EightballEnabled) { int ranMessage = random.Next (EightballMessages.Length - 1); if (command.ToLower ().Contains ("waluigibot1337") || command.ToLower ().Contains ("waluigibot") || command.ToLower ().Contains ("waluigi bot")) client.SendRawMessage ("PRIVMSG {0} :Waluigibot is a tool and will never come to fruition.", client.Channels [0].Name); else if (command.ToLower ().Contains ("bot") && !command.ToLower ().Contains ("luigi")) client.SendRawMessage ("PRIVMSG {0} :Your bot is inadequate for the job.", client.Channels [0].Name); else client.SendRawMessage ("PRIVMSG {0} :{1}", client.Channels [0].Name, EightballMessages [ranMessage]); } } if (command.StartsWith ("status")) { client.SendRawMessage ("PRIVMSG {0} :Slap Enabled: {1}. Eight Ball Enabled: {2}. Welcome Enabled: {3}. Command Prefix: {4}. URL Parsing: {5}", client.Channels [0].Name, ProgramSettings.settings.SlapEnabled, ProgramSettings.settings.EightballEnabled, ProgramSettings.settings.WelcomeUserEnabled, ProgramSettings.settings.CommandPrefix.ToString(), ProgramSettings.settings.UrlParsingEnabled); } if (command.StartsWith ("lastfm")) { #if __MONOCS__ client.SendRawMessage("PRIVMSG {0} :The Last.FM API we use isn't available on Mono.", client.Channels[0].Name); #elif __MSCS__ string[] split = command.Split (new char[] { ' ' }, 2); if (split.Length > 1) { client.SendRawMessage("PRIVMSG {0} :Sending LastFM request, this may take a few seconds..", client.Channels[0].Name); try { var lastfmClient = new LastfmClient ("4de0532fe30150ee7a553e160fbbe0e0", "0686c5e41f20d2dc80b64958f2df0f0c"); var response = lastfmClient.User.GetRecentScrobbles (split [1].ToString ().Trim (), null, 0, 1); LastTrack lastTrack = response.Result.Content [0]; client.SendRawMessage ("PRIVMSG {0} :{1} last listened to {2} by {3}.", client.Channels [0].Name, split [1].Trim (), lastTrack.Name, lastTrack.ArtistName); } catch (ArgumentOutOfRangeException iex) { client.SendRawMessage ("PRIVMSG {0} :That user doesn't exist or hasn't scrobbled anything yet!", client.Channels [0].Name); } catch (Exception ex) { client.SendRawMessage ("PRIVMSG {0} :Uh-oh! Luigibot encountered an error. Email Luigifan @ [email protected]", client.Channels [0].Name); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine ("UH OH BIG ERROR\nUH OH BIG ERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine (ex.Message + "\n"); } } #endif } if (command.StartsWith ("enable8ball") || command.StartsWith ("enableeightball")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ProgramSettings.settings.EightballEnabled = true; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Enabling eight ball"); Console.ForegroundColor = ConsoleColor.White; break; } } } if (command.StartsWith ("disable8ball") || command.StartsWith ("disableeightball")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ProgramSettings.settings.EightballEnabled = false; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("Disabling eight ball"); Console.ForegroundColor = ConsoleColor.White; break; } } } if (command.StartsWith ("selfdestruct")) { foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable) { if (sender.Nick.ToLower () == nick) { ExitSafely (); break; } } } if (command.StartsWith ("42")) { client.SendRawMessage ("PRIVMSG {0} :The Answer to Life, the Universe, and Everything.", client.Channels [0].Name); } if (command.StartsWith ("commands")) { client.SendRawMessage ("PRIVMSG {0} :You can find a list of my commands here: https://github.com/Luigifan/Luigibot/wiki/Luigibot-Commands", client.Channels [0].Name); } if (command.StartsWith ("seen")) { string[] splitCommand = command.Split (new char[] { ' ' }, 2); if (splitCommand.Length > 1) { if (splitCommand [1].ToLower () == "knux" || splitCommand [1].ToLower () == "knuckles" || splitCommand [1].ToLower () == "knuckles96") { client.SendRawMessage ("PRIVMSG {0} :Never.", client.Channels [0].Name); return; } var UsersListCopy = UsersList; var UserDatabaseCopy = UsersSeenDatabase.UsersSeenDatabase; //First, check to see if the user is on now bool foundInOnline = false; foreach (IrcUserAndSeen user in UsersListCopy) { if (user.User.Nick.ToLower () == splitCommand [1].ToLower ().Trim ()) { foundInOnline = true; if (user.User.Nick == client.User.Nick) client.SendRawMessage ("PRIVMSG {0} :I'm always online c:", client.Channels [0].Name); else client.SendRawMessage ("PRIVMSG {0} :That user is online now!", client.Channels [0].Name); foundInOnline = true; break; } } //Then, we'll check the database bool foundInDatabase = false; List<IrcUserAndSeen> removeLater = new List<IrcUserAndSeen>(); if (!foundInOnline) { foreach (IrcUserAndSeen user in UserDatabaseCopy) { if (user.User.Nick == null) { Console.WriteLine("Adding null entry to be removed later"); removeLater.Add(user); } else { if (user.User.Nick.ToLower() == splitCommand[1].ToLower().Trim()) { foundInDatabase = true; client.SendRawMessage("PRIVMSG {0} :{1} was last seen at {2} (EST)", client.Channels[0].Name, user.User.Nick, user.LastSeen.ToString()); break; } } } if (!foundInDatabase && !foundInOnline) client.SendRawMessage ("PRIVMSG {0} :I'm not sure :(", client.Channels [0].Name); } } else client.SendRawMessage ("PRIVMSG {0} :Last seen who?", client.Channels [0].Name); } }
/// <summary> /// Constructs an IRC user given a nick, user, and password. /// </summary> public IrcUser(IrcClient client, string nick, string user, string password) : this(client, nick, user) { Password = password; }
/// <summary> /// Constructs an IRC user given a nick, user, password, and real name. /// </summary> public IrcUser(IrcClient client, string nick, string user, string password, string realName) : this(client, nick, user, password) { RealName = realName; }
private static void RunBotTest() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine ("Connecting..."); Console.ForegroundColor = ConsoleColor.White; client = new IrcClient (ProgramSettings.settings.LastJoinedServer, new IrcUser (ProgramSettings.settings.LastUsedNick, "luigibot-oss")); client.ConnectionComplete += (s, e) => { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine ("Connected! Joining {0}..", ProgramSettings.settings.LastJoinedChannel); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Green; client.JoinChannel (ProgramSettings.settings.LastJoinedChannel); Console.WriteLine ("Connected!"); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Attempting NickServ authentication.."); Console.ForegroundColor = ConsoleColor.White; if (ProgramSettings.settings.NickServPass.Trim() != "") { client.SendRawMessage("PRIVMSG NickServ :IDENTIFY {0}", encrypter.DecryptString(ProgramSettings.settings.NickServPass)); } else Console.WriteLine("No NickServ password set! Set using /setnickservpass`"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine ("Loading database.."); Console.ForegroundColor = ConsoleColor.White; UsersSeenDatabase.LoadDatabase (client); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine ("Success!"); Console.ForegroundColor = ConsoleColor.White; updateUsersListThread.Start (); }; client.UserPartedChannel += (s, e) => { DateTime now = DateTime.Now; foreach (IrcUserAndSeen u in UsersSeenDatabase.UsersSeenDatabase) { if (u.User.Nick.ToLower() == e.User.Nick.ToLower()) { UsersSeenDatabase.UsersSeenDatabase.Remove (u); break; } } UsersSeenDatabase.UsersSeenDatabase.Add (new IrcUserAndSeen (e.User, now)); //Console.Beep(4400, 1000); Console.WriteLine ("Added new user to database {0} left at {1}", e.User.Nick, now.ToString ()); }; client.UserJoinedChannel += (s, e) => { if (e.User.Nick.ToLower () == "axiom") { client.SendAction ("welcomes daddy!", client.Channels [0].Name); return; } if (ProgramSettings.settings.WelcomeUserEnabled) { if (e.User.Nick != client.User.Nick) { if (ProgramSettings.settings.WelcomeMessage.Contains("/me")) { //set substring 4 to account for "/me" and the space after client.SendAction(String.Format(ProgramSettings.settings.WelcomeMessage.Substring(4), e.User.Nick), client.Channels[0].Name); } else { client.SendRawMessage("PRIVMSG {0} :{1}", client.Channels[0].Name, String.Format(ProgramSettings.settings.WelcomeMessage, e.User.Nick)); } } } }; client.NoticeRecieved += (s, e) => { Console.WriteLine ("NOTICE FROM {0}: {1}", e.Source, e.Notice.ToString ()); }; bool checkForNextHighfive = false; string firstuser = ""; client.ChannelMessageRecieved += (s, e) => { if (checkForNextHighfive) { if (e.PrivateMessage.Message.Trim() == "\\o") { if(e.PrivateMessage.User.Nick != firstuser) client.SendRawMessage("PRIVMSG {0} :{1} o/ *HIGHFIVED* \\o {2}!", client.Channels[0].Name, firstuser, e.PrivateMessage.User.Nick); } checkForNextHighfive = false; } var channel = client.Channels [e.PrivateMessage.Source]; Console.WriteLine ("{0} - {1}: {2}", e.PrivateMessage.Source, e.PrivateMessage.User, e.PrivateMessage.Message); //just output the stuff boss if (e.PrivateMessage.Message.StartsWith(ProgramSettings.settings.CommandPrefix.ToString())) { InterpretCommand(e.PrivateMessage.Message, e.PrivateMessage.User, client); } else if(e.PrivateMessage.Message.Contains("http://") || e.PrivateMessage.Message.Contains("https://")) { if(ProgramSettings.settings.UrlParsingEnabled) UrlSubmitted(e); } else if (e.PrivateMessage.Message.StartsWith(client.User.Nick)) { if (e.PrivateMessage.Message.Contains("help")) { client.SendRawMessage("PRIVMSG {0} :The current command prefix is: '{1}'. You can also find a list of my commands here: https://github.com/Luigifan/Luigibot/wiki/Luigibot-Commands", client.Channels[0].Name, ProgramSettings.settings.CommandPrefix); } } else if (e.PrivateMessage.Message.Trim() == "o/") { checkForNextHighfive = true; firstuser = e.PrivateMessage.User.Nick; } }; client.ModeChanged += (s, e) => { if (e.User.Nick == client.User.Nick) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Mode changed, added: " + e.Change); //string[] split = e.Change.Split(new char[] { ' ' }, 2); //client.User.Mode += split[0].Trim('+'); Console.WriteLine("New mode: " + client.User.Mode); Console.ForegroundColor = ConsoleColor.White; } }; client.RawMessageRecieved += (s, e) => { //:[email protected] QUIT :Client Quit string rawMessage = e.Message.ToString (); string[] split = rawMessage.Split (new char[] { ' ' }, 3); if (split.Length > 0) { if (split [1] == "QUIT") { string[] username = split [0].Split (new char[] { '!' }, 2); IrcUser ee = new IrcUser (username [0].ToString ().Trim (':'), username [1].ToString ().Trim ('~')); DateTime now = DateTime.Now; foreach (IrcUserAndSeen u in UsersSeenDatabase.UsersSeenDatabase) { if (u.User.Nick.ToLower() == ee.Nick.ToLower()) { UsersSeenDatabase.UsersSeenDatabase.Remove (u); break; } } UsersSeenDatabase.UsersSeenDatabase.Add (new IrcUserAndSeen (ee, now)); Console.WriteLine ("Added new user to database {0} left at {1} (Quit)", ee.Nick, now.ToString ()); } } }; client.ConnectAsync (); while (true) ; //just keeps everything going }