public void SendMessage(string destinationRoom, ChatMessage message) { string room = "#" + destinationRoom; try { string[] textLines = message.Text.Split('\n'); if (textLines.Length <= 1) { string messageText = $"{message.User}[{message.ServerId}]: {message.Text}"; client.SendRawMessage($"PRIVMSG {room} :{messageText}"); } else { // Handle multiline messages string hasteBinUrl = CreateHastebinFromText(message.Text); client.SendRawMessage( $"PRIVMSG {room} :{message.User}[{message.ServerId}]: {textLines[0]}"); client.SendRawMessage( $"PRIVMSG {room} :[Flood Prevention]: Multiline message from <{message.User}[{message.ServerId}]> truncated. Full message viewable here: {hasteBinUrl}"); } } catch (Exception ex) { Console.WriteLine($"{serverConfig.ServerId}|EXCEPTION: {ex}"); } }
static void Main(string[] args) { IrcRegistrationInfo info = new IrcUserRegistrationInfo() { NickName = "myBot", UserName = "******", RealName = "myBot" }; //Open IRC client connection irc.Connected += Irc_Connected; irc.RawMessageReceived += IrcClient_Receive; irc.MotdReceived += Irc_MotdReceived; irc.Connect("irc.SUPERSERVER.org", 6667, false, info); String cmd = ""; while (cmd != "/exit") { cmd = Console.ReadLine(); irc.SendRawMessage(cmd); } }
public void Send(string cmd) { if (cmd == null) { return; } if (irc != null && irc.IsConnected) { if (cmd.StartsWith("/list")) { var pos = cmd.IndexOf(" ", StringComparison.Ordinal); string channel = null; if (pos != -1) { channel = cmd.Substring(pos + 1); } var channelInfos = irc.Channels.Where(x => x.Name == channel).ToList(); Console.WriteLine("channel count: {0}", channelInfos.Count); foreach (var channelInfo in channelInfos) { Console.WriteLine("channel: {0} user count: {1} topic: {2}", channelInfo.Name, channelInfo.Users.Count, channelInfo.Topic); } } else { irc.SendRawMessage(cmd); } } }
public void SendChat(string codeString) { if (codeString.StartsWith("#/")) { HandleCommands(codeString); } else { myclient.SendRawMessage(codeString); } }
static bool HandlerRoutine(int CtrlType) { Console.WriteLine("Exiting..."); switch (CtrlType) { case 0: case 2: PingThread.Abort(); if (IRCClient != null) { IRCClient.SendRawMessage("QUIT"); IRCClient.Disconnect(); } Environment.Exit(0); break; } return(false); }
private void SendBtn_Click(object sender, EventArgs e) { string text = ChatInputTxb.Text; if (text != "") { if (text.Substring(0, 1) == "/") { client.SendRawMessage(text.Substring(1)); } else if (currentChannel != null) { List <string> targets = new List <string>() { currentChannel.Name }; client.SendPrivateMessage(targets, text); //ChannelTabCtb.LogChatLine("Me > " + text); } ChatInputTxb.Text = ""; } }
public bool Connect(BotType target) { switch (target) { case BotType.Osu: { IrcUserRegistrationInfo reg = new IrcUserRegistrationInfo() { NickName = m_credentials.OsuCredentials.Username, UserName = m_credentials.OsuCredentials.Username, RealName = m_credentials.OsuCredentials.Username, Password = m_credentials.OsuCredentials.Password, }; try { m_osuClient = new StandardIrcClient(); m_osuClient.Connected += (o, e) => { Console.WriteLine("Connected to irc.ppy.sh"); }; m_osuClient.ConnectFailed += (o, e) => { Console.WriteLine("Failed connecting to irc.ppy.sh"); }; Console.WriteLine("Connecting to irc.ppy.sh..."); m_osuClient.RawMessageReceived += m_osuClient_RawMessageReceived; m_osuClient.Disconnected += (o, e) => { m_osuClient.Disconnect(); Console.WriteLine("Got disconnected from irc.ppy.sh, reconnecting..."); m_osuClient.Connect("irc.ppy.sh", 6667, false, reg); }; m_osuClient.Connect("irc.ppy.sh", 6667, false, reg); m_osuClient.SendRawMessage($"PASS {m_credentials.OsuCredentials.Password}\r\n"); m_osuClient.SendRawMessage($"NICK {m_credentials.OsuCredentials.Username}\r\n"); return(true); } catch (Exception e) { Console.WriteLine($"Something happened while trying to connect to irc.ppy.sh, {e.Message}"); return(false); } } case BotType.Twitch: { { IrcUserRegistrationInfo reg = new IrcUserRegistrationInfo() { NickName = m_credentials.TwitchCredentials.Username, UserName = m_credentials.TwitchCredentials.Username, RealName = m_credentials.TwitchCredentials.Username, Password = m_credentials.TwitchCredentials.Password }; try { m_twitchClient = new TwitchIrcClient(); m_twitchClient.Connected += (o, e) => { Console.WriteLine("Connected to irc.twitch.tv"); }; m_twitchClient.ConnectFailed += (o, e) => { Console.WriteLine("Failed connecting to irc.twitch.tv"); }; Console.WriteLine("Connecting to irc.twitch.tv..."); m_twitchClient.RawMessageReceived += m_twitchClient_RawMessageReceived; m_twitchClient.Disconnected += (o, e) => { Console.WriteLine("Got disconnected from irc.twitch.tv, reconnecting..."); m_twitchClient.Connect("irc.twitch.tv", 6667, false, reg); }; m_twitchClient.Connect("irc.twitch.tv", 6667, false, reg); return(true); } catch (Exception e) { Console.WriteLine($"Something happened while trying to connect to irc.twitch.tv, {e.Message}"); return(false); } } } default: return(false); // wat } }
private async void ParseMessage(BotType target, IrcRawMessageEventArgs e) { switch (e.Message.Command) { // messages to ignore case "002": // twitch case "003": case "004": case "375": case "376": case "353": case "366": case "372": // osu! motd case "QUIT": break; case "PRIVMSG": #if DEBUG Console.WriteLine($"{target.ToString()}: {e.Message.Source.Name}: {e.Message.Parameters[1]}"); #endif if (target == BotType.Twitch) { string source = e.Message.Source.Name; string message = e.Message.Parameters[1]; string[] request = message.Split(' '); if (message.ToLowerInvariant().StartsWith("!request") || message.ToLowerInvariant().StartsWith("!req")) { if (!request[1].Contains("osu.ppy.sh/b/") && !request[1].Contains("osu.ppy.sh/s/")) { SendMessage(BotType.Twitch, $"@{source} that is an invalid beatmap."); return; } string[] map = await Globals.OsuApiHelper.GetBeatmap(request[1]); if (map[0] == "404") { SendMessage(BotType.Twitch, $"@{source} map not found."); } SendMessage(BotType.Osu, $"{source} requests {map[0]} to be played!"); SendMessage(BotType.Twitch, $"@{source} sent request for {map[1]} to be played"); } } break; case "PING": { switch (target) { case BotType.Osu: m_osuClient.SendRawMessage("PONG"); break; case BotType.Twitch: m_twitchClient.SendRawMessage("PONG"); break; } } break; case "JOIN": if (target == BotType.Twitch) { CommandLog(target, $"Joined channel #{m_twitchChat}"); } break; case "001": CommandLog(target, "Auth Success"); if (target == BotType.Twitch) { m_twitchClient.SendRawMessage($"JOIN #{m_twitchChat}\r\n"); } break; case "464": CommandLog(target, "Auth Fail"); break; default: #if DEBUG CommandLog(target, $"{e.Message.Source.Name}: {e.Message.Command} - {String.Join(", ", e.Message.Parameters)}"); #endif break; } }