WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Detect mail from ah (https://www.wowinterface.com/forums/showthread.php?t=49956)

Tntdruid 09-22-14 03:27 AM

Detect mail from ah
 
Hello,

first my code:

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.     auditorMode = "AH";
  6.         else
  7.     auditorMode = "MAIL";
  8.     end
  9. end

I'm trying to Detect if the mail is from a succesfull auction, it never return the AH or MAIL, i'm still new to lua stuff, been looking at
http://wowprogramming.com/docs/api/GetInboxInvoiceInfo
http://wowprogramming.com/docs/api/GetInboxNumItems

Duugu 09-22-14 03:55 AM

I don't know what the invoiceType string exactly looks like, but I guess it is something like "Sold item: Seller ..."?

In that case you'll have to search for the pattern "seller" inside the string. Comparing the full string does not work as "seller" is not equal to "Sold item: Seller ....".

Lua Code:
  1. if string.find(invoiceType, "seller") then

If you are unsure if it is "seller" or "Seller" or "SELLER" or whatever, then it could be helpful to convert invoiceType before comparing them:

Lua Code:
  1. if string.find(string.lower(invoiceType), "seller") then

And last but not least you should declare auditorMode as local and return it with you function:

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     local auditorMode
  5.     if invoiceType == "seller" then
  6.         auditorMode = "AH";
  7.     else
  8.         auditorMode = "MAIL";
  9.     end
  10.     return auditorMode
  11. end

If you do not use auditorMode somewhere else then this would be a better way to do it:
Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.         return "AH"
  6.     else
  7.         return "MAIL"
  8.     end
  9. end

Personally I would return a boolean instead of a string as this is a bit easyer to handle. Like

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.         return true
  6.     end
  7. end
Then use it like
Lua Code:
  1. if Accountant_DetectAhMail() then
  2.     --
  3. end
instead of doing something like
Lua Code:
  1. if Accountant_DetectAhMail() == "AH" then
  2.     --
  3. end

[e]
And if you're not using multiple files with you addon, then you should probably declare you function as local:
Lua Code:
  1. local function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.         return true
  6.     end
  7. end

Tntdruid 09-22-14 04:17 AM

Very nice thanks for the help, gonna play a bit whit it :)

Tntdruid 09-23-14 12:34 AM

Still don't fire when i get money from the ah in the mail.

Duugu 09-23-14 06:03 AM

do'h ... just had overwritten my on old post :D

Tntdruid 09-23-14 07:06 AM

Tested the last code you added, its never print any thing.

Duugu 09-23-14 07:22 AM

Hm. Wowprogramming says
Quote:

numItems, totalItems = GetInboxNumItems()
Returns:
•numItems - Number of mails in the player's inbox (number)
•totalItems - Total number of items both in the inbox and on the server. (number)
I'm not sure what the difference is as I never did something with the mail api. :)
Totally guessing: the first one is the number of mails the player had opened at least once, and the second one is the number of opened and unopened mails?

You could try:

Lua Code:
  1. local function Accountant_DetectAhMail()
  2.     local numItems, totalItems = GetInboxNumItems()
  3.     for x = 1, totalItems do   
  4.         local invoiceType = GetInboxInvoiceInfo(x)
  5.         print(x, invoiceType)
  6.         if string.find(string.lower(invoiceType), "seller") then
  7.             return true
  8.         end
  9.     end
  10. end

Does this change anything?

Tntdruid 09-23-14 07:43 AM

Still return nill, there are like no info on google about that :(

Duugu 09-23-14 07:49 AM

I'll look into it later on. Don't have any access to a wow client right now.

Tntdruid 09-23-14 07:50 AM

Sure no problems :)

Duugu 09-23-14 08:41 AM

Looks as GetInboxNumItems() returns the number of mails in your inbox that were in it when you opened it the last time.
I would say you can't query GetInboxNumItems() (or at least don't get up-to-date results) without an open inbox.

What does happen if you open your mailbox and then use the function?

Tntdruid 09-23-14 09:51 AM

