|
64 | 64 | end |
65 | 65 |
|
66 | 66 | do |
| 67 | + local GetTime = GetTime |
| 68 | + |
67 | 69 | local find = string.find |
68 | 70 | local makeStoreToken = util.makeStoreToken |
69 | 71 | local parseItemLink = util.parseItemLink |
|
78 | 80 | -- e.g. "You won: [Heavy Leather]" |
79 | 81 | local PATTERN_ITEM_LOOT_WON = "^You won: (.+)" |
80 | 82 |
|
| 83 | + local LOOT_TYPE_SELF = 0 |
| 84 | + local LOOT_TYPE_WON = 1 |
| 85 | + |
| 86 | + local loot_type |
| 87 | + local last_loot_time, last_won_code, last_self_code |
| 88 | + |
| 89 | + local function seenTooSoon(loot_time) |
| 90 | + return (GetTime() - loot_time) < 1 |
| 91 | + end |
| 92 | + |
81 | 93 | function A:CHAT_MSG_LOOT(msg) |
82 | 94 | local loot_string |
83 | 95 | _, _, loot_string = find(msg, PATTERN_ITEM_LOOT_SELF) |
84 | | - if not loot_string then |
| 96 | + if loot_string then |
| 97 | + loot_type = LOOT_TYPE_SELF |
| 98 | + else |
85 | 99 | _, _, loot_string = find(msg, PATTERN_ITEM_LOOT_WON) |
86 | 100 | if not loot_string then return end |
| 101 | + loot_type = LOOT_TYPE_WON |
87 | 102 | end |
88 | 103 |
|
89 | 104 | local item_link, _, id, code = parseItemLink(loot_string) |
90 | | - local _, _, count = find(loot_string, PATTERN_ITEM_LOOT_SELF_COUNT) |
91 | | - count = count and tonumber(count) or 1 |
| 105 | + if code then |
| 106 | + -- Check for immediate duplicate item loot messages across loot types |
| 107 | + if last_loot_time then |
| 108 | + if loot_type == LOOT_TYPE_SELF then |
| 109 | + last_self_code = code |
| 110 | + if last_won_code and code == last_won_code |
| 111 | + and seenTooSoon(last_loot_time) then |
| 112 | + last_loot_time = nil -- Found the Self duplicate message, so reset |
| 113 | + return |
| 114 | + end |
| 115 | + elseif loot_type == LOOT_TYPE_WON then |
| 116 | + last_won_code = code |
| 117 | + if last_self_code and code == last_self_code |
| 118 | + and seenTooSoon(last_loot_time) then |
| 119 | + last_loot_time = nil -- Found the Won duplicate message, so reset |
| 120 | + return |
| 121 | + end |
| 122 | + end |
| 123 | + end |
| 124 | + |
| 125 | + last_loot_time = GetTime() |
92 | 126 |
|
93 | | - if code then |
94 | 127 | local token = makeStoreToken(code) |
| 128 | + local _, _, count = find(loot_string, PATTERN_ITEM_LOOT_SELF_COUNT) |
| 129 | + count = count and tonumber(count) or 1 |
95 | 130 |
|
96 | 131 | if A:isEnabled() and filter.itemMatchQuality(id) then |
97 | 132 | local value = pricing.value(token) |
|
0 commit comments