Exemple #1
0
 private void HandleInvite(object sender, InviteChannelInfo inviteInfo)
 {
     if (Enabled &&
         !Bot.ServerConfig.NickBlacklist.Contains(inviteInfo.Requester.Nickname) &&
         !NickBlacklist.Contains(inviteInfo.Requester.Nickname))
     {
         if (!Bot.ServerConfig.ChannelBlacklist.Contains(inviteInfo.Channel) && !ChannelBlacklist.Contains(inviteInfo.Channel))
         {
             // Check to see if it's being spammed
             if (Bot.SpamCheck(Bot.IRC.Channels.Find(chan => chan.Name == inviteInfo.Channel), inviteInfo.Requester, this, new Command()
             {
                 Name = string.Format("{0} Commands", Name)
             }))
             {
                 Bot.IRC.Command.SendJoin(inviteInfo.Channel);
                 string helpMessage = string.Empty;
                 if (Bot.Modules.Exists(module => module.Commands.Exists(cmd => cmd.Triggers.Contains("help") && cmd.Enabled)))
                 {
                     helpMessage = string.Format("  For more information on what I can do, just type: {0}help", Bot.ServerConfig.CommandPrefix);
                 }
                 Bot.IRC.Command.SendPrivateMessage(inviteInfo.Channel, string.Format("{0} has invited me to this channel.  If you would like me to leave, just kick me.{1}", inviteInfo.Requester.Nickname, helpMessage));
             }
         }
         else
         {
             Bot.IRC.Command.SendNotice(inviteInfo.Requester.Nickname, "I am unable to join that channel.");
         }
     }
 }
Exemple #2
0
        public void HandleChannelMessage(object sender, ChannelMessage message)
        {
            Regex urlRegex = new Regex("(https?)://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?");

            if (Enabled &&
                !Bot.ServerConfig.ChannelBlacklist.Contains(message.Channel) &&
                !Bot.ServerConfig.NickBlacklist.Contains(message.Sender.Nickname) &&
                !ChannelBlacklist.Contains(message.Channel) &&
                !NickBlacklist.Contains(message.Sender.Nickname) &&
                !Bot.IsCommand(message.Message))
            {
                if (urlRegex.IsMatch(message.Message))
                {
                    // Check to see if it's being spammed
                    if (Bot.SpamCheck(Bot.IRC.Channels.Find(chan => chan.Name == message.Channel), message.Sender, this, new Command()
                    {
                        Name = string.Format("{0} Commands", Name)
                    }))
                    {
                        MatchCollection urlMatches = urlRegex.Matches(message.Message);
                        for (int i = 0; i < urlMatches.Count; i++)
                        {
                            DisplayTitle(message, urlMatches[i], true);
                        }
                    }
                }
            }
        }
Exemple #3
0
 private void LogNickChange(object sender, NickChangeInfo info)
 {
     if (!NickBlacklist.Contains(info.OldNick.Nickname) && !NickBlacklist.Contains(info.NewNick.Nickname))
     {
         AddNick(info.NewNick);
     }
     LogToFile(SERVERLOGNAME, info.TimeStamp, string.Format("{0} is now known as {1}", info.OldNick.Nickname, info.NewNick.Nickname));
 }
Exemple #4
0
 private void HandleChannelMessage(object sender, ChannelMessage message)
 {
     if (Enabled && !ChannelBlacklist.Contains(message.Channel) && !NickBlacklist.Contains(message.Sender.Nickname))
     {
         CheckFlood(message);
         CheckHighlight(message);
     }
 }
Exemple #5
0
 private void HandleJoinEvent(object sender, JoinChannelInfo info)
 {
     if (Enabled &&
         !Bot.ServerConfig.ChannelBlacklist.Contains(info.Channel) &&
         !Bot.ServerConfig.NickBlacklist.Contains(info.Nick.Nickname) &&
         !ChannelBlacklist.Contains(info.Channel) &&
         !NickBlacklist.Contains(info.Nick.Nickname))
     {
         ProcessAutoBan(info.Channel, info.Nick.Nickname, info.Nick.Host);
     }
 }
Exemple #6
0
 private void HandleChannelNoticeEvent(object sender, ChannelNotice info)
 {
     if (Enabled &&
         !Bot.ServerConfig.ChannelBlacklist.Contains(info.Channel) &&
         !Bot.ServerConfig.NickBlacklist.Contains(info.Sender.Nickname) &&
         !ChannelBlacklist.Contains(info.Channel) &&
         !NickBlacklist.Contains(info.Sender.Nickname))
     {
         ProcessAutoBan(info.Channel, info.Sender.Nickname, info.Sender.Host);
     }
 }
