68 lines
2.0 KiB
Lua
68 lines
2.0 KiB
Lua
local addonname, data = ...
|
|
---@cast addonname string
|
|
local channelNameLengthLowerBound = 5
|
|
local channelNameLengthUpperBound = 33
|
|
local messageLengthLowerBound = 12
|
|
local messageLengthUpperBound = 47
|
|
local lowerBound = 53
|
|
local upperBound = 77
|
|
local asciiStart = 97
|
|
local asciiEnd = 122
|
|
|
|
local function GetChannelId(channelName)
|
|
local channels = { GetChannelList() }
|
|
for i = 1, #channels, 2 do
|
|
local id = channels[i]
|
|
local name = channels[i + 1]
|
|
if name == channelName then
|
|
return id
|
|
end
|
|
end
|
|
end
|
|
|
|
local function GenerateString(length)
|
|
print(string.format("Generating string of length %d", length))
|
|
local string = ""
|
|
for i = 1, length do
|
|
string = string .. string.char(math.random(asciiStart, asciiEnd))
|
|
end
|
|
return string
|
|
end
|
|
local channelName = GenerateString(math.random(channelNameLengthLowerBound, channelNameLengthUpperBound))
|
|
|
|
local function Yap()
|
|
local message = GenerateString(math.random(messageLengthLowerBound, messageLengthUpperBound))
|
|
print(string.format("Yapping %s", tostring(message)))
|
|
|
|
local channelId = GetChannelId(channelName)
|
|
if channelId ~= nil then
|
|
SendChatMessage(message, "CHANNEL", nil, channelId)
|
|
else
|
|
print(string.format("Channel %s not found, trying to join again...", channelName))
|
|
JoinTemporaryChannel(channelName)
|
|
end
|
|
|
|
local delay = math.random(lowerBound, upperBound)
|
|
print(string.format("Yapper yapping in %d seconds", delay))
|
|
C_Timer.After(delay, Yap)
|
|
end
|
|
|
|
local function init()
|
|
JoinTemporaryChannel(channelName)
|
|
print(string.format("Yapper joined %s", tostring(channelName)))
|
|
Yap()
|
|
end
|
|
|
|
local loadedFrame = CreateFrame("Frame")
|
|
loadedFrame:RegisterEvent("ADDON_LOADED")
|
|
loadedFrame:SetScript("OnEvent", function(self, event, addonName)
|
|
if addonName == addonname then
|
|
init()
|
|
end
|
|
end)
|
|
|
|
local logoutFrame = CreateFrame("Frame")
|
|
logoutFrame:RegisterEvent("PLAYER_LOGOUT")
|
|
logoutFrame:SetScript("OnEvent", function(self, event)
|
|
end)
|