private static IrcClient Connect(HandleIRCMessage pReponses = null, string pChannel = "#theonlysykan") { var username = File.ReadAllText("Username.USER"); var password = File.ReadAllText("SecretTokenDontLOOK.TOKEN"); if (!password.ToLower().Contains("oauth:")) { password = "******" + password; } var client = new IrcClient("irc.chat.twitch.tv:6667", new IrcUser(username, username, password)); client.ConnectionComplete += (s, e) => { client.JoinChannel(pChannel); }; client.ChannelMessageRecieved += (s, e) => { //[email protected] var anotherUsername = e.IrcMessage.Prefix.Split('!')[0]; var messageInfo = new IRCMessage() { userName = anotherUsername, message = e.IrcMessage.Parameters[1], channel = e.IrcMessage.Parameters[0] }; pReponses?.Invoke(messageInfo); }; client.ConnectAsync(); return(client); }
private static void Main() { if (!Config.Init()) { Environment.Exit(1); } Console.Title = $"{Config.IRC_BotName} on {Config.IRC_Server} in channel {Config.IRC_ChannelName}."; ColoredWrite(ConsoleColor.Green, "*** Initialising " + Console.Title); SemiColoredWrite(ConsoleColor.Yellow, "[IRC] ", "Initialising IRC client."); client = new IrcClient(Config.IRC_Server, new IrcUser(Config.IRC_BotName, Config.IRC_BotName, Config.IRC_Password), Config.IRC_SSL); client.ConnectAsync(); SemiColoredWrite(ConsoleColor.Yellow, "[IRC] ", "Connected to IRC server."); SetupIRCClient(); do { Thread.Sleep(100); } while (!MenuEnabled); Start(); }
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(); }
public Connection(string configLocation) { CommandLibrary = new Library(SendMessage, JoinChannel, PartChannel, ChangeChannelPreferences, StupidQuit); SetPreferenceExplanations(); ConfigLocation = configLocation; config = LoadConfig(ConfigLocation); client = new IrcClient(string.Format("{0}:{1}", config.Server, config.port.ToString()), new IrcUser(config.nick, config.userName, config.password, config.realName), useSSL: config.ssl); client.IgnoreInvalidSSL = config.ignoreInvalidSSL; client.Settings.GenerateRandomNickIfRefused = true; // Might want to move this to the config EventWaitHandle wait = new EventWaitHandle(false, EventResetMode.AutoReset); if (config.debug) { client.NetworkError += (s, e) => Console.WriteLine("Error: " + e.SocketError); client.RawMessageSent += (s, e) => Console.WriteLine(">> {0}", e.Message); } client.RawMessageRecieved += Client_RawMessageRecieved; client.ConnectionComplete += client_ConnectionComplete; client.PrivateMessageRecieved += Client_PrivateMessageRecieved; // client.ChannelListRecieved += Client_ChannelListRecieved; client.ConnectAsync(); client.UserKicked += Client_UserKicked; wait.WaitOne(); }
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(); }
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"; }
public NetworkManager(Configuration.NetworkConfiguration config) { Configuration = config; Modules = new List <Module>(); Client = new IrcClient(config.Address, new IrcUser(config.Nick, config.User, config.Password, config.RealName)); Client.RawMessageRecieved += (sender, e) => Console.WriteLine("<< {0}", e.Message); Client.RawMessageSent += (sender, e) => Console.WriteLine(">> {0}", e.Message); Client.ConnectionComplete += HandleConnectionComplete; Client.NetworkError += (sender, e) => Console.WriteLine("Network error {0}", e.SocketError); Client.Settings.WhoIsOnJoin = true; Client.ConnectAsync(); }
public async Task SendsNickAndUserWhenConnected() { var nick = "guest"; var realName = "Ronnie Reagan"; var user = new User(nick, realName); var client = new IrcClient(user, mockConnection.Object); await Task.Run(() => client.ConnectAsync("localhost", 6667)); mockConnection.Verify(c => c.SendAsync($"NICK {nick}"), Times.Once()); mockConnection.Verify(c => c.SendAsync($"USER {nick} 0 - :{realName}"), Times.Once()); }
public static void InitIRC() { Console.WriteLine("Initializing IRC..."); const string token = "-twitch oauth2 token-"; var client = new IrcClient("irc.chat.twitch.tv", new IrcUser("-your twitch name-", "-your twitch name-", "oauth:" + token)); client.ConnectionComplete += (s, e) => { Console.WriteLine("Connected!"); client.SendRawMessage("CAP REQ :twitch.tv/membership"); Thread.Sleep(1000); client.JoinChannel("#-your twitch username-"); }; client.RawMessageRecieved += (s, e) => { Console.WriteLine(e.Message); }; client.UserJoinedChannel += (s, e) => { Console.WriteLine(e.User); }; client.PrivateMessageRecieved += (s, e) => { string arg = e.PrivateMessage.Message.ToLower(); switch (arg) { case "spin": Console.WriteLine("Space was pressed"); SendKeystroke(Keys.Space); break; case "bet1": Console.WriteLine("Bet amount changed to 1"); SendKeystroke(Keys.D1); break; case "bet3": Console.WriteLine("Bet amount changed to 3"); SendKeystroke(Keys.D2); break; case "bet5": Console.WriteLine("Bet amount changed to 5"); SendKeystroke(Keys.D3); break; } }; client.ConnectAsync(); }
public void ConnectAsync() { if (isRunning) { return; } isRunning = true; client.ConnectAsync(); while (isRunning) { Thread.Sleep(100); } }
public void Connect() { var client = new IrcClient(Instance.Config.ServerHostname, new IrcUser(Instance.Config.BotNick, Instance.Config.BotNick)); client.ConnectAsync(); Client = client; _listener = new EventListener(); _listener.Listen(); WatchForPlugins(); }
public IrcListener(Configuration.ServerConfiguration configServer) { Config = configServer; IrcSelf = Config.IrcSelf = new IrcUser(null, Config.NickName, Config.UserName, Config.serverPassword, Config.RealName); IrcClient = Config.IrcClient = new IrcClient($"{Config.server}:{Config.port}", IrcSelf, Config.SSL); IrcClient.IgnoreInvalidSSL = Config.IgnoreInvalidSSL; IrcClient.RawMessageRecieved += OnRawMessageRecieved; IrcClient.RawMessageSent += OnRawMessageSent; IrcClient.ConnectionComplete += OnConnect; IrcClient.UserJoinedChannel += OnUserJoinedChannel; IrcClient.PrivateMessageRecieved += OnPrivateMessageRecieved; //ircClient.ChannelMessageRecieved += onChannelMessageRecieved; IrcClient.Error += OnError; IrcClient.ConnectAsync(); }
public void Start() { if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Roomname)) { Debug.LogWarning("IRC client requires configuration!", this); } EventManager = new EventManager(); Debug.Log("[IRC] Starting..."); Client = new IrcClient("chat.eu.freenode.net", new IrcUser(Username, Username, Password)); Client.ConnectionComplete += Client_ConnectionComplete; Client.ChannelMessageRecieved += Client_ChannelMessageRecieved; Debug.Log("[IRC] Connecting..."); Client.ConnectAsync(); }
public bool Connect(string ip, string channel) { Logger.Verbose(nickname); if (state != IRCLinkState.Ready) { return(false); } client = new IrcClient(ip, new IrcUser(nickname, "HacknetLink")); client.ConnectionComplete += (s, e) => client.JoinChannel(channel); client.UserJoinedChannel += (s, e) => { os.write("User " + e.User.Nick + " has joined the channel."); }; client.UserPartedChannel += (s, e) => { os.write("User " + e.User.Nick + " has left the channel."); }; client.NetworkError += (s, e) => { if (state != IRCLinkState.Ready) { os.write("Connection error. Check your internet connection and the server details."); } }; client.ChannelMessageRecieved += (s, e) => { string SenderNick = Regex.Split(e.PrivateMessage.User.Nick, "!")[0]; string message = e.PrivateMessage.Message; os.write(SenderNick + ": " + message); }; state = IRCLinkState.Connected; ConnectServer = ip; ConnectedChannel = channel; client.ConnectAsync(); return(true); }
/// <summary> /// Overwritten Init method. /// This method connects to the M59 server. /// So we connect to IRC here as well. /// </summary> public override void Init() { // base handler connecting to m59 server base.Init(); // create IRC command queues ChatCommandQueue = new LockingQueue <string>(); AdminCommandQueue = new LockingQueue <string>(); IRCSendQueue = new IRCQueryQueue(); WhoXQueryQueue = new WhoXQueryQueue(); // Whether bot echoes to IRC or not. DisplayMessages = true; // Create list for keeping track of user registration. UserRegistration = new Dictionary <string, bool>(); // Init list of recent admins to send a command. RecentAdmins = new List <string>(); // create an IRC client instance, with connection info IrcClient = new IrcClient(Config.IRCServer, new IrcUser(Config.NickName, Config.NickName, Config.IRCPassword, Config.NickName)); // TODO: does ChatSharp use something like this? //IrcClient.FloodPreventer = new FloodPreventer(Config.MaxBurst, Config.Refill); // hook up IRC client event handlers // beware! these are executed by the internal workthread // of the library. IrcClient.ConnectionComplete += OnIrcClientConnected; // ChatSharp doesn't have fine-grained error handling // to my knowledge, likely we have to disconnect on any // network error. IrcClient.NetworkError += OnIrcClientDisconnected; IrcClient.WhoxReceived += OnWhoXReplyReceived; // log IRC connecting Log("SYS", "Connecting IRC to " + Config.IRCServer + ":" + Config.IRCPort); // connect the lib internally (this is async) IrcClient.ConnectAsync(); }
public void entry2(MultiSinkLogger log) { log.sinks.Add(new IrcLogger(logToIrc)); // from irc in #nars // oh big number zealand or math in the united states and canada . nickname : BNZ or BNZea string nick = "BNZea"; string user = nick; client = new IrcClient("irc.freenode.net", new IrcUser(nick, user)); client.ConnectionComplete += (s, e) => client.JoinChannel(channelToJoin); client.ChannelMessageRecieved += (s, e) => { var channel = client.Channels[e.PrivateMessage.Source]; if (e.PrivateMessage.Message == ".list") { channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick))); } string message = e.PrivateMessage.Message; client.SendMessage("ECHO", channelToJoin); }; bool isConnected = false; client.ConnectAsync(); client.ConnectionComplete += (s, e) => { isConnected = true; }; // wait till connected for (;;) { if (isConnected) { break; } } }
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) { ; } }
void BotLoop() { var client = new IrcClient("irc.freenode.net", new IrcUser("ChatSharp", "ChatSharp" + new Random().Next(0, 1000))); client.ConnectionComplete += (s, e) => { Console.Write("test"); client.JoinChannel("##an0nymC"); richTextBox.Dispatcher.Invoke( new UpdateTextCallback(this.UpdateText), new object[] { client.Users.Count().ToString(), "good" } ); }; client.ChannelMessageRecieved += (s, e) => { var channel = client.Channels[e.PrivateMessage.Source]; Console.Write(channel.Users.Count()); if (e.PrivateMessage.Message == ".list") { channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick))); } else if (e.PrivateMessage.Message.StartsWith(".ban ")) { if (!channel.UsersByMode['@'].Contains(client.User)) { channel.SendMessage("I'm not an op here!"); return; } var target = e.PrivateMessage.Message.Substring(5); client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname)); } }; client.ConnectAsync(); while (true) { GetUpdates(); Thread.Sleep(1000); } }
public static void Connect(IrcClient client) { DEBUG.SHOW("Connect start."); //:NickServ!NickServ@snoonet/services/NickServ NOTICE SoonTM :Password accepted - you are now recognized. client.ConnectionComplete += (s, e) => { client.NoticeRecieved += (t, f) => { DEBUG.SHOW(f.Message.RawMessage); if (f.Message.RawMessage.Contains("Password accepted")) { client.JoinChannel("##eldorito");//Settings.IRC_Chan); } }; }; client.ConnectAsync(); DEBUG.SHOW("Connect end."); }
public static void Initialize(ChatHandler chatHandler) { _chatHandler = chatHandler; _random = new System.Random(DateTime.Now.Millisecond); string username = String.Empty; // Plugin.Instance.Config.TwitchUsername; string oauthToken = String.Empty; // Plugin.Instance.Config.TwitchoAuthToken; if (username == String.Empty) { username = $"justinfan{_random.Next(0, int.MaxValue).ToString()}"; Plugin.Log($"Using username {username}"); } // Create a connection to our twitch chat and setup event listeners client = new IrcClient("irc.chat.twitch.tv", new IrcUser(username, username, oauthToken)); client.ConnectionComplete += Client_ConnectionComplete; client.RawMessageRecieved += Client_RawMessageRecieved; client.UserJoinedChannel += Client_UserJoinedChannel; client.ConnectAsync(); }
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..."); }
public void ConnectAsync_Always_RaisesNoError() { _ircClient = TestHelper.GetTestIrcClient(); using (var manualResetEvent = new ManualResetEventSlim(false)) { bool errorOccured = false; _ircClient.Connected += (sender, e) => manualResetEvent.Set(); _ircClient.Error += (sender, e) => { errorOccured = true; manualResetEvent.Set(); }; var t = _ircClient.ConnectAsync(); Assert.IsTrue(manualResetEvent.Wait(30000)); Assert.IsFalse(errorOccured); } }
protected override async Task StartAsyncInternal() { if (this.Config.Irc.Servers == null) { throw new InvalidConfigException("Irc server list is missing."); } if (this.Config.Irc.Servers.Any(s => s.Channels.Any(c => !c.StartsWith("#")))) { throw new InvalidConfigException("Invalid channel specified; all channels should start with #."); } foreach (IrcServer server in this.Config.Irc.Servers.Where(s => s.Enabled)) { this.serverData.Add(server.Host, new ServerData()); var ircClient = new IrcClient(server.Host, server.Nick ?? this.Config.Name, server.Host, server.Port, /* useSsl -- pending support */ false, server.Password); this.ircClients.Add(server.Host, ircClient); ircClient.OnIrcEvent += this.OnIrcEventAsync; await ircClient.ConnectAsync(); } }
public static async Task Main() { var ircClient = new IrcClient("irc.freenode.net", 6667, new IrcRegistrationInfo("imnotabot"), new IrcBasicAntiFlood(500)); ircClient.Connected += async(sender, e) => { Console.WriteLine(string.Format("Connected to the IRC server. ({0})", ircClient.Host)); await ircClient.JoinChannelAsync("channelname"); }; ircClient.ChannelJoined += async(sender, e) => { // The client joined a channel. if (e.User.IsClientUser()) { Console.WriteLine(string.Format("Joined channel: #{0}", e.Channel.Name)); } else { Console.WriteLine(string.Format("{0} joined #{1}", e.User.NickName, e.Channel.Name)); } }; ircClient.ChannelMessageReceived += async(sender, e) => { if (e.SourceType == IrcSourceType.User) { IrcUser user = ((IrcUser)e.Source); Console.WriteLine(string.Format("[{0}] {1}: {2}", e.Channel.Name, user.NickName, e.Message)); if (e.Message.ToLower() == "!whisperme") { await user.SendMessageAsync(string.Format("Hi {0}!", user.NickName)); } else { await e.Channel.SendMessageAsync(string.Format("Hi {0}!", user.NickName)); } } else if (e.SourceType == IrcSourceType.Server) { Console.WriteLine(string.Format("[{0}] SERVER ({1}): {2}", e.Channel.Name, ((IrcServer)e.Source).HostName, e.Message)); } }; ircClient.Disconnected += (sender, e) => { Console.WriteLine("Disconnected from IRC."); }; ircClient.Error += (sender, e) => { Console.WriteLine(e.Error); }; await ircClient.ConnectAsync(); Console.ReadKey(); await ircClient.DisconnectAsync(); }
static void Main(string[] args) { { Console.Title = "Tim's IRC Bot"; if (!File.Exists(Path.Combine(combine, "TimsBot/settings.ini"))) { Console.Title = "Tim's IRC Bot Setup"; Console.WriteLine("Welcome to Tims IRC bot, press enter to continue"); Console.ReadLine(); Console.Clear(); Console.WriteLine("Which server do you want the bot to join?"); string Server = Console.ReadLine(); Console.Clear(); Console.WriteLine("Which channel do you want the bot to join?"); string Channel = Console.ReadLine(); Console.Clear(); Console.WriteLine("Which nickname do you want to have?"); string Nickname = Console.ReadLine(); Console.Clear(); Console.WriteLine("Which username do you have?(NEEDED!)"); string username = Console.ReadLine(); Console.Clear(); Console.WriteLine("Which password do you have for the account?(NEEDED!)"); string password = Console.ReadLine(); Console.WriteLine("What is your username on the irc server? Then you have access to all the admin commands."); string Owner = Console.ReadLine(); Console.Clear(); CreateDir("TimsBot/"); CreateDir("TimsBot/data"); CreateDir("TimsBot/data/logs/"); CreateDir("TimsBot/data/systems/warnsystem/warning/"); CreateDir("TimsBot/data/systems/warnsystem/offtopic/"); CreateDir("TimsBot/data/access/"); CreateDir("TimsBot/data/access/commands/"); CreateDir("TimsBot/data/access/commands/owner/"); CreateDir("TimsBot/data/access/commands/users/"); WriteAllText("TimsBot/settings.ini", "Server=" + Server + Environment.NewLine + "Channel=" + Channel + Environment.NewLine + "Botname=" + Nickname + Environment.NewLine + "username="******"password="******"TimsBot/TimsBot.exe"))); WriteAllText("TimsBot/data/logs/log.txt", "This is the log File" + Environment.NewLine); WriteAllText("TimsBot/data/access/commands/owner/" + Owner, "Owner"); Console.Clear(); Console.WriteLine("You can open the ControlPanel by right clicking on the new system tray icon, when you run the program."); Console.ReadLine(); Console.WriteLine("Install successfull, you can open the program by going to the desktop and click on the shortcut or navigate to TimsBot/ and run TimsBot.exe."); Console.ReadLine(); Environment.Exit(0); } try { string readvalue = File.ReadAllText((Path.Combine(combine, "TimsBot/settings.ini"))); string modify1 = readvalue.Replace("Server=", "").Replace("Channel=", "").Replace("Botname=", "").Replace("username="******"").Replace("password="******""); string[] splitvalue = modify1.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Clear(); Console.Title = "Tim's IRC Bot is connecting"; Console.WriteLine("Connecting to the server."); var client = new IrcClient(splitvalue[0], new IrcUser(splitvalue[2], splitvalue[3], splitvalue[4])); client.ConnectionComplete += (s, e) => { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Connected to the server."); client.JoinChannel(splitvalue[1]); Console.Title = "Tim's IRC Bot is connected"; Console.WriteLine("Joining channel."); Console.ResetColor(); Console.Clear(); }; Console.ResetColor(); client.PrivateMessageRecieved += (s, f) => { if (f.PrivateMessage.Message == "!commands") { if (File.Exists(Path.Combine(combine, "TimsBot/data/access/commands/owner/" + f.PrivateMessage.Source))) { client.SendMessage("Owner Commands + syntax: !add_mod (nick), !say (channel/nick) (message) ,", f.PrivateMessage.Source); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("!commands requested by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("[OWNER]" + f.PrivateMessage.Source + Environment.NewLine); } else if (File.Exists(Path.Combine(combine, "TimsBot/data/access/commands/users/" + f.PrivateMessage.Source))) { client.SendMessage("Mod commands are the !commands commands.", f.PrivateMessage.Source); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("!commands requested by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("[MOD]" + f.PrivateMessage.Source + Environment.NewLine); } } if (f.PrivateMessage.Message.StartsWith("!add_mod ")) { if (File.Exists(Path.Combine(combine, "TimsBot/data/access/commands/owner/" + f.PrivateMessage.Source))) { File.Create((Path.Combine(combine, "TimsBot/data/access/commands/users/" + f.PrivateMessage.Message.Substring(9)))); } } }; client.ChannelMessageRecieved += (s, e) => { var channel = client.Channels[e.PrivateMessage.Source]; /*if (e.PrivateMessage.Message == "!list") * channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick)));*/ String[] Messageargs = e.PrivateMessage.Message.Split(' '); switch (Messageargs[0]) { case "!ban": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { var target = e.PrivateMessage.Message.Substring(5); client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname)); channel.Kick(e.PrivateMessage.Message.Substring(5)); client.SendMessage("You got banned from " + splitvalue[1], e.PrivateMessage.Message.Substring(5)); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write(e.PrivateMessage.Message.Substring(5) + " is banned in " + splitvalue[1] + " by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); channel.Kick(e.PrivateMessage.Message.Substring(5)); } break; case "!unban": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { var target = e.PrivateMessage.Message.Substring(7); client.WhoIs(target, whois => channel.ChangeMode("-b *!*@" + whois.User.Hostname)); Console.WriteLine(e.PrivateMessage.Message.Substring(7) + " " + "is unbanned"); client.SendMessage("You got unbanned from " + splitvalue[1], e.PrivateMessage.Message.Substring(7)); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write(e.PrivateMessage.Message.Substring(7) + " is unbanned in " + splitvalue[1] + " by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!leave": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { channel.Part(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("!leave requested by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!cycle": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { channel.Part(); client.JoinChannel(splitvalue[1]); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("!cycle requested by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!kick": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { channel.Kick(e.PrivateMessage.Message.Substring(6)); client.SendMessage("You got kicked from " + splitvalue[1], e.PrivateMessage.Message.Substring(6)); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write(e.PrivateMessage.Message.Substring(6) + " is kicked from " + splitvalue[1] + " by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!commands": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { channel.SendMessage(e.PrivateMessage.User.Nick + ", Commands: !ban, !unban, !kick, !join, !warn, !warn_offtopic, !op, !deop"); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("!commands requested by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!say": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { string[] splitvalue2 = e.PrivateMessage.Message.Split(' '); client.SendMessage(splitvalue2[1], splitvalue[1]); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("!say requested by "); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!join": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { client.JoinChannel(e.PrivateMessage.Message.Substring(5)); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Bot joined" + e.PrivateMessage.Message.Substring(5) + " by"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine); } break; case "!warn_offtopic": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { if (Directory.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15))) { if (File.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "4")) { var target = e.PrivateMessage.Message.Substring(15); client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname)); Console.WriteLine(e.PrivateMessage.Message.Substring(15) + " " + "is banned"); client.SendMessage("You got banned from " + splitvalue[1] + " because you keep going off topic", e.PrivateMessage.Message.Substring(15)); channel.Kick(e.PrivateMessage.Message.Substring(15)); } else { if (File.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "3")) { WriteAllText("TimsBot/data/systems/warnsystem/offtopic/" + e.PrivateMessage.Message.Substring(15) + "/" + "4", "Warning number 4"); channel.Kick(e.PrivateMessage.Message.Substring(15)); Console.WriteLine(e.PrivateMessage.Message.Substring(15) + " " + "is kicked"); client.SendMessage("You got kicked from " + splitvalue[1] + " because you keep going off topic", e.PrivateMessage.Message.Substring(6)); } else { if (File.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "2")) { WriteAllText("TimsBot/data/systems/warnsystem/offtopic/" + e.PrivateMessage.Message.Substring(15) + "/" + "3", "Warning number 3"); client.SendMessage("This is your last warning, please stop being off topic, you will be kicked if you go on in " + splitvalue[1], e.PrivateMessage.Message.Substring(15)); } else { WriteAllText("TimsBot/data/systems/warnsystem/offtopic/" + e.PrivateMessage.Message.Substring(15) + "/" + "2", "Warning number 2"); client.SendMessage("Please remember, this is a chat for chat with related topics in " + splitvalue[1], e.PrivateMessage.Message.Substring(15)); } } } } else { CreateDir("TimsBot/data/systems/warnsystem/offtopic/" + e.PrivateMessage.Message.Substring(15)); client.SendMessage("Please try and stay on topic in " + splitvalue[1], e.PrivateMessage.Message.Substring(15)); } } else { } break; case "!warn": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { if (Directory.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6))) { if (File.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "4")) { var target = e.PrivateMessage.Message.Substring(6); client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname)); Console.WriteLine(e.PrivateMessage.Message.Substring(6) + " " + "is banned"); client.SendMessage("You got banned from " + splitvalue[1] + " because you have 5 warnings", e.PrivateMessage.Message.Substring(6)); channel.Kick(e.PrivateMessage.Message.Substring(6)); } else { if (File.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "3")) { WriteAllText("TimsBot/data/systems/warnsystem/warning/" + e.PrivateMessage.Message.Substring(6) + "/" + "4", "Warning number 4"); channel.Kick(e.PrivateMessage.Message.Substring(6)); Console.WriteLine(e.PrivateMessage.Message.Substring(6) + " " + "is kicked"); client.SendMessage("You got kicked from " + splitvalue[1] + " because you have 4 warnings, if you get one more warning you will get banned.", e.PrivateMessage.Message.Substring(6)); } else { if (File.Exists((Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "2")) { WriteAllText("TimsBot/data/systems/warnsystem/warning/" + e.PrivateMessage.Message.Substring(6) + "/" + "3", "Warning number 3"); client.SendMessage("Please remember, this is your 3th warning in in " + splitvalue[1], e.PrivateMessage.Message.Substring(6)); } else { WriteAllText("TimsBot/data/systems/warnsystem/warning/" + e.PrivateMessage.Message.Substring(6) + "/" + "2", "Warning number 2"); client.SendMessage("Please remember, this is your second warning in " + splitvalue[1], e.PrivateMessage.Message.Substring(6)); } } } } else { CreateDir("TimsBot/data/systems/warnsystem/warning/" + e.PrivateMessage.Message.Substring(6)); client.SendMessage("Please remember, this is your first warning in " + splitvalue[1], e.PrivateMessage.Message.Substring(6)); } } break; case "!op": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { var target = e.PrivateMessage.User.Nick; client.WhoIs(target, whois => channel.ChangeMode("+o " + e.PrivateMessage.User.Nick)); } break; case "!deop": if (File.Exists((Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick)) { var target = e.PrivateMessage.User.Nick; client.WhoIs(target, whois => channel.ChangeMode("-o " + e.PrivateMessage.User.Nick)); } break; } }; client.ConnectAsync(); while (true) { ; } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] Error: '{0}'", e); Console.ReadLine(); } } }
/// <summary> /// Connect to the IRC server /// </summary> public async Task ConnectAsync() { await client.ConnectAsync(config.Server, config.Port); }
public void Connect(ConnectionOptions options) { if (Clients.Any(c => c.ServerAddress == options.Server)) { return; } IrcClient Client = new IrcClient(options.Server, new IrcUser(options.Nickname, options.Nickname), options.Ssl); if (options.ZncLogin) { Client.User = new IrcUser(options.Nickname, string.Format("{0}@bot/{1}", options.ZncUsername, options.ZncNetwork), options.ZncPassword); } Client.Options = options; Client.Delay = options.Delay; Client.IgnoreInvalidSSL = true; Client.SetHandler("INVITE", new IrcClient.MessageHandler((c, msg) => { if (msg.Prefix.StartsWith(options.Owner)) { c.JoinChannel(msg.Parameters[1]); } })); Client.SetHandler("KICK", new IrcClient.MessageHandler((c, msg) => { if (msg.Parameters[1] == options.Nickname) { c.PartChannel(msg.Parameters[0]); System.Threading.Thread.Sleep(10000); c.JoinChannel(msg.Parameters[0]); } })); Client.SetHandler("PONG", new IrcClient.MessageHandler((c, msg) => { Console.WriteLine("Received PONG from {0}", c.ServerAddress); c.LastPong = DateTime.Now; })); Client.ConnectionComplete += (s, e) => { Console.WriteLine("Connection complete on {0}", Client.ServerAddress); if (!Client.authed) { Client.authact(); } }; //Client.PrivateMessageRecieved += ChannelMessage; Client.ChannelMessageRecieved += ChannelMessage; Client.NoticeRecieved += Client_NoticeRecieved; Client.RawMessageRecieved += Client_RawMessageRecieved; Client.UserJoinedChannel += Client_UserJoinedChannel; Client.ModeChanged += Client_ModeChanged; Client.NickChanged += Client_NickChanged; Client.UserPartedChannel += Client_UserPartedChannel; Client.NetworkError += Client_NetworkError; //Client.AddHandler Client.authact = delegate { if (options.NickServ) { Client.SendMessage("identify " + options.NickServPassword, "NickServ"); } Client.authed = true; Client.Reconnecting = false; Task.Factory.StartNew(delegate { Thread.Sleep(10000); foreach (string str in options.Autojoin) { Client.JoinChannel(str); } }); }; Client.ConnectAsync(); Client.Owner = options.Owner; Clients.Add(Client); ConnectionGuard(Client); }
public IrcProvider() { client = new IrcClient(Config.IrcServer, new IrcUser("Consensusbot", "ConsensusBot")); client.ConnectAsync(); }
static async Task <int> Main(string[] args) //Don't question what this stands for, because it works and intellisense clearly knows what to suggest better than me. { //Initializing and/or resetting the messages so that we don't need to worry about leftover data, hopefully. Globals.discordMessage = new TransferMessage(); Globals.ircMessage = new TransferMessage(); #region Discord Login //Enables asynchronous functions & stuff await NBCD.StartAsync(); //Logs in asynchronously loginstate = NBCD.LoginState.ToString(); //Get loginstate as string if (loginstate == "LoggedOut") { await NBCD.LoginAsync(TokenType.Bot, TOKEN, true); //Check if logged out, if so then login } //Adds the command interface that I normally need but didn't use. await Commands.AddModulesAsync(Assembly.GetEntryAssembly(), null); #endregion #region IRC Login //Declares a new IRC Bot var NBCIRC = new IrcClient("irc.esper.net", new IrcUser("NomBot", "NomBot")); //Waits until it can connect, and then connects to #nom NBCIRC.ConnectionComplete += (s, e) => { NBCIRC.JoinChannel("#nom"); }; #endregion #region IRC Message Handling //Upon recieving a message, it breaks it down into local variables that are easier to work with. NBCIRC.ChannelMessageRecieved += (s, e) => { string message = e.PrivateMessage.Message.ToString(); string channel = NBCIRC.Channels[e.PrivateMessage.Source].Name.ToString(); string user = e.PrivateMessage.User.Nick.ToString(); string userRaw = e.PrivateMessage.User.ToString(); //Again; not using command interface, a pseudocommand for registering the bot before use. if (!hasOwner && message.Contains("~register")) { BoundChannel = NBCIRC.Channels[e.PrivateMessage.Source]; Console.WriteLine("This instance has no owner! Giving user " + userRaw + " owner priviledge by first use."); NBCIRC.Channels[e.PrivateMessage.Source].SendMessage(userRaw + " registered to instance owner!"); hasOwner = true; originalUser = userRaw; } //ircMessage() = "<" + channel + " | " + user + "> " + message; Globals.ircMessage = new TransferMessage(user, channel, "IRC", message, true, false); Console.WriteLine(Globals.ircMessage.getPrint()); //A rudimentary command not using command interface in order for the owner to manually request the bot to join new channels. //Requires console verification for safety. if (userRaw == originalUser && message.Contains("~join ")) { message = message.Remove(0, 5); NBCIRC.Channels[e.PrivateMessage.Source].SendMessage("Joining channel " + message + ". Please confirm in console."); Console.WriteLine("Join " + message + "? Y/N: "); string choice = ""; choice = Console.ReadLine(); if (choice == "Y") { NBCIRC.Channels[e.PrivateMessage.Source].SendMessage("Join confirmed. Joining channel " + message + "."); Console.WriteLine("Joining " + message + "."); NBCIRC.JoinChannel(message); } else { NBCIRC.Channels[e.PrivateMessage.Source].SendMessage("Join request denied."); } } //Relays messages from IRC to discord if they haven't been already and they weren't sent from the bot itself. if (hasOwnerDiscord && !Globals.ircMessage.inDiscord && hasOwner && Globals.ircMessage.user != "NomBot") { Globals.ircMessage.inDiscord = true; NBCD.GetGuild(Globals.defaultGuildiD).DefaultChannel.SendMessageAsync(Globals.ircMessage.getPrint().ToString(), false, null, null); } }; #endregion #region Discord Message Handling //Calls the async nonsense at the head of the program NBCD.MessageReceived += NBCD_MessageRecieved; #endregion //Makes sure the bot stays connected NBCIRC.ConnectAsync(); //Sets the bot's status for amusement await NBCD.SetGameAsync("NomBot Incorporated"); while (true) { ; } }
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) { ; } }