Legacy-of-Sylvanaar / wow-instant-messenger

WIM (WoW Instant Messenger) is a World of Warcraft addon which brings an instant messenger feel to communication in game.
https://www.curseforge.com/wow/addons/wim-3
MIT License
11 stars 8 forks source link

Can't send message in active VIM window #26

Closed Devinmarra closed 1 year ago

Devinmarra commented 1 year ago

This came to me via DM in Discord from Manuel#1982

im trying to figure out how to send a message to the active wim window /run SELECTED_CHAT_FRAME.editBox:SetText("test message") ChatEdit_SendText(SELECTED_CHAT_FRAME.editBox, 0)

this is working on the default whisper tabs but wont on the wim ones

thank you

Pazza commented 1 year ago

Thanks, he messaged me as well. I replied to him. For record I will respond here as well:

You'll want to look for WIM.EditBoxInFocus. If it isn't nil, then you'll want to SetText to it. The SendText function will not work in WIM however. You will need to use WoW's API to send messages directly to the user. You can get the selected user like this:

if (WIM.EditBoxInFocus ~= nil) then
    local user = WIM.EditBoxInFocus:GetParent().theUser
    local isWhisper = WIM.EditBoxInFocus:GetParent().type == 'whisper'
    if (isWhisper) then
         SendChatMessage("My special message", "WHISPER", nil, user)
    end
end

Unfortunately that is a lot and limits you in your macro size. Ideally, it'd be helpful to write yourself a little addon that does the bulk of this for you that you can execute using a macro.

I'll see about adding something to do all this for you. Where you can just execute a command to send a message in the window currently in focus. I'm not sure when I will get around to that yet... Might be in the new year.

Pazza commented 1 year ago

I just pushed an update with the tool you need. The caveat is that the editbox must be focused so you wont be able to keybind it because you'd be typing in the box instead, you'd have to click the macro.

/run WIM.sendToFocused("This is my message")

It takes a separate parameter to match the window type if you only want it to sent to chat windows for example and not a whisper.

/run WIM.sendToFocused("This is for chat windows only, whispers will not get it.", "chat")

Hope that accomplishes what you're looking for.