Code:
--[[
AuctionBot
Version: 0.1
Author(s): ChatGPT / LitchLightIII / TheFiddler
Revision: No.
URL: http://youwillbemine/
This is an addon for World of Warcraft that conducts an auction within
a specified chat channel.
License:
Vapourware. Now you see it ... Now you don't!
Note:
Yes.
--]]
local testmessage = "WTS |cff0070dd|Hitem:12345|h[Example Item]|h|r"
local itemLink = string.match(testmessage, "|%x+|Hitem:%d+")
print("@AuctionBot test link IV ... " .. itemLink)
local thinking = 0
if type(GetChannelMessage) == "function" then
print("@GetChannelMessage ... Pass." .. itemLink)
else
print("@GetChannelMessage ... Fail." .. itemLink)
end
local function StartPrivateAuction(self, itemLink, itemName, itemSellPrice, channelName, channelNumber, author)
-- Announce the item for sale in the Trade channel
print("@StartPrivateAuction ... channelNumber == " .. channelNumber)
SendChatMessage("THANK YOU SIR! NOW AT AUCTION - " .. itemLink .. ". Who will start me off at 1g?", "CHANNEL", nil, channelNumber)
-- Wait for bids
local highestBid = 0
local highestBidder = nil
local timeLeft = 30
while timeLeft > 0 do
timeLeft = timeLeft - 1
if highestBidder ~= nil then
SendChatMessage("Any more bids for " .. itemLink .. " - currently " .. GetCoinTextureString(highestBid) .. " from " .. highestBidder .. "?", "CHANNEL", nil, channelNumber)
else
SendChatMessage("Any bids for " .. itemLink .. " - starting at 1g?", "CHANNEL", nil, channelNumber)
end
-- Check for new messages in the trade channel and parse any bids
local newBid = false
local newBidAmount = 0
local newBidder = nil
local chatIndex = 1
while true do
local message = select(2, GetChannelMessage(channelNumber, chatIndex))
if message == nil then
break
end
local bidAmount = string.match(message, "(%d+)([sgcp])")
if bidAmount ~= nil then
newBid = true
newBidAmount = tonumber(bidAmount)
newBidder = string.match(message, "%[(.+)%]")
if newBidder == nil then
newBidder = "unknown"
end
if string.find(message, "bid") ~= nil or string.find(message, "BID") ~= nil then
break
end
end
chatIndex = chatIndex + 1
end
-- Handle new bid if there is one
if newBid and newBidAmount > highestBid then
highestBid = newBidAmount
highestBidder = newBidder
timeLeft = 30
SendChatMessage("New bid of " .. GetCoinTextureString(newBidAmount) .. " from " .. newBidder .. " for " .. itemLink .. ".", "CHANNEL", nil, channelNumber)
end
-- Exit loop if there have been no new bids for 30 seconds
if not newBid and timeLeft <= 0 then
break
end
-- Wait one second before checking for bids again
coroutine.yield(1)
end
-- No more bids, announce the winner
if highestBidder ~= nil then
SendChatMessage("THANK YOU " .. highestBidder .. "! You win " .. itemLink .. " for " .. GetCoinTextureString(highestBid) .. ".", "CHANNEL", nil, channelNumber)
else
SendChatMessage("No bids received for " .. itemLink .. ".", "CHANNEL", nil, channelNumber)
end
end
local function OnChatMessage(self, event, message, author, language, channel, target, flags, unknown, channelNumber, channelName, unknown2, counter, guid)
print("@OnChatMessage ... Message detected: " .. message .. " " .. author .. " " .. channelName .. " " .. channelNumber)
if channelNumber == 2 then
print("@context.match ... channelNumber == " .. channelNumber)
if (message:lower():find("^%s*wts") == 1) then
print("@string.match ... Message Recognised: " .. message)
-- The message is a trade offer, extract the item link from the message and start the auction
local itemLink = string.match(message, "|%x+|Hitem:%d+")
if itemLink then
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemLink)
if itemName then
print("@StartPrivateAuction ... Starting Private Auction... ")
-- Start the auction for the item
thinking = StartPrivateAuction(self, itemLink, itemName, itemSellPrice, channelName, channelNumber, author)
print("@thinking = " .. thinking)
end
end
end
end
--
end
function GetChannelMessage(channelNumber, messageIndex)
local channelName = GetChannelName(channelNumber)
local numMessages = GetNumMessages(channelNumber)
local message = ""
for i = 1, numMessages do
print("@GetChannelMessage ... i = " .. i)
local msg = GetChatMessage(i, channelName)
-- Check if the message is relevant to your purpose
if (msg) then
-- Do something with the relevant message
print("@GetChannelMessage ... msg = " .. msg)
message = msg
end
end
return message
end
function GetNumMessages()
local numMessages = 0
local index = 1
local message = ""
-- iterate through trade channel messages until there are no more
while true do
message, _, _, _, _, _, _, _, _, _, _ = GetChannelMessage(2, index)
if message == nil then
break
end
numMessages = numMessages + 1
index = index + 1
end
return numMessages
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_CHANNEL")
frame:SetScript("OnEvent", OnChatMessage)
You will notice that there's alot missing in terms of the API - stuff "Mike" thinks will work simply has no basis in Trinitycore's implementation.