When i open the mailbox i get:
Message: Interface\AddOns\Accountant_Classic\Accountant.lua:459: attempt to call global 'Accountant_DetectAhMail' (a nil value)
Time: 09/23/14 17:51:09
Count: 1
Stack: Interface\AddOns\Accountant_Classic\Accountant.lua:459: in function `Accountant_OnEvent'
[string "*:OnEvent"]:1: in function <[string "*:OnEvent"]:1>
[C]: in function `TurnOrActionStop'
[string "TURNORACTION"]:4: in function <[string "TURNORACTION"]:1>

Locals: self = AccountantFrame {
0 = <userdata>
numTabs = 5
selectedTab = AccountantFrameTab1 {
}
}
event = "MAIL_SHOW"
arg1 = nil
arg2 = nil
oldmode = ""
(*temporary) = nil
(*temporary) = "attempt to call global 'Accountant_DetectAhMail' (a nil value)"


link to the code https://github.com/Tntdruid/Accounta...Accountant.lua

Duugu 09-23-14 10:16 AM

Remove the local keyword from
Lua Code:
  1. local function Accountant_DetectAhMail()
There's another problem. You can't check on MAIL_SHOW as this event is triggered if the inbox is opened. There won't be any data at this point as the client needs a moment to query the mail data from the server.
Use MAIL_INBOX_UPDATE instead:
Lua Code:
  1. elseif event == "MAIL_INBOX_UPDATE" then
  2.         Accountant_DetectAhMail();
and add
Lua Code:
  1. self:RegisterEvent("MAIL_INBOX_UPDATE");
to Accountant_RegisterEvents(self)

Tntdruid 09-23-14 10:39 AM

it's still trigger the OTHER event and not the AH.

Can see seller is corect for mail from ah whit gold.

Duugu 09-23-14 10:42 AM

Did you remove
Lua Code:
  1. 458     elseif event == "MAIL_SHOW" then
  2. 459         Accountant_DetectAhMail();

? :)

Tntdruid 09-23-14 10:43 AM

yes its gone

Duugu 09-23-14 10:51 AM

Well, then let's talk about what you're trying to accomplish. :)

Are you looking for something like this?

Lua Code:
  1. ...
  2. elseif event == "MAIL_INBOX_UPDATE" then
  3.     if Accountant_DetectAhMail() then
  4.         Accountant_Mode = "AH"
  5.     end
  6. ...

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems, totalItems = GetInboxNumItems()
  3.     for x = 1, totalItems do    
  4.         local invoiceType = GetInboxInvoiceInfo(x)
  5.         if invoiceType == "seller" then
  6.             return true
  7.         end
  8.     end
  9. end

Tntdruid 09-23-14 11:23 AM

I want the AH when i sell stuff on ah, MAIL for normal mails.

Tntdruid 09-23-14 02:19 PM

Quote:

Originally Posted by Duugu (Post 297150)
Well, then let's talk about what you're trying to accomplish. :)

Are you looking for something like this?

Lua Code:
  1. ...
  2. elseif event == "MAIL_INBOX_UPDATE" then
  3.     if Accountant_DetectAhMail() then
  4.         Accountant_Mode = "AH"
  5.     end
  6. ...

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems, totalItems = GetInboxNumItems()
  3.     for x = 1, totalItems do    
  4.         local invoiceType = GetInboxInvoiceInfo(x)
  5.         if invoiceType == "seller" then
  6.             return true
  7.         end
  8.     end
  9. end

This code works 100%, only problem if i send gold to an alt its gonna show up as AH and not in the MAIL section :)

Phanx 09-23-14 08:05 PM

Quote:

Originally Posted by Tntdruid (Post 297159)
This code works 100%, only problem if i send gold to an alt its gonna show up as AH and not in the MAIL section :)

Based on a reading of the documentation for GetInboxInvoiceInfo that function would not return any data for mail not sent by the AH itself. If you want to see if non-AH messages have gold attached, use GetInboxHeaderInfo instead.


All times are GMT -6. The time now is 02:24 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2019 MMOUI