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