예제 #1
0
        public void Tran(XivChatType type, string messageString, string senderName)
        {
            string output = Translate(messageString);

            if (injectChat == true)
            {
                PrintChat(type, senderName, lTr + output + rTr);
            }

            foreach (var tab in items)
            {
                if (tab.Logs[ConvertForArray(type.ToString())] && tab.Config[2])
                {
                    ChatText tmp = new ChatText();

                    tmp.Time         = GetTime();
                    tmp.ChannelShort = GetChannelName(type.ToString());
                    tmp.Channel      = type.ToString();
                    tmp.Sender       = senderName;

                    TextTypes translate = new TextTypes();
                    translate.Text = lTr + output + rTr;
                    translate.Type = PayloadType.RawText;
                    tmp.Text.Add(translate);

                    tab.Chat.Add(tmp);
                }
            }
        }
        private TextPayload FormatTextStyle(XivChatType type)
        {
            string FullTypeName;

            try
            {
                FullTypeName = XivChatTypeExtensions.GetFancyName(type);
            }
            catch (ArgumentException)
            {
                FullTypeName = type.ToString();
            }

            if ($"{(int)type}" == FullTypeName)
            {
                return(new TextPayload($"[{(Config.quietmode ? "Chat type " : "")}{type}] "));
            }

            return(new TextPayload($"[{(int)type}/{(Config.quietmode ? XivChatTypeExtensions.GetSlug(type) : FullTypeName)}] "));
        }
