Guild Chat Macro

I am trying to write a macro to advertise in guild chat a raffle we are currently having within guild only.

/g -------------------------
/g Guild Raffle
/g [WoW Item]
/g Worth: 40,000g
/g -------------------------

The macro posts it in guild chat in a different order each time i use the macro. Is there any way i can fix this? I couldnt find much luck on google.

You could use something like the following to try and orchestrate the timing.

/run local i,s = 0,{ "-------------","Guild Raffle",select(2, GetItemInfo(169114)),"Worth: 40,000g","-------------" } local function x()i=i+1 if i > #s then return end SendChatMessage(s[i],"GUILD") C_Timer.After(.5, x) end x()

Each line to send is an element in a table so they can be sent individually. You can change the Item Number in the GetItemInfo() function. This sends a new line every half (.5) second until each line in the table is sent.

If you want to test without sending to the guild, you can change “GUILD” to “SAY” and find a quiet area like your Garrison.

I got this to work, however, i am running into the issue now with the 255 word maximum characters. I was going to try to write my own addon for this but that seems harder than i thought. Any way around this?

You can paste the code below into the website addon.bool.no to create/download the addon.

It’s a very rough (ie. not every possibility or sticking point thought through) version of what could be something quite elaborate.

To run:
/ms command messageid arg1 arg2

  • /ms test mornin 1953 my peeps
  • /ms play mo
  • /ms run raffle 169114 40,000g

Commands: play test run

  • play: prints message directly to your chat box
  • test: sends message via the SAY channel
  • run: sends message via the GUILD channel

messageid: one of the messages names in the Message table. You can add/delete/change messages

arg1, arg2: in this case, just optional parameters for messages that can use them (I’ve set them up to be arg1 (a number, item/spell id), arg2 (some text)). Proably best to keep them like this so you don’t need to alter the command line splitting.

Code:

local Pause = 0.5
local Options={
	PAUSE = 0.5,
	ID = 169114,
	EXTRA = "40,000g",
}
local RunAction
local RunMsg

local Messages={
	RAFFLE={
		"-------------",
		"Guild Raffle",
		function() local i = "--== " .. select(2, GetItemInfo(Options.ID)) or "" .. " ==--" return i end,
		function() return "Worth: " ..Options.EXTRA end,
		 "-------------"
	},
	MORNIN={
		"'Mornin' all",
		function() local i = GetSpellLink(Options.ID) return "Just woke up ".. i .. " " .. i end,
		function() return "What's happenening ".. Options.EXTRA end,
	},
	RA={
		"-------------",
		"Guild Raffle",
		"--== " .. select(2, GetItemInfo(169114)) .. " ==--",
		"Worth: 40k gold",
		 "-------------"
	},
	MO={
		"'Mornin' all",
		function() local i = GetSpellLink(1953) return "Just woke up ".. i .. " " .. i end,
		"What's happenening peoples",
	},
}

local function Play(msg, line)
	print(line, msg)
end
local function Test(msg)
	SendChatMessage(msg, "SAY")
end
local function Run(msg)
	SendChatMessage(msg, "GUILD")
end

LineNum = 0
local function RunMessage()
	LineNum = LineNum + 1 
	if LineNum > #Messages[RunMsg] then 
		LineNum = 0
		return 
	end 
	if string.find(tostring(Messages[RunMsg][LineNum]), "function()") then
		RunAction(Messages[RunMsg][LineNum](), LineNum)
	else
		RunAction(Messages[RunMsg][LineNum], LineNum)
	end
	C_Timer.After(Pause, RunMessage)
end

local function Setup(msg, id, extra)
	if not Messages[msg] then
		print("no message named: ", msg)
		return
	end
	if id and id ~= "0" then
		Options.ID = tonumber(id)
	end
	if extra then
		Options.EXTRA = extra
	end
	return true
end

local function PlayMessage(action, msg, arg1, arg2, arg3)
	if not Setup(msg, arg1, arg2, arg3) then return end
	RunAction = action
	RunMsg = msg
	RunMessage()
end

SLASH_FIZZMESSAGESYNC1 = "/ms"
SlashCmdList["FIZZMESSAGESYNC"] = function(msg)
	local command, arg1, arg2, arg3 = string.split(" ", strupper(msg))
	if arg3 then
		arg3 = string.sub(msg, string.len(command .. " " .. arg1 .. " " .. arg2) + 2)
	end
	if command == "PLAY" then
		Pause = 0.01
		PlayMessage(Play, arg1, arg2, arg3)
	elseif command == "TEST" then
		Pause = Options.PAUSE
		PlayMessage(Test, arg1, arg2, arg3)
	elseif command == "RUN" then
		Pause = Options.PAUSE
		PlayMessage(Run, arg1, arg2, arg3)
	else
		print("Unknown command:", command)
	end
end

Having the addon probably negates the need for syncing the message so that part could probably be replaced with just a straight to SendChatMessage operation.

Thank you so much, I been trying to experiment with it to customize it a little more but have run into a problem. I wanted to be able to add in a date in there and can’t figure out how to add that in without breaking the addon.