Exemple #7
0
 public void HandleCommandEvent(CommandMessage command)
 {
     try
     {
         // Check to make sure the command exists, the nick or channel isn't on a blacklist, and the module is loaded.
         if (Loaded &&
             Enabled &&
             !ChannelBlacklist.Contains(command.Location) &&
             !NickBlacklist.Contains(command.Nick.Nickname) &&
             Commands.Exists(c => c.Triggers.Contains(command.Command) &&
                             c.Enabled &&
                             !c.ChannelBlacklist.Contains(command.Location) &&
                             !c.NickBlacklist.Contains(command.Nick.Nickname)
                             )
             )
         {
             Bot.Log("Checking Command " + command.Command);
             // Figure out access of the nick
             Command           cmd             = Commands.Find(c => c.Triggers.Contains(command.Command));
             List <AccessType> nickAccessTypes = new List <AccessType>()
             {
                 AccessType.User
             };
             foreach (PrivilegeMode privilege in command.Nick.Privileges)
             {
                 nickAccessTypes.Add(Bot.PrivilegeModeMapping[privilege]);
             }
             if ((Bot.ServerConfig.Owners.Contains(command.Nick.Nickname) && command.Nick.Modes.Exists(mode => mode == UserMode.r || mode == UserMode.o)) || command.Nick.Nickname == Bot.IRC.Nickname)
             {
                 nickAccessTypes.Add(AccessType.Owner);
             }
             command.Access.AddRange(nickAccessTypes);
             // If they have the correct access for the command, send it
             if (cmd.AllowedAccess.Exists(access => nickAccessTypes.Contains(access)))
             {
                 // Make sure that the command isn't being spammed
                 if (Bot.SpamCheck(Bot.IRC.Channels.Find(chan => chan.Name == command.Location), command.Nick, this, cmd))
                 {
                     ParseCommand(command);
                 }
             }
             else
             {
                 string noAccessMessage = string.Format("You do not have access to use \u0002{0}\u000F.", command.Command);
                 SendResponse(command.MessageType, command.Location, command.Nick.Nickname, noAccessMessage, true);
             }
         }
     }
     catch (Exception ex)
     {
         ThrowException(ex, "Unable to handle module command.");
     }
 }
Exemple #8
0
 private void LogQuit(object sender, QuitInfo info)
 {
     if (!NickBlacklist.Contains(info.Nick.Nickname))
     {
         AddNick(info.Nick);
         string query = "INSERT INTO `quits` SET " +
                        "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                        "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
                        "`message` = {3}, " +
                        "`date_added` = {4}";
         Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Nick.Nickname, info.Message, info.TimeStamp });
     }
     LogToFile(SERVERLOGNAME, info.TimeStamp, string.Format("{0} has Quit.", info.Nick.Nickname));
 }
Exemple #9
0
 private void LogPrivateMessage(object sender, PrivateMessage message)
 {
     if (!NickBlacklist.Contains(message.Sender.Nickname))
     {
         AddNick(message.Sender);
         string query = "INSERT INTO `privatemessages` SET " +
                        "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                        "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
                        "`message` = {3}, " +
                        "`date_added` = {4}";
         Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
     }
     LogToFile(message.Sender.Nickname, message.TimeStamp, message.Message);
 }
Exemple #10
0
 public void HandleVersionQuery(object sender, CTCPMessage message)
 {
     if (Enabled &&
         !Bot.ServerConfig.NickBlacklist.Contains(message.Sender.Nickname) &&
         !NickBlacklist.Contains(message.Sender.Nickname))
     {
         if (message.Command.ToLower() == "version")
         {
             Assembly        assembly        = Assembly.GetExecutingAssembly();
             FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
             string          version         = fileVersionInfo.ProductVersion;
             Bot.IRC.Command.SendCTCPNotice(message.Sender.Nickname, "VERSION", string.Format("Combot v{0} on {1}", version, GetOptionValue("Machine Reply")));
         }
     }
 }
