public void DoSeenPlugin(IrcConnection conn, IrcLine line) { // :[email protected] JOIN #channel // :Nick!~User@unaffiliated/Nick JOIN #channel // :Nick!~User@unaffiliated/Nick PART #channel // :Nick!~User@unaffiliated/Nick PART #channel :"screw you" // :[email protected] QUIT :Quit: Quit! // :[email protected] NICK :FourHalfWorms // :[email protected] PRIVMSG Lumbricus :!info Nick2 Channel channel = null; IrcCommand ircCommand = (IrcCommand)Enum.Parse(typeof(IrcCommand), line.IrcCommand); switch (ircCommand) { case IrcCommand.JOIN: case IrcCommand.PART: case IrcCommand.PRIVMSG: if (line.IrcCommandArgsRaw.StartsWith("#")) { channel = conn.GetChannel(line.IrcCommandArgsRaw); } goto case IrcCommand.NICK; case IrcCommand.NICK: case IrcCommand.NOTICE: case IrcCommand.QUIT: Nick nick = Nick.FetchOrCreate(line.Nick, conn.Server); if (nick == null) { throw new Exception(String.Format("Unable to fetch or create nick `{0}`", nick)); } Seen.Update(conn.Server, nick, nick.Account, channel); break; } }
void Handle354(IrcLine line) { if (line.AccountName == "0") { if (queue.ContainsKey(line.Nick)) { SendPrivmsg(line.Nick, "You must be identified with nickserv to use this command."); queue.Remove(line.Nick); } } else { Channel channel = Server.ConnectedChannels.FirstOrDefault(x => x.Name == line.IrcCommandArgsRaw); Nick ircNick = FetchIrcNick(line.Nick); if (ircNick == null) { if (queue.ContainsKey(line.Nick)) { queue.Remove(line.Nick); } throw new Exception(String.Format("Unable to fetch or create nick `{0}`", line.Nick)); } bool found = false; foreach (Channel c in Server.ConnectedChannels) { if (c.ConnectedNicks.Contains(ircNick) || ircNick.ConnectedChannels.Contains(c)) { found = true; break; } } if (!found) { List <string> channels = new List <string>(); foreach (Channel c in Server.ConnectedChannels) { channels.Add(c.Name); } if (queue.ContainsKey(line.Nick)) { queue.Remove(line.Nick); } logger.Info("Ignoring {0} because they're not in at least one of the following channels: {1}", line.Nick, string.Join(", ", channels)); return; } Account ircAccount = Account.FetchOrCreate(line.AccountName, Server); if (ircAccount == null) { if (queue.ContainsKey(line.Nick)) { queue.Remove(line.Nick); } throw new Exception(String.Format("Unable to fetch or create account `{0}`", line.AccountName)); } if (ircNick.Account == null) { ircNick.Account = ircAccount; ircNick.AccountId = ircAccount.Id; LumbricusContext.db.SaveChanges(); } else if (ircNick.Account.Id != ircAccount.Id && queue.ContainsKey(line.Nick)) { SendPrivmsg(line.Nick, "Sorry, but nick `{0}` is not registered to your services account. Please log in on that account and try again."); SendPrivmsg("TwoWholeWorms", String.Format("Services account `{0}` attempted to access features for nick `{1}` but that nick is registered to services account `{2}`.", ircAccount.Name, ircNick.Name, ircNick.Account.Name)); if (queue.ContainsKey(line.Nick)) { queue.Remove(line.Nick); } return; } Seen.Update(Server, ircNick, ircAccount, channel); if (queue.ContainsKey(line.Nick)) { if (CheckBans(ircNick, ircAccount, line.User, line.Host)) { if (queue.ContainsKey(line.Nick)) { queue.Remove(line.Nick); } return; } foreach (IrcLine queuedLine in queue.Single(x => x.Key == line.Nick).Value) { if (!string.IsNullOrWhiteSpace(queuedLine.Command)) { if (Commands.ContainsKey(queuedLine.Command)) { AbstractCommand command = Commands.Single(x => x.Key == queuedLine.Command).Value; if (command == null) { SendPrivmsg(queuedLine.Nick, String.Format("Sorry, {0}, but I'm unable to do that at this time. Poke TwoWholeWorms to fix me. :(", queuedLine.Nick)); logger.Error("Command `{0}` is registered with a null handler!", queuedLine.Command); } else { command.HandleCommand(queuedLine, ircNick, channel); } } else { SendPrivmsg(queuedLine.Nick, String.Format("Sorry, {0}, but that command does not exist. Try !help.", queuedLine.Nick)); } } // switch (command) { // case "setmugshot": // Command.HandleSetMugshot(ircNick, args, this); // break; // // case "clearmugshot": // Command.HandleClearMugshot(ircNick, args, this); // break; // // case "setinfo": // Command.HandleSetInfo(ircNick, args, this); // break; // // case "clearinfo": // Command.HandleClearInfo(ircNick, args, this); // break; // // case "seen": // Command.HandleSeen(ircNick, args, this, c); // break; // // case "help": // Command.HandleHelp(ircNick, args, this, c); // break; // // case "baninfo": // Command.HandleBanInfo(ircNick, args, this, c); // break; // // case "botban": // Command.HandleBotBan(ircNick, args, this, c); // break; // // case "searchlog": // Command.HandleSearchLog(ircNick, args, this, c); // break; // // case "restart": // Command.HandleUnwrittenAdminCommand(ircNick, args, this, c); // break; // if (channel != null && !channel.AllowCommandsInChannel && queuedLine.IrcCommandArgsRaw != Server.BotNick) { SendPrivmsg(line.Nick, "Also, please try to only interact with me directly through this window. Bot commands in the channel are against channel policy, and some people get really annoyed about it. :("); } } queue.Remove(line.Nick); } } }
void InsertOrUpdateUserAccountInfo(string account, string nick, string channel, string user, string host, string status) { Account ircAccount = null; if (account != "0") { ircAccount = Server.ServerAccounts.FirstOrDefault(x => x.Name == account); if (ircAccount == null) { ircAccount = Account.FetchOrCreate(account, Server); if (ircAccount == null) { throw new Exception(String.Format("Unable to fetch or create account `{0}`", account)); } } if (ircAccount != null) { Server.AddAccount(ircAccount); } } Nick ircNick = Server.ServerNicks.FirstOrDefault(x => x.Name == nick); if (ircNick == null) { ircNick = Nick.FetchOrCreate(nick, Server); if (ircNick == null) { throw new Exception(String.Format("Unable to fetch or create nick `{0}`", nick)); } ircNick.UserName = user; ircNick.Host = host; if (ircAccount != null && ircNick.Account == null) { logger.Debug("Setting AccountId for nick `" + ircNick.Name + "` to `" + ircAccount.Id + "`"); ircNick.Account = ircAccount; ircNick.AccountId = ircAccount.Id; LumbricusContext.db.SaveChanges(); } else { if (ircNick.Account.Id != ircAccount.Id) { throw new Exception(String.Format("Data error? Nick `{0}` is signed in as account `{1}` but linked to account `{2}`", ircNick.Name, ircAccount.Name, ircNick.Account.Name)); } } } if (ircNick != null) { Server.AddNick(ircNick); } Channel ircChannel = Server.ConnectedChannels.FirstOrDefault(x => x.Name == channel); if (ircChannel == null) { ircChannel = Channel.FetchOrCreate(channel, Server); if (ircChannel == null) { throw new Exception(String.Format("Unable to fetch or create channel `{0}`", channel)); } } if (ircChannel != null) { ircChannel.AddNick(ircNick); } Seen.Update(Server, ircNick, ircAccount, ircChannel); }