Example:

/ms run raffle 169114 40,000g 8/19/19

 ------------------------------------------
 Guild Raffle - Ends: 8/19/19

The problem comes with deciding how many “parameters” you want to be able to pass/consume on the slash command line. The way I wrote it above accepts 4 (the command (play/run/test), the message to use plus up to 2 others).

The Setup function then assigns the parameters to variables to “merge” into the messages.

Your example added another parameter which needs to be incorporated.

My code breaks the parameters based on finding Space characters in the string passed to the slash command. If it finds a fourth parameter (arg3) it then “re-loads” arg3 with everything after the split for that parameter allowing the last argument to be “free” text with multiple spaces.

The extra parameter in your example needs to be accounted for in the slash command function and how that’s done depends on how you want addon to work (what you are most likely to want to to pass as parameters).

You could change arg3 to another fixed (no spaces) parameter which would work for a date in the xx/xx/xx format but not say, “Dec. 25, 2019”. Effectively the “date” parameter would be an extra no-spaces free text parameter.

Same thing, with slight change (zero “0” will leave a parameter as is)
/ms Parameters:
Command, MessagId, Number(id etc. for functions), NoSpacesText1, NoSpacesText2, FreeText(everything else)

local Pause = 0.5
local Options = {
	PAUSE = 0.5,
	ARG1 = 169114,			-- converts to a number
	ARG2 = "NoSpaceText1",		-- Text with no spaces
	ARG3 = "NoSpaceText2",		-- More text with no spaces
	ARG4 = "Everything else",	-- free text
}

local RunAction
local Messages
local ActionMsg={}

local function Setup(message, number, fixedtext1, fixedtext2, freetext)
	if not Messages then
		Messages={
			RAFFLE={
				"-------------",
				function() return "Guild Raffle - Ends: " .. Options.ARG3 end,
				function() local i = "--== " .. select(2, GetItemInfo(Options.ARG1)) .. " ==--" return i end,
				function() return "Worth: " ..Options.ARG2 end,
				 "-------------",
				function() return Options.ARG4 end,
			},
			MORNIN={
				"'Mornin' all",
				function() local i = GetSpellLink(Options.ARG1) return "Just woke up ".. i .. " " .. i end,
				function() return "What's happenening ".. Options.ARG4 end,
			},
			RA={
				"-------------",
				"Guild Raffle",
				"--== |cff0070dd|Hitem:169114::::::::112:71::::::|h[Personal Time Displacer]|h|r ==--",
				"Worth: 40k gold",
				 "-------------"
			},
			MO={
				"'Mornin' all",
				function() local i = GetSpellLink(Options.ARG1) return "Just woke up ".. i .. " " .. i end,
				"What's happenening peoples",
			},
		}

	end
	if not Messages[message] then
		print("no message named: ", message)
		return
	end
	if number and number ~= "0" then
		Options.ARG1 = tonumber(number)
	end
	if fixedtext1 and fixedtext1 ~= "0" then
		Options.ARG2 = fixedtext1
	end
	if fixedtext2 and fixedtext2 ~= "0" then
		Options.ARG3 = fixedtext2
	end
	if freetext then
		Options.ARG4 = freetext
	end
	ActionMsg = Messages[message]
	return true
end

local function Play(msg, line)
	print(line, msg)
end
local function Test(msg)
	SendChatMessage(msg, "SAY")
end
local function Run(msg)
	SendChatMessage(msg, "GUILD")
end

LineNum = 0
local function RunMessage()
	LineNum = LineNum + 1 
	if LineNum > #ActionMsg then 
		LineNum = 0
		return 
	end 
	if string.find(tostring(ActionMsg[LineNum]), "function()") then
		RunAction(ActionMsg[LineNum](), LineNum)
	else
		RunAction(ActionMsg[LineNum], LineNum)
	end
	C_Timer.After(Pause, RunMessage)
end

SLASH_FIZZMESSAGESYNC1 = "/ms"
SlashCmdList["FIZZMESSAGESYNC"] = function(msg)
	local command, message, number, fixedtext1, fixedtext2, freetext = string.split(" ", msg)
	if freetext then -- add everything that comes "after" fixedtext2 to freetext
		freetext = string.sub(msg, string.len(command .. " " .. message .. " " .. number .. " " .. fixedtext1 .. " " .. fixedtext2) + 2)
	end
	command = string.upper(command)
	message = string.upper(message)
	if not Setup(message, number, fixedtext1, fixedtext2, freetext) then return end
	if command == "PLAY" then
		Pause = 0.01
		RunAction = Play
	elseif command == "TEST" then
		Pause = Options.PAUSE
		RunAction = Test
	elseif command == "RUN" then
		Pause = Options.PAUSE
		RunAction = Run
	else
		print("Unknown command:", command)
	end
	RunMessage()
end

This could be change where the options list is effectively a bunch of replacement parameters which you can use the command line to change (/ms change optionx isnumber New value goes here) and then just /ms run messageid over an over until you want to change parameters again.

or you could save the options individually for each message or… I did say this could get elaborate quite quickly :wink: :grin: