WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Twitter bug (https://www.wowinterface.com/forums/showthread.php?t=52106)

VikingP 03-20-15 09:44 AM

Twitter bug
 
Im using a UI that it's not been updated, but i would like to keep using it.
So looking for some help to see if i can fix this.
Have little lua skills. Tested a few things without any luck.
It's ShestakUI, https://github.com/Shestak/ShestakUI

Here is how the copyurl.lua looks like:
Lua Code:
  1. local T, C, L, _ = unpack(select(2, ...))
  2. if C.chat.enable ~= true then return end
  3.  
  4. ----------------------------------------------------------------------------------------
  5. --  Copy url from chat(module from Gibberish by p3lim)
  6. ----------------------------------------------------------------------------------------
  7. local patterns = {
  8.     "(https://%S+)",
  9.     "(http://%S+)",
  10.     "(www%.%S+)",
  11.     "(%d+%.%d+%.%d+%.%d+:?%d*)"
  12. }
  13.  
  14. for _, event in pairs({
  15.     "CHAT_MSG_GUILD",
  16.     "CHAT_MSG_PARTY",
  17.     "CHAT_MSG_PARTY_LEADER",
  18.     "CHAT_MSG_RAID",
  19.     "CHAT_MSG_RAID_LEADER",
  20.     "CHAT_MSG_CHANNEL",
  21.     "CHAT_MSG_WHISPER",
  22.     "CHAT_MSG_BN_WHISPER",
  23.     "CHAT_MSG_SAY",
  24.     "CHAT_MSG_INSTANCE_CHAT",
  25.     "CHAT_MSG_INSTANCE_CHAT_LEADER"
  26. }) do
  27.     ChatFrame_AddMessageEventFilter(event, function(self, event, str, ...)
  28.         for _, pattern in pairs(patterns) do
  29.             local result, match = string.gsub(str, pattern, "|cff00FF00|Hurl:%1|h[%1]|h|r")
  30.             if match > 0 then
  31.                 return false, result, ...
  32.             end
  33.         end
  34.     end)
  35. end
  36.  
  37. local orig = SetItemRef
  38. function SetItemRef(link, str, ...)
  39.     if string.sub(link, 1, 3) ~= "url" then return orig(link, str, ...) end
  40.  
  41.     local editbox = ChatEdit_ChooseBoxForSend()
  42.     ChatEdit_ActivateChat(editbox)
  43.     editbox:Insert(string.sub(link, 5))
  44.     editbox:HighlightText()
  45. end

Error:
Lua Code:
  1. Message: ...rface\AddOns\Blizzard_SocialUI\Blizzard_SocialUI.lua:119: Attempt to access forbidden object from code tainted by an AddOn
  2. Time: 03/20/15 16:44:01
  3. Count: 13
  4. Stack: [C]: in function `Show'
  5. ...rface\AddOns\Blizzard_SocialUI\Blizzard_SocialUI.lua:119: in function `SocialPostFrame_ShowScreenshot'
  6. Interface\FrameXML\ItemRef.lua:249: in function <Interface\FrameXML\ItemRef.lua:1>
  7. (tail call): ?
  8. (tail call): ?
  9. ...ace\AddOns\Blizzard_CombatLog\Blizzard_CombatLog.lua:3602: in function `SetItemRef'
  10. Interface\FrameXML\ChatFrame.lua:3374: in function `ChatFrame_OnHyperlinkShow'
  11. [string "*:OnHyperlinkClick"]:1: in function <[string "*:OnHyperlinkClick"]:1>
  12.  
  13. Locals: (*temporary) = SocialPostFrame {
  14.  0 = <userdata>
  15.  TitleText = <unnamed> {
  16.  }
  17.  RightBorder = <unnamed> {
  18.  }
  19.  LeftBorder = <unnamed> {
  20.  }
  21.  ImageFrame = <unnamed> {
  22.  }
  23.  ShareIcon = <unnamed> {
  24.  }
  25.  EdgeArt-Right = <unnamed> {
  26.  }
  27.  TopRightCorner = <unnamed> {
  28.  }
  29.  TopLeftCorner = <unnamed> {
  30.  }
  31.  Bg = <unnamed> {
  32.  }
  33.  ScreenshotButton = <unnamed> {
  34.  }
  35.  TopBorder = <unnamed> {
  36.  }
  37.  PostButton = <unnamed> {
  38.  }
  39.  TopTileStreaks = <unnamed> {
  40.  }
  41.  TitleBg = <unnamed> {
  42.  }
  43.  BottomBorder = <unnamed> {
  44.  }
  45.  BotRightCorner = <unnamed> {
  46.  }
  47.  BorderFrame = <unnamed> {
  48.  }
  49.  SocialMessageFrame = SocialPostFrameMessageFrame {
  50.  }
  51.  CloseButton = <unnamed> {
  52.  }
  53.  Title = <unnamed> {
  54.  }
  55.  AchievementButton = <unnamed> {
  56.  }
  57.  BotLeftCorner = <unnamed> {
  58.  }
  59.  DragBar = <unnamed> {
  60.  }
  61.  EdgeArt-Left = <unnamed> {
  62.  }
  63.  ItemButton = <unnamed> {
  64.  }
  65. }

Any help or tip would be nice :)

