Пример #1
0
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // get relevant data about the packet
            dAmnCommandPacket commandPacket = new dAmnCommandPacket(packet);
            string from = commandPacket.From.ToLower();
            string message = commandPacket.Message;
            string owner = Bot.Username;

            // make sure chat hasn't been sent from us
            if (from.ToLower() == Bot.Username.ToLower())
                return;

            // check to see if user is in our list
            foreach (KeyValuePair<string, string> away in AwayMessages)
            {
                // since the away key is room_username, have to get the username out of the key
                string username = away.Key.Substring(away.Key.IndexOf('_') + 1);

                // see if message contains the username
                if (Utility.IsMessageToUser(message, username, MsgUsernameParse.Lazy))
                {
                    Say(chatroom, username + " is currently away. Reason: <b><i>" + away.Value + "</i></b>");
                    return;
                }
            }
        }
Пример #2
0
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // get relevant data about the packet
            dAmnCommandPacket commandPacket = new dAmnCommandPacket(packet);
            string from = commandPacket.From;
            string message = commandPacket.Message;
            string username = Bot.Username;

            // make sure we didn't send a message!
            if (from.ToLower() == username.ToLower())
                return;

            // see if message is to us or not
            if (Utility.IsMessageToUser(message, username, MsgUsernameParse.Lazy))
            {
                // send message to console
                Bot.Console.Notice(string.Format("[{0}] <{1}> {2}", chatroom, from, message));

                // flash the window
                FlashWindow(_NumberOfTimesToFlash);
            }
        }
Пример #3
0
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // get relevant data about the packet
            var commandPacket = new dAmnCommandPacket(packet);
            string from = commandPacket.From;
            string message = commandPacket.Message;
            string username = Bot.Username;

            // ignore message from ourselves or a command sent to us
            if (username.ToLower() == from.ToLower() || message.StartsWith(Bot.Trigger))
                return;

            // get rp settings for this room
            RpSettings settings = RpSettings.GetOrAdd(chatroom);

            // process the string if needed
            if (settings.Enabled && settings.IsRpPost(message))
            {
                settings.RecordMessage(from, message);
                // users may be pissed if lose an rp chat or a whole session.
                // let's save our data after each new entry
                SaveSettings();
            }
        }
Пример #4
0
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // get relevant data about the packet
            dAmnCommandPacket commandPacket = new dAmnCommandPacket(packet);
            string from = commandPacket.From;
            string message = commandPacket.Message;
            string username = Bot.Username;

            // make sure we didn't send a message! otherwise we would be replying to ourselves
            if (from.ToLower() == username.ToLower())
                return;

            // see if message is to us or not
            if (Utility.IsMessageToUser(message, username, MsgUsernameParse.Lazy))
            {
                string awayMessage = AwayMessages.Get(chatroom);
                if (!string.IsNullOrEmpty(awayMessage))
                {
                    Say(chatroom, "I am currently away. Reason: " + awayMessage);
                    return;
                }
            }
        }
Пример #5
0
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // if room isn't enabled, don't bother processing
            if (!IsBannedWordsEnabled(chatroom))
                return;

            // get relevant data about the packet
            dAmnCommandPacket commandPacket = new dAmnCommandPacket(packet);

            // if the message from us (could be we're listing banned words) don't
            // kick ourselves
            if (commandPacket.From.ToLower() == Bot.Username.ToLower())
                return;

            // see if message contains a banned word
            if (ContainsBannedWord(chatroom, commandPacket.Message))
            {
                // get kick message if there is one
                string kickMessage = string.Empty;
                if (KickMessage.ContainsRoom(chatroom))
                    kickMessage = KickMessage[chatroom];

                // kick message
                dAmn.Kick(chatroom, commandPacket.From, kickMessage);
            }
        }
Пример #6
0
        private void UserJoined(string chatroom, dAmnServerPacket packet)
        {
            // get data from packet
            dAmnCommandPacket command = new dAmnCommandPacket(packet);

            // retrieve welcome settings for room
            WelcomeSettings welcomeSettings = WelcomeMessages.GetOrAdd(chatroom);

            if (welcomeSettings.Enabled)
            {
                // get our variables
                string from = command.From;
                string privClass = GetChat(welcomeSettings.ChatroomName).GetUser(from).PrivClass;
                string welcomeMsg = welcomeSettings.GetMessage(from, privClass);

                // send welcome message if we have one
                if (!string.IsNullOrEmpty(welcomeMsg))
                {
                    welcomeMsg = welcomeMsg.Replace("{channel}", chatroom);
                    welcomeMsg = welcomeMsg.Replace("{ns}", chatroom);
                    welcomeMsg = welcomeMsg.Replace("{from}", from);
                    Say(chatroom, welcomeMsg);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Process the chat packet from the dAmn server and decide whether or not
        /// to have the AI respond to it.
        /// </summary>
        /// <param name="chatroom">Chatroom.</param>
        /// <param name="packet">Packet received.</param>
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // if we're not set to respond don't bother processing packet
            bool respond = Responses.Get(chatroom);
            if (!respond)
                return;

            // get relevant data about the packet
            dAmnCommandPacket commandPacket = new dAmnCommandPacket(packet);
            string from = commandPacket.From.ToLower();
            string message = commandPacket.Message;
            string owner = Bot.Username;
            bool toBot = false;

            // determine if the message was directed at us
            toBot = (message.ToLower().StartsWith(owner.ToLower() + ":"));
            if (toBot)
            {
                // First let's make sure the owner didn't send it accidently...otherwise
                // we'll respond and then we'll see the response as a message and try to
                // respond...and make one big recursive loop
                if (from.ToLower() == owner.ToLower())
                    return;

                string input = StripUsername(message);

                try
                {
                    // form request
                    WebRequest request = HttpWebRequest.Create(BotWebService + from + "/" + EncodeStringToBase64(input));
                    request.Timeout = (int)TimeSpan.FromSeconds(30.0).TotalMilliseconds;

                    // get the response
                    WebResponse response = request.GetResponse();
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    // read response into string
                    string reply = reader.ReadToEnd();

                    // send it to the client!
                    base.Respond(chatroom, from, reply);
                }
                catch (WebException ex)
                {
                    // log error and try to restart the conversation
                    Bot.Console.Log("Error getting AI response. " + ex.ToString());
                    base.Respond(chatroom, from, "Sorry, I missed that. Could you say that again?");
                }
            }
        }
Пример #8
0
        private void ChatReceived(string chatroom, dAmnServerPacket packet)
        {
            // get relevant data about the packet
            dAmnCommandPacket commandPacket = new dAmnCommandPacket(packet);
            string from = commandPacket.From;

            // make sure room is enabled before we start processing
            if (!IsResponseEnabled(chatroom))
                return;

            // get trigger
            string trigger = ParseArg(commandPacket.Message, 0);
            if (string.IsNullOrEmpty(trigger))
                return;

            // if we have a response, send it
            string response = GetResponse(trigger);
            if (!string.IsNullOrEmpty(response))
            {
                response = response.Replace("{from}", from);
                response = response.Replace("{channel}", chatroom);
                Say(chatroom, response);
            }
        }