Exemple #11
0
 private void LogChannelPart(object sender, PartChannelInfo info)
 {
     if (!ChannelBlacklist.Contains(info.Channel) &&
         !NickBlacklist.Contains(info.Nick.Nickname))
     {
         AddChannel(info.Channel);
         AddNick(info.Nick);
         string query = "INSERT INTO `channelparts` SET " +
                        "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                        "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
                        "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
                        "`date_added` = {5}";
         Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
     }
     LogToFile(info.Channel, info.TimeStamp, string.Format("{0} has left the channel.", info.Nick.Nickname));
 }
Exemple #12
0
 private void LogChannelMessage(object sender, ChannelMessage message)
 {
     if (!ChannelBlacklist.Contains(message.Channel) &&
         !NickBlacklist.Contains(message.Sender.Nickname))
     {
         AddChannel(message.Channel);
         AddNick(message.Sender);
         string query = "INSERT INTO `channelmessages` SET " +
                        "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                        "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
                        "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
                        "`message` = {5}, " +
                        "`date_added` = {6}";
         Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Channel, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
     }
     LogToFile(message.Channel, message.TimeStamp, string.Format("<{0}> {1}", message.Sender.Nickname, message.Message));
 }
Exemple #13
0
 private void HandleJoinEvent(object sender, JoinChannelInfo info)
 {
     if (Enabled &&
         !Bot.ServerConfig.ChannelBlacklist.Contains(info.Channel) &&
         !Bot.ServerConfig.NickBlacklist.Contains(info.Nick.Nickname) &&
         !ChannelBlacklist.Contains(info.Channel) &&
         !NickBlacklist.Contains(info.Nick.Nickname))
     {
         List <Dictionary <string, object> > results = GetIntroductionList(info.Channel, info.Nick.Nickname);
         if (results.Any())
         {
             Random randNum = new Random();
             int    index   = randNum.Next(0, results.Count);
             Dictionary <string, object> intro = results[index];
             Bot.IRC.Command.SendPrivateMessage(info.Channel, string.Format("\u200B{0}", intro["message"]));
         }
     }
 }
Exemple #14
0
 private void LogChannelInvite(object sender, InviteChannelInfo info)
 {
     if (!ChannelBlacklist.Contains(info.Channel) &&
         !NickBlacklist.Contains(info.Requester.Nickname))
     {
         AddChannel(info.Channel);
         AddNick(info.Requester);
         AddNick(info.Recipient);
         string query = "INSERT INTO `channelinvites` SET " +
                        "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                        "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
                        "`requester_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nicks`.`nickname` = {4}), " +
                        "`recipient_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nicks`.`nickname` = {6}), " +
                        "`date_invited` = {7}";
         Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Requester.Nickname, Bot.ServerConfig.Name, info.Recipient.Nickname, info.TimeStamp });
     }
     LogToFile(info.Channel, info.TimeStamp, string.Format("{0} has invited {1} to the channel.", info.Requester.Nickname, info.Recipient.Nickname));
 }
Exemple #15
0
 private void LogChannelKick(object sender, KickInfo info)
 {
     if (!ChannelBlacklist.Contains(info.Channel) &&
         !NickBlacklist.Contains(info.KickedNick.Nickname))
     {
         AddChannel(info.Channel);
         AddNick(info.Nick);
         AddNick(info.KickedNick);
         string query = "INSERT INTO `channelkicks` SET " +
                        "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
                        "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
                        "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
                        "`kicked_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nickname` = {6}), " +
                        "`reason` = {7}, " +
                        "`date_added` = {8}";
         Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, Bot.ServerConfig.Name, info.KickedNick.Nickname, info.Reason, info.TimeStamp });
     }
     LogToFile(info.Channel, info.TimeStamp, string.Format("{0} kicked {1} [{2}]", info.Nick.Nickname, info.KickedNick.Nickname, info.Reason));
 }
Exemple #16
0
 public void HandleVersionResponse(object sender, CTCPMessage message)
 {
     if (Enabled &&
         !Bot.ServerConfig.NickBlacklist.Contains(message.Sender.Nickname) &&
         !NickBlacklist.Contains(message.Sender.Nickname))
     {
         if (message.Command == "VERSION")
         {
             listLock.EnterReadLock();
             VersionItem versionItem = versionList.Find(item => item.Nick.ToLower() == message.Sender.Nickname.ToLower());
             listLock.ExitReadLock();
             if (versionItem != null)
             {
                 string verResponse = string.Format("[{0}] Using version: {1}", versionItem.Nick, message.Arguments);
                 SendResponse(versionItem.MessageType, versionItem.Location, message.Sender.Nickname, verResponse);
                 listLock.EnterWriteLock();
                 versionList.RemoveAll(item => item.Nick == versionItem.Nick);
                 listLock.ExitWriteLock();
             }
         }
     }
 }