Munglunch 03-20-15 10:04 AM

Whats happening is that the older method of parsing chat strings for hyperlinks has no protection from the new "share" linktype.

Try this

In your code:
Lua Code:
  1. for _, event in pairs({
  2.     "CHAT_MSG_GUILD",
  3.     "CHAT_MSG_PARTY",
  4.     "CHAT_MSG_PARTY_LEADER",
  5.     "CHAT_MSG_RAID",
  6.     "CHAT_MSG_RAID_LEADER",
  7.     "CHAT_MSG_CHANNEL",
  8.     "CHAT_MSG_WHISPER",
  9.     "CHAT_MSG_BN_WHISPER",
  10.     "CHAT_MSG_SAY",
  11.     "CHAT_MSG_INSTANCE_CHAT",
  12.     "CHAT_MSG_INSTANCE_CHAT_LEADER"
  13. }) do
  14.     ChatFrame_AddMessageEventFilter(event, function(self, event, str, ...)
  15.         for _, pattern in pairs(patterns) do
  16.             local result, match = string.gsub(str, pattern, "|cff00FF00|Hurl:%1|h[%1]|h|r")
  17.             if match > 0 then
  18.                 return false, result, ...
  19.             end
  20.         end
  21.     end)
  22. end

You need to add this
Lua Code:
  1. if(str:find("%pHshare%p+")) then return end

So re-written it will look like this:

Lua Code:
  1. for _, event in pairs({
  2.     "CHAT_MSG_GUILD",
  3.     "CHAT_MSG_PARTY",
  4.     "CHAT_MSG_PARTY_LEADER",
  5.     "CHAT_MSG_RAID",
  6.     "CHAT_MSG_RAID_LEADER",
  7.     "CHAT_MSG_CHANNEL",
  8.     "CHAT_MSG_WHISPER",
  9.     "CHAT_MSG_BN_WHISPER",
  10.     "CHAT_MSG_SAY",
  11.     "CHAT_MSG_INSTANCE_CHAT",
  12.     "CHAT_MSG_INSTANCE_CHAT_LEADER"
  13. }) do
  14.     ChatFrame_AddMessageEventFilter(event, function(self, event, str, ...)
  15.         if(str:find("%pHshare%p+")) then return end
  16.         for _, pattern in pairs(patterns) do
  17.             local result, match = string.gsub(str, pattern, "|cff00FF00|Hurl:%1|h[%1]|h|r")
  18.             if match > 0 then
  19.                 return false, result, ...
  20.             end
  21.         end
  22.     end)
  23. end

VikingP 03-20-15 12:52 PM

Thank you for trying, but that didn't solve it. Still same error.

Torhal 03-20-15 02:08 PM

Quote:

Originally Posted by Munglunch (Post 307649)
Lua Code:
  1. for _, event in pairs({...}) do
  2.     ChatFrame_AddMessageEventFilter(event, function(self, event, str, ...)
  3.         if(str:find("%pHshare%p+")) then return end

Yeah...no. Terminating the entire iteration when finding "share" won't do anything remotely bad... :D

VikingP 03-20-15 04:28 PM

Quote:

Originally Posted by Torhal (Post 307654)
Yeah...no. Terminating the entire iteration when finding "share" won't do anything remotely bad... :D

Joke? didn't get that 1:o

Torhal 03-20-15 05:20 PM

Quote:

Originally Posted by VikingP (Post 307655)
Joke? didn't get that 1:o

I was just pointing out that using the solution you were given would actually break things worse than what they are.

VikingP 03-20-15 07:08 PM

Quote:

Originally Posted by Torhal (Post 307657)
I was just pointing out that using the solution you were given would actually break things worse than what they are.

Ahh :o
Above my skills :) Credit for trying atleast!

Munglunch 03-20-15 07:36 PM

Quote:

Originally Posted by Torhal (Post 307657)
I was just pointing out that using the solution you were given would actually break things worse than what they are.

That's weird, I could have sworn that in the native function ChatFrame_MessageEventHandler (ChatFrame.lua @line 2913), while parsing/executing chat filters (ChatFrame.lua @line 2929) will initially check the first return value for anything that evaluates (ie... anything OTHER than false or nil).

...But that would mean that my solution would cause NO HARM AT ALL, ..... so ... that can't be right. Right?

Actually, posting anything other than a possible solution to the problem presented is in fact making "things worse than what they are".

Torhal 03-20-15 08:28 PM

