· 7 years ago · Oct 26, 2018, 01:30 AM
1-- GLOBALS: TriviaBot_Config,TriviaBot_Scores,SLASH_TRIVIABOT1,SLASH_TRIVIABOT2
2--[[
3TriviaBot Version 2.8.7 for World of Warcraft 5.4.1
4TriviaBot Version 2.8.5a for World of Warcraft 5.0.4/Mists of Pandaria
5TriviaBot Version 2.8.4 for World of Warcraft 4.0.x
6Originally written by Guri of Trollbane
7Based on work created by Psy of Frostwolf
8Code blocks written by ReZeftY and StrangeWill modified
9Rewritten by KeeZ (Araina of EU-Agamaggan)
10Updated for 3.2.0, 3.3.5 and rewritten for 4.0.x by Dridzt (Driizt of EU-Bronzebeard)
11Update for 5.0.4 by Dridzt (Driizt of EU-Bronzebeard)
12--]]
13
14-- Local vars declared with TB_
15-- TriviaBot version
16local addonName, private = ...
17private.api = {}
18local API = private.api
19local TB_VERSION = GetAddOnMetadata(addonName,"Version")
20
21local L = TriviaBotLocalization
22-- Declared colour codes for console messages
23local TB_RED = "|cffff0000";
24local TB_MAGENTA = "|cffff00ff";
25local TB_WHITE = "|cffffffff";
26
27-- Control flags
28local TB_Running = false; -- To check if TriviaBot is started
29local TB_Accept_Answers = false; -- Whether or not answers are accepted
30local TB_Loaded = false; -- Set to true when TriviaBot is fully loaded
31local TB_Player_Entered = false;
32
33-- Control counters
34local TB_Active_Question = 0; -- The currently active question
35local TB_Report_Counter = 0; -- Count for how many questions have been asked
36local TB_Round_Counter = 0; -- Count for which question we're on in a round
37local TB_Hint_Counter = 0; -- What hint was sent before
38local TB_Question_Starttime = 0; -- When the question was asked
39local TB_Question_Hinttime = 0; -- When hints can be sent
40local TB_Min_Interval = 2;
41local TB_Max_Interval = 600;
42local TB_Min_Timeout = 10;
43local TB_Max_Timeout = 120;
44local TB_Min_Round = 5;
45local TB_Max_Round = 100;
46local TB_Infinite_Round = 0;
47local TB_Min_Timeout_Warning = 5;
48local TB_Max_Timeout_Warning = 60;
49local TB_Min_Topscore = 3;
50local TB_Max_Topscore = 10;
51local TB_Min_Topscore_Interval = 5;
52local TB_Max_Topscore_Interval = 50;
53local TB_Update_Interval = 0.5;
54local TB_limit_out -- extra sparse output when in public channel
55
56-- Control arrays
57local TB_Question_Order = {}; -- The order in which the questions will be asked
58local TB_Question_List = {}; -- Current list of questions to use
59local TB_Game_Scores = {}; -- Round scores
60TB_Game_Scores['Best_Win_Streak'] = {};
61TB_Game_Scores['Temp_Win_Streak'] = {};
62TB_Game_Scores['Speed'] = {};
63TB_Game_Scores['Player_Scores'] = {};
64local TB_Genders = {"its", "his", "her"}; -- Gender selection
65local TB_Question_Sets = {}; -- Faster listing of question-sets and categories
66local TB_Questions = {}; -- Pointer to the active question set
67local TB_Schedule = {}; -- The array used for scheduling events
68local TB_Caps_Restricted = {"a", "and", "as", "at", "in", "of", "on", "the", "to", "vs"}; -- Words that won't be capitalized
69
70local TriviaBot_Questions = {}; -- All question-sets
71local TriviaBot_QuestionPacks = {}; -- Populated with load on demand question lists available
72
73-- Global vars declared with TriviaBot_
74TriviaBot_Config = {}; -- Configuration array
75TriviaBot_Scores = {}; -- Player scores
76TriviaBot_Scores['Win_Streak'] = {};
77TriviaBot_Scores['Speed'] = {};
78TriviaBot_Scores['Player_Scores'] = {};
79
80-- Channel usage
81local TB_NewChannel; -- Used for changing custom channel
82local TB_Zone; -- Used to store the current zone
83local TB_Message_Prefix = "!tb"; -- Incoming whispers prefix
84local TB_Short_Prefix = "[TB]"; -- Short tag prefix
85local TB_Long_Prefix = "[TriviaBot]"; -- Long tag prefix
86local TB_Channel_Prefix = TB_Long_Prefix; -- Channel/Console prefix
87local TB_ServerChannels = {}; -- globalName = {id=id,fullName=channelName}
88local TB_Chat_Restricted = {}; -- globalName = fullName --
89local CUSTOM_IID,GENERAL_IID,TRADE_IID,LD_IID,WD_IID,LFG_IID = 0,1,2,22,23,26
90local SERVER_CHANNEL_INTERNAL_ID = {[GENERAL_IID]="General",[TRADE_IID]="Trade",[LD_IID]="LocalDefense",[WD_IID]="WorldDefense",[LFG_IID]="LookingForGroup"}
91local SERVER_CHANNEL_ORDER_ID_CITY = {[1]="General",[2]="Trade",[3]="LocalDefense",[4]="WorldDefense",[5]="LookingForGroup"}
92local SERVER_CHANNEL_ORDER_ID_WORLD = {[1]="General",[2]="LocalDefense",[3]="WorldDefense"}
93local SERVER_CHANNEL_INTERNAL_TO_ORDER = {
94 ["SERVER_CHANNEL_ORDER_ID_CITY"] = {[GENERAL_IID]=1,[TRADE_IID]=2,[LD_IID]=3,[WD_IID]=4,[LFG_IID]=5},
95 ["SERVER_CHANNEL_ORDER_ID_WORLD"] = {[GENERAL_IID]=1,[LD_IID]=2,[WD_IID]=3},
96}
97local CHANNEL_ACTIONS = {["YOU_JOINED"]=true,["YOU_LEFT"]=true,["YOU_CHANGED"]=true,["SUSPENDED"]=true,["THROTTLED"]=true}
98
99----------------------------------------------------------------------------
100-- Utility Functions
101----------------------------------------------------------------------------
102local function findSide(frame)
103 local side = "left";
104 local rightDist = 0;
105 local leftPos = frame:GetLeft();
106 local rightPos = frame:GetRight();
107 if ( not rightPos ) then
108 rightPos = 0;
109 end
110 if ( not leftPos ) then
111 leftPos = 0;
112 end
113 rightDist = GetScreenWidth() - rightPos;
114 if (leftPos and (rightDist < leftPos)) then
115 side = "left";
116 else
117 side = "right";
118 end
119 return side
120end
121local function tCount(t)
122 local count=0
123 for _,_ in pairs(t) do
124 count = count+1
125 end
126 return count
127end
128local function deepcopy(object)
129 local lookup_table = {}
130 local function _copy(object)
131 if type(object) ~= "table" then
132 return object
133 elseif lookup_table[object] then
134 return lookup_table[object]
135 end
136 local new_table = {}
137 lookup_table[object] = new_table
138 for index, value in pairs(object) do
139 new_table[_copy(index)] = _copy(value)
140 end
141 return setmetatable(new_table, _copy(getmetatable(object)))
142 end
143 return _copy(object)
144end
145local prevClick
146local function IsDoubleClick(thisClick)
147 local isDouble = nil
148 if prevClick and (thisClick-prevClick) < 0.3 then
149 isDouble = true
150 end
151 prevClick = thisClick
152 return isDouble
153end
154local SERVER_CHANNEL_NUM_TO_LOC = {[tCount(SERVER_CHANNEL_ORDER_ID_CITY)]="SERVER_CHANNEL_ORDER_ID_CITY",[tCount(SERVER_CHANNEL_ORDER_ID_WORLD)]="SERVER_CHANNEL_ORDER_ID_WORLD"}
155
156----------------------------------------------------------------------------
157-- Addon frame, and frame scripts
158----------------------------------------------------------------------------
159local TriviaBot = CreateFrame("Frame")
160local TriviaBotGUI_Header = CreateFrame("Frame", "TriviaBotGUI_Header", UIParent);
161local TriviaBotGUI = CreateFrame("Frame", nil, TriviaBotGUI_Header)
162TriviaBot.TimeSinceLastUpdate = 0
163TriviaBot:RegisterEvent("ADDON_LOADED")
164TriviaBot.OnEvent = function(self,event,...)
165 local arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9 = ...;
166 if (event == "ADDON_LOADED" and arg1 == addonName) then
167 -- Register Slash Command
168 SLASH_TRIVIABOT1 = "/trivia";
169 SLASH_TRIVIABOT2 = "/triviabot";
170 SlashCmdList['TRIVIABOT'] = TriviaBot.Command;
171 if (not TB_Loaded) then
172 -- Load the saved variables
173 if (not TriviaBot_Config.Version) then
174 TriviaBot.Print(L.TB_PRINT_NEWCONFIG);
175 TriviaBot.NewConfig();
176 end
177 if (TriviaBot_Config.Version ~= TB_VERSION) then
178 TriviaBot.Print(L.TB_PRINT_OLDDETECTUPGRADE);
179 TriviaBot.Print(L.TB_PRINT_OLD .. TriviaBot_Config.Version .. L.TB_PRINT_NEW .. TB_VERSION);
180 TriviaBot.NewConfig();
181 end
182 -- Start in the 'off' state
183 TB_Accept_Answers = false;
184 -- Send a message
185 TriviaBot.Print(L.TB_PRINT_VERSION .. TB_VERSION .. L.TB_PRINT_BLANKLOADED);
186 -- Discover LoD Question Lists and create stubs
187 TriviaBot.QuestionPackRegistry()
188 -- Load question-sets and categories
189 TriviaBot.LoadQuestionSets();
190 -- Load the questions
191 TriviaBot.LoadTrivia(TriviaBot_Config['Question_Set'], TriviaBot_Config['Question_Category']);
192 -- Check to see if general was the last selected chat and change it
193 if (TriviaBot_Config['Chat_Type'] == "general") then
194 TriviaBot_Config['Chat_Type'] = "channel";
195 end
196 -- delegate rest of initialization
197 self:RegisterEvent("PLAYER_ENTERING_WORLD"); -- reload
198 TB_Loaded = true;
199 end
200 elseif (event == "CHAT_MSG_CHANNEL" and TB_Accept_Answers) then
201 local msg = arg1;
202 local player = arg2;
203 local channel = string.lower(arg9);
204 if (msg and player and channel) then
205 local generalCh = TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]] and TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]].fullName
206 if (channel == string.lower(TriviaBot_Config['Channel']) or (generalCh and channel == string.lower(generalCh)) ) then
207 if (string.lower(msg) ~= "!hint") then
208 TriviaBot.CheckAnswer(player, msg);
209 else
210 TriviaBot.CheckHints();
211 end
212 end
213 end
214 elseif (event == "CHAT_MSG_WHISPER") then
215 local msg = string.lower(arg1);
216 local player = arg2;
217
218 if (msg and player) then
219 TriviaBot.WhisperControl(player, msg);
220 end
221 elseif ((event == "CHAT_MSG_SAY" or
222 event == "CHAT_MSG_GUILD" or
223 event == "CHAT_MSG_OFFICER" or
224 event == "CHAT_MSG_RAID" or
225 event == "CHAT_MSG_RAID_LEADER" or
226 event == "CHAT_MSG_PARTY" or
227 event == "CHAT_MSG_PARTY_LEADER" or
228 event == "CHAT_MSG_INSTANCE_CHAT" or
229 event == "CHAT_MSG_INSTANCE_CHAT_LEADER") and TB_Accept_Answers) then
230 -- Something was said, and the bot is on
231 local msg = arg1;
232 local player = arg2;
233 if (msg and player) then
234 if (string.lower(msg) ~= "!hint") then
235 TriviaBot.CheckAnswer(player, msg);
236 else
237 TriviaBot.CheckHints();
238 end
239 end
240 elseif (event == "CHAT_MSG_SYSTEM" and arg1 == ERR_TOO_MANY_CHAT_CHANNELS) then
241 TriviaBot.UnSchedule("all");
242 TriviaBot.Print(L.TB_PRINT_CHANNELLEAVE);
243 elseif (event == "CHAT_MSG_CHANNEL_NOTICE") then
244 local action,channelServerID,channelIndex,channelName = arg1,arg7,arg8,arg9
245 if not action or not CHANNEL_ACTIONS[action] then return end
246 if not channelServerID or (channelServerID ~= CUSTOM_IID and not SERVER_CHANNEL_INTERNAL_ID[channelServerID]) then
247 TriviaBot.PrintError(format("Channel (%d) %q has an unknown internal id: %s",channelIndex,channelName,(channelServerID or "nil")))
248 return
249 end
250 TriviaBot.UpdateServerChannels(action,channelServerID,channelIndex,channelName)
251 elseif (event == "NEXT_QUESTION") then TriviaBot.AskQuestion();
252 elseif (event == "QUESTION_TIMEOUT") then TriviaBot.QuestionTimeout();
253 elseif (event == "TIMEOUT_WARNING") and not TB_limit_out then TriviaBot.Send(TriviaBot_Config['Timeout_Warning'] .. L.TB_SEND_SECONDSLEFT);
254 elseif (event == "REPORT_SCORES") then TriviaBot.Report("midreport");
255 elseif (event == "END_REPORT") then TriviaBot.Report("endreport");
256 elseif (event == "STOP_GAME") then TriviaBot.Stop();
257 elseif (event == "SHOW_ANSWER") then TriviaBot.PrintAnswers();
258 elseif (event == "SHOW_HINT") then TriviaBot.CheckHints();
259 elseif (event == "RETRY_CHANNEL_CHANGE") then TriviaBot.ChangeCustomChannel();
260 elseif (event == "SCAN_CHANNELS") then TriviaBot.UpdateServerChannels();
261 elseif (event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_ENTERING_WORLD" or event == "GUILD_ROSTER_UPDATE" or event == "GROUP_ROSTER_UPDATE") then
262 if ((event == "PLAYER_ENTERING_WORLD" or event == "ZONE_CHANGED_NEW_AREA") and not TB_Player_Entered) then
263 TB_Zone = GetRealZoneText();
264 if TB_Zone and TB_Zone ~= "" then
265 TriviaBot.InitEnd(self)
266 else
267 self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
268 end
269 end
270 if TB_Loaded and TB_Player_Entered then
271 TB_Zone = GetRealZoneText();
272 TriviaBot.CheckChannel(event);
273 end
274 end
275end
276TriviaBot.OnUpdate = function(self,elapsed)
277 self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
278 if (self.TimeSinceLastUpdate > TriviaBot_Config['Update_Interval']) then
279 TriviaBot.DoSchedule(self);
280 self.TimeSinceLastUpdate = 0;
281 end
282end
283TriviaBot:SetScript("OnEvent",TriviaBot.OnEvent)
284TriviaBot:SetScript("OnUpdate",TriviaBot.OnUpdate)
285
286----------------------------------------------------------------------------
287-- ChatFrame message filter
288----------------------------------------------------------------------------
289function TriviaBot.MessageFilter(self, event, messg, ...)
290 if TriviaBot.Starts(string.lower(messg), string.lower(TB_Message_Prefix)) then
291 return true
292 else
293 return false, messg, ...
294 end
295end
296
297----------------------------------------------------------------------------
298-- Server channel discovery / refresh
299----------------------------------------------------------------------------
300function TriviaBot.UpdateServerChannels(action,channelServerID,channelIndex,channelName)
301 local tempAllChannels = {GetChannelList()}
302 local tempServerChannels = {EnumerateServerChannels()}
303 local numServerChannels = tCount(tempServerChannels)
304 local numChannels = tCount(tempAllChannels)
305 if numServerChannels == 0 or numChannels == 0 then
306 TriviaBot.Schedule("SCAN_CHANNELS",5)
307 return
308 end
309 local loc = SERVER_CHANNEL_NUM_TO_LOC[numServerChannels]
310 if not loc then
311 TriviaBot.PrintError(format("Unexpected number of server channels:%d",numServerChannels))
312 return
313 end
314 for orderid,globalName in pairs(tempServerChannels) do
315 if not TB_Chat_Restricted[strlower(globalName)] then TB_Chat_Restricted[strlower(globalName)] = true end
316 end
317 if not action then -- full refresh / initial update
318 for k,v in pairs(tempAllChannels) do
319 if k%2 == 0 then
320 local chIdx = tempAllChannels[k-1]
321 local id, chName = GetChannelName(chIdx)
322 local lv = strlower(v)
323 if TB_Chat_Restricted[lv] and (chName) then TB_Chat_Restricted[lv] = strlower(chName) end
324 if v == SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID] then
325 if not (IsInInstance()) then
326 TB_ServerChannels[v] = {["id"]=id,["fullName"]=chName} -- globalName = {id,fullName}
327 end
328 end
329 end
330 end
331 else
332 if channelServerID == GENERAL_IID then
333 if (IsInInstance()) or action == "YOU_LEFT" or action == "SUSPENDED" then
334 TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]] = nil
335 TriviaBot.CheckChannel()
336 elseif action == "YOU_JOINED" or action == "YOU_CHANGED" then
337 TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]] = {["id"]=channelIndex,["fullName"]=channelName}
338 elseif action == "THROTTLED" then
339 TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]] = nil
340 TriviaBot.CheckChannel()
341 TriviaBot.PrintError(L.TB_ERROR_CHANNELTHROTTLED)
342 TriviaBot.Print(L.TB_PRINT_THROTTLEHELP)
343 end
344 end
345 end
346end
347
348----------------------------------------------------------------------------
349-- Core functions
350----------------------------------------------------------------------------
351----------------------------------------------------------------------------
352-- Discover load on demand Question Packs
353----------------------------------------------------------------------------
354function TriviaBot.QuestionPackRegistry()
355 for i = 1, GetNumAddOns() do
356 local questionPack = GetAddOnInfo(i)
357 if not IsAddOnLoaded(i) and IsAddOnLoadOnDemand(i) then
358 local valid = GetAddOnMetadata(i, "X-TriviaBot-Questions")
359
360 if valid then
361 TriviaBot_QuestionPacks[#TriviaBot_QuestionPacks+1] = questionPack
362 end
363 end
364 end
365 -- create stub sets
366 if next(TriviaBot_QuestionPacks) then
367 for i, v in pairs(TriviaBot_QuestionPacks) do
368 if not TriviaBot_Questions[i] then
369 TriviaBot_Questions[i] = {}
370 end
371 if not TriviaBot_Questions[i]['Categories'] then
372 TriviaBot_Questions[i]['Categories']={}
373 end
374 if not TriviaBot_Questions[i]['Question'] then
375 TriviaBot_Questions[i]['Question']={}
376 end
377 if not TriviaBot_Questions[i]['Answers'] then
378 TriviaBot_Questions[i]['Answers']={}
379 end
380 if not TriviaBot_Questions[i]['Category'] then
381 TriviaBot_Questions[i]['Category']={}
382 end
383 if not TriviaBot_Questions[i]['Points'] then
384 TriviaBot_Questions[i]['Points']={}
385 end
386 if not TriviaBot_Questions[i]['Hints'] then
387 TriviaBot_Questions[i]['Hints']={}
388 end
389 TriviaBot_Questions[i]['Title'] = GRAY_FONT_COLOR_CODE..GetAddOnMetadata(v, "Notes")..FONT_COLOR_CODE_CLOSE
390 TriviaBot_Questions[i]['Description'] = L.TB_GUI_LOD
391 TriviaBot_Questions[i]['Author'] = GetAddOnMetadata(v, "Author")
392 TriviaBot_Questions[i]['Categories'][1] = GRAY_FONT_COLOR_CODE..L.TB_GUI_LOD..FONT_COLOR_CODE_CLOSE
393 TriviaBot_Questions[i]['Question'][1] = L.TB_GUI_LOD
394 TriviaBot_Questions[i]['Answers'][1] = {L.TB_GUI_LOD}
395 TriviaBot_Questions[i]['Category'][1] = 1
396 TriviaBot_Questions[i]['Points'][1] = 1
397 TriviaBot_Questions[i]['Hints'][1] = {}
398 TriviaBot_Questions[i]['Stub'] = true
399 end
400 local setid = TriviaBot_Config['Question_Set']
401 if setid and not TriviaBot_QuestionPacks[setid] then
402 TriviaBot_Config['Question_Set'] = 1
403 -- TriviaBot_Config['Question_Category'] = 0 -- all
404 end
405 else -- no question packs found
406 if not TriviaBot_Questions[1] then
407 TriviaBot_Questions[1] = {}
408 end
409 if not TriviaBot_Questions[1]['Categories'] then
410 TriviaBot_Questions[1]['Categories']={}
411 end
412 if not TriviaBot_Questions[1]['Question'] then
413 TriviaBot_Questions[1]['Question']={}
414 end
415 if not TriviaBot_Questions[1]['Answers'] then
416 TriviaBot_Questions[1]['Answers']={}
417 end
418 if not TriviaBot_Questions[1]['Category'] then
419 TriviaBot_Questions[1]['Category']={}
420 end
421 if not TriviaBot_Questions[1]['Points'] then
422 TriviaBot_Questions[1]['Points']={}
423 end
424 if not TriviaBot_Questions[1]['Hints'] then
425 TriviaBot_Questions[1]['Hints']={}
426 end
427 TriviaBot_Questions[1]['Title'] = RED_FONT_COLOR_CODE..L.TB_GUI_NOPACKS..FONT_COLOR_CODE_CLOSE
428 TriviaBot_Questions[1]['Description'] = L.TB_GUI_NOPACKS
429 TriviaBot_Questions[1]['Author'] = L.TB_GUI_NOPACKS
430 TriviaBot_Questions[1]['Categories'][1] = GRAY_FONT_COLOR_CODE..L.TB_GUI_NOPACKS..FONT_COLOR_CODE_CLOSE
431 TriviaBot_Questions[1]['Question'][1] = L.TB_GUI_NOPACKS
432 TriviaBot_Questions[1]['Answers'][1] = {L.TB_GUI_NOPACKS}
433 TriviaBot_Questions[1]['Category'][1] = 1
434 TriviaBot_Questions[1]['Points'][1] = 1
435 TriviaBot_Questions[1]['Hints'][1] = {}
436 TriviaBot_Questions[1]['Stub'] = true
437 TriviaBot_Config['Question_Set'] = 1
438 end
439end
440
441----------------------------------------------------------------------------
442-- Abort current question
443----------------------------------------------------------------------------
444function TriviaBot.AbortQuestion()
445 if (TB_Running) then
446 TriviaBot.UnSchedule("all");
447 TB_Accept_Answers = false;
448 else
449 TriviaBot.PrintError(L.TB_ERROR_NOGAME);
450 end
451end
452
453----------------------------------------------------------------------------
454-- Ask a question
455----------------------------------------------------------------------------
456function TriviaBot.AskQuestion(announce)
457 TB_Active_Question = TB_Active_Question + 1;
458
459 -- Check if there is questions left
460 if (TB_Active_Question == #TB_Questions['Question'] + 1) then
461 -- Reshuffle the order
462 TriviaBot.Randomize();
463 TB_Active_Question = 1;
464 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_OUTOFQUESTIONS); end
465 TriviaBot.Print(L.TB_PRINT_OUTOFQUESTIONS);
466 end
467
468 local questionNumber = 0;
469 if (TriviaBot_Config['Round_Size'] ~= TB_Infinite_Round) then
470 questionNumber = TB_Round_Counter + 1;
471 end
472
473 local setid = TriviaBot_Config['Question_Set'];
474 local qid = TB_Question_List[TB_Question_Order[TB_Active_Question]];
475 if (questionNumber ~= 0) then
476 if (announce and not TB_limit_out) then TriviaBot.Send("C: " .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']) .. " - " .. TB_Question_Sets[setid]['Categories'][TB_Questions['Category'][qid]]); end -- config this
477 TriviaBot.Send("Q" .. questionNumber .. ": " .. TB_Questions['Question'][qid]);
478 else
479 if (announce and not TB_limit_out) then TriviaBot.Send("C: " .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']) .. " - " .. TB_Question_Sets[setid]['Categories'][TB_Questions['Category'][qid]]); end
480 TriviaBot.Send("Q: " .. TB_Questions['Question'][qid]);
481 end
482
483 TB_Question_Starttime = GetTime();
484 TB_Question_Hinttime = TB_Question_Starttime + (TriviaBot_Config['Question_Timeout']/2);
485 TB_Hint_Counter = 0;
486 TB_Accept_Answers = true;
487 TriviaBotGUI.SkipButton:Enable();
488 if TriviaBot_Config['Show_Hints'] and #TB_Questions['Hints'][qid] > 0 then
489 TriviaBot.Schedule("SHOW_HINT", (TriviaBot_Config['Question_Timeout']/2));
490 end
491 TriviaBot.Schedule("QUESTION_TIMEOUT", TriviaBot_Config['Question_Timeout']);
492 TriviaBot.Schedule("TIMEOUT_WARNING", TriviaBot_Config['Question_Timeout'] - TriviaBot_Config['Timeout_Warning']);
493end
494
495----------------------------------------------------------------------------
496-- Capitalize string excluding restricted
497----------------------------------------------------------------------------
498function TriviaBot.Capitalize(str)
499 -- str = str:lower(); -- Lowercase the string
500 str = str:gsub("^%l", string.upper); -- Capitalize first letter
501 local function tchelper(first, rest)
502 if (TriviaBot.RestrictionCheck(first..rest, TB_Caps_Restricted)) then
503 return first:upper()..rest:lower();
504 else
505 return first..rest;
506 end
507 end
508 str = str:gsub("(%a)([%w_']*)", tchelper);
509 return str;
510end
511
512----------------------------------------------------------------------------
513-- Change custom channel
514----------------------------------------------------------------------------
515function TriviaBot.ChangeCustomChannel()
516 -- Check if the old channel is still joined
517 if (GetChannelName(TriviaBot_Config['Channel']) > 0) then
518 -- It still exists, try to leave it and re-try this method.
519 LeaveChannelByName(TriviaBot_Config['Channel']);
520 TriviaBot.Schedule("RETRY_CHANNEL_CHANGE", 1);
521 else
522 -- Set and join the new channel
523 JoinChannelByName(TB_NewChannel);
524 ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, TB_NewChannel);
525
526 -- Check if the new channel is joined
527 if (GetChannelName(TB_NewChannel) > 0) then
528 -- Finalize the change
529 TriviaBot_Config['Channel'] = TB_NewChannel;
530 TriviaBot_Config['Chat_Type'] = "channel";
531 TriviaBotGUI.Channel:SetText(TriviaBot_Config['Channel']);
532
533 -- Announce the action
534 TriviaBot.Print(L.TB_PRINT_CHANNELCHANGE .. TB_NewChannel);
535 else
536 -- If it doesn't exist yet, re-try this method again
537 TriviaBot.Schedule("RETRY_CHANNEL_CHANGE", 1);
538 end
539 end
540end
541
542----------------------------------------------------------------------------
543-- Change chat type
544----------------------------------------------------------------------------
545function TriviaBot.ChatSelect(type, channel)
546 -- Unregister old chat type
547 TriviaBot.UnregEvent(TriviaBot_Config['Chat_Type']);
548 if (type ~= "channel") then
549 -- Leave the custom channel if another chat type is selected
550 if (GetChannelName(TriviaBot_Config['Channel']) > 0) then
551 LeaveChannelByName(TriviaBot_Config['Channel']);
552 end
553 TriviaBot_Config['Chat_Type'] = type;
554 TriviaBot.Print(L.TB_PRINT_CHANNELCHANGE .. TriviaBot.Capitalize(type));
555 -- Disable custom channel stuff
556 TriviaBotGUI.Channel:EnableMouse(false);
557 TriviaBotGUI.Channel:ClearFocus();
558 TriviaBotGUI.Channel:SetTextColor(1,0,0);
559 TriviaBotGUI.ChannelButton:Disable();
560 else
561 -- Enable custom channel stuff
562 if (type ~= TriviaBot_Config['Chat_Type']) then
563 TriviaBotGUI.Channel:EnableMouse(true);
564 TriviaBotGUI.Channel:SetTextColor(1,1,1);
565 TriviaBotGUI.ChannelButton:Enable();
566 end
567 TB_NewChannel = channel;
568 TriviaBot.ChangeCustomChannel();
569 end
570 -- Register new chat type
571 TriviaBot.RegEvent(type);
572end
573
574----------------------------------------------------------------------------
575-- Compares user's answer to question
576----------------------------------------------------------------------------
577function TriviaBot.CheckAnswer(player, msg)
578 -- don't get the answer from the bot prints
579 if string.find(msg,TB_Channel_Prefix,1,true) then return end
580 -- Remove invalid chars from the message
581 msg = TriviaBot.StringCorrection(msg);
582 -- Current Question id
583 local qid = TB_Question_List[TB_Question_Order[TB_Active_Question]];
584 -- For every answer in the list of answers
585 for i = 1, #TB_Questions['Answers'][qid], 1 do
586 -- Check if answer is correct
587 if string.find(string.lower(msg), string.lower(TB_Questions['Answers'][qid][i]), 1, true) then
588 -- Unschedule warnings and timeout
589 TriviaBot.UnSchedule("all");
590
591 -- Time the answer
592 local timeTaken = GetTime() - TB_Question_Starttime;
593 timeTaken = math.floor(timeTaken * 100 + 0.5) / 100;
594
595 -- Tell player they don't suck as badly as they think they do.
596 if not TB_limit_out then TriviaBot.Send("'".. msg .. L.TB_SEND_CORRECTANSWERQUOTE .. player .. L.TB_SEND_BLANKIN .. timeTaken .. L.TB_SEND_BLANKSECONDS); end
597
598 -- Generate personal arrays
599 if (not TB_Game_Scores['Player_Scores'][player]) then
600 TB_Game_Scores['Player_Scores'][player] = {['Win_Streak'] = 0, ['Speed'] = 120, ['Points'] = 0, ['Score'] = 0};
601 end
602 if (not TriviaBot_Scores['Player_Scores'][player]) then
603 TriviaBot_Scores['Player_Scores'][player] = {['Win_Streak'] = 0, ['Speed'] = 120, ['Points'] = 0, ['Score'] = 0};
604 end
605
606 -- New game speed record
607 if (not TB_Game_Scores['Speed']['Holder'] or timeTaken < TB_Game_Scores['Speed']['Time']) then
608 TB_Game_Scores['Speed']['Holder'] = player;
609 TB_Game_Scores['Speed']['Time'] = timeTaken;
610 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_NEWGAMESPEED); end
611 end
612
613 -- New all-time speed record
614 if (not TriviaBot_Scores['Speed']['Holder'] or timeTaken < TriviaBot_Scores['Speed']['Time']) then
615 TriviaBot_Scores['Speed']['Holder'] = player;
616 TriviaBot_Scores['Speed']['Time'] = timeTaken;
617 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_ALLTIMESPEED); end
618 end
619
620 -- Check the temporary win streak
621 if (TB_Game_Scores['Temp_Win_Streak']['Holder'] == player) then
622 TB_Game_Scores['Temp_Win_Streak']['Count'] = TB_Game_Scores['Temp_Win_Streak']['Count'] + 1;
623 -- Check personal game win streak
624 if (TB_Game_Scores['Player_Scores'][player]['Win_Streak'] < TB_Game_Scores['Temp_Win_Streak']['Count']) then
625 TB_Game_Scores['Player_Scores'][player]['Win_Streak'] = TB_Game_Scores['Temp_Win_Streak']['Count'];
626 end
627 -- Check personal all-time win streak
628 if (TriviaBot_Scores['Player_Scores'][player]['Win_Streak'] < TB_Game_Scores['Temp_Win_Streak']['Count']) then
629 TriviaBot_Scores['Player_Scores'][player]['Win_Streak'] = TB_Game_Scores['Temp_Win_Streak']['Count'];
630 -- Announce the record if checked
631 if (TriviaBot_Config['Report_Personal'] and not TB_limit_out) then
632 TriviaBot.Send(player .. L.TB_SEND_BLANKBEAT .. "their" .. L.TB_SEND_BLANKOWNSTREAK .. TB_Game_Scores['Temp_Win_Streak']['Count'] .. L.TB_SEND_BLANKINAROW);
633 end
634 end
635 else
636 TB_Game_Scores['Temp_Win_Streak']['Holder'] = player;
637 TB_Game_Scores['Temp_Win_Streak']['Count'] = 1;
638 end
639
640 -- New game win streak record
641 if (not TB_Game_Scores['Best_Win_Streak']['Holder'] or TB_Game_Scores['Temp_Win_Streak']['Count'] > TB_Game_Scores['Best_Win_Streak']['Count']) then
642 TB_Game_Scores['Best_Win_Streak']['Holder'] = player;
643 TB_Game_Scores['Best_Win_Streak']['Count'] = TB_Game_Scores['Temp_Win_Streak']['Count'];
644 if (TriviaBot_Config['Report_Win_Streak'] and TB_Game_Scores['Best_Win_Streak']['Count']%5 == 0 and not TB_limit_out) then
645 TriviaBot.Send(player .. L.TB_SEND_HASSTREAK .. TB_Game_Scores['Best_Win_Streak']['Count'] .. L.TB_SEND_BLANKINAROW);
646 end
647 end
648
649 -- New all-time win streak record
650 if (not TriviaBot_Scores['Win_Streak']['Holder'] or TB_Game_Scores['Temp_Win_Streak']['Count'] > TriviaBot_Scores['Win_Streak']['Count']) then
651 TriviaBot_Scores['Win_Streak']['Holder'] = player;
652 TriviaBot_Scores['Win_Streak']['Count'] = TB_Game_Scores['Temp_Win_Streak']['Count'];
653 end
654
655 -- Check personal speed records
656 if (timeTaken < TB_Game_Scores['Player_Scores'][player]['Speed']) then
657 TB_Game_Scores['Player_Scores'][player]['Speed'] = timeTaken;
658 end
659 if (timeTaken < TriviaBot_Scores['Player_Scores'][player]['Speed']) then
660 TriviaBot_Scores['Player_Scores'][player]['Speed'] = timeTaken;
661 -- Announce the record if checked
662 if (TriviaBot_Config['Report_Personal'] and not TB_limit_out) then
663 TriviaBot.Send(player .. L.TB_SEND_BLANKBEAT .. "their" .. L.TB_SEND_BLANKOWNSPEED .. timeTaken .. L.TB_SEND_BLANKSECONDS);
664 end
665 end
666
667 -- Add points if point mode is enabled
668 if (TriviaBot_Config['Point_Mode']) then
669 TriviaBot_Scores['Player_Scores'][player]['Points'] = TriviaBot_Scores['Player_Scores'][player]['Points'] + TB_Questions['Points'][qid];
670 TB_Game_Scores['Player_Scores'][player]['Points'] = TB_Game_Scores['Player_Scores'][player]['Points'] + TB_Questions['Points'][qid];
671 end
672
673 -- Update the score
674 TriviaBot_Scores['Player_Scores'][player]['Score'] = TriviaBot_Scores['Player_Scores'][player]['Score'] + 1;
675 TB_Game_Scores['Player_Scores'][player]['Score'] = TB_Game_Scores['Player_Scores'][player]['Score'] + 1;
676
677 TriviaBot.EndQuestion(false);
678 end
679 end
680end
681
682----------------------------------------------------------------------------
683-- Check selected channel is available
684----------------------------------------------------------------------------
685function TriviaBot.CheckChannel(event)
686 if (not TB_Loaded or not TB_Player_Entered) then
687 -- Addon isn't loaded there's no reason to check the events
688 return;
689 end
690
691 local chat = TriviaBot_Config['Chat_Type'];
692 if (chat == "guild" and not IsInGuild()) or
693 (chat == "officer" and not TriviaBot.IsOfficer()) or
694 (chat == "party" and not IsInGroup(LE_PARTY_CATEGORY_HOME)) or
695 (chat == "raid" and not IsInRaid(LE_PARTY_CATEGORY_HOME)) or
696 (chat == "general" and not TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]]) or
697 (chat == "instance_chat" and TB_Zone ~= L.TB_ZONE_AB and TB_Zone ~= L.TB_ZONE_WSG and TB_Zone ~= L.TB_ZONE_AV and TB_Zone ~= L.TB_ZONE_EOTS and TB_Zone ~= L.TB_ZONE_SOTA and TB_Zone ~= L.TB_ZONE_IOC and TB_Zone ~= L.TB_ZONE_TBFG and TB_Zone ~= L.TB_ZONE_TP) then
698 if (TB_Running) then
699 TriviaBot.Stop(); -- We can't broadcast so TriviaBot is stopped
700 end
701 TriviaBot.ChatSelect("channel", TriviaBot_Config['Channel']);
702 TriviaBotGUI.Update();
703 end
704end
705
706----------------------------------------------------------------------------
707-- Checks if there're any hints to send
708----------------------------------------------------------------------------
709function TriviaBot.CheckHints()
710 -- if (TB_Question_Hinttime <= GetTime()) then
711 if (GetTime() >= TB_Question_Hinttime) then
712 local qid = TB_Question_List[TB_Question_Order[TB_Active_Question]];
713 if (TB_Hint_Counter < #TB_Questions['Hints'][qid]) then
714 TriviaBot.Send(L.TB_SEND_HINT .. TB_Questions['Hints'][qid][TB_Hint_Counter + 1]);
715 TB_Hint_Counter = TB_Hint_Counter + 1;
716 -- todo: consider scheduling a new SHOW_HINT if more hints available
717 end
718 TB_Question_Hinttime = GetTime() + TB_Min_Interval;
719 end
720end
721
722----------------------------------------------------------------------------
723-- Command handler
724----------------------------------------------------------------------------
725function TriviaBot.Command(cmd)
726 if (not TB_Player_Entered or not TB_Loaded) then
727 -- Addon isn't finished loading, gui may be unavailable.
728 TriviaBot.PrintError(L.TB_ERROR_NOTINIT)
729 return
730 end
731 -- Create variables
732 local msgArgs = {};
733
734 -- Convert to lower case
735 cmd = string.lower(cmd);
736
737 -- Seperate our args
738 for value in string.gmatch(cmd, "[^ ]+") do
739 table.insert(msgArgs, value);
740 end
741
742 if (#msgArgs == 0) then
743 -- Toggle the GUI
744 if (TriviaBotGUI_Header:IsVisible()) then
745 TriviaBotGUI_Header:Hide();
746 else
747 TriviaBotGUI_Header:Show();
748 TriviaBotGUI.Update();
749 end
750 elseif (msgArgs[1] == "clear") then
751 TB_Game_Scores = {};
752 TB_Game_Scores['Best_Win_Streak'] = {};
753 TB_Game_Scores['Temp_Win_Streak'] = {};
754 TB_Game_Scores['Speed'] = {};
755 TB_Game_Scores['Player_Scores'] = {};
756 TriviaBot.Print(L.TB_PRINT_SCORESCLEARED);
757 elseif (msgArgs[1] == "clearall") then
758 TriviaBot_Scores = {};
759 TriviaBot_Scores['Win_Streak'] = {};
760 TriviaBot_Scores['Speed'] = {};
761 TriviaBot_Scores['Player_Scores'] = {};
762 TriviaBot.Print(L.TB_PRINT_ALLSCORESCLEARED);
763 elseif (msgArgs[1] == "help") then
764 TriviaBot.Print(L.TB_PRINT_HELP);
765 TriviaBot.Print(L.TB_PRINT_CMDCLEAR);
766 TriviaBot.Print(L.TB_PRINT_CMDCLEARALL);
767 TriviaBot.Print(L.TB_PRINT_CMDHELP);
768 TriviaBot.Print(L.TB_PRINT_CMDRESET);
769 elseif (msgArgs[1] == "reset") then
770 TriviaBot.NewConfig(true);
771 TriviaBot.ChatSelect(TriviaBot_Config['Chat_Type'], TriviaBot_Config['Channel']);
772 TriviaBotGUI.Update();
773 end
774end
775
776----------------------------------------------------------------------------
777-- Do scheduled events
778----------------------------------------------------------------------------
779function TriviaBot.DoSchedule(self)
780 if (TB_Schedule) then
781 for id, events in pairs(TB_Schedule) do
782 -- Get the time of each event
783 -- If it should be run (i.e. equal or less than current time)
784 if (events['time'] <= GetTime()) then
785 TriviaBot.OnEvent(self, events['name']);
786 TriviaBot.UnSchedule(id);
787 end
788 end
789 end
790end
791
792----------------------------------------------------------------------------
793-- Called when a question is finished
794----------------------------------------------------------------------------
795function TriviaBot.EndQuestion(showAnswer)
796 -- Prevent further answers
797 TB_Accept_Answers = false;
798 TriviaBotGUI.SkipButton:Disable();
799
800 -- Increment the counters
801 TB_Round_Counter = TB_Round_Counter + 1;
802
803 local wait = 0;
804 if (showAnswer) then
805 wait = wait + TB_Min_Interval;
806 TriviaBot.Schedule("SHOW_ANSWER", wait);
807 end
808
809 -- See if we've reached the end of the round
810 if (TB_Round_Counter == TriviaBot_Config['Round_Size']) then
811 TriviaBot.Schedule("END_REPORT", wait + 4);
812 TriviaBot.Schedule("STOP_GAME", wait + 8);
813 else
814 -- Count how long it's been since a question report
815 if (TriviaBot_Config['Show_Reports']) then
816 TB_Report_Counter = TB_Report_Counter + 1;
817 if (TB_Report_Counter == TriviaBot_Config['Top_Score_Interval']) then
818 wait = wait + 4;
819 TriviaBot.Schedule("REPORT_SCORES", wait);
820 TB_Report_Counter = 0;
821 end
822 end
823 TriviaBot.Schedule("NEXT_QUESTION", TriviaBot_Config['Question_Interval'] + wait);
824 end
825end
826
827----------------------------------------------------------------------------
828-- Index trivia questions
829----------------------------------------------------------------------------
830function TriviaBot.IndexTrivia(setid)
831 if (TriviaBot_Questions[setid]) then
832 if (not TB_Question_Sets[setid]['CatIdx']) then
833 TB_Question_Sets[setid]['CatIdx'] = {[0] = {}};
834 for id,_ in pairs(TB_Question_Sets[setid]['Categories']) do
835 TB_Question_Sets[setid]['CatIdx'][id] = {};
836 end
837 for id,_ in pairs(TriviaBot_Questions[setid]['Question']) do
838 table.insert(TB_Question_Sets[setid]['CatIdx'][0], id);
839 local catid = TriviaBot_Questions[setid]['Category'][id];
840 if (TB_Question_Sets[setid]['CatIdx'][catid]) then
841 table.insert(TB_Question_Sets[setid]['CatIdx'][catid], id);
842 end
843 end
844 end
845 end
846end
847
848----------------------------------------------------------------------------
849-- Checks if the player can listen to and speak in the officer chat
850----------------------------------------------------------------------------
851function TriviaBot.IsOfficer()
852
853 return false;
854-- local _,_,playerrank = GetGuildInfo("player");
855
856-- GuildControlSetRank(playerrank + 1);
857
858-- local _,_,officerchat_listen,officerchat_speak = GuildControlGetRankFlags();
859
860-- if (officerchat_listen == 1 and officerchat_speak == 1) then
861
862-- return true;
863
864-- else
865
866-- return false;
867
868-- end
869
870end
871
872----------------------------------------------------------------------------
873-- Load question-sets info and categories
874----------------------------------------------------------------------------
875function TriviaBot.LoadQuestionSets()
876 for id,_ in pairs(TriviaBot_Questions) do
877 TB_Question_Sets[id] = {};
878 TB_Question_Sets[id]['Title'] = TriviaBot_Questions[id]['Title'];
879 TB_Question_Sets[id]['Description'] = TriviaBot_Questions[id]['Description'];
880 TB_Question_Sets[id]['Author'] = TriviaBot_Questions[id]['Author'];
881 TB_Question_Sets[id]['Categories'] = TriviaBot_Questions[id]['Categories'];
882 TriviaBot.IndexTrivia(id);
883 end
884end
885
886----------------------------------------------------------------------------
887-- Load trivia into trivia memory
888----------------------------------------------------------------------------
889function TriviaBot.LoadTrivia(setid, catid)
890 -- If we're running we need to skip the current question before hopping databases.
891 if (TB_Running) then
892 TriviaBot.AbortQuestion();
893 end
894
895 -- See if question-set and category exists
896 if (TB_Question_Sets[setid]) then
897 TB_Questions = TriviaBot_Questions[setid];
898 if (TB_Question_Sets[setid]['Categories'][catid] or catid == 0) then
899 TB_Question_List = TB_Question_Sets[setid]['CatIdx'][catid];
900 local category = L.TB_GUI_ALL;
901 if (catid ~= 0) then -- Single categories
902 category = TB_Question_Sets[setid]['Categories'][catid];
903 end
904 if (#TB_Questions['Question'] > 0) then
905 TriviaBot.Print(L.TB_PRINT_QUESTIONCOUNT .. #TB_Question_Sets[setid]['CatIdx'][catid]);--#TB_Questions['Question']);
906 if (TriviaBot_Config['Question_Set'] ~= setid) then
907 TriviaBot.Print(L.TB_PRINT_DATABASENAME .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']) .. L.TB_PRINT_HYPHENDESCRIPTION .. TB_Question_Sets[setid]['Description'].. L.TB_PRINT_HYPHENAUTHORS .. TB_Question_Sets[setid]['Author'] .. ".");
908 else
909 TriviaBot.Print(L.TB_PRINT_DATABASENAME .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']) .. L.TB_PRINT_HYPHENCATEGORY .. category .. L.TB_PRINT_BLANKLOADED);
910 end
911 else
912 TriviaBot.Print(L.TB_PRINT_DATABASENAME .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']) .. L.TB_PRINT_HYPHENCATEGORY .. category .. L.TB_PRINT_NOQUESTIONLOAD);
913 end
914
915 -- Always randomize the question order
916 TriviaBot.Randomize();
917 if (TB_Running)then
918 -- If we're switching databases mid-game, we should alert our players that the questions has changed
919 if not TB_limit_out then TriviaBot.Send(L.TB_PRINT_SWITCHDATABASE .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']) .. L.TB_PRINT_DOTDESCRIPTION .. TB_Question_Sets[setid]['Description'].. L.TB_PRINT_DOTAUTHOR .. TB_Question_Sets[setid]['Author'] .. "."); end
920 TriviaBot.Schedule("NEXT_QUESTION", TriviaBot_Config['Question_Interval']);
921 end
922 collectgarbage("collect") -- Do a cleanup
923 else
924 TriviaBot.Print(L.TB_PRINT_CATEGORYID..catid..L.TB_PRINT_NOTEXIST);
925 TriviaBot.Print(L.TB_PRINT_AVAILABLECATEGORIES);
926 TriviaBot.Print(L.TB_PRINT_ID0);
927 for id, cat in pairs(TB_Question_Sets[setid]['Categories']) do
928 TriviaBot.Print("ID: " .. id .. " - " .. cat);
929 end
930 end
931 else
932 TriviaBot.Print(L.TB_PRINT_QUESTIONSETID..setid..L.TB_PRINT_NOTEXIST);
933 TriviaBot.Print(L.TB_PRINT_LIBRARIES);
934 for id, set in pairs(TB_Question_Sets) do
935 TriviaBot.Print("ID: " .. id .. " - " .. set['Title']);
936 end
937 end
938end
939
940----------------------------------------------------------------------------
941-- Create new configuation
942----------------------------------------------------------------------------
943function TriviaBot.NewConfig(reset)
944 if (reset) then
945 TriviaBot_Config = {};
946 TriviaBot.Print(L.TB_PRINT_RESETCONFIG);
947 end
948
949 -- Default amount of answers shown (0 = all)
950 if (not TriviaBot_Config['Answers_Shown']) then TriviaBot_Config['Answers_Shown'] = 0; end
951
952 -- Default private channel (Trivia)
953 if (not TriviaBot_Config['Channel']) then TriviaBot_Config['Channel'] = "Trivia"; end
954
955 -- Default chat type (channel)
956 if (not TriviaBot_Config['Chat_Type']) then TriviaBot_Config['Chat_Type'] = "channel"; end
957
958 -- Using point-mode (true)
959 if (not TriviaBot_Config['Point_Mode']) then TriviaBot_Config['Point_Mode'] = true; end
960
961 -- Default question category (0 = all)
962 if (not TriviaBot_Config['Question_Category']) then TriviaBot_Config['Question_Category'] = 0; end
963
964 -- Default question interval (10 seconds)
965 if (not TriviaBot_Config['Question_Interval']) then TriviaBot_Config['Question_Interval'] = 10; end
966
967 -- Default question-set (1)
968 if (not TriviaBot_Config['Question_Set']) then TriviaBot_Config['Question_Set'] = 1; end
969
970 -- Default question timeout (45 seconds)
971 if (not TriviaBot_Config['Question_Timeout']) then TriviaBot_Config['Question_Timeout'] = 45; end
972
973 -- Report personal records (true)
974 if (not TriviaBot_Config['Report_Personal']) then TriviaBot_Config['Report_Personal'] = true; end
975
976 -- Report win streak updates (true)
977 if (not TriviaBot_Config['Report_Win_Streak']) then TriviaBot_Config['Report_Win_Streak'] = true; end
978
979 -- Defaults questions per round (0 = unlimited)
980 if (not TriviaBot_Config['Round_Size']) then TriviaBot_Config['Round_Size'] = TB_Infinite_Round; end
981
982 -- Use Short Channel Tag (false)
983 if (not TriviaBot_Config['Short_Tag']) then TriviaBot_Config['Short_Tag'] = false; end
984
985 -- Show answers (true)
986 if (not TriviaBot_Config['Show_Answers']) then TriviaBot_Config['Show_Answers'] = true; end
987
988 -- Show hints (true)
989 if (not TriviaBot_Config['Show_Hints']) then TriviaBot_Config['Show_Hints'] = true; end
990
991 -- Show reports (true)
992 if (not TriviaBot_Config['Show_Reports']) then TriviaBot_Config['Show_Reports'] = true; end
993
994 -- Show whispers (false)
995 if (not TriviaBot_Config['Show_Whispers']) then TriviaBot_Config['Show_Whispers'] = false; end
996
997 -- Default timeout warning (20 seconds)
998 if (not TriviaBot_Config['Timeout_Warning']) then TriviaBot_Config['Timeout_Warning'] = 20; end
999
1000 -- Top score count (5)
1001 if (not TriviaBot_Config['Top_Score_Count']) then TriviaBot_Config['Top_Score_Count'] = 5; end
1002
1003 -- Default top score interval (5 answers)
1004 if (not TriviaBot_Config['Top_Score_Interval']) then TriviaBot_Config['Top_Score_Interval'] = TB_Min_Topscore_Interval; end
1005
1006 -- Default Update interval. Tweaking may increase performance.
1007 if (not TriviaBot_Config['Update_Interval']) then TriviaBot_Config['Update_Interval'] = TB_Update_Interval; end
1008
1009 -- Store the version
1010 TriviaBot_Config.Version = TB_VERSION;
1011end
1012
1013function TriviaBot.InitEnd(self)
1014 TriviaBot.UpdateServerChannels()
1015 -- Initialize the GUI
1016 TriviaBot.GUIInitialize();
1017 TriviaBot.ChatSelect(TriviaBot_Config['Chat_Type'], TriviaBot_Config['Channel']);
1018 -- Register Events
1019 self:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE"); -- channel join/leave/suspend etc
1020 self:RegisterEvent("CHAT_MSG_SYSTEM"); -- Should the server report something important
1021 self:RegisterEvent("CHAT_MSG_WHISPER"); -- Enables whisper commands
1022 self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); -- Battleground check
1023 self:RegisterEvent("GUILD_ROSTER_UPDATE"); -- Guild check
1024 self:RegisterEvent("GROUP_ROSTER_UPDATE"); -- Party/Raid check
1025
1026 if not (TriviaBot_Config['Show_Whispers']) then
1027 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER",TriviaBot.MessageFilter)
1028 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM",TriviaBot.MessageFilter)
1029 else
1030 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER_INFORM",TriviaBot.MessageFilter)
1031 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER",TriviaBot.MessageFilter)
1032 end
1033 -- Set loaded state
1034 TB_Player_Entered = true;
1035end
1036
1037----------------------------------------------------------------------------
1038-- Print message in console
1039----------------------------------------------------------------------------
1040function TriviaBot.Print(msg)
1041 -- Check if the default frame exists
1042 if (DEFAULT_CHAT_FRAME) then
1043 -- Format the message
1044 msg = TB_MAGENTA .. TB_Channel_Prefix .. ": " .. TB_WHITE .. msg;
1045 DEFAULT_CHAT_FRAME:AddMessage(msg);
1046 end
1047end
1048
1049----------------------------------------------------------------------------
1050-- Print answers to the channel
1051----------------------------------------------------------------------------
1052function TriviaBot.PrintAnswers()
1053 if (TriviaBot_Config['Answers_Shown'] == 1 or #TB_Questions['Answers'][TB_Question_List[TB_Question_Order[TB_Active_Question]]] == 1) then
1054 TriviaBot.Send(L.TB_SEND_CORRECTANSWER .. TB_Questions['Answers'][TB_Question_List[TB_Question_Order[TB_Active_Question]]][1]);
1055 else
1056 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_CORRECTANSWERS); end
1057 if (TriviaBot_Config['Answers_Shown'] == 0) then
1058 for _,answer in pairs(TB_Questions['Answers'][TB_Question_List[TB_Question_Order[TB_Active_Question]]]) do
1059 TriviaBot.Send(answer);
1060 if TB_limit_out then break end
1061 end
1062 else
1063 local count = TriviaBot_Config['Answers_Shown'];
1064 if (#TB_Questions['Answers'][TB_Question_List[TB_Question_Order[TB_Active_Question]]] < count) then
1065 count = #TB_Questions['Answers'][TB_Question_List[TB_Question_Order[TB_Active_Question]]];
1066 end
1067 for i = 1, count, 1 do
1068 TriviaBot.Send(TB_Questions['Answers'][TB_Question_List[TB_Question_Order[TB_Active_Question]]][i]);
1069 if TB_limit_out then break end
1070 end
1071 end
1072 end
1073end
1074
1075----------------------------------------------------------------------------
1076-- Print Category List to the channel
1077----------------------------------------------------------------------------
1078function TriviaBot.PrintCategoryList()
1079 if TB_limit_out then return end
1080 local setid = TriviaBot_Config['Question_Set'];
1081 if not TriviaBot_Questions[setid]['Stub'] then
1082 TriviaBot.Send(L.TB_SEND_TITLE .. TriviaBot.Capitalize(TB_Question_Sets[setid]['Title']));
1083 end
1084 TriviaBot.Send(L.TB_SEND_DESCRIPTION .. TB_Question_Sets[setid]['Description']);
1085 TriviaBot.Send(L.TB_SEND_AUTHOR .. TB_Question_Sets[setid]['Author']);
1086 TriviaBot.Send(L.TB_SEND_CATEGORIESQUESTIONCOUNT);
1087 TriviaBot.Send(L.TB_SEND_0ALL .. #TriviaBot_Questions[setid]['Question'] .. ")");
1088 for id,_ in pairs(TB_Question_Sets[setid]['Categories']) do
1089 TriviaBot.Send("#" .. id .. ": " .. TB_Question_Sets[setid]['Categories'][id] .. " (" .. #TB_Question_Sets[setid]['CatIdx'][id] .. ")");
1090 end
1091end
1092
1093----------------------------------------------------------------------------
1094-- Print error message in console
1095----------------------------------------------------------------------------
1096function TriviaBot.PrintError(msg)
1097 -- Check if the default frame exists
1098 if (DEFAULT_CHAT_FRAME) then
1099 -- Format the message
1100 msg = TB_RED .. "[ERROR]" .. TB_Channel_Prefix .. ": " .. TB_WHITE .. msg;
1101 DEFAULT_CHAT_FRAME:AddMessage(msg);
1102 end
1103end
1104
1105----------------------------------------------------------------------------
1106-- Print Question List to the channel
1107----------------------------------------------------------------------------
1108function TriviaBot.PrintQuestionList()
1109 if TB_limit_out then return end
1110 TriviaBot.Send(L.TB_SEND_QUESTIONSETQUESTIONCOUNT);
1111 for id,_ in pairs(TB_Question_Sets) do
1112 if not TriviaBot_Questions[id]['Stub'] then
1113 TriviaBot.Send(L.TB_SEND_TITLE .. TriviaBot.Capitalize(TB_Question_Sets[id]['Title']) .. " (" .. #TriviaBot_Questions[id]['Question'] .. ")");
1114 end
1115 end
1116end
1117
1118----------------------------------------------------------------------------
1119-- Answers question and prepares next one
1120----------------------------------------------------------------------------
1121function TriviaBot.QuestionTimeout()
1122 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_TIMEUPNOANSWERS); end
1123 TriviaBot.EndQuestion(TriviaBot_Config['Show_Answers']);
1124end
1125
1126----------------------------------------------------------------------------
1127-- Randomize the trivia questions
1128----------------------------------------------------------------------------
1129function TriviaBot.Randomize()
1130 -- Initialise the table
1131 TB_Question_Order = {};
1132
1133 -- Number of questions
1134 local noq = #TB_Question_List;
1135
1136 -- Fill the order array
1137 for i = 1, noq, 1 do
1138 TB_Question_Order[i] = i;
1139 end
1140
1141 local temp, rand; -- Temporary value holders
1142 for j = 1, 5, 1 do -- Do the switch 5 times
1143 -- Swap each element with a random element
1144 for k = 1, noq, 1 do
1145 rand = math.random(noq);
1146 temp = TB_Question_Order[k];
1147 TB_Question_Order[k] = TB_Question_Order[rand]
1148 TB_Question_Order[rand] = temp;
1149 end
1150 end
1151end
1152
1153----------------------------------------------------------------------------
1154-- Register Chat Event
1155----------------------------------------------------------------------------
1156function TriviaBot.RegEvent(chat_type)
1157 if (chat_type == "channel") then
1158 TriviaBot:RegisterEvent("CHAT_MSG_CHANNEL");
1159 elseif (chat_type == "say") then
1160 TriviaBot:RegisterEvent("CHAT_MSG_SAY");
1161 elseif (chat_type == "general") then
1162 TriviaBot:RegisterEvent("CHAT_MSG_CHANNEL");
1163 elseif (chat_type == "guild") then
1164 TriviaBot:RegisterEvent("CHAT_MSG_GUILD");
1165 elseif (chat_type == "officer") then
1166 TriviaBot:RegisterEvent("CHAT_MSG_OFFICER");
1167 elseif (chat_type == "party") then
1168 TriviaBot:RegisterEvent("CHAT_MSG_PARTY");
1169 TriviaBot:RegisterEvent("CHAT_MSG_PARTY_LEADER");
1170 elseif (chat_type == "raid") then
1171 TriviaBot:RegisterEvent("CHAT_MSG_RAID");
1172 TriviaBot:RegisterEvent("CHAT_MSG_RAID_LEADER");
1173 elseif (chat_type == "instance_chat") then
1174 TriviaBot:RegisterEvent("CHAT_MSG_INSTANCE_CHAT");
1175 TriviaBot:RegisterEvent("CHAT_MSG_INSTANCE_CHAT_LEADER");
1176 else
1177 TriviaBot.Print(L.TB_PRINT_NOCHATEVENTS);
1178 end
1179end
1180
1181----------------------------------------------------------------------------
1182-- Print report to the channel
1183----------------------------------------------------------------------------
1184function TriviaBot.Report(type)
1185 if TB_limit_out and type ~= "endreport" then return end
1186 local Sorted_Scores = {};
1187 local exists;
1188 local limit = TriviaBot_Config['Top_Score_Count']
1189 if (type == "alltimereport") then
1190 for player, scores in pairs(TriviaBot_Scores['Player_Scores']) do
1191 exists = true;
1192 table.insert(Sorted_Scores, {['Player'] = player, ['Points'] = scores['Points'], ['Score'] = scores['Score']});
1193 end
1194
1195 if (exists) then
1196 if (TriviaBot_Config['Point_Mode']) then
1197 table.sort(Sorted_Scores, function(v1, v2)
1198 if (v1['Points'] == v2['Points']) then
1199 return v1['Score'] > v2['Score'];
1200 else
1201 return v1['Points'] > v2['Points'];
1202 end
1203 end);
1204 else
1205 table.sort(Sorted_Scores, function(v1, v2)
1206 if (v1['Score'] == v2['Score']) then
1207 return v1['Points'] > v2['Points'];
1208 else
1209 return v1['Score'] > v2['Score'];
1210 end
1211 end)
1212 end
1213 if (limit > #Sorted_Scores) then
1214 limit = #Sorted_Scores;
1215 end
1216 TriviaBot.Send(L.TB_SEND_ALLTIMESTANDINGS);
1217 for i = 1, limit, 1 do
1218 local pess = "s";
1219 local sess = "s";
1220 if (Sorted_Scores[i]['Points'] == 1) then
1221 pess = "";
1222 end
1223 if (Sorted_Scores[i]['Score'] == 1) then
1224 sess = "";
1225 end
1226 TriviaBot.Send("#" .. i .. ": " .. Sorted_Scores[i]['Player'] .. L.TB_SEND_BLANKWITH .. Sorted_Scores[i]['Points'] .. L.TB_SEND_BLANKPOINT .. pess .. L.TB_SEND_BLANKAND .. Sorted_Scores[i]['Score'] .. L.TB_SEND_BLANKANSWER .. sess .. ".");
1227 end
1228 if (TriviaBot_Scores['Speed']['Holder']) then
1229 TriviaBot.Send(L.TB_SEND_SPEEDRECORD .. TriviaBot_Scores['Speed']['Holder'] .. L.TB_SEND_BLANKIN .. TriviaBot_Scores['Speed']['Time'] .. L.TB_SEND_BLANKSECONDS);
1230 end
1231 if (TriviaBot_Scores['Win_Streak']['Holder']) then
1232 TriviaBot.Send(L.TB_SEND_WINSTREAK .. TriviaBot_Scores['Win_Streak']['Holder'] .. L.TB_SEND_BLANKWITH .. TriviaBot_Scores['Win_Streak']['Count'] .. L.TB_SEND_BLANKINAROW);
1233 end
1234 else
1235 TriviaBot.Send(L.TB_SEND_NOALLTIMESCORE);
1236 end
1237 else
1238 for player, scores in pairs(TB_Game_Scores['Player_Scores']) do
1239 exists = true;
1240 table.insert(Sorted_Scores, {['Player'] = player, ['Points'] = scores['Points'], ['Score'] = scores['Score']});
1241 end
1242
1243 if (exists) then
1244 if (TriviaBot_Config['Point_Mode']) then
1245 table.sort(Sorted_Scores, function(v1, v2)
1246 if (v1['Points'] == v2['Points']) then
1247 return v1['Score'] > v2['Score'];
1248 else
1249 return v1['Points'] > v2['Points'];
1250 end
1251 end);
1252 else
1253 table.sort(Sorted_Scores, function(v1, v2)
1254 if (v1['Score'] == v2['Score']) then
1255 return v1['Points'] > v2['Points'];
1256 else
1257 return v1['Score'] > v2['Score'];
1258 end
1259 end)
1260 end
1261 if (type == "gamereport") then
1262 TriviaBot.Send(L.TB_SEND_STANDINGS);
1263 elseif (type == "midreport") then
1264 TriviaBot.Send(L.TB_SEND_MIDSTANDINGS);
1265 limit = 3;
1266 elseif (type == "endreport") then
1267 TriviaBot.Send(L.TB_SEND_FINALSTANDINGS);
1268 if TB_limit_out then limit = 1 end
1269 end
1270 if (limit > #Sorted_Scores) then
1271 limit = #Sorted_Scores;
1272 end
1273 for i = 1, limit, 1 do
1274 local pess = "s";
1275 local sess = "s";
1276 if (Sorted_Scores[i]['Points'] == 1) then
1277 pess = "";
1278 end
1279 if (Sorted_Scores[i]['Score'] == 1) then
1280 sess = "";
1281 end
1282 if (TriviaBot_Config['Point_Mode']) then
1283 TriviaBot.Send("#" .. i .. ": " .. Sorted_Scores[i]['Player'] .. L.TB_SEND_BLANKWITH .. Sorted_Scores[i]['Points'] .. " (" .. Sorted_Scores[i]['Score'] .. ")"..L.TB_SEND_BLANKPOINT .. pess .. ".");
1284 else
1285 TriviaBot.Send("#" .. i .. ": " .. Sorted_Scores[i]['Player'] .. L.TB_SEND_BLANKWITH .. Sorted_Scores[i]['Score'] .. L.TB_SEND_BLANKPOINT .. sess .. ".");
1286 end
1287 end
1288 if (TB_Game_Scores['Speed']['Holder']) then
1289 TriviaBot.Send(L.TB_SEND_SPEEDRECORD .. TB_Game_Scores['Speed']['Holder'] .. L.TB_SEND_BLANKIN .. TB_Game_Scores['Speed']['Time'] .. L.TB_SEND_BLANKSECONDS);
1290 end
1291 if (TB_Game_Scores['Best_Win_Streak']['Holder']) then
1292 TriviaBot.Send(L.TB_SEND_WINSTREAK .. TB_Game_Scores['Best_Win_Streak']['Holder'] .. L.TB_SEND_BLANKWITH .. TB_Game_Scores['Best_Win_Streak']['Count'] .. L.TB_SEND_BLANKINAROW);
1293 end
1294 else
1295 if (type == "gamereport") then
1296 TriviaBot.Send(L.TB_SEND_NOSCOREFOUND);
1297 elseif (type == "midreport") then
1298 TriviaBot.Send(L.TB_SEND_NOPOINTSEARNED);
1299 elseif (type == "endreport") then
1300 TriviaBot.Send(L.TB_SEND_FINALNOSCORE);
1301 end
1302 end
1303 end
1304end
1305
1306----------------------------------------------------------------------------
1307-- Check if string is restricted
1308----------------------------------------------------------------------------
1309function TriviaBot.RestrictionCheck(str, list)
1310 for _, word in ipairs(list) do
1311 if (str == word) then
1312 return false;
1313 end
1314 end
1315 return true;
1316end
1317
1318----------------------------------------------------------------------------
1319-- Schedule an event
1320----------------------------------------------------------------------------
1321function TriviaBot.Schedule(name, time)
1322 local thisEvent = {['name'] = name, ['time'] = GetTime() + time};
1323 table.insert(TB_Schedule, thisEvent);
1324end
1325
1326----------------------------------------------------------------------------
1327-- Send a TriviaBot message to the channel
1328----------------------------------------------------------------------------
1329function TriviaBot.Send(msg)
1330 -- Send a message to the trivia channel
1331 msg = TB_Channel_Prefix .. ": " .. msg; -- Add the trivia tag to each message
1332 local cid = GetChannelName(TriviaBot_Config['Channel']); -- Custom channel id
1333 local gdata = TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]]
1334 local gid = gdata and gdata["id"] or 0; -- General channel id
1335 if (TriviaBot_Config['Chat_Type'] ~= "channel" and TriviaBot_Config['Chat_Type'] ~= "general") then
1336 SendChatMessage(msg, string.upper(TriviaBot_Config['Chat_Type']));
1337 elseif (TriviaBot_Config['Chat_Type'] == "channel" and cid > 0) then
1338 SendChatMessage(msg, "CHANNEL", nil, cid);
1339 elseif (TriviaBot_Config['Chat_Type'] == "general" and gid > 0) then
1340 SendChatMessage(msg, "CHANNEL", nil, gid);
1341 else
1342 -- Print error if no valid channels were found
1343 TriviaBot.PrintError(L.TB_ERROR_NOVALIDCHANNEL);
1344 end
1345end
1346
1347----------------------------------------------------------------------------
1348-- Send a whisper message back to the player
1349----------------------------------------------------------------------------
1350function TriviaBot.SendWhisper(player, msg)
1351 msg = TB_Short_Prefix .. ": " .. msg; -- Add a more diskrete trivia tag to the message
1352 SendChatMessage(msg, "WHISPER", nil, player);
1353end
1354
1355----------------------------------------------------------------------------
1356-- Skip current question
1357----------------------------------------------------------------------------
1358function TriviaBot.SkipQuestion()
1359 TriviaBotGUI.SkipButton:Disable();
1360 if (TB_Running) then
1361 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_QUESTIONSKIPPED); end
1362 TriviaBot.UnSchedule("all");
1363 TB_Accept_Answers = false;
1364
1365 -- Show the answer anyway (for those that wanted to know)
1366 if (TriviaBot_Config['Show_Answers']) then
1367 TriviaBot.Schedule("SHOW_ANSWER", TB_Min_Interval);
1368 end
1369
1370 -- Schedule the next question
1371 TriviaBot.Schedule("NEXT_QUESTION", TriviaBot_Config['Question_Interval']);
1372 TriviaBot.Print(L.TB_PRINT_QUESTIONSKIP);
1373 else
1374 TriviaBot.PrintError(L.TB_ERROR_NOGAME);
1375 end
1376end
1377
1378----------------------------------------------------------------------------
1379-- Start trivia session
1380----------------------------------------------------------------------------
1381function TriviaBot.Start(announce)
1382 local id = TriviaBot_Config['Question_Set'];
1383 if TriviaBot_Questions[id]['Stub'] and not TriviaBot.questionmaker then
1384 TriviaBot.PrintError(L.TB_ERROR_NOLOADED)
1385 return
1386 end -- not yet loaded set
1387 -- Set Running
1388 TB_Running = true;
1389
1390 -- Check if the channel is present
1391 TriviaBot.CheckChannel();
1392
1393 TB_limit_out = TriviaBot_Config['Chat_Type']
1394 TB_limit_out = strlower(TB_limit_out)=="general" and true or false
1395 -- Announce the start
1396 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_POWEREDBY); end
1397 local category;
1398 if (TriviaBot_Config['Question_Category'] ~= 0) then
1399 category = TB_Question_Sets[id]['Categories'][TriviaBot_Config['Question_Category']];
1400 else
1401 category = L.TB_GUI_ALL;
1402 end
1403 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_USINGDATABASE .. TB_Question_Sets[id]['Title']); end
1404 if (announce and not TB_limit_out) then -- todo: config this
1405 TriviaBot.Send(L.TB_SEND_DESCRIPTION .. TB_Question_Sets[id]['Description']);
1406 TriviaBot.Send(L.TB_SEND_AUTHOR .. TB_Question_Sets[id]['Author']);
1407 TriviaBot.Send(L.TB_SEND_CATEGORYSELECTED .. category);
1408 end
1409 if (TriviaBot_Config['Round_Size'] ~= TB_Infinite_Round) then
1410 if not TB_limit_out then TriviaBot.Send(L.TB_SEND_STARTROUND .. TriviaBot_Config['Round_Size'] .. L.TB_SEND_BLANKQUESTIONS); end
1411 end
1412 if (announce) then -- todo: config this
1413 TriviaBot.Print(L.TB_PRINT_FIRSTQUESTION);
1414 end
1415
1416 -- Schedule start
1417 TriviaBot.Schedule("NEXT_QUESTION", TB_Min_Interval);
1418
1419 -- Clear game scores
1420 TB_Game_Scores = {};
1421 TB_Game_Scores['Best_Win_Streak'] = {};
1422 TB_Game_Scores['Temp_Win_Streak'] = {};
1423 TB_Game_Scores['Speed'] = {};
1424 TB_Game_Scores['Player_Scores'] = {};
1425
1426 if (not TriviaBot_Scores) then
1427 TriviaBot_Scores = {};
1428 end
1429 if (not TriviaBot_Scores['Win_Streak']) then
1430 TriviaBot_Scores['Win_Streak'] = {};
1431 end
1432 if (not TriviaBot_Scores['Speed']) then
1433 TriviaBot_Scores['Speed'] = {};
1434 end
1435 if (not TriviaBot_Scores['Player_Scores']) then
1436 TriviaBot_Scores['Player_Scores'] = {};
1437 end
1438
1439 -- Reset Round and Report Counters
1440 TB_Report_Counter = 0;
1441 TB_Round_Counter = 0;
1442
1443 -- GUI Update
1444 TriviaBotGUI.StartStopToggle();
1445end
1446
1447----------------------------------------------------------------------------
1448-- Check if str starts with start
1449----------------------------------------------------------------------------
1450function TriviaBot.Starts(str, start)
1451 return string.sub(str,1,string.len(start)) == start;
1452end
1453
1454----------------------------------------------------------------------------
1455-- Start/Stop Toggle
1456----------------------------------------------------------------------------
1457function TriviaBot.StartStopToggle()
1458 if(TB_Running) then
1459 TriviaBot.Stop(true);
1460 else
1461 TriviaBot.Start();
1462 end
1463end
1464
1465----------------------------------------------------------------------------
1466-- QuestionMaker Toggle (if the optional addon is loaded)
1467----------------------------------------------------------------------------
1468function TriviaBot.QuestionMakerToggle(self,button)
1469 if TriviaBot_QuestionMakerGUI:IsShown() then
1470 TriviaBot_QuestionMakerGUI:Hide()
1471 else
1472 TriviaBot_QuestionMakerGUI:ClearAllPoints()
1473 local side = findSide(TriviaBotGUI_Header)
1474 TriviaBotGUI_Header:ClearAllPoints()
1475 if side == "left" then
1476 TriviaBot_QuestionMakerGUI:SetPoint("TOPRIGHT",TriviaBotGUI_Header,"TOPLEFT",0,-32)
1477 else
1478 TriviaBot_QuestionMakerGUI:SetPoint("TOPLEFT",TriviaBotGUI_Header,"TOPRIGHT",0,-32)
1479 end
1480 TriviaBot_QuestionMakerGUI:Show()
1481 end
1482end
1483
1484function TriviaBot.ReloadQuestionsOnClick(self,button)
1485 TB_Question_Sets = {}
1486 TriviaBot.LoadQuestionSets()
1487 TriviaBot.LoadTrivia(TriviaBot_Config['Question_Set'], TriviaBot_Config['Question_Category'])
1488 self:Hide()
1489 TriviaBot.questionmaker = nil
1490 TriviaBotGUI.Update();
1491end
1492
1493function API.GUIUpdate()
1494 -- wrapper function for use by quizmaker
1495 TriviaBotGUI.Update()
1496end
1497
1498function API.LoadQuestionMakerSet()
1499 if next(_G["TriviaBotQuestionMakerExports"]["ActiveSet"]) then
1500 TB_Question_Sets = {}
1501 TB_Question_Sets = deepcopy(_G["TriviaBotQuestionMakerExports"]["ActiveSet"])
1502 TB_Questions = TB_Question_Sets[1];
1503 TB_Questions['Title'] = "QMaker:"..TB_Question_Sets[1]['Title'];
1504 if (not TB_Questions['CatIdx']) then
1505 TB_Questions['CatIdx'] = {[0] = {}};
1506 for id,_ in pairs(TB_Questions['Categories']) do
1507 TB_Questions['CatIdx'][id] = {};
1508 end
1509 for id,_ in pairs(TB_Questions['Question']) do
1510 table.insert(TB_Questions['CatIdx'][0], id);
1511 local catid = TB_Questions['Category'][id];
1512 if (TB_Questions['CatIdx'][catid]) then
1513 table.insert(TB_Questions['CatIdx'][catid], id);
1514 end
1515 end
1516 end
1517 TriviaBot_Config['Question_Set'] = 1;
1518 TriviaBot_Config['Question_Category'] = 0;
1519 TB_Question_List = TB_Questions['CatIdx'][0]
1520 local category = L.TB_GUI_ALL;
1521 if (#TB_Questions['Question'] > 0) then
1522 TriviaBot.Print(L.TB_PRINT_QUESTIONCOUNT .. #TB_Questions['Question'])
1523 TriviaBot.Print(L.TB_PRINT_DATABASENAME .. TriviaBot.Capitalize(TB_Questions['Title']) .. L.TB_PRINT_HYPHENCATEGORY .. category .. L.TB_PRINT_BLANKLOADED);
1524 else
1525 TriviaBot.Print(L.TB_PRINT_DATABASENAME .. TriviaBot.Capitalize(TB_Questions['Title']) .. L.TB_PRINT_HYPHENCATEGORY .. category .. L.TB_PRINT_NOQUESTIONLOAD);
1526 end
1527 -- Always randomize the question order
1528 TriviaBot.Randomize();
1529 if (TB_Running)then
1530 -- If we're switching databases mid-game, we should alert our players that the questions has changed
1531 TriviaBot.Send(L.TB_SEND_SWITCHDATABASE .. TriviaBot.Capitalize(TB_Questions['Title']) .. L.TB_PRINT_DOTDESCRIPTION .. TB_Questions['Description'].. L.TB_PRINT_DOTAUTHOR .. TB_Questions['Author'] .. ".");
1532 TriviaBot.Schedule("NEXT_QUESTION", TriviaBot_Config['Question_Interval']);
1533 end
1534 collectgarbage("collect") -- Do a cleanup
1535 TriviaBotGUI.ReloadQuestionsButton:Show();
1536 TriviaBot.questionmaker = true
1537 end
1538end
1539
1540----------------------------------------------------------------------------
1541-- Stop trivia session
1542----------------------------------------------------------------------------
1543function TriviaBot.Stop(announce)
1544 -- Clear all scheduled events
1545 TriviaBot.UnSchedule("all");
1546 TB_Accept_Answers = false;
1547 TB_Running = false;
1548
1549 if (announce) then
1550 TriviaBot.Send(L.TB_PRINT_TRIVIASTOPPED);
1551 end
1552 TriviaBot.Print(L.TB_PRINT_TRIVIASTOPPED)
1553
1554 -- GUI Update
1555 TriviaBotGUI.StartStopToggle();
1556end
1557
1558----------------------------------------------------------------------------
1559-- Extracts name from links
1560-- Removes leading/trailing spaces and punctuation chars from the string
1561----------------------------------------------------------------------------
1562function TriviaBot.StringCorrection(str)
1563 -- Strip name out of links
1564 str = strmatch(str,"|h%[(.-)%]|h|r") or str
1565 -- Remove whitespaces
1566 str = str:gsub("^%s*(.-)%s*$", "%1");
1567 -- Remove punctuation
1568 str = str:gsub("^%p*(.-)%p*$", "%1");
1569 return str;
1570end
1571
1572----------------------------------------------------------------------------
1573-- Unregister Chat Event
1574----------------------------------------------------------------------------
1575function TriviaBot.UnregEvent(chat_type)
1576 if (chat_type == "channel") then
1577 TriviaBot:UnregisterEvent("CHAT_MSG_CHANNEL");
1578 elseif (chat_type == "say") then
1579 TriviaBot:UnregisterEvent("CHAT_MSG_SAY");
1580 elseif (chat_type == "general") then
1581 TriviaBot:UnregisterEvent("CHAT_MSG_CHANNEL");
1582 elseif (chat_type == "guild") then
1583 TriviaBot:UnregisterEvent("CHAT_MSG_GUILD");
1584 elseif (chat_type == "officer") then
1585 TriviaBot:UnregisterEvent("CHAT_MSG_OFFICER");
1586 elseif (chat_type == "party") then
1587 TriviaBot:UnregisterEvent("CHAT_MSG_PARTY");
1588 TriviaBot:UnregisterEvent("CHAT_MSG_PARTY_LEADER");
1589 elseif (chat_type == "raid") then
1590 TriviaBot:UnregisterEvent("CHAT_MSG_RAID");
1591 TriviaBot:UnregisterEvent("CHAT_MSG_RAID_LEADER");
1592 elseif (chat_type == "instance_chat") then
1593 TriviaBot:UnregisterEvent("CHAT_MSG_INSTANCE_CHAT");
1594 TriviaBot:UnregisterEvent("CHAT_MSG_INSTANCE_CHAT_LEADER");
1595 else
1596 TriviaBot.Print(L.TB_PRINT_NOCHATEVENTSUNREG);
1597 end
1598end
1599
1600----------------------------------------------------------------------------
1601-- Removes an event from the schedule
1602----------------------------------------------------------------------------
1603function TriviaBot.UnSchedule(id)
1604 -- Unschedule an event
1605 if (id == "all") then
1606 TB_Schedule = {};
1607 else
1608 table.remove(TB_Schedule, id);
1609 end
1610end
1611
1612----------------------------------------------------------------------------
1613-- Whisper command handler
1614----------------------------------------------------------------------------
1615function TriviaBot.WhisperControl(player, msg)
1616 -- Create variables
1617 local msgArgs = {};
1618
1619 -- Seperate our args
1620 for value in string.gmatch(msg, "[^ ]+") do
1621 table.insert(msgArgs, value);
1622 end
1623
1624 if TriviaBot.Starts(msg, string.lower(TB_Message_Prefix)) then
1625 if (msgArgs[2] == "help") then
1626 TriviaBot.SendWhisper(player, "Help Menu:");
1627 TriviaBot.SendWhisper(player, "!tb help - For this help menu.");
1628 TriviaBot.SendWhisper(player, "!tb info - Info about the current game.");
1629 TriviaBot.SendWhisper(player, "!tb score - Score help menu.");
1630 elseif (msgArgs[2] == "info") then
1631 TriviaBot.SendWhisper(player, "Title: " .. TB_Question_Sets[TriviaBot_Config['Question_Set']]['Title']);
1632 if (TriviaBot_Config['Question_Category'] == 0) then
1633 TriviaBot.SendWhisper(player, "Category: All");
1634 else
1635 TriviaBot.SendWhisper(player, "Category: " .. TB_Question_Sets[TriviaBot_Config['Question_Set']]['Categories'][TriviaBot_Config['Question_Category']]);
1636 end
1637 if (TB_Running) then
1638 if (TriviaBot_Config['Round_Size'] ~= TB_Infinite_Round) then
1639 TriviaBot.SendWhisper(player, "Round Size: " .. TriviaBot_Config['Round_Size']);
1640 TriviaBot.SendWhisper(player, "Current Round: " .. TB_Round_Counter + 1);
1641 else
1642 TriviaBot.SendWhisper(player, "Round Size: Unlimited");
1643 end
1644 else
1645 TriviaBot.SendWhisper(player, "No games currently running");
1646 end
1647 elseif (msgArgs[2] == "score") then
1648 if (msgArgs[3] == "game") then
1649 if (TB_Game_Scores['Player_Scores'][player]) then
1650 TriviaBot.SendWhisper(player, "Speed Record: " .. TB_Game_Scores['Player_Scores'][player]['Speed']);
1651 TriviaBot.SendWhisper(player, "Win Streak Record: " .. TB_Game_Scores['Player_Scores'][player]['Win_Streak']);
1652 TriviaBot.SendWhisper(player, "Points: " .. TB_Game_Scores['Player_Scores'][player]['Points']);
1653 TriviaBot.SendWhisper(player, "Score: " .. TB_Game_Scores['Player_Scores'][player]['Score']);
1654 else
1655 TriviaBot.SendWhisper(player, "No current game scores found.");
1656 end
1657 elseif (msgArgs[3] == "alltime") then
1658 if (TriviaBot_Scores['Player_Scores'][player]) then
1659 TriviaBot.SendWhisper(player, "Speed Record: " .. TriviaBot_Scores['Player_Scores'][player]['Speed']);
1660 TriviaBot.SendWhisper(player, "Win Streak Record: " .. TriviaBot_Scores['Player_Scores'][player]['Win_Streak']);
1661 TriviaBot.SendWhisper(player, "Points: " .. TriviaBot_Scores['Player_Scores'][player]['Points']);
1662 TriviaBot.SendWhisper(player, "Score: " .. TriviaBot_Scores['Player_Scores'][player]['Score']);
1663 else
1664 TriviaBot.SendWhisper(player, "No all-time scores found.");
1665 end
1666 else
1667 TriviaBot.SendWhisper(player, "Score Help Menu:");
1668 TriviaBot.SendWhisper(player, "!tb score game - For your current (or previous) game scores:");
1669 TriviaBot.SendWhisper(player, "!tb score alltime - For your all-time scores");
1670 end
1671 else
1672 TriviaBot.SendWhisper(player, "Help Menu:");
1673 TriviaBot.SendWhisper(player, "!tb help - For this help menu.");
1674 TriviaBot.SendWhisper(player, "!tb info - Info about the current game.");
1675 TriviaBot.SendWhisper(player, "!tb score - Score help menu.");
1676 end
1677 end
1678end
1679
1680----------------------------------------------------------------------------
1681-- GUI functions
1682----------------------------------------------------------------------------
1683
1684----------------------------------------------------------------------------
1685-- Initialize all GUI objects
1686----------------------------------------------------------------------------
1687-- If you want a control to have a help tooltip add a .toolTip key
1688-- to the frame and set the string you want to appear there and
1689-- OnEnter/OnLeave scripts.
1690-- Example:
1691-- myEditbox.toolTip = "My localized help string";
1692-- myEditbox:SetScript("OnEnter", TriviaBotGUI.OnMouseEnter);
1693-- myEditbox:SetScript("OnLeave", GameTooltip_Hide);
1694function TriviaBot.GUIInitialize()
1695 local editboxspace = 8;
1696 local checkboxspace = 5;
1697
1698 TriviaBotGUI.OnMouseEnter = function(self)
1699 if self.toolTip then
1700 GameTooltip:SetOwner(self, "ANCHOR_TOP")
1701 GameTooltip:SetText(self.toolTip, nil, nil, nil, 1.0)
1702 end
1703 end
1704 TriviaBotGUI.EditBox_Highlight = function(self)
1705 self:HighlightText(0,0); -- We don't want any highlighting
1706 end
1707 -- Header Frame for dragging and minimizing
1708 TriviaBotGUI_Header:SetWidth(tonumber(L.TB_GUI_WIDTH));
1709 TriviaBotGUI_Header:SetHeight(31);
1710 TriviaBotGUI_Header:SetBackdrop(
1711 {
1712 bgFile = "Interface/Tooltips/UI-Tooltip-Background",
1713 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
1714 tile = true, tileSize = 16, edgeSize = 16,
1715 insets = {left = 5, right = 5, top = 5, bottom = 5}
1716 });
1717 TriviaBotGUI_Header:SetBackdropColor(0,0,0,1);
1718 TriviaBotGUI_Header:SetFrameStrata("BACKGROUND");
1719 TriviaBotGUI_Header:SetClampedToScreen(true);
1720 TriviaBotGUI_Header:SetClampRectInsets(-5,5,5,-50);
1721 TriviaBotGUI_Header:SetPoint("TOP", 0, -200);
1722 TriviaBotGUI_Header:EnableMouse(true);
1723 TriviaBotGUI_Header:SetMovable(true);
1724 TriviaBotGUI_Header:RegisterForDrag("LeftButton");
1725 TriviaBotGUI_Header.toolTip = L.TB_GUI_PANELCONTROL_TIP;
1726 TriviaBotGUI_Header:SetScript("OnDragStart", TriviaBotGUI_Header.StartMoving);
1727 TriviaBotGUI_Header:SetScript("OnDragStop", TriviaBotGUI_Header.StopMovingOrSizing);
1728 TriviaBotGUI_Header:SetScript("OnHide", TriviaBotGUI_Header.StopMovingOrSizing);
1729 TriviaBotGUI_Header:SetScript("OnShow", TriviaBotGUI.Show);
1730 TriviaBotGUI_Header:SetScript("OnMouseDown",
1731 function(_,button)
1732 if button == "LeftButton" then
1733 if IsDoubleClick(GetTime()) then
1734 if TriviaBotGUI:IsShown() then TriviaBotGUI:Hide() else TriviaBotGUI:Show() end
1735 end
1736 end
1737 end)
1738 TriviaBotGUI_Header:SetScript("OnEnter", TriviaBotGUI.OnMouseEnter);
1739 TriviaBotGUI_Header:SetScript("OnLeave", GameTooltip_Hide);
1740 tinsert(UISpecialFrames, "TriviaBotGUI_Header");
1741 TriviaBotGUI_Header:Hide();
1742
1743 TriviaBotGUI.HeaderLabel = TriviaBotGUI_Header:CreateFontString(nil, "ARTWORK", "GameFontNormal");
1744 TriviaBotGUI.HeaderLabel:ClearAllPoints();
1745 TriviaBotGUI.HeaderLabel:SetPoint("TOP", TriviaBotGUI_Header, "TOP", 0, -8);
1746
1747 -- Close Button
1748 TriviaBotGUI.CloseButton = CreateFrame("Button", nil, TriviaBotGUI_Header, "UIPanelCloseButton");
1749 TriviaBotGUI.CloseButton:ClearAllPoints();
1750 TriviaBotGUI.CloseButton:SetPoint("TOPRIGHT", TriviaBotGUI_Header, "TOPRIGHT", 0, 0);
1751 TriviaBotGUI.CloseButton:SetScript("OnClick", function() TriviaBotGUI_Header:Hide() end);
1752 TriviaBotGUI.CloseButton.toolTip = L.TB_GUI_CLOSE_TIP;
1753 TriviaBotGUI.CloseButton:SetScript("OnEnter", TriviaBotGUI.OnMouseEnter);
1754 TriviaBotGUI.CloseButton:SetScript("OnLeave", GameTooltip_Hide);
1755
1756 -- Set the main GUI screen
1757 TriviaBotGUI:ClearAllPoints();
1758 TriviaBotGUI:SetWidth(tonumber(L.TB_GUI_WIDTH));
1759 TriviaBotGUI:SetHeight(445);
1760 TriviaBotGUI:SetBackdrop(
1761 {
1762 bgFile = "Interface/Tooltips/UI-Tooltip-Background",
1763 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
1764 tile = true, tileSize = 32, edgeSize = 16,
1765 insets = {left = 5, right = 5, top = 5, bottom = 5}
1766 });
1767 TriviaBotGUI:SetBackdropColor(0,0,0,1);
1768 TriviaBotGUI:SetFrameLevel(TriviaBotGUI_Header:GetFrameLevel()-1);
1769 TriviaBotGUI:SetPoint("TOPLEFT", TriviaBotGUI_Header, "BOTTOMLEFT");
1770
1771 -- Question List
1772 TriviaBotGUI.QuestionList = CreateFrame("Frame", "TriviaBotGUI_QuestionList", TriviaBotGUI, "Lib_UIDropDownMenuTemplate");
1773 TriviaBotGUI.QuestionList.OnClick = function(self)
1774 local set = self.value;
1775 if TriviaBot_Questions[set]['Stub'] then
1776 local questionPack = TriviaBot_QuestionPacks[set]
1777 if questionPack then
1778 local loaded, reason = LoadAddOn(questionPack)
1779 if not loaded then
1780 TriviaBot.PrintError(questionPack..":".._G["ADDON_"..reason])
1781 else
1782 TriviaBot_Questions[set]['Stub'] = nil;
1783 TriviaBot_Questions[set]={};
1784 TriviaBot_Questions[set]=_G[questionPack]["QuestionList"]
1785 TriviaBot.LoadQuestionSets();
1786 end
1787 end
1788 end
1789 if (TB_Question_Sets[set]) then
1790 if not TriviaBot.questionmaker then
1791 TriviaBot.LoadTrivia(set, 0); -- 'All' category
1792 end
1793 TriviaBot_Config['Question_Set'] = set;
1794 TriviaBot_Config['Question_Category'] = 0;
1795 end
1796
1797 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.QuestionList, TriviaBot_Config['Question_Set']);
1798 Lib_UIDropDownMenu_SetText(TriviaBotGUI.QuestionList, TriviaBot.Capitalize(TB_Question_Sets[TriviaBot_Config['Question_Set']]['Title']))
1799 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.CategoryList, 0);
1800 Lib_UIDropDownMenu_SetText(TriviaBotGUI.CategoryList, L.TB_GUI_ALL)
1801 end
1802 TriviaBotGUI.QuestionList.Initialize = function()
1803 local info;
1804
1805 for id,_ in pairs(TB_Question_Sets) do
1806 info = Lib_UIDropDownMenu_CreateInfo();
1807 info.value = id;
1808 info.text = TriviaBot.Capitalize(TB_Question_Sets[id]['Title']);
1809 info.func = TriviaBotGUI.QuestionList.OnClick;
1810 Lib_UIDropDownMenu_AddButton(info);
1811 end
1812
1813 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.QuestionList, TriviaBot_Config['Question_Set']);
1814 Lib_UIDropDownMenu_SetText(TriviaBotGUI.QuestionList, TriviaBot.Capitalize(TB_Question_Sets[TriviaBot_Config['Question_Set']]['Title']))
1815 end
1816 TriviaBotGUI.QuestionList:ClearAllPoints();
1817 Lib_UIDropDownMenu_SetWidth(TriviaBotGUI.QuestionList, 150);
1818 Lib_UIDropDownMenu_SetButtonWidth(TriviaBotGUI.QuestionList, 20);
1819 TriviaBotGUI.QuestionList:SetPoint("TOPLEFT", TriviaBotGUI, "TOP", -35, -20);
1820 Lib_UIDropDownMenu_Initialize(TriviaBotGUI.QuestionList, TriviaBotGUI.QuestionList.Initialize);
1821 -- Question List Label
1822 TriviaBotGUI.QuestionList.Label = TriviaBotGUI.QuestionList:CreateFontString(nil, "ARTWORK", "GameFontNormal");
1823 TriviaBotGUI.QuestionList.Label:ClearAllPoints();
1824 TriviaBotGUI.QuestionList.Label:SetText(L.TB_GUI_QUESTIONLIST);
1825 TriviaBotGUI.QuestionList.Label:SetPoint("RIGHT", TriviaBotGUI.QuestionList, "LEFT", 10, 2);
1826 -- Question List Print Button
1827 TriviaBotGUI.QuestionList.PrintButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
1828 TriviaBotGUI.QuestionList.PrintButton:ClearAllPoints();
1829 TriviaBotGUI.QuestionList.PrintButton:SetWidth(tonumber(L.TB_GUI_PRINT_WIDTH));
1830 TriviaBotGUI.QuestionList.PrintButton:SetText(L.TB_GUI_PRINT);
1831 TriviaBotGUI.QuestionList.PrintButton:SetPoint("TOPLEFT", TriviaBotGUI, "TOPLEFT", 15, -25);
1832 TriviaBotGUI.QuestionList.PrintButton:SetScript("OnClick", TriviaBot.PrintQuestionList);
1833
1834 -- Category List
1835 TriviaBotGUI.CategoryList = CreateFrame("Frame", "TriviaBotGUI_CategoryList", TriviaBotGUI, "Lib_UIDropDownMenuTemplate");
1836 TriviaBotGUI.CategoryList.OnClick = function(self)
1837 local cat = self.value;
1838 local set = TriviaBot_Config['Question_Set'];
1839
1840 if ((TB_Question_Sets[set]['Categories'][cat] or cat == 0) and cat ~= TriviaBot_Config['Question_Category']) then
1841 if not TriviaBot.questionmaker then
1842 TriviaBot.LoadTrivia(set, cat);
1843 end
1844 TriviaBot_Config['Question_Category'] = cat;
1845 end
1846
1847 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.CategoryList, TriviaBot_Config['Question_Category']);
1848 end
1849 TriviaBotGUI.CategoryList.Initialize = function()
1850 local info;
1851 local set = TriviaBot_Config['Question_Set'];
1852
1853 if (#TB_Question_Sets > 0 and TB_Question_Sets[set]) then
1854 -- Add 'All' option
1855 info = Lib_UIDropDownMenu_CreateInfo();
1856 info.value = 0;
1857 info.text = L.TB_GUI_ALL;
1858 info.func = TriviaBotGUI.CategoryList.OnClick;
1859 Lib_UIDropDownMenu_AddButton(info);
1860
1861 for id,_ in pairs(TB_Question_Sets[set]['Categories']) do
1862 info = Lib_UIDropDownMenu_CreateInfo();
1863 info.value = id;
1864 info.text = TB_Question_Sets[set]['Categories'][id];
1865 info.func = TriviaBotGUI.CategoryList.OnClick;
1866 Lib_UIDropDownMenu_AddButton(info);
1867 end
1868 local cat = TriviaBot_Config['Question_Category']
1869 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.CategoryList, cat);
1870 if tonumber(cat) == 0 then
1871 Lib_UIDropDownMenu_SetText(TriviaBotGUI.CategoryList, L.TB_GUI_ALL)
1872 else
1873 Lib_UIDropDownMenu_SetText(TriviaBotGUI.CategoryList, TB_Question_Sets[set]['Categories'][TriviaBot_Config['Question_Category']])
1874 end
1875 end
1876 end
1877 TriviaBotGUI.CategoryList:ClearAllPoints();
1878 Lib_UIDropDownMenu_SetWidth(TriviaBotGUI.CategoryList, 150);
1879 Lib_UIDropDownMenu_SetButtonWidth(TriviaBotGUI.CategoryList, 20);
1880 TriviaBotGUI.CategoryList:SetPoint("TOPLEFT", TriviaBotGUI.QuestionList, "BOTTOMLEFT", 0, 0);
1881 Lib_UIDropDownMenu_Initialize(TriviaBotGUI.CategoryList, TriviaBotGUI.CategoryList.Initialize);
1882 -- Category List Label
1883 TriviaBotGUI.CategoryList.Label = TriviaBotGUI.CategoryList:CreateFontString(nil, "ARTWORK", "GameFontNormal");
1884 TriviaBotGUI.CategoryList.Label:ClearAllPoints();
1885 TriviaBotGUI.CategoryList.Label:SetText(L.TB_GUI_CATEGORYLIST);
1886 TriviaBotGUI.CategoryList.Label:SetPoint("RIGHT", TriviaBotGUI.CategoryList, "LEFT", 10, 2);
1887 -- Category List Print Button
1888 TriviaBotGUI.CategoryList.PrintButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
1889 TriviaBotGUI.CategoryList.PrintButton:ClearAllPoints();
1890 TriviaBotGUI.CategoryList.PrintButton:SetWidth(tonumber(L.TB_GUI_PRINT_WIDTH));
1891 TriviaBotGUI.CategoryList.PrintButton:SetText(L.TB_GUI_PRINT);
1892 TriviaBotGUI.CategoryList.PrintButton:SetPoint("TOPLEFT", TriviaBotGUI, "TOPLEFT", 15, -55);
1893 TriviaBotGUI.CategoryList.PrintButton:SetScript("OnClick", TriviaBot.PrintCategoryList);
1894
1895 -- Chat Type List
1896 TriviaBotGUI.ChatType = CreateFrame("Frame", "TriviaBotGUI_ChatType", TriviaBotGUI, "Lib_UIDropDownMenuTemplate");
1897 TriviaBotGUI.ChatType.OnClick = function(self)
1898 -- Get the chat type value
1899 local type = self.value;
1900 -- No reason to change if the selected chat is the same as previous
1901 if (type == TriviaBot_Config['Chat_Type']) then
1902 return;
1903 end
1904 if (type == "channel") then
1905 TriviaBot.ChatSelect(type, TriviaBot_Config['Channel']);
1906 else
1907 TriviaBot.ChatSelect(type);
1908 end
1909 -- Warn for public channels
1910 if (type == "say" or type == "instance_chat" or type == "general") then
1911 TriviaBot.Print(TB_RED .. L.TB_PRINT_WARNINGCAPS .. TB_WHITE .. L.TB_PRINT_PUBLICCHANNEL);
1912 TriviaBot.Print(L.TB_PRINT_PUBLICANNOYING);
1913 TriviaBot.Print(L.TB_PRINT_REPORTBAN);
1914 TriviaBot.Print(L.TB_PRINT_RESPONSIBILITY);
1915 end
1916 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.ChatType, TriviaBot_Config['Chat_Type']);
1917 end
1918 TriviaBotGUI.ChatType.Initialize = function()
1919 local info;
1920 -- Say channel
1921 info = Lib_UIDropDownMenu_CreateInfo();
1922 info.value = "say";
1923 info.text = "Say";
1924 info.func = TriviaBotGUI.ChatType.OnClick;
1925 Lib_UIDropDownMenu_AddButton(info);
1926 -- General channel
1927 if (TB_ServerChannels[SERVER_CHANNEL_INTERNAL_ID[GENERAL_IID]]) then
1928 info = Lib_UIDropDownMenu_CreateInfo();
1929 info.value = "general";
1930 info.text = "General";
1931 info.func = TriviaBotGUI.ChatType.OnClick;
1932 Lib_UIDropDownMenu_AddButton(info);
1933 end
1934 -- Guild channel
1935 if (IsInGuild()) then
1936 info = Lib_UIDropDownMenu_CreateInfo();
1937 info.value = "guild";
1938 info.text = "Guild";
1939 info.func = TriviaBotGUI.ChatType.OnClick;
1940 Lib_UIDropDownMenu_AddButton(info);
1941 end
1942 -- Officer channel
1943 if (TriviaBot.IsOfficer()) then
1944 info = Lib_UIDropDownMenu_CreateInfo();
1945 info.value = "officer";
1946 info.text = "Officer";
1947 info.func = TriviaBotGUI.ChatType.OnClick;
1948 Lib_UIDropDownMenu_AddButton(info);
1949 end
1950 -- Party channel
1951 if (IsInGroup(LE_PARTY_CATEGORY_HOME)) then
1952 info = Lib_UIDropDownMenu_CreateInfo();
1953 info.value = "party";
1954 info.text = "Party";
1955 info.func = TriviaBotGUI.ChatType.OnClick;
1956 Lib_UIDropDownMenu_AddButton(info);
1957 end
1958 -- Raid channel
1959 if (IsInRaid(LE_PARTY_CATEGORY_HOME)) then
1960 info = Lib_UIDropDownMenu_CreateInfo();
1961 info.value = "raid";
1962 info.text = "Raid";
1963 info.func = TriviaBotGUI.ChatType.OnClick;
1964 Lib_UIDropDownMenu_AddButton(info);
1965 end
1966 -- Battleground channel
1967 if (TB_Zone == L.TB_ZONE_AB or TB_Zone == L.TB_ZONE_WSG or TB_Zone == L.TB_ZONE_AV or TB_Zone == L.TB_ZONE_EOTS or TB_Zone == L.TB_ZONE_IOC or TB_Zone == L.TB_ZONE_TBFG or TB_Zone == L.TB_ZONE_TP) then
1968 info = Lib_UIDropDownMenu_CreateInfo();
1969 info.value = "instance_chat";
1970 info.text = "Instance";
1971 info.func = TriviaBotGUI.ChatType.OnClick;
1972 Lib_UIDropDownMenu_AddButton(info);
1973 end
1974 -- Custom channel
1975 info = Lib_UIDropDownMenu_CreateInfo();
1976 info.value = "channel";
1977 info.text = "Custom Channel";
1978 info.func = TriviaBotGUI.ChatType.OnClick;
1979 Lib_UIDropDownMenu_AddButton(info);
1980
1981 Lib_UIDropDownMenu_SetSelectedValue(TriviaBotGUI.ChatType, TriviaBot_Config['Chat_Type']);
1982 end
1983 TriviaBotGUI.ChatType:ClearAllPoints();
1984 Lib_UIDropDownMenu_SetWidth(TriviaBotGUI.ChatType, 150);
1985 Lib_UIDropDownMenu_SetButtonWidth(TriviaBotGUI.ChatType, 20);
1986 TriviaBotGUI.ChatType:SetPoint("TOPLEFT", TriviaBotGUI.CategoryList, "BOTTOMLEFT", 0, 0);
1987 Lib_UIDropDownMenu_Initialize(TriviaBotGUI.ChatType, TriviaBotGUI.ChatType.Initialize);
1988 -- Chat Type List Label
1989 TriviaBotGUI.ChatType.Label = TriviaBotGUI.ChatType:CreateFontString(nil, "ARTWORK", "GameFontNormal");
1990 TriviaBotGUI.ChatType.Label:ClearAllPoints();
1991 TriviaBotGUI.ChatType.Label:SetText(L.TB_GUI_CHATTYPE);
1992 TriviaBotGUI.ChatType.Label:SetPoint("RIGHT", TriviaBotGUI.ChatType, "LEFT", 10, 2);
1993
1994 -- Channel Update Button
1995 TriviaBotGUI.ChannelButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
1996 TriviaBotGUI.ChannelButton:ClearAllPoints();
1997 TriviaBotGUI.ChannelButton:SetWidth(tonumber(L.TB_GUI_UPDATE_WIDTH));
1998 TriviaBotGUI.ChannelButton:SetText(L.TB_GUI_UPDATE);
1999 TriviaBotGUI.ChannelButton:SetPoint("TOPLEFT", TriviaBotGUI.ChatType, "BOTTOM", 15, -5);
2000
2001 -- Channel TextBox
2002 TriviaBotGUI.Channel = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2003 TriviaBotGUI.Channel.OnEditFocusLost = function(self)
2004 if (self:GetText():len() == 0) then
2005 self:SetText(TriviaBot_Config['Channel']);
2006 end
2007 end
2008 TriviaBotGUI.Channel.OnEscapePressed = function(self)
2009 self:SetText(TriviaBot_Config['Channel']);
2010 self:ClearFocus();
2011 end
2012 TriviaBotGUI.Channel.Update = function()
2013 local channel = TriviaBotGUI.Channel:GetText();
2014 if(channel == "") then
2015 -- Someone forgot to put text here so we simply put it back
2016 TriviaBotGUI.Channel:SetText(TriviaBot_Config['Channel']);
2017 return;
2018 end
2019 -- Let's check if the channel is valid
2020 local lchannel, invalid = strlower(channel)
2021 for gcn,fcn in pairs(TB_Chat_Restricted) do
2022 if lchannel == gcn or lchannel == fcn then
2023 invalid = true
2024 break
2025 end
2026 end
2027 if not invalid then
2028 TriviaBotGUI.Channel:SetText(L.TB_GUI_CHANNELCHANGE);
2029 TriviaBot.ChatSelect("channel", channel);
2030 else
2031 TriviaBot.PrintError(L.TB_ERROR_INVALIDCHANNELCHOOSE);
2032 TriviaBotGUI.Channel:SetText(TriviaBot_Config['Channel']);
2033 return;
2034 end
2035 if (GetChannelName(channel) > 0) then
2036 if (TriviaBot_Config['Channel'] == channel) then
2037 TriviaBot.Print(L.TB_PRINT_ALREADYJOINED);
2038 else
2039 TriviaBot_Config['Channel'] = channel;
2040 TriviaBot.Print(L.TB_PRINT_CHANNELCHANGE .. channel);
2041 end
2042 return;
2043 end
2044 TriviaBotGUI.Channel:ClearFocus();
2045 end
2046 TriviaBotGUI.Channel:ClearAllPoints();
2047 TriviaBotGUI.Channel:SetWidth(100);
2048 TriviaBotGUI.Channel:SetHeight(36);
2049 TriviaBotGUI.Channel:SetMaxLetters(20);
2050 TriviaBotGUI.Channel:SetAutoFocus(false);
2051 TriviaBotGUI.Channel:SetPoint("RIGHT", TriviaBotGUI.ChannelButton, "LEFT", -10, 1);
2052 TriviaBotGUI.Channel:SetScript("OnEnterPressed", TriviaBotGUI.Channel.Update);
2053 TriviaBotGUI.Channel:SetScript("OnEscapePressed", TriviaBotGUI.Channel.OnEscapePressed);
2054 TriviaBotGUI.Channel:SetScript("OnEditFocusLost", TriviaBotGUI.Channel.OnEditFocusLost);
2055 TriviaBotGUI.Channel:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2056 TriviaBotGUI.ChannelButton:SetScript("OnClick", TriviaBotGUI.Channel.Update);
2057 -- Channel TextBox Label
2058 TriviaBotGUI.Channel.Label = TriviaBotGUI.Channel:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2059 TriviaBotGUI.Channel.Label:ClearAllPoints();
2060 TriviaBotGUI.Channel.Label:SetText(L.TB_GUI_CUSTOMCHANNEL);
2061 TriviaBotGUI.Channel.Label:SetPoint("RIGHT", TriviaBotGUI.Channel, "LEFT", -15, 0);
2062
2063 -- Round Size TextBox
2064 TriviaBotGUI.RoundSize = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2065 TriviaBotGUI.RoundSize.OnEditFocusLost = function(self)
2066 local value = tonumber(self:GetText());
2067 if (not value or (value ~= TB_Infinite_Round and value < TB_Min_Round) or value > TB_Max_Round) then
2068 TriviaBot.PrintError(string.format(L.TB_ERROR_FMTROUNDSIZE,TB_Min_Round,TB_Max_Round,TB_Infinite_Round));
2069 self:SetText(TriviaBot_Config['Round_Size']);
2070 end
2071 end
2072 TriviaBotGUI.RoundSize.OnEscapePressed = function(self)
2073 self:SetText(TriviaBot_Config['Round_Size']);
2074 self:ClearFocus();
2075 end
2076 TriviaBotGUI.RoundSize.Update = function(self)
2077 if(self:GetText() == "") then
2078 -- Field is blanked out so we do nothing
2079 return;
2080 end
2081 local num = self:GetNumber();
2082 if (num == TB_Infinite_Round or (num >= TB_Min_Round and num <= TB_Max_Round)) then
2083 TriviaBot_Config['Round_Size'] = num;
2084 end
2085 end
2086 TriviaBotGUI.RoundSize:ClearAllPoints();
2087 TriviaBotGUI.RoundSize:SetWidth(40);
2088 TriviaBotGUI.RoundSize:SetHeight(36);
2089 TriviaBotGUI.RoundSize:SetMaxLetters(3);
2090 TriviaBotGUI.RoundSize:SetAutoFocus(false);
2091 TriviaBotGUI.RoundSize:SetNumeric(true);
2092 TriviaBotGUI.RoundSize:SetJustifyH("CENTER");
2093 TriviaBotGUI.RoundSize:SetTextInsets(0,6,0,0);
2094 TriviaBotGUI.RoundSize:SetPoint("TOPLEFT", TriviaBotGUI.Channel, "BOTTOMLEFT", 0, editboxspace);
2095 TriviaBotGUI.RoundSize:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2096 TriviaBotGUI.RoundSize:SetScript("OnTextChanged", TriviaBotGUI.RoundSize.Update);
2097 TriviaBotGUI.RoundSize:SetScript("OnEscapePressed", TriviaBotGUI.RoundSize.OnEscapePressed);
2098 TriviaBotGUI.RoundSize:SetScript("OnEditFocusLost", TriviaBotGUI.RoundSize.OnEditFocusLost);
2099 TriviaBotGUI.RoundSize:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2100 -- Round Size TextBox Label
2101 TriviaBotGUI.RoundSize.Label = TriviaBotGUI.RoundSize:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2102 TriviaBotGUI.RoundSize.Label:ClearAllPoints();
2103 TriviaBotGUI.RoundSize.Label:SetText(L.TB_GUI_ROUNDSIZE);
2104 TriviaBotGUI.RoundSize.Label:SetPoint("RIGHT", TriviaBotGUI.RoundSize, "LEFT", -15, 0);
2105
2106 -- Question Interval TextBox
2107 TriviaBotGUI.QuestionInterval = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2108 TriviaBotGUI.QuestionInterval.OnEditFocusLost = function(self)
2109 local value = tonumber(self:GetText());
2110 if (not value or value < TB_Min_Interval or value > TB_Max_Interval) then
2111 TriviaBot.PrintError(string.format(L.TB_ERROR_FMTQUESTIONINTERVAL,TB_Min_Interval,TB_Max_Interval));
2112 self:SetText(TriviaBot_Config['Question_Interval']);
2113 end
2114 end
2115 TriviaBotGUI.QuestionInterval.OnEscapePressed = function(self)
2116 self:SetText(TriviaBot_Config['Question_Interval']);
2117 self:ClearFocus();
2118 end
2119 TriviaBotGUI.QuestionInterval.Update = function(self)
2120 if(self:GetText() == "") then
2121 -- Field is blanked out so we do nothing
2122 return;
2123 end
2124 local num = self:GetNumber();
2125 if (num >= TB_Min_Interval and num <= TB_Max_Interval) then
2126 TriviaBot_Config['Question_Interval'] = num;
2127 end
2128 end
2129 TriviaBotGUI.QuestionInterval:ClearAllPoints();
2130 TriviaBotGUI.QuestionInterval:SetWidth(40);
2131 TriviaBotGUI.QuestionInterval:SetHeight(36);
2132 TriviaBotGUI.QuestionInterval:SetMaxLetters(3);
2133 TriviaBotGUI.QuestionInterval:SetAutoFocus(false);
2134 TriviaBotGUI.QuestionInterval:SetNumeric(true);
2135 TriviaBotGUI.QuestionInterval:SetJustifyH("CENTER");
2136 TriviaBotGUI.QuestionInterval:SetTextInsets(0,6,0,0);
2137 TriviaBotGUI.QuestionInterval:SetPoint("TOPLEFT", TriviaBotGUI.RoundSize, "BOTTOMLEFT", 0, editboxspace);
2138 TriviaBotGUI.QuestionInterval:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2139 TriviaBotGUI.QuestionInterval:SetScript("OnTextChanged", TriviaBotGUI.QuestionInterval.Update);
2140 TriviaBotGUI.QuestionInterval:SetScript("OnEscapePressed", TriviaBotGUI.QuestionInterval.OnEscapePressed);
2141 TriviaBotGUI.QuestionInterval:SetScript("OnEditFocusLost", TriviaBotGUI.QuestionInterval.OnEditFocusLost);
2142 TriviaBotGUI.QuestionInterval:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2143 -- Question Interval TextBox Label
2144 TriviaBotGUI.QuestionInterval.Label = TriviaBotGUI.QuestionInterval:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2145 TriviaBotGUI.QuestionInterval.Label:ClearAllPoints();
2146 TriviaBotGUI.QuestionInterval.Label:SetText(L.TB_GUI_QUESTIONINTERVAL);
2147 TriviaBotGUI.QuestionInterval.Label:SetPoint("RIGHT", TriviaBotGUI.QuestionInterval, "LEFT", -15, 0);
2148
2149 -- Question Timeout TextBox
2150 TriviaBotGUI.QuestionTimeout = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2151 TriviaBotGUI.QuestionTimeout.OnEditFocusLost = function(self)
2152 local value = tonumber(self:GetText());
2153 if (not value or value < TB_Min_Timeout or value > TB_Max_Timeout) then
2154 TriviaBot.PrintError(string.format(L.TB_ERROR_FMTQUESTIONTIMEOUT,TB_Min_Timeout,TB_Max_Timeout));
2155 self:SetText(TriviaBot_Config['Question_Timeout']);
2156 end
2157 end
2158 TriviaBotGUI.QuestionTimeout:ClearAllPoints();
2159 TriviaBotGUI.QuestionTimeout.OnEscapePressed = function(self)
2160 self:SetText(TriviaBot_Config['Question_Timeout']);
2161 self:ClearFocus();
2162 end
2163 TriviaBotGUI.QuestionTimeout.Update = function(self)
2164 if(self:GetText() == "") then
2165 -- Field is blanked out so we do nothing
2166 return;
2167 end
2168 local num = self:GetNumber();
2169 if (num >= TB_Min_Timeout and num <= TB_Max_Timeout) then
2170 TriviaBot_Config['Question_Timeout'] = num;
2171 if (TriviaBot_Config['Timeout_Warning']*2 > num) then
2172 TriviaBot_Config['Timeout_Warning'] = math.floor(num/2);
2173 TriviaBotGUI.TimeoutWarning:SetText(TriviaBot_Config['Timeout_Warning']);
2174 end
2175 end
2176 end
2177 TriviaBotGUI.QuestionTimeout:SetWidth(40);
2178 TriviaBotGUI.QuestionTimeout:SetHeight(36);
2179 TriviaBotGUI.QuestionTimeout:SetMaxLetters(3);
2180 TriviaBotGUI.QuestionTimeout:SetAutoFocus(false);
2181 TriviaBotGUI.QuestionTimeout:SetNumeric(true);
2182 TriviaBotGUI.QuestionTimeout:SetJustifyH("CENTER");
2183 TriviaBotGUI.QuestionTimeout:SetTextInsets(0,6,0,0);
2184 TriviaBotGUI.QuestionTimeout:SetPoint("TOPLEFT", TriviaBotGUI.QuestionInterval, "BOTTOMLEFT", 0, editboxspace);
2185 TriviaBotGUI.QuestionTimeout:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2186 TriviaBotGUI.QuestionTimeout:SetScript("OnTextChanged", TriviaBotGUI.QuestionTimeout.Update);
2187 TriviaBotGUI.QuestionTimeout:SetScript("OnEscapePressed", TriviaBotGUI.QuestionTimeout.OnEscapePressed);
2188 TriviaBotGUI.QuestionTimeout:SetScript("OnEditFocusLost", TriviaBotGUI.QuestionTimeout.OnEditFocusLost);
2189 TriviaBotGUI.QuestionTimeout:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2190 -- Question Timeout TextBox Label
2191 TriviaBotGUI.QuestionTimeout.Label = TriviaBotGUI.QuestionTimeout:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2192 TriviaBotGUI.QuestionTimeout.Label:ClearAllPoints();
2193 TriviaBotGUI.QuestionTimeout.Label:SetText(L.TB_GUI_QUESTIONTIMEOUT);
2194 TriviaBotGUI.QuestionTimeout.Label:SetPoint("RIGHT", TriviaBotGUI.QuestionTimeout, "LEFT", -15, 0);
2195
2196 -- Timeout Warning TextBox
2197 TriviaBotGUI.TimeoutWarning = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2198 TriviaBotGUI.TimeoutWarning.OnEditFocusLost = function(self)
2199 local value = tonumber(self:GetText());
2200 if (not value or value < TB_Min_Timeout_Warning or value > TB_Max_Timeout_Warning or value*2 > TriviaBot_Config['Question_Timeout']) then
2201 TriviaBot.PrintError(string.format(L.TB_ERROR_FMTTIMEOUTWARN,TB_Min_Timeout_Warning,TB_Max_Timeout_Warning));
2202 self:SetText(TriviaBot_Config['Timeout_Warning']);
2203 end
2204 end
2205 TriviaBotGUI.TimeoutWarning.OnEscapePressed = function(self)
2206 self:SetText(TriviaBot_Config['Timeout_Warning']);
2207 self:ClearFocus();
2208 end
2209 TriviaBotGUI.TimeoutWarning.Update = function(self)
2210 if(self:GetText() == "") then
2211 -- Field is blanked out so we do nothing
2212 return;
2213 end
2214 local num = self:GetNumber();
2215 if (num >= TB_Min_Timeout_Warning and num <= TB_Max_Timeout_Warning) then
2216 if (TriviaBot_Config['Question_Timeout'] < num*2) then
2217 TriviaBot_Config['Timeout_Warning'] = math.floor(TriviaBot_Config['Question_Timeout']/2);
2218 TriviaBotGUI.TimeoutWarning:SetText(TriviaBot_Config['Timeout_Warning']);
2219 else
2220 TriviaBot_Config['Timeout_Warning'] = num;
2221 end
2222 end
2223 end
2224 TriviaBotGUI.TimeoutWarning:ClearAllPoints();
2225 TriviaBotGUI.TimeoutWarning:SetWidth(40);
2226 TriviaBotGUI.TimeoutWarning:SetHeight(36);
2227 TriviaBotGUI.TimeoutWarning:SetMaxLetters(3);
2228 TriviaBotGUI.TimeoutWarning:SetAutoFocus(false);
2229 TriviaBotGUI.TimeoutWarning:SetNumeric(true);
2230 TriviaBotGUI.TimeoutWarning:SetJustifyH("CENTER");
2231 TriviaBotGUI.TimeoutWarning:SetTextInsets(0,6,0,0);
2232 TriviaBotGUI.TimeoutWarning:SetPoint("TOPLEFT", TriviaBotGUI.QuestionTimeout, "BOTTOMLEFT", 0, editboxspace);
2233 TriviaBotGUI.TimeoutWarning:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2234 TriviaBotGUI.TimeoutWarning:SetScript("OnTextChanged", TriviaBotGUI.TimeoutWarning.Update);
2235 TriviaBotGUI.TimeoutWarning:SetScript("OnEscapePressed", TriviaBotGUI.TimeoutWarning.OnEscapePressed);
2236 TriviaBotGUI.TimeoutWarning:SetScript("OnEditFocusLost", TriviaBotGUI.TimeoutWarning.OnEditFocusLost);
2237 TriviaBotGUI.TimeoutWarning:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2238 -- Timeout Warning TextBox Label
2239 TriviaBotGUI.TimeoutWarning.Label = TriviaBotGUI.TimeoutWarning:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2240 TriviaBotGUI.TimeoutWarning.Label:ClearAllPoints();
2241 TriviaBotGUI.TimeoutWarning.Label:SetText(L.TB_GUI_TIMEOUTWARNING);
2242 TriviaBotGUI.TimeoutWarning.Label:SetPoint("RIGHT", TriviaBotGUI.TimeoutWarning, "LEFT", -15, 0);
2243
2244 -- Top Score Count TextBox
2245 TriviaBotGUI.TopScoreCount = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2246 TriviaBotGUI.TopScoreCount.OnEditFocusLost = function(self)
2247 local value = tonumber(self:GetText());
2248 if (not value or value < TB_Min_Topscore or value > TB_Max_Topscore) then
2249 TriviaBot.PrintError(string.format(L.TB_ERROR_FMTTOPSCORECOUNT,TB_Min_Topscore,TB_Max_Topscore));
2250 self:SetText(TriviaBot_Config['Top_Score_Count']);
2251 end
2252 end
2253 TriviaBotGUI.TopScoreCount.OnEscapePressed = function(self)
2254 self:SetText(TriviaBot_Config['Top_Score_Count']);
2255 self:ClearFocus();
2256 end
2257 TriviaBotGUI.TopScoreCount.Update = function(self)
2258 if(self:GetText() == "") then
2259 -- Field is blanked out so we do nothing
2260 return;
2261 end
2262 local num = self:GetNumber();
2263 if (num >= TB_Min_Topscore and num <= TB_Max_Topscore) then
2264 TriviaBot_Config['Top_Score_Count'] = num;
2265 end
2266 end
2267 TriviaBotGUI.TopScoreCount:ClearAllPoints();
2268 TriviaBotGUI.TopScoreCount:SetWidth(40);
2269 TriviaBotGUI.TopScoreCount:SetHeight(36);
2270 TriviaBotGUI.TopScoreCount:SetMaxLetters(3);
2271 TriviaBotGUI.TopScoreCount:SetAutoFocus(false);
2272 TriviaBotGUI.TopScoreCount:SetNumeric(true);
2273 TriviaBotGUI.TopScoreCount:SetJustifyH("CENTER");
2274 TriviaBotGUI.TopScoreCount:SetTextInsets(0,6,0,0);
2275 TriviaBotGUI.TopScoreCount:SetPoint("TOPLEFT", TriviaBotGUI.TimeoutWarning, "BOTTOMLEFT", 0, editboxspace);
2276 TriviaBotGUI.TopScoreCount:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2277 TriviaBotGUI.TopScoreCount:SetScript("OnTextChanged", TriviaBotGUI.TopScoreCount.Update);
2278 TriviaBotGUI.TopScoreCount:SetScript("OnEscapePressed", TriviaBotGUI.TopScoreCount.OnEscapePressed);
2279 TriviaBotGUI.TopScoreCount:SetScript("OnEditFocusLost", TriviaBotGUI.TopScoreCount.OnEditFocusLost);
2280 TriviaBotGUI.TopScoreCount:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2281 -- Top Score Count TextBox Label
2282 TriviaBotGUI.TopScoreCount.Label = TriviaBotGUI.TopScoreCount:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2283 TriviaBotGUI.TopScoreCount.Label:ClearAllPoints();
2284 TriviaBotGUI.TopScoreCount.Label:SetText(L.TB_GUI_TOPSCORECOUNT);
2285 TriviaBotGUI.TopScoreCount.Label:SetPoint("RIGHT", TriviaBotGUI.TopScoreCount, "LEFT", -15, 0);
2286
2287 -- Top Score Interval TextBox
2288 TriviaBotGUI.TopScoreInterval = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2289 TriviaBotGUI.TopScoreInterval.OnEditFocusLost = function(self)
2290 local value = tonumber(self:GetText());
2291 if (not value or value < TB_Min_Topscore_Interval or value > TB_Max_Topscore_Interval) then
2292 TriviaBot.PrintError(string.format(L.TB_ERROR_FMTTOPSCOREINTERVAL,TB_Min_Topscore_Interval,TB_Max_Topscore_Interval));
2293 self:SetText(TriviaBot_Config['Top_Score_Interval']);
2294 end
2295 end
2296 TriviaBotGUI.TopScoreInterval.OnEscapePressed = function(self)
2297 self:SetText(TriviaBot_Config['Top_Score_Interval']);
2298 self:ClearFocus();
2299 end
2300 TriviaBotGUI.TopScoreInterval.Update = function(self)
2301 if(self:GetText() == "") then
2302 -- Field is blanked out so we do nothing
2303 return;
2304 end
2305 local num = self:GetNumber();
2306 if (num >= TB_Min_Topscore_Interval and num <= TB_Max_Topscore_Interval) then
2307 TriviaBot_Config['Top_Score_Interval'] = num;
2308 end
2309 end
2310 TriviaBotGUI.TopScoreInterval:ClearAllPoints();
2311 TriviaBotGUI.TopScoreInterval:SetWidth(40);
2312 TriviaBotGUI.TopScoreInterval:SetHeight(36);
2313 TriviaBotGUI.TopScoreInterval:SetMaxLetters(3);
2314 TriviaBotGUI.TopScoreInterval:SetAutoFocus(false);
2315 TriviaBotGUI.TopScoreInterval:SetNumeric(true);
2316 TriviaBotGUI.TopScoreInterval:SetJustifyH("CENTER");
2317 TriviaBotGUI.TopScoreInterval:SetTextInsets(0,6,0,0);
2318 TriviaBotGUI.TopScoreInterval:SetPoint("TOPLEFT", TriviaBotGUI.TopScoreCount, "BOTTOMLEFT", 0, editboxspace);
2319 TriviaBotGUI.TopScoreInterval:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2320 TriviaBotGUI.TopScoreInterval:SetScript("OnTextChanged", TriviaBotGUI.TopScoreInterval.Update);
2321 TriviaBotGUI.TopScoreInterval:SetScript("OnEscapePressed", TriviaBotGUI.TopScoreInterval.OnEscapePressed);
2322 TriviaBotGUI.TopScoreInterval:SetScript("OnEditFocusLost", TriviaBotGUI.TopScoreInterval.OnEditFocusLost);
2323 TriviaBotGUI.TopScoreInterval:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2324 -- Top Score Interval TextBox Label
2325 TriviaBotGUI.TopScoreInterval.Label = TriviaBotGUI.TopScoreInterval:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2326 TriviaBotGUI.TopScoreInterval.Label:ClearAllPoints();
2327 TriviaBotGUI.TopScoreInterval.Label:SetText(L.TB_GUI_TOPSCOREINTERVAL);
2328 TriviaBotGUI.TopScoreInterval.Label:SetPoint("RIGHT", TriviaBotGUI.TopScoreInterval, "LEFT", -15, 0);
2329
2330 -- Answers Shown TextBox
2331 TriviaBotGUI.AnswersShown = CreateFrame("EditBox", nil, TriviaBotGUI, "InputBoxTemplate");
2332 TriviaBotGUI.AnswersShown.OnEditFocusLost = function(self)
2333 local value = tonumber(self:GetText());
2334 if (not value or value < 0) then
2335 TriviaBot.PrintError(L.TB_ERROR_ANSWERSHOWN);
2336 self:SetText(TriviaBot_Config['Answers_Shown']);
2337 end
2338 end
2339 TriviaBotGUI.AnswersShown.OnEscapePressed = function(self)
2340 self:SetText(TriviaBot_Config['Answers_Shown']);
2341 self:ClearFocus();
2342 end
2343 TriviaBotGUI.AnswersShown.Update = function(self)
2344 if(self:GetText() == "") then
2345 -- Field is blanked out so we do nothing
2346 return;
2347 end
2348 local num = self:GetNumber();
2349 if (num >= 0) then
2350 TriviaBot_Config['Answers_Shown'] = num;
2351 end
2352 end
2353 TriviaBotGUI.AnswersShown:ClearAllPoints();
2354 TriviaBotGUI.AnswersShown:SetWidth(40);
2355 TriviaBotGUI.AnswersShown:SetHeight(36);
2356 TriviaBotGUI.AnswersShown:SetMaxLetters(3);
2357 TriviaBotGUI.AnswersShown:SetAutoFocus(false);
2358 TriviaBotGUI.AnswersShown:SetNumeric(true);
2359 TriviaBotGUI.AnswersShown:SetJustifyH("CENTER");
2360 TriviaBotGUI.AnswersShown:SetTextInsets(0,6,0,0);
2361 TriviaBotGUI.AnswersShown:SetPoint("TOPLEFT", TriviaBotGUI.TopScoreInterval, "BOTTOMLEFT", 0, editboxspace);
2362 TriviaBotGUI.AnswersShown:SetScript("OnEnterPressed", function(self) self:ClearFocus(); end);
2363 TriviaBotGUI.AnswersShown:SetScript("OnTextChanged", TriviaBotGUI.AnswersShown.Update);
2364 TriviaBotGUI.AnswersShown:SetScript("OnEscapePressed", TriviaBotGUI.AnswersShown.OnEscapePressed);
2365 TriviaBotGUI.AnswersShown:SetScript("OnEditFocusLost", TriviaBotGUI.AnswersShown.OnEditFocusLost);
2366 TriviaBotGUI.AnswersShown:SetScript("OnEditFocusGained", TriviaBotGUI.EditBox_Highlight);
2367 TriviaBotGUI.AnswersShown.toolTip = L.TB_GUI_ANSWERSSHOWN_TIP;
2368 TriviaBotGUI.AnswersShown:SetScript("OnEnter", TriviaBotGUI.OnMouseEnter);
2369 TriviaBotGUI.AnswersShown:SetScript("OnLeave", GameTooltip_Hide);
2370 -- Answers Shown TextBox Label
2371 TriviaBotGUI.AnswersShown.Label = TriviaBotGUI.AnswersShown:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2372 TriviaBotGUI.AnswersShown.Label:ClearAllPoints();
2373 TriviaBotGUI.AnswersShown.Label:SetText(L.TB_GUI_ANSWERSSHOWN);
2374 TriviaBotGUI.AnswersShown.Label:SetPoint("RIGHT", TriviaBotGUI.AnswersShown, "LEFT", -15, 0);
2375
2376 -- Show Answers Checkbox
2377 TriviaBotGUI.ShowAnswersCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2378 TriviaBotGUI.ShowAnswersCheckBox.OnClick = function(self)
2379 TriviaBot_Config['Show_Answers'] = self:GetChecked();
2380 end
2381 TriviaBotGUI.ShowAnswersCheckBox:ClearAllPoints();
2382 TriviaBotGUI.ShowAnswersCheckBox:SetPoint("LEFT", TriviaBotGUI.RoundSize, "RIGHT", 5, 0);
2383 TriviaBotGUI.ShowAnswersCheckBox:SetScript("OnClick", TriviaBotGUI.ShowAnswersCheckBox.OnClick);
2384 -- Show Answers Checkbox Label
2385 TriviaBotGUI.ShowAnswersCheckBox.Label = TriviaBotGUI.ShowAnswersCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2386 TriviaBotGUI.ShowAnswersCheckBox.Label:ClearAllPoints();
2387 TriviaBotGUI.ShowAnswersCheckBox.Label:SetText(L.TB_GUI_SHOWANSWERS);
2388 TriviaBotGUI.ShowAnswersCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ShowAnswersCheckBox, "RIGHT", 5, 0);
2389
2390 -- Show Reports Checkbox
2391 TriviaBotGUI.ShowReportsCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2392 TriviaBotGUI.ShowReportsCheckBox.OnClick = function(self)
2393 TriviaBot_Config['Show_Reports'] = self:GetChecked();
2394 end
2395 TriviaBotGUI.ShowReportsCheckBox:ClearAllPoints();
2396 TriviaBotGUI.ShowReportsCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.ShowAnswersCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2397 TriviaBotGUI.ShowReportsCheckBox:SetScript("OnClick", TriviaBotGUI.ShowReportsCheckBox.OnClick);
2398 -- Show Reports Checkbox Label
2399 TriviaBotGUI.ShowReportsCheckBox.Label = TriviaBotGUI.ShowReportsCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2400 TriviaBotGUI.ShowReportsCheckBox.Label:ClearAllPoints();
2401 TriviaBotGUI.ShowReportsCheckBox.Label:SetText(L.TB_GUI_SHOWREPORTS);
2402 TriviaBotGUI.ShowReportsCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ShowReportsCheckBox, "RIGHT", 5, 0);
2403
2404 -- Show Hints Checkbox
2405 TriviaBotGUI.ShowHintsCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2406 TriviaBotGUI.ShowHintsCheckBox.OnClick = function(self)
2407 TriviaBot_Config['Show_Hints'] = self:GetChecked();
2408 end
2409 TriviaBotGUI.ShowHintsCheckBox:ClearAllPoints();
2410 TriviaBotGUI.ShowHintsCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.ShowReportsCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2411 TriviaBotGUI.ShowHintsCheckBox:SetScript("OnClick", TriviaBotGUI.ShowHintsCheckBox.OnClick);
2412 -- Show Hints Checkbox Label
2413 TriviaBotGUI.ShowHintsCheckBox.Label = TriviaBotGUI.ShowHintsCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2414 TriviaBotGUI.ShowHintsCheckBox.Label:ClearAllPoints();
2415 TriviaBotGUI.ShowHintsCheckBox.Label:SetText(L.TB_GUI_SHOWHINTS);
2416 TriviaBotGUI.ShowHintsCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ShowHintsCheckBox, "RIGHT", 5, 0);
2417
2418 -- Show Whispers Checkbox
2419 TriviaBotGUI.ShowWhispersCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2420 TriviaBotGUI.ShowWhispersCheckBox.OnClick = function(self)
2421 TriviaBot_Config['Show_Whispers'] = self:GetChecked();
2422 if not (TriviaBot_Config['Show_Whispers']) then
2423 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER",TriviaBot.MessageFilter)
2424 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM",TriviaBot.MessageFilter)
2425 else
2426 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER_INFORM",TriviaBot.MessageFilter)
2427 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER",TriviaBot.MessageFilter)
2428 end
2429 end
2430 TriviaBotGUI.ShowWhispersCheckBox:ClearAllPoints();
2431 TriviaBotGUI.ShowWhispersCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.ShowHintsCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2432 TriviaBotGUI.ShowWhispersCheckBox:SetScript("OnClick", TriviaBotGUI.ShowWhispersCheckBox.OnClick);
2433 -- Show Whispers Checkbox Label
2434 TriviaBotGUI.ShowWhispersCheckBox.Label = TriviaBotGUI.ShowWhispersCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2435 TriviaBotGUI.ShowWhispersCheckBox.Label:ClearAllPoints();
2436 TriviaBotGUI.ShowWhispersCheckBox.Label:SetText(L.TB_GUI_SHOWWHISPERS);
2437 TriviaBotGUI.ShowWhispersCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ShowWhispersCheckBox, "RIGHT", 5, 0);
2438
2439 -- Report Win Streak Checkbox
2440 TriviaBotGUI.ReportWinStreakCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2441 TriviaBotGUI.ReportWinStreakCheckBox.OnClick = function(self)
2442 TriviaBot_Config['Report_Win_Streak'] = self:GetChecked();
2443 end
2444 TriviaBotGUI.ReportWinStreakCheckBox:ClearAllPoints();
2445 TriviaBotGUI.ReportWinStreakCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.ShowWhispersCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2446 TriviaBotGUI.ReportWinStreakCheckBox:SetScript("OnClick", TriviaBotGUI.ReportWinStreakCheckBox.OnClick);
2447 -- Report Win Streak Checkbox Label
2448 TriviaBotGUI.ReportWinStreakCheckBox.Label = TriviaBotGUI.ReportWinStreakCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2449 TriviaBotGUI.ReportWinStreakCheckBox.Label:ClearAllPoints();
2450 TriviaBotGUI.ReportWinStreakCheckBox.Label:SetText(L.TB_GUI_REPORTWINSTREAK);
2451 TriviaBotGUI.ReportWinStreakCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ReportWinStreakCheckBox, "RIGHT", 5, 0);
2452
2453 -- Report Personal Checkbox
2454 TriviaBotGUI.ReportPersonalCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2455 TriviaBotGUI.ReportPersonalCheckBox.OnClick = function(self)
2456 TriviaBot_Config['Report_Personal'] = self:GetChecked();
2457 end
2458 TriviaBotGUI.ReportPersonalCheckBox:ClearAllPoints();
2459 TriviaBotGUI.ReportPersonalCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.ReportWinStreakCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2460 TriviaBotGUI.ReportPersonalCheckBox:SetScript("OnClick", TriviaBotGUI.ReportPersonalCheckBox.OnClick);
2461 -- Report Personal Checkbox Label
2462 TriviaBotGUI.ReportPersonalCheckBox.Label = TriviaBotGUI.ReportPersonalCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2463 TriviaBotGUI.ReportPersonalCheckBox.Label:ClearAllPoints();
2464 TriviaBotGUI.ReportPersonalCheckBox.Label:SetText(L.TB_GUI_REPORTPERSONAL);
2465 TriviaBotGUI.ReportPersonalCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ReportPersonalCheckBox, "RIGHT", 5, 0);
2466
2467 -- Point Mode Checkbox
2468 TriviaBotGUI.PointModeCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2469 TriviaBotGUI.PointModeCheckBox.OnClick = function(self)
2470 TriviaBot_Config['Point_Mode'] = self:GetChecked();
2471 end
2472 TriviaBotGUI.PointModeCheckBox:ClearAllPoints();
2473 TriviaBotGUI.PointModeCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.ReportPersonalCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2474 TriviaBotGUI.PointModeCheckBox:SetScript("OnClick", TriviaBotGUI.PointModeCheckBox.OnClick);
2475 -- Point Mode Checkbox Label
2476 TriviaBotGUI.PointModeCheckBox.Label = TriviaBotGUI.PointModeCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2477 TriviaBotGUI.PointModeCheckBox.Label:ClearAllPoints();
2478 TriviaBotGUI.PointModeCheckBox.Label:SetText(L.TB_GUI_POINTMODE);
2479 TriviaBotGUI.PointModeCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.PointModeCheckBox, "RIGHT", 5, 0);
2480
2481 -- Short Channel Tag Checkbox
2482 TriviaBotGUI.ShortChannelTagCheckBox = CreateFrame("CheckButton", nil, TriviaBotGUI, "OptionsCheckButtonTemplate");
2483 TriviaBotGUI.ShortChannelTagCheckBox.OnClick = function(self)
2484 TriviaBot_Config['Short_Tag'] = self:GetChecked();
2485 if (self:GetChecked()) then
2486 TB_Channel_Prefix = TB_Short_Prefix;
2487 else
2488 TB_Channel_Prefix = TB_Long_Prefix;
2489 end
2490 end
2491 TriviaBotGUI.ShortChannelTagCheckBox:ClearAllPoints();
2492 TriviaBotGUI.ShortChannelTagCheckBox:SetPoint("TOPLEFT", TriviaBotGUI.PointModeCheckBox, "BOTTOMLEFT", 0, checkboxspace);
2493 TriviaBotGUI.ShortChannelTagCheckBox:SetScript("OnClick", TriviaBotGUI.ShortChannelTagCheckBox.OnClick);
2494 -- Short Channel Tag Checkbox Label
2495 TriviaBotGUI.ShortChannelTagCheckBox.Label = TriviaBotGUI.ShortChannelTagCheckBox:CreateFontString(nil, "ARTWORK", "GameFontNormal");
2496 TriviaBotGUI.ShortChannelTagCheckBox.Label:ClearAllPoints();
2497 TriviaBotGUI.ShortChannelTagCheckBox.Label:SetText(L.TB_GUI_SHORTCHANNEL);
2498 TriviaBotGUI.ShortChannelTagCheckBox.Label:SetPoint("LEFT", TriviaBotGUI.ShortChannelTagCheckBox, "RIGHT", 5, 0);
2499
2500 -- Start/Stop Button
2501 TriviaBotGUI.StartStopButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
2502 TriviaBotGUI.StartStopButton:ClearAllPoints();
2503 TriviaBotGUI.StartStopButton:SetWidth(140);
2504 TriviaBotGUI.StartStopButton:SetText(L.TB_GUI_STARTTRIVIA);
2505 TriviaBotGUI.StartStopButton:SetPoint("BOTTOMRIGHT", TriviaBotGUI, "BOTTOM", -5, 45);
2506 TriviaBotGUI.StartStopButton:SetScript("OnClick", TriviaBot.StartStopToggle);
2507
2508 -- Skip Button
2509 TriviaBotGUI.SkipButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
2510 TriviaBotGUI.SkipButton:ClearAllPoints();
2511 TriviaBotGUI.SkipButton:SetWidth(140);
2512 TriviaBotGUI.SkipButton:SetText(L.TB_GUI_SKIPQUESTION);
2513 TriviaBotGUI.SkipButton:SetPoint("TOPRIGHT", TriviaBotGUI.StartStopButton, "BOTTOMRIGHT", 0, -5);
2514 TriviaBotGUI.SkipButton:SetScript("OnClick", TriviaBot.SkipQuestion);
2515 TriviaBotGUI.SkipButton:Disable();
2516
2517 -- Game Score Button
2518 TriviaBotGUI.GameScoresButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
2519 TriviaBotGUI.GameScoresButton:ClearAllPoints();
2520 TriviaBotGUI.GameScoresButton:SetWidth(140);
2521 TriviaBotGUI.GameScoresButton:SetText(L.TB_GUI_GAMESCORES);
2522 TriviaBotGUI.GameScoresButton:SetPoint("BOTTOMLEFT", TriviaBotGUI, "BOTTOM", 5, 45);
2523 TriviaBotGUI.GameScoresButton:SetScript("OnClick", function() TriviaBot.Report("gamereport"); end);
2524
2525 -- Question Maker Button
2526 if IsAddOnLoaded("TriviaBot_QuestionMaker") then
2527 TriviaBotGUI.QuestionMakerButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
2528 TriviaBotGUI.QuestionMakerButton:ClearAllPoints();
2529 TriviaBotGUI.QuestionMakerButton:SetWidth(140);
2530 TriviaBotGUI.QuestionMakerButton:SetText(L.TB_GUI_QUESTIONMAKER);
2531 TriviaBotGUI.QuestionMakerButton:SetPoint("BOTTOMRIGHT", TriviaBotGUI.GameScoresButton, "TOPRIGHT", 0, 5);
2532 TriviaBotGUI.QuestionMakerButton:SetScript("OnClick", TriviaBot.QuestionMakerToggle)
2533
2534 TriviaBotGUI.ReloadQuestionsButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
2535 TriviaBotGUI.ReloadQuestionsButton:ClearAllPoints();
2536 TriviaBotGUI.ReloadQuestionsButton:SetWidth(140);
2537 TriviaBotGUI.ReloadQuestionsButton:SetText(L.TB_GUI_RELOAD);
2538 TriviaBotGUI.ReloadQuestionsButton:SetPoint("BOTTOMRIGHT", TriviaBotGUI.StartStopButton, "TOPRIGHT", 0, 5);
2539 TriviaBotGUI.ReloadQuestionsButton:SetScript("OnClick", TriviaBot.ReloadQuestionsOnClick)
2540 TriviaBotGUI.ReloadQuestionsButton:Hide()
2541 end
2542
2543 -- All-Time Score Button
2544 TriviaBotGUI.AllTimeScoresButton = CreateFrame("Button", nil, TriviaBotGUI, "OptionsButtonTemplate");
2545 TriviaBotGUI.AllTimeScoresButton:ClearAllPoints();
2546 TriviaBotGUI.AllTimeScoresButton:SetWidth(140);
2547 TriviaBotGUI.AllTimeScoresButton:SetText(L.TB_GUI_ALLTIMESCORES);
2548 TriviaBotGUI.AllTimeScoresButton:SetPoint("TOPLEFT", TriviaBotGUI.GameScoresButton, "BOTTOMLEFT", 0, -5);
2549 TriviaBotGUI.AllTimeScoresButton:SetScript("OnClick", function() TriviaBot.Report("alltimereport"); end);
2550
2551 TriviaBotGUI.ClearFocus = function()
2552 TriviaBotGUI.Channel:ClearFocus();
2553 TriviaBotGUI.RoundSize:ClearFocus();
2554 TriviaBotGUI.QuestionInterval:ClearFocus();
2555 TriviaBotGUI.QuestionTimeout:ClearFocus();
2556 TriviaBotGUI.TimeoutWarning:ClearFocus();
2557 TriviaBotGUI.TopScoreCount:ClearFocus();
2558 TriviaBotGUI.TopScoreInterval:ClearFocus();
2559 TriviaBotGUI.AnswersShown:ClearFocus();
2560 end
2561 TriviaBotGUI:SetScript("OnMouseDown", TriviaBotGUI.ClearFocus);
2562 TriviaBotGUI.StartStopToggle = function()
2563 if (TB_Running) then
2564 TriviaBotGUI.StartStopButton:SetText(L.TB_GUI_STOPTRIVIA);
2565 Lib_UIDropDownMenu_DisableDropDown(TriviaBotGUI.ChatType);
2566 TriviaBotGUI.RoundSize:EnableMouse(false);
2567 TriviaBotGUI.RoundSize:ClearFocus();
2568 TriviaBotGUI.RoundSize:SetTextColor(1,0,0);
2569 TriviaBotGUI.PointModeCheckBox:Disable();
2570 if (TriviaBot_Config['Chat_Type'] == "channel") then
2571 TriviaBotGUI.Channel:EnableMouse(false);
2572 TriviaBotGUI.Channel:ClearFocus();
2573 TriviaBotGUI.Channel:SetTextColor(1,0,0);
2574 TriviaBotGUI.ChannelButton:Disable();
2575 end
2576 else
2577 TriviaBotGUI.StartStopButton:SetText(L.TB_GUI_STARTTRIVIA);
2578 TriviaBotGUI.SkipButton:Disable();
2579 Lib_UIDropDownMenu_EnableDropDown(TriviaBotGUI.ChatType);
2580 TriviaBotGUI.RoundSize:EnableMouse(true);
2581 TriviaBotGUI.RoundSize:SetTextColor(1,1,1);
2582 TriviaBotGUI.PointModeCheckBox:Enable();
2583 if (TriviaBot_Config['Chat_Type'] == "channel") then
2584 TriviaBotGUI.Channel:EnableMouse(true);
2585 TriviaBotGUI.Channel:SetTextColor(1,1,1);
2586 TriviaBotGUI.ChannelButton:Enable();
2587 end
2588 end
2589 end
2590 TriviaBotGUI.Update = function()
2591 -- Display Version
2592 TriviaBotGUI.HeaderLabel:SetText("TriviaBot " .. TB_VERSION);
2593 -- Load Channel
2594 TriviaBotGUI.Channel:SetText(TriviaBot_Config['Channel']);
2595 -- Load Round Size
2596 TriviaBotGUI.RoundSize:SetText(TriviaBot_Config['Round_Size']);
2597 -- Load Question Interval
2598 TriviaBotGUI.QuestionInterval:SetText(TriviaBot_Config['Question_Interval']);
2599 -- Load Question Timeout
2600 TriviaBotGUI.QuestionTimeout:SetText(TriviaBot_Config['Question_Timeout']);
2601 -- Load Timeout Warning
2602 TriviaBotGUI.TimeoutWarning:SetText(TriviaBot_Config['Timeout_Warning']);
2603 -- Load Top Score Count
2604 TriviaBotGUI.TopScoreCount:SetText(TriviaBot_Config['Top_Score_Count']);
2605 -- Load Top Score Interval
2606 TriviaBotGUI.TopScoreInterval:SetText(TriviaBot_Config['Top_Score_Interval']);
2607 -- Load Answers Shown
2608 TriviaBotGUI.AnswersShown:SetText(TriviaBot_Config['Answers_Shown']);
2609 -- Set Show Answers state
2610 TriviaBotGUI.ShowAnswersCheckBox:SetChecked(TriviaBot_Config['Show_Answers']);
2611 -- Set Show Reports state
2612 TriviaBotGUI.ShowReportsCheckBox:SetChecked(TriviaBot_Config['Show_Reports']);
2613 -- Set Show Hints state
2614 TriviaBotGUI.ShowHintsCheckBox:SetChecked(TriviaBot_Config['Show_Hints']);
2615 -- Set Show Whispers state
2616 TriviaBotGUI.ShowWhispersCheckBox:SetChecked(TriviaBot_Config['Show_Whispers']);
2617 -- Set Report Win Streak state
2618 TriviaBotGUI.ReportWinStreakCheckBox:SetChecked(TriviaBot_Config['Report_Win_Streak']);
2619 -- Set Report Personal state
2620 TriviaBotGUI.ReportPersonalCheckBox:SetChecked(TriviaBot_Config['Report_Personal']);
2621 -- Set Point Mode state
2622 TriviaBotGUI.PointModeCheckBox:SetChecked(TriviaBot_Config['Point_Mode']);
2623 -- Short Channel Tag state
2624 TriviaBotGUI.ShortChannelTagCheckBox:SetChecked(TriviaBot_Config['Short_Tag']);
2625 if (TriviaBot_Config['Short_Tag']) then
2626 TB_Channel_Prefix = TB_Short_Prefix;
2627 end
2628 -- Make sure QuestionList drop-down menu is initalized
2629 TriviaBotGUI.QuestionList.Initialize();
2630 -- Make sure CategoryList drop-down menu is initalized
2631 TriviaBotGUI.CategoryList.Initialize();
2632 -- Make sure ChatType drop-down menu is initalized
2633 TriviaBotGUI.ChatType.Initialize();
2634 -- Disable custom channel stuff
2635 if (TriviaBot_Config['Chat_Type'] ~= "channel") then
2636 TriviaBotGUI.Channel:EnableMouse(false);
2637 TriviaBotGUI.Channel:SetTextColor(1,0,0);
2638 TriviaBotGUI.ChannelButton:Disable();
2639 else
2640 TriviaBotGUI.Channel:EnableMouse(true);
2641 TriviaBotGUI.Channel:SetTextColor(1,1,1);
2642 TriviaBotGUI.ChannelButton:Enable();
2643 end
2644 end
2645end
2646_G[addonName] = API