예제 #3
0
        private void Chat_OnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled)
        {
            try
            {
                if (!isHandled)
                {
                    if (outputAllJsons)
                    {
                        try
                        {
                            JsonLog(new OnChatMessageArgs(type, senderId, sender, message));
                        }
                        catch (Exception e)
                        {
                            ErrorLog(e.ToString());
                        }
                    }

                    ChannelSettings channel = GetChannelSettings(type);

                    if (channel.Name == "None" && type != XivChatType.None)
                    {
                        DebugLog($"{type.ToString()} ({(int)type})\t{message.TextValue}");
                    }

                    var splitPayloads      = new List <List <Payload> >();
                    var currentPayloadList = new List <Payload>();

                    foreach (var payload in message.Payloads)
                    {
                        if (payload.Type == PayloadType.RawText && ((TextPayload)payload).Text.Contains('\n'))
                        {
                            var newPayloads = ((TextPayload)payload).Text.Split('\n').Select(x => new TextPayload(x)).ToList();

                            currentPayloadList.Add(newPayloads[0]);
                            splitPayloads.Add(currentPayloadList);
                            for (int i = 1; i < newPayloads.Count - 1; i++)
                            {
                                splitPayloads.Add(new List <Payload>
                                {
                                    newPayloads[i]
                                });
                            }
                            currentPayloadList = new List <Payload>
                            {
                                newPayloads[newPayloads.Count - 1]
                            };
                        }
                        else
                        {
                            currentPayloadList.Add(payload);
                        }
                    }
                    splitPayloads.Add(currentPayloadList);

                    var textLogEntries = new List <TextLogEntry>();
                    textLogEntries.Add(CreateTextLogEntry(channel, senderId, sender.Payloads, splitPayloads.First()));

                    foreach (var payloads in splitPayloads.Skip(1))
                    {
                        textLogEntries.Add(CreateTextLogEntry(channel, 0, null, payloads));
                    }

                    foreach (var textLogEntry in textLogEntries)
                    {
                        chatBuffer.Enqueue(textLogEntry);

                        while (chatBuffer.Count > 200000)
                        {
                            TextLogEntry removedLogEntry;
                            chatBuffer.TryDequeue(out removedLogEntry);

                            foreach (var tab in tabs)
                            {
                                if (tab.EnabledChannels.ContainsKey(channel.Name) && tab.EnabledChannels[channel.Name])
                                {
                                    tab.FilteredLogs.RemoveAt(0);
                                }
                            }
                        }

                        foreach (var tab in tabs)
                        {
                            if (tab.EnabledChannels.ContainsKey(channel.Name))
                            {
                                if (tab.EnabledChannels[channel.Name])
                                {
                                    tab.AddLine(textLogEntry);
                                }
                            }
                            else
                            {
                                ErrorLog($"Channel name not found: {channel.Name}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                PluginLog.LogError(e.ToString());
                if (outputErrorJsons)
                {
                    JsonLogError(new OnChatMessageArgs(type, senderId, sender, message));
                }
            }
        }
예제 #4
0
        private void Chat_OnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled)
        {
            try
            {
                var            senderName = sender.TextValue;
                List <Payload> payloads   = message.Payloads;


                foreach (var tab in items)
                {
                    int chan = ConvertForArray(type.ToString());
                    if (chan < Channels.Length)
                    {
                        if (tab.Logs[chan])
                        {
                            ChatText tmp = new ChatText();

                            tmp.Time         = GetTime();
                            tmp.ChannelShort = GetChannelName(type.ToString());
                            try
                            {
                                tmp.Channel = Channels[chan].Trim().Replace(" ", "");
                            }
                            catch (Exception)
                            {
                                tmp.Channel = chan.ToString();
                            }

                            tmp.Sender        = senderName;
                            tmp.ChannelColour = ConvertForArray(type.ToString());
                            List <TextTypes> rawtext = new List <TextTypes>();

                            int         replace     = 0;
                            Payload     payloader   = null;
                            PayloadType payloadType = PayloadType.RawText;
                            foreach (var payload in payloads)
                            {
                                //if (payload.Type == PayloadType.AutoTranslateText) { texttype = 0; }
                                //if (payload.Type == PayloadType.Item) { texttype = 1; }
                                if (payload.Type == PayloadType.MapLink)
                                {
                                    replace     = 2;
                                    payloadType = PayloadType.MapLink;
                                    payloader   = payload;
                                }
                                //if (payload.Type == PayloadType.Player) { texttype = 3; }
                                //if (payload.Type == PayloadType.RawText) { texttype = 4; }
                                //if (payload.Type == PayloadType.Status) { texttype = 5; }
                                //if (payload.Type == PayloadType.UIForeground) { texttype = 6; }
                                //if (payload.Type == PayloadType.UIGlow) { texttype = 7; }

                                if (payload.Type == PayloadType.RawText)
                                {
                                    TextTypes wrangler = new TextTypes();
                                    wrangler.Text = payload.ToString().Split(new[] { ' ' }, 4)[3];

                                    if (replace == 1)
                                    {
                                        if (payloadType == PayloadType.MapLink)
                                        {
                                            rawtext.RemoveAt(rawtext.Count - 1);
                                            wrangler.Payload = payloader;
                                        }
                                    }

                                    if (replace == 0)
                                    {
                                        payloadType = PayloadType.RawText;
                                    }

                                    wrangler.Type = payloadType;
                                    rawtext.Add(wrangler);

                                    if (replace > 0)
                                    {
                                        replace--;
                                    }
                                }

                                //PluginLog.Log(payload.ToString());
                            }

                            tmp.Text = rawtext;

                            String messageString     = message.TextValue;
                            String predictedLanguage = Lang(messageString);

                            if (predictedLanguage == language)
                            {
                                Task.Run(() => Tran(type, messageString, senderName));
                            }

                            tab.Chat.Add(tmp);

                            if (tab.Chat.Count > 256)
                            {
                                tab.Chat.RemoveAt(0);
                            }

                            if (tab.Config[3])
                            {
                                //Writing to file
                                string filename = GetDate() + "_" + tab.Title + ".txt";
                                if (!System.IO.Directory.Exists(pathString))
                                {
                                    System.IO.Directory.CreateDirectory(pathString);
                                }

                                if (!System.IO.File.Exists(pathString + filename))
                                {
                                    System.IO.File.WriteAllText(pathString + filename, tab.Title + "\n");
                                }

                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(pathString + filename, true))
                                {
                                    file.WriteLine(tmp.Time + "[" + tmp.Channel + "]" + "<" + tmp.Sender + ">:" + TextTypesToString(rawtext));
                                }
                            }

                            if (tab.AutoScroll == true)
                            {
                                tab.Scroll = true;
                            }
                            tab.msg = true;
                        }
                    }
                    else
                    {
                        PluginLog.Log("[" + chan.ToString() + "] " + message.TextValue);
                    }
                }
            }
            catch (Exception e)
            {
                PluginLog.LogError(e.ToString());
            }
        }
예제 #5
0
        private void Chat_OnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled)
        {
            try
            {
                if (!isHandled)
                {
                    var            senderName = sender.TextValue;
                    List <Payload> payloads   = message.Payloads;
                    int            chan       = ConvertForArray(type.ToString());
                    ChatText       tmp        = new ChatText();

                    tmp.Time         = GetTime();
                    tmp.DateTime     = DateTime.Now;
                    tmp.ChannelShort = GetChannelName(type.ToString());
                    tmp.SenderId     = senderId;

                    //PluginLog.Log(senderId.ToString());
                    //PluginLog.Log(senderName);

                    try
                    {
                        tmp.Channel = Channels[chan].Trim().Replace(" ", "");
                    }
                    catch (Exception)
                    {
                        tmp.Channel = chan.ToString();
                    }

                    tmp.Sender        = senderName;
                    tmp.ChannelColour = ConvertForArray(type.ToString());

                    List <TextTypes> rawtext = new List <TextTypes>();

                    int         replace     = 0;
                    Payload     payloader   = null;
                    PayloadType payloadType = PayloadType.RawText;

                    //Handling Emotes
                    if (tmp.Channel == "StandardEmote")
                    {
                        tmp.Sender = "";
                    }

                    if (tmp.Channel == "CustomEmote")
                    {
                        tmp.Sender = "";
                        TextTypes wrangle = new TextTypes();
                        wrangle.Type = PayloadType.RawText;
                        wrangle.Text = senderName;
                        rawtext.Add(wrangle);
                    }
                    //Handling Tells
                    if (tmp.Channel == "TellOutgoing")
                    {
                        TextTypes wrangle = new TextTypes();
                        wrangle.Type = PayloadType.RawText;
                        wrangle.Text = ">>" + tmp.Sender + ":";
                        rawtext.Add(wrangle);
                        tmp.Sender = pluginInterface.ClientState.LocalPlayer.Name.ToString();
                    }
                    if (tmp.Channel == "TellIncoming")
                    {
                        TextTypes wrangle = new TextTypes();
                        wrangle.Type = PayloadType.RawText;
                        wrangle.Text = ">>";
                        rawtext.Add(wrangle);
                    }


                    foreach (var payload in payloads)
                    {
                        if (payload.Type == PayloadType.MapLink)
                        {
                            replace     = 2;
                            payloadType = PayloadType.MapLink;
                            payloader   = payload;
                        }

                        if (payload.Type == PayloadType.RawText)
                        {
                            TextTypes wrangler = new TextTypes();
                            wrangler.Text = payload.ToString().Split(new[] { ' ' }, 4)[3];

                            if (replace == 1)
                            {
                                if (payloadType == PayloadType.MapLink)
                                {
                                    rawtext.RemoveAt(rawtext.Count - 1);
                                    wrangler.Payload = payloader;
                                }
                            }

                            if (replace == 0)
                            {
                                payloadType = PayloadType.RawText;
                            }

                            wrangler.Type = payloadType;
                            rawtext.Add(wrangler);

                            if (replace > 0)
                            {
                                replace--;
                            }
                        }
                    }

                    tmp.Text = rawtext;

                    if (System.Text.RegularExpressions.Regex.Match(tmp.Sender, "^[-]").Success)
                    {
                        tmp.Sender = tmp.Sender.Substring(1);
                    }

                    if (bubbleEnable[chan])
                    {
                        ChatBubbleAdd(tmp);
                    }



                    foreach (var tab in items)
                    {
                        if (chan < Channels.Length && tab.Logs[chan])
                        {
                            tab.Chat.Enqueue(tmp);
                            tab.msg = true;

                            if (tab.Chat.Count > 256)
                            {
                                tab.Chat.TryDequeue(out ChatText pop);
                            }

                            if (tab.Config[3])
                            {
                                //Writing to file
                                string filename = GetDate() + "_" + tab.Title + ".txt";
                                if (!System.IO.Directory.Exists(pathString))
                                {
                                    System.IO.Directory.CreateDirectory(pathString);
                                }

                                if (!System.IO.File.Exists(pathString + filename))
                                {
                                    System.IO.File.WriteAllText(pathString + filename, tab.Title + "\n");
                                }

                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(pathString + filename, true))
                                { file.WriteLine(tmp.Time + "[" + tmp.Channel + "]" + "<" + tmp.Sender + ">:" + TextTypesToString(rawtext)); }
                            }

                            if (tab.AutoScroll == true)
                            {
                                tab.Scroll = true;
                            }
                        }
                        else
                        {
                        }       //PluginLog.Log("[" + chan.ToString() + "] " + message.TextValue);
                    }

                    if (allowTranslation)
                    {
                        String messageString     = message.TextValue;
                        String predictedLanguage = Lang(messageString);
                        if (predictedLanguage == language)
                        {
                            Task.Run(() => Tran(type, messageString, senderName));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                PluginLog.LogError(e.ToString());
            }
        }