I don't have the solution, because I didn't fully look at the code, but when you're iterating over things to set them up, terminating the iteration altogether instead of gracefully handling it will lead to a bad state. So, if "share" was found for "CHAT_MSG_PARTY" the others that came after would never have the filter applied, even if they should. That's not causing no harm at all, it is in fact making things worse. I'm not trying to pick a fight here; I was merely pointing out that there was a logic error in case you wanted to re-address.

I'll refrain from being helpful now.

10leej 03-20-15 11:12 PM

Wait....... WoW has twitter now? Is this recent?

/derailed

VikingP 03-21-15 04:33 AM

Quote:

Originally Posted by 10leej (Post 307664)
Wait....... WoW has twitter now? Is this recent?

/derailed

Since 6.1
http://www.wowhead.com/guide=2957/how-to-tweet-in-game

Lombra 03-21-15 06:05 AM

Quote:

Originally Posted by Torhal (Post 307661)
I don't have the solution, because I didn't fully look at the code, but when you're iterating over things to set them up, terminating the iteration altogether instead of gracefully handling it will lead to a bad state. So, if "share" was found for "CHAT_MSG_PARTY" the others that came after would never have the filter applied, even if they should. That's not causing no harm at all, it is in fact making things worse. I'm not trying to pick a fight here; I was merely pointing out that there was a logic error in case you wanted to re-address.

I'll refrain from being helpful now.

The return is inside the function!

Torhal 03-21-15 12:38 PM

Quote:

Originally Posted by Lombra (Post 307669)
The return is inside the function!

And this is why I generally don't write replies when I just skim code. Yay.

Munglunch 03-21-15 04:08 PM

Quote:

Originally Posted by Torhal (Post 307684)
And this is why I generally don't write replies when I just skim code. Yay.

Torhal, I'm sorry for the way that I worded that post, it was unnecessary and unprofessional.

... And that is why I generally don't write replies when I am in a bad mood. Bad Mung!

Torhal 03-21-15 06:13 PM

Quote:

Originally Posted by Munglunch (Post 307690)
Torhal, I'm sorry for the way that I worded that post, it was unnecessary and unprofessional.

... And that is why I generally don't write replies when I am in a bad mood. Bad Mung!

It's all good. I still have all my limbs. I think. Damn it!

VikingP 03-21-15 08:21 PM

Nice of you all to kiss and make up :p

After 4 hours i found a solution (error was also caused from 2 other files altinvite and multitip)

Here is how it ended up.

Lua Code:
  1. local T, C, L, _ = unpack(select(2, ...))
  2. if C.chat.enable ~= true then return end
  3.  
  4. ----------------------------------------------------------------------------------------
  5. --  Copy url from chat(module from Gibberish by p3lim)
  6. ----------------------------------------------------------------------------------------
  7. local patterns = {
  8.     "(https://%S+)",
  9.     "(http://%S+)",
  10.     "(www%.%S+)",
  11.     "(%d+%.%d+%.%d+%.%d+:?%d*)"
  12. }
  13.  
  14. for _, event in pairs({
  15.     "CHAT_MSG_GUILD",
  16.     "CHAT_MSG_PARTY",
  17.     "CHAT_MSG_PARTY_LEADER",
  18.     "CHAT_MSG_RAID",
  19.     "CHAT_MSG_RAID_LEADER",
  20.     "CHAT_MSG_CHANNEL",
  21.     "CHAT_MSG_WHISPER",
  22.     "CHAT_MSG_BN_WHISPER",
  23.     "CHAT_MSG_SAY",
  24.     "CHAT_MSG_INSTANCE_CHAT",
  25.     "CHAT_MSG_INSTANCE_CHAT_LEADER",
  26.     "CHAT_MSG_BATTLEGROUND_LEADER",
  27.     "CHAT_MSG_BN_CONVERSATION",
  28.     "CHAT_MSG_RAID_WARNING",
  29.     "CHAT_MSG_OFFICER",
  30.     "CHAT_MSG_BATTLEGROUND",
  31.     "CHAT_MSG_YELL"
  32. }) do
  33.     ChatFrame_AddMessageEventFilter(event, function(self, event, str, ...)
  34.         for _, pattern in pairs(patterns) do
  35.             local result, match = string.gsub(str, pattern, "|cff00FF00|Hurl:%1|h[%1]|h|r")
  36.             if match > 0 then
  37.                 return false, result, ...
  38.             end
  39.         end
  40.     end)
  41. end
  42.  
  43. local SetHyperlink = _G.ItemRefTooltip.SetHyperlink
  44. function _G.ItemRefTooltip:SetHyperlink(link, ...)
  45.     if link and (strsub(link, 1, 3) == "url") then
  46.         local url = strsub(link, 5)
  47.        
  48.         local editbox = ChatEdit_ChooseBoxForSend()
  49.         ChatEdit_ActivateChat(editbox)
  50.         editbox:Insert(string.sub(link, 5))
  51.         editbox:HighlightText()
  52.        
  53.         return
  54.      end
  55.      
  56.      SetHyperlink(self, link, ...)
  57. end


All times are GMT -6. The time now is 09:53 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI