A Defias Bandit
Join Date: Aug 2015
Posts: 2
|
I found something like that in the trivianswers.lua but it's nothing like the one in the pedia
SendChatMessage(answer,struct[3],nil,struct[4])
also if you want the lua i have it here
TriviaAnswers = LibStub("AceAddon-3.0"):NewAddon("TriviaAnswers","AceConsole-3.0", "AceEvent-3.0");
local options = {
type = 'group',
args = {
main = {
type = 'group',
childGroups = 'tab',
order = 1,
args = {
label = {
name = " Version " .. GetAddOnMetadata("TriviaAnswers","version"),
type = "description",
order = 1,
},
params = {
type = 'group',
name = 'Global Settings',
inline = true,
order = 10,
args = {
lowercase = {
name = 'Lower Case',
desc = 'Lower case answers',
handler = TriviaAnswers, -- should become self
get = "GetConfigValue",
set = "SetConfigValue",
type = 'toggle',
},
mintime = {
order = 20,
name = 'Min Time',
desc = 'Minimum time before answer',
type = 'range',
min = 0,
max = 10,
step = 0.5,
handler = TriviaAnswers, -- should become self
get = "GetConfigValue",
set = "SetConfigValue",
},
maxtime = {
order = 30,
name = 'Max Time',
desc = 'Maximum time before answer',
type = 'range',
min = 0,
max = 10,
step = 0.5,
handler = TriviaAnswers, -- should become self
get = "GetConfigValue",
set = "SetConfigValue",
},
errorrate = {
order = 20,
name = 'Error rate',
desc = 'Percent of time to make a typo',
type = 'range',
min = 0,
max = 1,
step = .01,
handler = TriviaAnswers, -- should become self
get = "GetConfigValue",
set = "SetConfigValue",
},
requeuetime = {
order = 50,
name = 'Requeue Time',
desc = 'Time to submit a "fixed" answer',
type = 'range',
min = 0,
max = 5,
step = 0.1,
handler = TriviaAnswers,
get = "GetConfigValue",
set = "SetConfigValue",
},
channel = {
name = 'Channel',
desc = 'Channel to answer on',
type = 'select',
values = {say='say',yell='yell',whisper='whisper',party='party',raid='raid',global='global',guild='guild',officer='officer'},
handler = TriviaAnswers, -- should become self
get = "GetConfigValue",
set = "SetConfigValue",
},
},
},
},
},
},
}
local DEFAULTS = {
params = {
mintime = 1,
maxtime = 2,
channel = 'say',
errorrate = 0,
requeuetime = 0.5,
lowercase = false,
},
}
local chat_types = {
['whisper'] = {"CHAT_MSG_WHISPER"},
['party'] = {"CHAT_MSG_PARTY","CHAT_MSG_PARTY_LEADER"},
['raid'] = {"CHAT_MSG_RAID","CHAT_MSG_RAID_LEADER"},
['guild'] = {"CHAT_MSG_GUILD"},
['officer'] = {"CHAT_MSG_OFFICER"},
['global'] = {"CHAT_MSG_GLOBAL"},
['say'] = {"CHAT_MSG_SAY"},
['yell'] = {"CHAT_MSG_YELL"},
}
local TriviaBot_QuestionPacks = {}
local TriviaBot_Questions = {}
function TriviaAnswers:GetVersion()
local ver = GetAddOnMetadata("TriviaAnswers","version");
if (ver) then return "v" .. ver; else return ""; end;
end
function TriviaAnswers:OnInitialize()
self.defaults = {
profile = {
TriviaAnswers = { },
}
}
self.db = LibStub("AceDB-3.0"):New("TriviaAnswersData", self.defaults,"global");
options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfig-3.0"):RegisterOptionsTable("TriviaAnswers", options.args.main)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TriviaAnswers Profile",options.args.profile)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TriviaAnswers","TriviaAnswers")
self.profileFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("TriviaAnswers Profile","Profile","TriviaAnswers")
self.db.RegisterCallback(self, 'OnNewProfile', 'OnProfileReset')
self.db.RegisterCallback(self, 'OnProfileChanged', 'OnProfileReset')
self.db.RegisterCallback(self, 'OnProfileCopied', 'OnProfileReset')
self.db.RegisterCallback(self, 'OnProfileReset', 'OnProfileReset')
self.db.RegisterCallback(self, 'OnProfileDeleted', 'OnProfileReset')
self:RegisterChatCommand("TriviaAnswers","ChatCommand")
self:RegisterChatCommand("ta","ChatCommand")
local ver = self:GetVersion()
if (ver) then
self:Print("TriviaAnswers " .. ver .. " Initialized")
else
self:Print("TriviaAnswers Initialized")
end
end
function TriviaAnswers:GetValue(frame,name,noProfile)
if (not self.db.profile.TriviaAnswers) then self.db.profile.TriviaAnswers = {}; end;
if (frame) then
if ((not noProfile) and self.db.profile.TriviaAnswers[frame] and self.db.profile.TriviaAnswers[frame][name] ~= nil) then
return self.db.profile.TriviaAnswers[frame][name]
end
return DEFAULTS[frame][name]
end
return nil
end
function TriviaAnswers:SetValue(frame,name,value)
if (not self.db.profile.TriviaAnswers) then self.db.profile.TriviaAnswers = {}; end;
if (frame) then
if (not self.db.profile.TriviaAnswers[frame]) then self.db.profile.TriviaAnswers[frame] = {}; end
self.db.profile.TriviaAnswers[frame][name] = value;
end
return value
end
function TriviaAnswers:GetConfigValue(info)
-- this is so broken - I need a string, not a number
local frame = info[#info-1]
local name = info[#info]
local tmp = self:GetValue(frame,name)
if (info.type=='input') then
return tostring(tmp)
else
return tmp;
end
end
function TriviaAnswers:SetConfigValue(info,value)
local frame = info[#info-1]
local name = info[#info]
-- special checks
if (name == "channel") then
self:UnListen(self:GetValue("params","channel"))
end
self:SetValue(frame,name,value)
if (name == "channel") then
self:Listen(value)
end
end
function TriviaAnswers:OnProfileReset()
self:LoadProfile()
end
function TriviaAnswers:ApplySettings()
self:LoadProfile()
end
function TriviaAnswers:ChatCommand(input)
if (not input or input:trim()=="") then
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
return
end
input=input:trim()
self:Print("Valid Commands")
self:Print("<blank>: Open the config pane")
end
function TriviaAnswers:Reset()
self.data = {}
end
function TriviaAnswers:LoadProfile()
self:Reset();
self:Listen(self:GetValue("params","channel"))
self:FindPacks()
end
function TriviaAnswers:OnEnable()
if (not self.frame) then
self.frame = CreateFrame("Frame")
self.frame:SetScript("OnUpdate",function() self:OnUpdate(); end)
end
self:LoadProfile()
self.frame:Show()
end
function TriviaAnswers:OnDisable()
if (self.frame) then self.frame:Hide(); end
self:Reset()
-- i really need to do more here
end
function TriviaAnswers:OnUpdate()
if (not self.data or not self.data.answers) then return; end
for i=1,#self.data.answers do
-- going to do a stupid recursive version because i'm lazy
if (self.data.answers[i][1] < GetTime()) then
local struct = self.data.answers[i]
table.remove(self.data.answers,i)
-- remove first in case announcenswer goes splat
self:AnnounceAnswer(struct)
self:OnUpdate()
return
end
end
end
function TriviaAnswers:Listen(channel)
if (not channel) then return; end
local events = chat_types[channel]
if (not events) then
self:Print("Unknown type " .. channel .. ". Not listening")
return
end
for _,e in pairs(events) do
self:RegisterEvent(e,"ChatIn")
end
end
function TriviaAnswers:UnListen(channel)
if (not channel) then return; end
local events = chat_types[channel]
if (not events) then
self:Print("Unknown type " .. channel .. ". Not unlistening")
return
end
for _,e in pairs(events) do
self:UnregisterEvent(e,"ChatIn")
end
end
function TriviaAnswers:ComputeDelay()
local mintime = tonumber(self:GetValue("params","mintime"))
local maxtime = tonumber(self:GetValue("params","maxtime"))
if (maxtime < mintime) then maxtime = mintime; end
local range = maxtime - mintime;
return mintime + random()* range;
end
function TriviaAnswers:MungeResponse(struct)
local answer = struct[2]
if (self:GetValue("params","lowercase")) then
answer = string.lower(answer)
end
if (random() < self:GetValue("params","errorrate")) then
-- requeue to do correction
struct[1] = struct[1] + self:GetValue("params","requeuetime")
tinsert(self.data.answers,struct)
-- single transposition for now
local pos = random(answer:len())
answer = answer:sub(1,pos-1) .. string.char(string.byte(answer:sub(pos,pos))+1) .. answer:sub(pos+1)
end
return answer
end
function TriviaAnswers:AnnounceAnswer(struct)
if (not struct) then return; end
local answer = self:MungeResponse(struct)
SendChatMessage(answer,struct[3],nil,struct[4])
end
function TriviaAnswers:QueueResponse(answer)
if (not self.data) then self.data = {}; end
if (not self.data.answers) then self.data.answers = {}; end
local delay = self:ComputeDelay()
local struct = {delay + GetTime(), answer,self:GetValue("params","channel")}
if (delay > 0) then
tinsert(self.data.answers,struct)
else
self:AnnounceAnswer(struct)
end
end
function TriviaAnswers:ChatIn(event,msg)
local question = string.match(msg,"%[TriviaBot%]: Q?:? ?(.*)");
if (not question) then
question = string.match(msg,"%[TB%]: Q?:? ?(.*)");
end
if (not question) then -- didn't match expected patterns. not a question
return
end
for _,c in pairs(TriviaBot_Questions) do
if (c) then
for j,q in pairs(c.Question) do
if (q==question) then
self:QueueResponse(c.Answers[j][1])
return
end
end
end
end
end
function TriviaAnswers:FindPacks()
for i = 1, GetNumAddOns() do
local questionPack, _, _, enabled = GetAddOnInfo(i)
if enabled and not IsAddOnLoaded(i) and IsAddOnLoadOnDemand(i) then
local valid = GetAddOnMetadata(i, "X-TriviaBot-Questions")
if valid then
TriviaBot_QuestionPacks[#TriviaBot_QuestionPacks+1] = questionPack
local loaded, reason = LoadAddOn(questionPack)
if (loaded) then
self:Print(questionPack)
TriviaBot_Questions[i] = _G[questionPack]["QuestionList"]
else
self:Print("Not loaded")
end
end
end
end
end
|
Last edited by rivriv0 : 08-16-15 at 09:43 AM.
|