Exemple #17
0
        private void HandleChannelMessageEvent(object sender, ChannelMessage message)
        {
            if (Enabled &&
                !Bot.ServerConfig.ChannelBlacklist.Contains(message.Channel) &&
                !Bot.ServerConfig.NickBlacklist.Contains(message.Sender.Nickname) &&
                !ChannelBlacklist.Contains(message.Channel) &&
                !NickBlacklist.Contains(message.Sender.Nickname))
            {
                bool nickEnabled = false;
                Boolean.TryParse(GetOptionValue("Nickname Enabled").ToString(), out nickEnabled);
                bool channelEnabled = false;
                Boolean.TryParse(GetOptionValue("Channel Enabled").ToString(), out channelEnabled);
                int maxMessages = 10;
                Int32.TryParse(GetOptionValue("Max Messages").ToString(), out maxMessages);

                string key = string.Empty;
                if (nickEnabled && channelEnabled)
                {
                    key = string.Format("{0} {1}", message.Channel, message.Sender.Nickname);
                }
                else if (nickEnabled)
                {
                    key = message.Sender.Nickname;
                }
                else if (channelEnabled)
                {
                    key = message.Channel;
                }
                else
                {
                    key = string.Empty;
                }

                Regex sedRegex = new Regex(@"^s\/(?<Match>[^\/\\]*(?:\\.[^\/\\]*)*)\/(?<Replace>[^\/\\]*(?:\\.[^\/\\]*)*)\/(?<Option>[g|I|0-9]*)?");
                if (sedRegex.IsMatch(message.Message))
                {
                    Match        sedMatch = sedRegex.Match(message.Message);
                    string       match    = sedMatch.Groups["Match"].ToString().Replace(@"\/", @"/");
                    string       replace  = sedMatch.Groups["Replace"].ToString().Replace(@"\/", @"/");
                    string       option   = sedMatch.Groups["Option"].ToString();
                    RegexOptions matchOptions;
                    int          optionVal;
                    int          replaceNum;
                    if (int.TryParse(option, out optionVal))
                    {
                        matchOptions = RegexOptions.None;
                        replaceNum   = optionVal;
                    }
                    else if (option == "g")
                    {
                        matchOptions = RegexOptions.None;
                        replaceNum   = -1;
                    }
                    else if (option == "I" || option == "i")
                    {
                        matchOptions = RegexOptions.IgnoreCase;
                        replaceNum   = 1;
                    }
                    else
                    {
                        matchOptions = RegexOptions.None;
                        replaceNum   = 1;
                    }
                    bool foundResult = false;
                    MessageLock.EnterWriteLock();
                    if (LastMessages.ContainsKey(key))
                    {
                        List <string> msgList = new List <string>();
                        msgList.AddRange(LastMessages[key]);
                        msgList.Reverse();
                        foreach (string msg in msgList)
                        {
                            try
                            {
                                Regex messageRegex = new Regex(match, matchOptions);
                                if (messageRegex.IsMatch(msg))
                                {
                                    string newMessage = string.Empty;
                                    if (replaceNum < 0)
                                    {
                                        newMessage = messageRegex.Replace(msg, replace);
                                    }
                                    else
                                    {
                                        newMessage = messageRegex.Replace(msg, replace, replaceNum);
                                    }
                                    string replacedMessage = string.Format("\u0002{0}\u0002 meant to say: {1}", message.Sender.Nickname, newMessage);
                                    SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, replacedMessage);
                                    foundResult = true;
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                ThrowError(ex);
                            }
                        }
                    }
                    MessageLock.ExitWriteLock();
                    if (!foundResult)
                    {
                        string noMatch = string.Format("You do not have any previous messages that match \u0002{0}\u0002.", match);
                        SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, noMatch, true);
                    }
                }
                else
                {
                    // Add or replace the message for the user/channel
                    MessageLock.EnterWriteLock();
                    if (LastMessages.ContainsKey(key))
                    {
                        List <string> messages = LastMessages[key];
                        if (messages.Count >= maxMessages)
                        {
                            messages.RemoveAt(0);
                        }
                        messages.Add(message.Message);
                        LastMessages[key] = messages;
                    }
                    else
                    {
                        LastMessages.Add(key, new List <string> {
                            message.Message
                        });
                    }
                    MessageLock.ExitWriteLock();
                }
            }
        }