Thread Tools Display Modes
09-22-14, 03:27 AM   #1
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
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
  Reply With Quote
09-22-14, 03:55 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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

Last edited by Duugu : 09-22-14 at 04:04 AM.
  Reply With Quote
09-22-14, 04:17 AM   #3
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Very nice thanks for the help, gonna play a bit whit it
  Reply With Quote
09-23-14, 12:34 AM   #4
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Still don't fire when i get money from the ah in the mail.
  Reply With Quote
09-23-14, 06:03 AM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
do'h ... just had overwritten my on old post

Last edited by Duugu : 09-23-14 at 07:22 AM.
  Reply With Quote
09-23-14, 07:06 AM   #6
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Tested the last code you added, its never print any thing.
  Reply With Quote
09-23-14, 07:22 AM   #7
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Hm. Wowprogramming says
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?
  Reply With Quote
09-23-14, 07:43 AM   #8
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Still return nill, there are like no info on google about that
  Reply With Quote
09-23-14, 07:49 AM   #9
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I'll look into it later on. Don't have any access to a wow client right now.
  Reply With Quote
09-23-14, 07:50 AM   #10
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Sure no problems
  Reply With Quote
09-23-14, 08:41 AM   #11
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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?
  Reply With Quote
09-23-14, 09:51 AM   #12
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
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
  Reply With Quote
09-23-14, 10:16 AM   #13
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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)
  Reply With Quote
09-23-14, 10:39 AM   #14
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
it's still trigger the OTHER event and not the AH.

Can see seller is corect for mail from ah whit gold.
  Reply With Quote
09-23-14, 10:42 AM   #15
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Did you remove
Lua Code:
  1. 458     elseif event == "MAIL_SHOW" then
  2. 459         Accountant_DetectAhMail();

?
  Reply With Quote
09-23-14, 10:43 AM   #16
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
yes its gone
  Reply With Quote
09-23-14, 10:51 AM   #17
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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
  Reply With Quote
09-23-14, 11:23 AM   #18
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
I want the AH when i sell stuff on ah, MAIL for normal mails.
  Reply With Quote
09-23-14, 02:19 PM   #19
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Originally Posted by Duugu View Post
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
  Reply With Quote
09-23-14, 08:05 PM   #20
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Tntdruid View Post
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Detect mail from ah

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off