Skip to content

Instantly share code, notes, and snippets.

@hyperdefined
Created March 26, 2024 21:58
Show Gist options
  • Save hyperdefined/b8d4d144f5b09816652166c08680dffb to your computer and use it in GitHub Desktop.
Save hyperdefined/b8d4d144f5b09816652166c08680dffb to your computer and use it in GitHub Desktop.
Simple WOW addon to reply to whispers with an AFK message if you're set /afk. Thank you ChatGPT for making this since I was too lazy.
-- Define the addon name and version
local ADDON_NAME, ADDON_VERSION = "AutoAFKMessage", "1.0"
-- Create a frame to handle events
local frame = CreateFrame("Frame")
-- Register for events
frame:RegisterEvent("CHAT_MSG_WHISPER")
-- Set the away message
local awayMessage = "[AutoMsg] Hey! I am currently away right now."
-- Addon enabled flag
local addonEnabled = true
-- Event handler function
local function eventHandler(self, event, ...)
if event == "CHAT_MSG_WHISPER" then
if addonEnabled then
local message, sender = ...
-- Check if the message is whisper and the player is AFK
if UnitIsAFK("player") and not UnitIsDND("player") then
-- Reply to the whisper
SendChatMessage(awayMessage, "WHISPER", nil, sender)
end
end
end
end
-- Slash command handler
local function SlashCmdHandler(msg)
if msg == "toggle" then
addonEnabled = not addonEnabled
if addonEnabled then
print(ADDON_NAME.." enabled.")
else
print(ADDON_NAME.." disabled.")
end
else
print("Usage: /afkm toggle - to enable/disable the addon.")
end
end
-- Register slash command
SLASH_AFKM1 = "/afkm"
SlashCmdList["AFKM"] = SlashCmdHandler
-- Assign the event handler function to the frame
frame:SetScript("OnEvent", eventHandler)
-- Display a message when the addon is loaded
print(ADDON_NAME.." v"..ADDON_VERSION.." loaded.")
## Interface: 90005
## Title: AutoAFKMessage
## Author: ChatGPT
## Version: 1.0
## Notes: Automatically replies to whispers when the player is AFK.
## DefaultState: Enabled
AutoAFKMessage.lua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment