Zeile 5: |
Zeile 5: |
| * Motd - Massage of the Day - Info beim verbinden | | * Motd - Massage of the Day - Info beim verbinden |
| * Webserver - Info fuer den Hub-betreiber | | * Webserver - Info fuer den Hub-betreiber |
| + | |
| ===zusätzliche skripte (nuetzliches und spass usw.)=== | | ===zusätzliche skripte (nuetzliches und spass usw.)=== |
| * Quiz - Triviaquiz-bot | | * Quiz - Triviaquiz-bot |
Zeile 10: |
Zeile 11: |
| * voting, zusatz-chat, kleine textgame usw. | | * voting, zusatz-chat, kleine textgame usw. |
| | | |
− | * hi,habs mein telefon vergessen - komm gleich mal bei dir rum - bye,Bastian | + | ====skripte Lua 5.0.2.==== |
| + | * Trivia Quiz-bot |
| + | <pre> |
| + | -- Converted to Lua5 By Jelf 15/03/05 |
| + | -- Translated by Psycho Chihuahua 16/03/05 |
| + | |
| + | BotName = "Quiz" |
| + | ScriptVersion = "WeimarnetzQuiz" |
| + | BotVersion = BotName.." "..ScriptVersion |
| + | |
| + | -- This file is not needed it will be created if it not exists |
| + | strTrivScoreFile = "TriviaScores.dat" |
| + | |
| + | -- This file is needed unless you want to run a Trivia with only two questions ;) |
| + | strDefTrivFile = "Trivia Fragen & Antworten.dat" |
| + | strTrivFile = strDefTrivFile |
| + | strQFile = "Trivia Fragen & Antworten selfmade.dat" |
| + | |
| + | -- This char will be the global separator? (Make it one that is not used in nicknames nor questions ;) |
| + | strGSep = "*" |
| + | |
| + | -- This char is used to mask the unrevealed chars |
| + | strCMask = "" |
| + | |
| + | -- Default startup mode of Trivia! |
| + | lngDefMode = 0 -- (0 = game is played in chat!, 1 = game is played in chat but questions only show for players, 2 = game is played in pm with players) |
| + | lngMode = lngDefMode |
| + | |
| + | -- Max number of questions to show when a Operator ask to see list Questions 0 = 0, -1 = Disabled |
| + | lngMaxShowList = 5 |
| + | |
| + | -- Max no of Hints per word, and always hit on a hidden char |
| + | lngMaxHints = 4 |
| + | boolHintAlwaysHitHidden = nil -- (nil = off, 1 = on) |
| + | |
| + | -- How much time before a question end. Time in Trivia is measured in 15 seconds, 1 = 15 seconds, 2 = 30 seconds etc! |
| + | -- Rest is how long to rest after a question is solved depening on when the word is solved in the Timer loop it is 15 secs to the setting! |
| + | lngMaxTime = 8 -- (Needs to be a multiple of 4 i.e. 4 / 8 / 12 / 16) |
| + | lngRestTime = 2 |
| + | lngHintTime = lngMaxTime / 4 |
| + | |
| + | -- How often should the bot autosave the scores |
| + | boolAutoSaveScores = 1 -- (nil = off, 1 = on) |
| + | countSaveTurns = 10 -- After how many questions should the scores be saved |
| + | |
| + | -- Should bot reveal the correct answer once time is up? |
| + | boolRevealAnswer = 1 -- (nil = off, 1 = on) |
| + | |
| + | -- Should the bot display what guess made the word become a little clearer if played in PM! |
| + | boolShowGuessesInPM = 1 -- (nil = off, 1 = on) |
| + | |
| + | -- Should the bot Auto Reveal Hints? |
| + | boolAutoHint = 1 -- (nil = off, 1 = on) |
| + | |
| + | -- Should the bot auto login every user on connect ? |
| + | boolAutoLogin = nil -- (nil = off, 1 = on) |
| + | |
| + | -- Do you want users to be able to add questions ? Operators can always add questions. |
| + | boolAddQuestion = 1 -- (nil = No, 1 = Yes) |
| + | |
| + | -- TriggStart is what char the commands should begin with I use ! but you can use # or whatever |
| + | TriggStart = "#" |
| + | |
| + | -- Theese are the different triggers I've tried to name them so that one easily understand what they do! |
| + | -- I include TriggStart and then the word within "" this word is not casesensitive! |
| + | JoinTrigg = TriggStart.."qmitmach" |
| + | PartTrigg = TriggStart.."qraus" |
| + | StartTrigg = TriggStart.."qstart" |
| + | StopTrigg = TriggStart.."qstop" |
| + | WordTrigg = TriggStart.."qwort" |
| + | QuizTrigg = TriggStart.."qfrage" |
| + | RestartTrigg = TriggStart.."qneustart" |
| + | PointTrigg = TriggStart.."qpunkte" |
| + | ScoreTrigg = TriggStart.."qergebnis" |
| + | PlayerTrigg = TriggStart.."qspieler" |
| + | QuestionsTrigg = TriggStart.."qfragen" |
| + | ReloadTrigg = TriggStart.."qneuladen" |
| + | HelpTrigg = TriggStart.."qhilfe" |
| + | ExtraHelpTrigg = TriggStart.."qhilfe+" |
| + | SaveTrigg = TriggStart.."qsicherergebnis" |
| + | LoadTrigg = TriggStart.."qladeergebnis" |
| + | ModeTrigg = TriggStart.."qmodus" |
| + | HintTrigg = TriggStart.."qtip" |
| + | TopTrigg = TriggStart.."qtopten" |
| + | AddTrigg = TriggStart.."qfragedazu" |
| + | |
| + | bcount = 0 |
| + | scount = 0 |
| + | sQuestion = "" |
| + | sAnswer = "" |
| + | guessArray = {} |
| + | lngGuessmax = 0 |
| + | playerArray = {} |
| + | pointArray = {} |
| + | lngWord = 0 |
| + | lngPassed = 0 |
| + | lngHinted = 0 |
| + | strWord = "" |
| + | strQuestion = "" |
| + | strSolved = "" |
| + | strBanner = "Schreibe '"..StartTrigg.."' um den Quizzbot zu starten, '"..StopTrigg.."' um den Quizzbot anzuhalten, '"..JoinTrigg.."' um am Quizz teilzunehmen und '"..PartTrigg.."' um das Quizz zu verlassen." |
| + | strStart = "Quizzbot "..ScriptVersion.." gestartet! "..strBanner |
| + | strStopp = "Quizzbot "..ScriptVersion.." angehalten! "..strBanner |
| + | ---------------------- |
| + | function Main() |
| + | frmHub:RegBot(BotName) |
| + | ReloadQuestions() |
| + | end |
| + | ------------------------ |
| + | function NewUserConnected(curUser) |
| + | if (boolAutoLogin) then |
| + | if (not (playerArray[curUser.sName])) then |
| + | playerArray[curUser.sName] = 1 |
| + | else |
| + | playerArray[curUser.sName] = nil |
| + | end |
| + | end |
| + | end |
| + | ------------------------------ |
| + | function OpConnected(curUser) |
| + | if (boolAutoLogin) then |
| + | if (not (playerArray[curUser.sName])) then |
| + | playerArray[curUser.sName] = 1 |
| + | else |
| + | playerArray[curUser.sName] = nil |
| + | end |
| + | end |
| + | end |
| + | -------------------------------- |
| + | function UserDisconnected(curUser) |
| + | playerArray[curUser.sName] = nil |
| + | end |
| + | -------------------------------- |
| + | function OpDisconnected(curUser) |
| + | playerArray[curUser.sName] = nil |
| + | end |
| + | -------------------------------- |
| + | function ChatArrival(curUser, data) |
| + | data = string.sub(data, 1, (string.len(data) - 1)) |
| + | if ((lngMode == 0) or (lngMode == 1)) then |
| + | boolPlaydata = 1 |
| + | end |
| + | GotoTriggs(curUser, data) |
| + | end |
| + | ---------------------------------- |
| + | function ToArrival(curUser, data) |
| + | data = string.sub(data, 1, (string.len(data) - 1)) |
| + | local _, _, whoTo = string.find(data,"$To:%s+(%S+)") |
| + | if (whoTo == BotName) then |
| + | data = string.sub(data, (15 + string.len(BotName) + string.len(curUser.sName))) |
| + | if (lngMode == 2) then |
| + | boolPlaydata = 1 |
| + | local _, _, chat = string.find(data, "%b<>%s(.+)") |
| + | SendChatToOthers(chat, curUser) |
| + | end |
| + | end |
| + | GotoTriggs(curUser, data) |
| + | end |
| + | ------------------------------------------- |
| + | function GotoTriggs(curUser, data) |
| + | local _, _, firstWord = string.find(data, "%b<>%s+(%S+)") |
| + | |
| + | if (firstWord ~= nil) then |
| + | if ((string.lower(firstWord) == string.lower(HelpTrigg)) or (string.lower(firstWord) == string.lower(ExtraHelpTrigg))) then |
| + | showHelp(curUser) |
| + | elseif (string.lower(firstWord) == string.lower(SaveTrigg)) then |
| + | if (curUser.bOperator) then |
| + | SaveScores(curUser) |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(LoadTrigg)) then |
| + | if (curUser.bOperator) then |
| + | LoadScores(curUser) |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(TopTrigg)) then |
| + | TopTen(user) |
| + | elseif (string.lower(firstWord) == string.lower(AddTrigg)) then |
| + | if (boolAddQuestion) then |
| + | s,e,sQuestion,sAnswer = string.find(data, "%b<>%s+%S+%s+(.+)#(.+)") |
| + | AddQuestion(curUser,sQuestion,sAnswer) |
| + | elseif (curUser.bOperator) then |
| + | s,e,sQuestion,sAnswer = string.find(data, "%b<>%s+%S+%s+(.+)#(.+)") |
| + | AddQuestion(curUser,sQuestion,sAnswer) |
| + | else |
| + | SendToPlayers("Fragen koennen jetzt nicht hinzugefuegt werden.") |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(ModeTrigg)) then |
| + | if (curUser.bOperator) then |
| + | local _, _, ModeDigit = string.find(data, "%b<>%s+%S+%s+(%d+)") |
| + | if (ModeDigit ~= nil) then |
| + | lngMode = tonumber(ModeDigit) |
| + | if (lngMode == 0) then |
| + | SendToPlayers("Quizz wird im Mainchat gespielt") |
| + | elseif (lngMode == 1) then |
| + | SendToPlayers("Quizz wird im Mainchat gespielt aber Fragen koennen nur Quizzer sehen") |
| + | elseif (lngMode == 2) then |
| + | SendToPlayers("Quizz wird ueber PM gespielt") |
| + | else |
| + | SendToPlayers("Falscher Modus gewaehlt, wurde auf Voreinstellung gesetzt") |
| + | lngMode = lngDefMode |
| + | end |
| + | end |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(JoinTrigg)) then |
| + | if (not (playerArray[curUser.sName])) then |
| + | playerArray[curUser.sName] = 1 |
| + | SendToPlayers(curUser.sName.." ist jetzt mit dabei!") |
| + | else curUser:SendPM(BotName, "Du bist schon Mitspieler. Es kann sein das Du automatisch eingeloggt wurdest.") |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(PartTrigg)) then |
| + | if (playerArray[curUser.sName]) then |
| + | SendToPlayers(curUser.sName.." ist nicht länger Mitspieler!") |
| + | playerArray[curUser.sName] = nil |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(RestartTrigg)) then |
| + | if (curUser.bOperator) then |
| + | SendToPlayers("Quizzbot neugestartet. Alle Punkte sind nun weg!") |
| + | SendToPlayers("Wenn Du jetzt speicherst wird der alte Punktestand überschrieben!") |
| + | pointArray = {} |
| + | StopQuiz(1) |
| + | end |
| + | elseif ((string.lower(firstWord) == string.lower(PointTrigg)) and (playerArray[curUser.sName])) then |
| + | if (pointArray[curUser.sName]) then |
| + | SendToPlayers(curUser.sName.." Du hast "..pointArray[curUser.sName].." Punkte!") |
| + | else |
| + | SendToPlayers(curUser.sName.." Du hast 0 Punkte!") |
| + | end |
| + | elseif ((string.lower(firstWord) == string.lower(HintTrigg)) and (playerArray[curUser.sName])) then |
| + | if ((lngWord ~= 0) and string.find(strSolved, strCMask, 1, plain)) then |
| + | if (lngHinted < lngMaxHints) then |
| + | for nn=1,bcount do |
| + | local lngRepChar = math.random(1, string.len(strWord)) |
| + | while 1 do |
| + | if (boolHintAlwaysHitHidden) then |
| + | if (strsub(strSolved, lngRepChar, lngRepChar) == strCMask) then |
| + | break |
| + | end |
| + | else |
| + | break |
| + | end |
| + | lngRepChar = math.random(1, string.len(strWord)) |
| + | end |
| + | local strTurn = "" |
| + | for x=1, string.len(strWord) do |
| + | if (x == lngRepChar) then |
| + | strTurn = strTurn..string.sub(strWord, x, x) |
| + | else |
| + | strTurn = strTurn..string.sub(strSolved, x, x) |
| + | end |
| + | end |
| + | strSolved = strTurn |
| + | end |
| + | lngHinted = lngHinted + 1 |
| + | lngHintTimeCount = lngHintTimeCount + lngHintTime |
| + | SendToPlayers("Hinweis: "..strSolved) |
| + | acount = "" |
| + | else |
| + | SendToPlayers("Alle Hinweise aufgebraucht!") |
| + | end |
| + | else |
| + | SendToPlayers("Kein Hinweis gebraucht!") |
| + | end |
| + | elseif ((string.lower(firstWord) == string.lower(ScoreTrigg)) and (playerArray[curUser.sName])) then |
| + | curUser:SendPM(BotName, "ERGEBNISSE:") |
| + | curUser:SendPM(BotName, "---------------------------------------------------------") |
| + | for index, value in pointArray do |
| + | curUser:SendPM(BotName, index.."'s punkte: "..value) |
| + | end |
| + | curUser:SendPM(BotName, "---------------------------------------------------------") |
| + | elseif ((string.lower(firstWord) == string.lower(PlayerTrigg)) and (playerArray[curUser.sName])) then |
| + | curUser:SendPM(BotName, "SPIELER:") |
| + | curUser:SendPM(BotName, "---------------------------------------------------------") |
| + | for index, value in playerArray do |
| + | curUser:SendPM(BotName, index) |
| + | end |
| + | curUser:SendPM(BotName, "---------------------------------------------------------") |
| + | elseif (string.lower(firstWord) == string.lower(QuestionsTrigg)) then |
| + | if (curUser.bOperator) then |
| + | curUser:SendPM(BotName, "TOP "..lngMaxShowList.." FRAGEN:") |
| + | curUser:SendPM(BotName, "---------------------------------------------------------") |
| + | local lngShowMax = lngMaxShowList |
| + | for index, value in guessArray do |
| + | if (lngShowMax == 0) then |
| + | break |
| + | end |
| + | arrTmp = tokenize(guessArray[index], strGSep) |
| + | strTmp = arrTmp[1] |
| + | curUser:SendPM(BotName, "["..index.."] "..strTmp) |
| + | lngShowMax = lngShowMax - 1 |
| + | end |
| + | curUser:SendPM(BotName, "Total # an Fragen: "..lngGuessmax) |
| + | curUser:SendPM(BotName, "---------------------------------------------------------") |
| + | curUser:SendPM(BotName, " ") |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(StartTrigg)) then |
| + | if (curUser.sName) then |
| + | if (lngWord == 0) then |
| + | playerArray[curUser.sName] = 1 |
| + | SendToAll(BotName, strStart) |
| + | if (lngMode == 2) then |
| + | SendToPlayers(strStart) |
| + | end |
| + | StopQuiz(1) |
| + | else |
| + | SendToAll(BotName, "Da ist ein Quizz im gange, schreibe "..JoinTrigg.." um mitzuspielen!") |
| + | end |
| + | else |
| + | curUser:SendPM(BotName, "Nur Op's koennen das Quizz starten.") |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(StopTrigg)) then |
| + | if (curUser.sName) then |
| + | HoldQuiz() |
| + | StopQuiz() |
| + | SendToAll(BotName, strStopp) |
| + | if (lngMode == 2) then |
| + | SendToPlayers(strStopp) |
| + | end |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(WordTrigg)) then |
| + | if ((lngWord ~= 0) and (playerArray[curUser.sName] == "Player")) then |
| + | SendToPlayers("Die derzeitige Frage lautet: "..strSolved.." ("..strlen(strSolved)..")") |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(QuizTrigg)) then |
| + | if ((lngWord ~= 0) and (playerArray[curUser.sName])) then |
| + | SendToPlayers("Frage: "..strQuestion) |
| + | end |
| + | elseif (string.lower(firstWord) == string.lower(ReloadTrigg)) then |
| + | if (curUser.bOperator) then |
| + | local _, _, secondWord = string.find(data, "%b<>%s+%S+%s+(%S+)") |
| + | if (secondWord) then |
| + | handle = io.open(secondWord, "r") |
| + | if (handle) then |
| + | handle:close() |
| + | strTrivFile = secondWord |
| + | end |
| + | end |
| + | |
| + | HoldQuiz() |
| + | ReloadQuestions() |
| + | end |
| + | else |
| + | if ((lngWord ~= 0) and (boolPlaydata)) then |
| + | if (playerArray[curUser.sName]) then |
| + | local msg = string.sub(data, (4 + string.len(curUser.sName))) |
| + | if (string.len(msg) >= string.len(strWord)) then |
| + | local boolDisc = nil |
| + | |
| + | local strTurn = "" |
| + | if string.lower(msg) == string.lower(strWord) then |
| + | strTurn = strWord |
| + | boolDisc = 1 |
| + | else |
| + | strTurn = strSolved |
| + | end |
| + | |
| + | |
| + | if (boolDisc) then |
| + | strSolved = strTurn |
| + | end |
| + | if (boolDisc) then |
| + | if (string.lower(msg) ~= string.lower(strWord)) then |
| + | SendToOthers(curUser, msg) |
| + | SendToPlayers("Die Antwort ist nun: "..strSolved) |
| + | end |
| + | end |
| + | if (string.lower(msg) == string.lower(strWord)) then |
| + | if (not (pointArray[curUser.sName])) then |
| + | pointArray[curUser.sName] = 0 |
| + | end |
| + | if lngHinted == 3 then pointArray[curUser.sName] = pointArray[curUser.sName] + 1 |
| + | elseif lngHinted == 2 then pointArray[curUser.sName] = pointArray[curUser.sName] + 2 |
| + | elseif lngHinted == 1 then pointArray[curUser.sName] = pointArray[curUser.sName] + 3 |
| + | else pointArray[curUser.sName] = pointArray[curUser.sName] + 4 |
| + | end |
| + | SendToPlayers("Die Antwort war: "..strSolved) |
| + | SendToPlayers("Die Antwort wurde erraten von: "..curUser.sName) |
| + | SendToPlayers("Naechste Frage in "..(lngRestTime * 15).." (15) Secs") |
| + | lngPassed = lngMaxTime |
| + | SendToPlayers(curUser.sName.."'s Punkte: "..pointArray[curUser.sName]) |
| + | HoldQuiz() |
| + | end |
| + | end |
| + | end |
| + | end |
| + | end |
| + | end |
| + | end |
| + | -------------------------------- |
| + | function HoldQuiz() |
| + | strWord = "" |
| + | strQuestion = "" |
| + | strSolved = "" |
| + | end |
| + | |
| + | function StopQuiz(restart) |
| + | lngWord = 0 |
| + | lngPassed = 0 |
| + | strWord = "" |
| + | strQuestion = "" |
| + | strSolved = "" |
| + | StopTimer() |
| + | if (restart) then |
| + | StartQuiz() |
| + | end |
| + | end |
| + | |
| + | function StartQuiz() |
| + | lngWord = math.random(1, lngGuessmax) |
| + | QWarray = tokenize(guessArray[lngWord], strGSep) |
| + | strQuestion = QWarray[1] |
| + | strWord = QWarray[2] |
| + | strSolved = "" |
| + | for x=1, string.len(strWord) do |
| + | if (string.sub(strWord, x, x) == " ") then |
| + | strSolved = strSolved.." " |
| + | else |
| + | strSolved = strSolved..strCMask |
| + | end |
| + | end |
| + | lngPassed = 0 |
| + | lngHinted = 0 |
| + | lngHintTimeCount = lngHintTime |
| + | if string.len(strWord) < 4 then |
| + | bcount = math.random(1, 2) |
| + | elseif string.len(strWord) >= 4 and string.len(strWord) <= 9 then |
| + | bcount = math.random(1, 3) |
| + | elseif string.len(strWord) >= 9 and string.len(strWord) <= 20 then |
| + | bcount = math.random(2, 4) |
| + | else |
| + | bcount = math.random(3, 5) |
| + | end |
| + | SetTimer(15000) |
| + | StartTimer() |
| + | SendToPlayers("Frage: "..strQuestion) |
| + | SendToPlayers("Antwort: "..strSolved.." ("..string.len(strSolved)..")") |
| + | end |
| + | ----------------------------------------- |
| + | function OnTimer() |
| + | lngPassed = lngPassed + 1 |
| + | if (lngPassed == lngMaxTime) then |
| + | scount = scount + 1 |
| + | if scount == countSaveTurns then |
| + | local handle = io.open(strTrivScoreFile, "w") |
| + | for index, value in pointArray do |
| + | handle:write(index..strGSep..value.."\r\n") |
| + | end |
| + | handle:close() |
| + | scount = 0 |
| + | end |
| + | if (boolRevealAnswer) then |
| + | SendToPlayers("Die Antwort war '"..strWord.."' und wurde nicht erraten!") |
| + | else |
| + | SendToPlayers("Die Antwort wurde nicht erraten!") |
| + | end |
| + | SendToPlayers("Naechste Frage in "..(lngRestTime * 15).." Sekunden") |
| + | HoldQuiz() |
| + | elseif (lngPassed >= (lngRestTime + lngMaxTime)) then |
| + | StopQuiz(1) |
| + | elseif (lngPassed == lngHintTimeCount) then |
| + | if (boolAutoHint) then |
| + | for nn=1,bcount do |
| + | local lngRepChar = math.random(1, string.len(strWord)) |
| + | while 1 do |
| + | if (boolHintAlwaysHitHidden) then |
| + | if (string.sub(strSolved, lngRepChar, lngRepChar) == strCMask) then |
| + | break |
| + | end |
| + | else |
| + | break |
| + | end |
| + | lngRepChar = math.random(1, string.len(strWord)) |
| + | end |
| + | local strTurn = "" |
| + | for x=1, string.len(strWord) do |
| + | if (x == lngRepChar) then |
| + | strTurn = strTurn..string.sub(strWord, x, x) |
| + | else |
| + | strTurn = strTurn..string.sub(strSolved, x, x) |
| + | end |
| + | end |
| + | strSolved = strTurn |
| + | end |
| + | lngHinted = lngHinted + 1 |
| + | lngHintTimeCount = lngHintTimeCount + lngHintTime |
| + | SendToPlayers("Hinweis: "..strSolved) |
| + | end |
| + | end |
| + | end |
| + | --------------------------------------- |
| + | function tokenize (inString,token) |
| + | _WORDS = {} |
| + | local matcher = "([^"..token.."]+)" |
| + | string.gsub(inString, matcher, function (w) table.insert(_WORDS,w) end) |
| + | return _WORDS |
| + | end |
| + | ---------------------------------------- |
| + | function ReloadQuestions() |
| + | guessArray = {} |
| + | lngGuessmax = 0 |
| + | local boolRestart = nil |
| + | if (lngWord ~= 0) then |
| + | SendToPlayers("Lade Fragen neu, Quizz wird beendet!") |
| + | StopQuiz() |
| + | boolRestart = 1 |
| + | end |
| + | handle = io.open(strTrivFile, "r") |
| + | if (handle) then |
| + | local line = handle:read() |
| + | |
| + | while line do |
| + | if ((line ~= "") and (string.find(line, strGSep, 1, plain))) then |
| + | table.insert(guessArray, line) |
| + | lngGuessmax = lngGuessmax + 1 |
| + | end |
| + | line = handle:read() |
| + | end |
| + | handle:close() |
| + | end |
| + | if (lngGuessmax < 1) then |
| + | guessArray = { |
| + | "Wie nennt man ein Boomerang der nicht zurückkommt?"..strGSep.."ein Stock", |
| + | "Wie heisst das Rundling-Dorf in der nähe von Weimar?"..strGSep.."Tiefengruben", |
| + | "Welcher deutsche Kaiser starb in Memmleben?"..strGSep.."Otto der Erste", |
| + | "Welches ist das meistgebaute Auto der Welt?"..strGSep.."VW Kaefer", |
| + | "An welchem Wochentag ist meistens das Weimarnetztreffen?"..strGSep.."Dienstag", |
| + | "Wieviel Aldi Filialen gibt es in Weimar?"..strGSep.."3", |
| + | "Wie heisst der Konstrukteur des VW Käfer?"..strGSep.."Ferdinand Porsche", |
| + | "In welcher Stadt ist das grösste Freifunknetz?"..strGSep.."Berlin" |
| + | } |
| + | lngGuessmax = 2 |
| + | end |
| + | if (boolRestart) then |
| + | SendToPlayers("Lade Fragen neu, Quizz wird neugestartet! Derzeitige Anzahl der Fragen: "..lngGuessmax) |
| + | StartQuiz() |
| + | end |
| + | strTrivFile = strDefTrivFile |
| + | end |
| + | ---------------------------------------- |
| + | function SaveScores(curUser) |
| + | local handle = io.open(strTrivScoreFile, "w") |
| + | for index, value in pointArray do |
| + | handle:write(index..strGSep..value.."\r\n") |
| + | end |
| + | curUser:SendData(BotName,"Punktestand gesichert") |
| + | handle:close() |
| + | end |
| + | ----------------------------------------- |
| + | function LoadScores(curUser) |
| + | local handle = io.open(strTrivScoreFile, "r") |
| + | if (handle) then |
| + | local line = handle:read() |
| + | while line do |
| + | local arrTmp = tokenize(line, strGSep) |
| + | if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then |
| + | pointArray[arrTmp[1]] = tonumber(arrTmp[2]) |
| + | end |
| + | line = handle:read() |
| + | end |
| + | curUser:SendData(BotName,"Punktestand geladen") |
| + | handle:close() |
| + | end |
| + | end |
| + | --------------------------------------------------- |
| + | function AddQuestion(curUser, sQuestion, sAnswer) |
| + | local handle = io.open(strQFile, "a") |
| + | handle:write("Vorgeschlagen von <"..curUser.sName.."> "..sQuestion..strGSep..sAnswer.."\r\n") |
| + | SendToPlayers(curUser.sName.." hat eine Frage hinzufefuegt "..sQuestion) |
| + | curUser:SendPM(BotName,curUser.sName.." Du gabst als Antwort "..sAnswer) |
| + | handle:close() |
| + | end |
| + | -------------------------------------------- |
| + | function SendToPlayers(msg) |
| + | if ((lngMode > 2) or (lngMode < 0)) then |
| + | lngMode = lngDefMode |
| + | end |
| + | |
| + | if (lngMode == 0) then |
| + | SendToAll(BotName, msg) |
| + | elseif (lngMode == 1) then |
| + | for index, value in playerArray do |
| + | SendToNick(index, "<"..BotName.."> "..msg) |
| + | end |
| + | elseif (lngMode == 2) then |
| + | for index, value in playerArray do |
| + | SendPmToNick(index, BotName, msg) |
| + | end |
| + | end |
| + | end |
| + | --------------------------------------------- |
| + | function SendToOthers(msg, curUser) |
| + | if ((lngMode == 2) and (boolShowGuessesInPM)) then |
| + | for index, value in playerArray do |
| + | if (index ~= curUser.sName) then |
| + | SendPmToNick(index, BotName, "<"..curUser.sName.."> "..msg) |
| + | end |
| + | end |
| + | end |
| + | end |
| + | ----------------------------------------------- |
| + | function SendChatToOthers(chat, curUser) |
| + | if (lngMode == 2) then |
| + | for index, value in playerArray do |
| + | if (index ~= curUser.sName) then |
| + | SendToNick(index, "$To: "..index.." From: "..BotName.." $<"..curUser.sName.."> "..chat) |
| + | end |
| + | end |
| + | end |
| + | end |
| + | -------------------------------------------- |
| + | function showHelp(curUser) |
| + | curUser:SendData("<Help> ") |
| + | curUser:SendData("<Help> "..BotVersion.." Befehle:") |
| + | curUser:SendData("<Help> ") |
| + | if (lngMode == 0) then |
| + | curUser:SendData("<Help> "..BotVersion.." spielt das Quizz nun im Mainchat") |
| + | elseif (lngMode == 1) then |
| + | curUser:SendData("<Help> "..BotVersion.." spielt das Quizz nun versteckt im Mainchat") |
| + | else |
| + | curUser:SendData("<Help> "..BotVersion.." spielt das Quizz nun als PM") |
| + | end |
| + | curUser:SendData("<Help> "..HelpTrigg.." - Zeigt diese Hilfe") |
| + | curUser:SendData("<Help> "..JoinTrigg.." - damit kannst Du am Quizz teilnehmen") |
| + | curUser:SendData("<Help> "..PartTrigg.." - damit verlaesst Du das Quizz") |
| + | curUser:SendData("<Help> "..WordTrigg.." - zeigt das derzeitig gesuchte Wort (Antwort)") |
| + | curUser:SendData("<Help> "..QuizTrigg.." - zeigt die derzeitige Frage") |
| + | curUser:SendData("<Help> "..PointTrigg.." - zeigt Deine Punkte") |
| + | curUser:SendData("<Help> "..ScoreTrigg.." - zeigt die Ergebnisse von allen") |
| + | curUser:SendData("<Help> "..PlayerTrigg.." - zeigt alle Spieler die am derzeitigen Quizz teilnehmen") |
| + | curUser:SendData("<Help> "..HintTrigg.." - enthuellt einen Buchstaben in der derzeitigen Antwort") |
| + | curUser:SendData("<Help> "..TopTrigg.." - zeigt die Top Ten Ergebnisse") |
| + | curUser:SendData("<Help> "..AddTrigg.." - fuegt ein Frage zum Fragenfile hinzu. Schreibe die Frage und trenne die Antwort von der Frage mit einer #") |
| + | curUser:SendData("<Help> BEISPIEL : qfrage Wie schnell fliegt ein Vogel?#keine Ahnung") |
| + | if (curUser.bOperator) then |
| + | curUser:SendData("<Help> ") |
| + | curUser:SendData("<Help> "..BotVersion.." Operator Befehle:") |
| + | curUser:SendData("<Help> "..StopTrigg.." - Stoppt den Quizzbot") |
| + | curUser:SendData("<Help> "..RestartTrigg.." - startet den Quizzbot neu, alle Ergebnisse werden zurueckgesetzt!") |
| + | curUser:SendData("<Help> "..QuestionsTrigg.." - zeigt alle Fragen im derzeitigen Quizz") |
| + | curUser:SendData("<Help> "..ReloadTrigg.." (<filename>) - laedt die Fragen von "..strDefTrivFile) |
| + | curUser:SendData("<Help> "..ModeTrigg.." - aendert den Spielmodus (0-2)!") |
| + | curUser:SendData("<Help> "..SaveTrigg.." - speichert die Ergebnisse in "..strTrivScoreFile) |
| + | curUser:SendData("<Help> "..LoadTrigg.." - laedt die Ergebnisse von "..strTrivScoreFile) |
| + | curUser:SendData("<Help> "..StartTrigg.." - startet den Quizzbot und Du nimmst automatisch daran teil") |
| + | curUser:SendData("<Help> ") |
| + | curUser:SendData("<Help> "..BotVersion.." Modis:") |
| + | curUser:SendData("<Help> ".."0 = gespielt wird im Mainchat!") |
| + | curUser:SendData("<Help> ".."1 = gespielt wird im Mainchat aber die Fragen sind nur sichtbar fuer Mitspieler") |
| + | curUser:SendData("<Help> ".."2 = gespielt wird komplett als PM") |
| + | end |
| + | end |
| + | ---------------------------------------------- |
| + | function TopTen(user) |
| + | local index = {n=0} |
| + | table.foreach(pointArray, function(nick, score) table.insert(index, nick) end) |
| + | local func = function(a, b) return pointArray[a] > pointArray[b] end |
| + | table.sort(index, func) |
| + | |
| + | x = x or 10 if x > index.n then x = index.n end |
| + | local result = "\r\nTop "..x.." Quizz Ergebnisse in diesem Hub..\r\n Pos\t Score\t\t Nick\t\r\n" |
| + | for i = 1, x do result = result.."\r\n "..i..".\t"..pointArray[index[i]].."\t\t"..index[i] end |
| + | msg = result |
| + | SendToPlayers(msg) |
| + | end |
| + | </pre> |
| + | |
| + | * Postman(mailserver)-bot |
| + | <pre> |
| + | -- PostMan Bot 0.3 by bastya_elvtars (the rock n' roll doctor) |
| + | -- offline message system |
| + | -- code ripped from law maker bot |
| + | -- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D) |
| + | -- the commands are case insensitive, the parameters aren't :) |
| + | |
| + | ------- 0.2: |
| + | -- added function so ppl cannot post 2 online users |
| + | |
| + | ------- 0.3: |
| + | -- converted to lua5 |
| + | -- washere is now global, no more CPU spikes |
| + | |
| + | ------- 0.4: |
| + | -- touched by Herodes (optimisation tsunami) |
| + | -- added : more details on the bot |
| + | -- added : message privacy ;) |
| + | -- changed : better way to parseenv ;) |
| + | -- changed : better way to display messages and inbox |
| + | -- changed : better way to parsecmds ( thx bastya_elvtars ;) |
| + | |
| + | ------- 0.5: |
| + | -- touched by Skippy84 |
| + | -- fix error: make offline.dat thx goto Herodes for the idea to fix the problem |
| + | -- fix error: false command !showmsg |
| + | -- added: commands can edit at the Settings section |
| + | -- added: shown commands linked to the editable commands (so ther change on the fly) |
| + | |
| + | ------- 0.51: |
| + | -- bastya_elvtars put his hands back on this |
| + | -- script now creates an empty offline.dat if does not exist... you guys keep ignoring new Lua5 features :P |
| + | -- thx guys for the features you added, they are really eye-candy |
| + | |
| + | ------- 0.6: |
| + | -- touched again by Skippy84 |
| + | -- added: a little rightclick menu |
| + | |
| + | --------------------------------SETTINGS---------------------------------------- |
| + | |
| + | Bot = { |
| + | name = "Weimarnetz-Mailserver" , -- bot's name |
| + | email = "postman@mail.me", -- bot's email |
| + | desc = "Nachrichten senden an User die gerade nicht da sind..", -- bot's desc |
| + | } |
| + | |
| + | inboxsize=15 -- the maximum amount of messages users can have in their inbox |
| + | |
| + | cmdpost = "postmsg" -- Shows the Hub Stats |
| + | cmdread = "readmsg" -- Shows the Hub Stats |
| + | cmdibox = "inbox" -- Shows the Hub Stats |
| + | cmddbox = "delmsg" -- Shows the Hub Stats |
| + | |
| + | ----------------------END OF SETTINGS------------------------------------------- |
| + | |
| + | |
| + | -------------------------------------- Utility Functions |
| + | |
| + | function cls() |
| + | collectgarbage() |
| + | io.flush() |
| + | end |
| + | |
| + | function Main() |
| + | local function load() |
| + | local t = {}; local f = io.open("washere.lst", "r") |
| + | if f then for l in f:lines() do t[l] = 1; end; f:close(); end |
| + | return t; |
| + | end |
| + | washere = load() |
| + | message = {} |
| + | if loadfile("offline.dat") then |
| + | dofile("offline.dat") |
| + | else |
| + | io.output("offline.dat") |
| + | io.write("") |
| + | io.output() |
| + | end |
| + | frmHub:RegBot(Bot.name, 1, Bot.desc, Bot.email ) |
| + | Bot = Bot.name |
| + | end |
| + | |
| + | -------------------------------------- Command Functions |
| + | |
| + | --- post msg |
| + | |
| + | function postmsg( user, data, how ) |
| + | local _,_,nick,msg = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)") |
| + | if nick then |
| + | if not GetItemByName(nick) then |
| + | if washere[nick] then |
| + | local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end |
| + | if not message[nick] then message[nick] = {}; end |
| + | if (checksize(nick) < inboxsize) then |
| + | table.insert( message[nick], { ["message"] = msg, ["who"] = user.sName, ["when"] = os.date("%Y. %m. %d. %X"), ["read"] = 0, } ) |
| + | SendBack( user, "Erfolgreich gesendete Nachricht!", Bot, how ) |
| + | savemsg() |
| + | else |
| + | SendBack( user, "Sorry, aber "..nick.." hat eine volle Mailbox. Probier es später.", Bot, how ) |
| + | end |
| + | else |
| + | SendBack( user, "User "..nick.." wart nie gesehen in diesem Hub.", Bot, how ) |
| + | end |
| + | else |
| + | SendBack( user, nick.." ist online! PM ist doch einfacher...", Bot, how ) |
| + | end |
| + | else |
| + | SendBack( user, "Falscher syntax! Schreibe: !"..cmdpost.." ", Bot, how ) |
| + | end |
| + | cls(); return 1; |
| + | end |
| + | |
| + | --- del msg |
| + | |
| + | function delmsg( user, data, how ) |
| + | if message[user.sName] then |
| + | local _,_,args = string.find(data,"%b<>%s+%S+%s+(.+)") |
| + | if args then |
| + | local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end |
| + | local function resort(t) local r ={}; for i,v in t do table.insert(r, v); end; return r; end |
| + | for num in string.gfind( args, "%s-(%d+)%s-" ) do |
| + | if num then |
| + | num = tonumber(num); |
| + | if message[user.sName][num] then |
| + | message[user.sName][num] = nil |
| + | SendBack( user, "Nachricht #"..num.." erfolgreich gelöscht!", Bot, how ) |
| + | else |
| + | SendBack( user, "Nachricht #"..num.." existiert nicht!", Bot, how ) |
| + | end |
| + | end |
| + | end |
| + | message[user.sName] = resort(message[user.sName]); |
| + | if checksize(user.sName) == 0 then message[user.sName] = nil; end |
| + | savemsg() |
| + | else |
| + | SendBack( user, "Falscher syntax! Schreibe: !"..cmddbox.." . Mehrere Zahlen mit Leerzeichen trennen.", Bot, how ) |
| + | end |
| + | else |
| + | SendBack( user, "Deine Mailbox ist leer.", Bot, how ) |
| + | end |
| + | cls(); return 1; |
| + | end |
| + | |
| + | ---------------------------------------------------------------------------------- |
| + | --------------------------------------------------------------------------------- |
| + | ---------------------------------------------------------------------------------- show inbox |
| + | |
| + | function inbox( user, how ) |
| + | local sep, msg = string.rep( "=", 75 ), "\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n" |
| + | msg = msg..sep.."\r\n Msg#\tSender\tTime of sending\t\tRead\r\n"..sep |
| + | if message[user.sName] then |
| + | local function numess ( r ) if r == 0 then return "no"; end return "yes"; end |
| + | local function checksize ( n ) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end |
| + | local function dcode ( s ) if (string.sub(s,1,3) == "-n#") then s=string.sub(s,4,-1); local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;end |
| + | for num, t in message[user.sName] do |
| + | msg=msg.."\r\n "..num.."\t"..dcode(t.who).."\t"..t.when.."\t"..numess(t.read).."\r\n"..sep |
| + | end |
| + | SendBack( user, msg, Bot, true ) |
| + | SendBack( user, "Schreibe !"..cmdread.." um die Nachricht zu sehen. Mehrere Zahlen mit Leerzeichen trennen.", Bot, true ) |
| + | if checksize(user.sName) >= inboxsize then SendBack( user, "Alarm: Deine Mailbox ist voll!", Bot, true ); end |
| + | else |
| + | SendBack( user, "Du hast keine Nachrichten.", Bot, how ) |
| + | end |
| + | cls(); return 1; |
| + | end |
| + | |
| + | --- read msg(s) |
| + | |
| + | function readmsg( user, data, how ) |
| + | if message[user.sName] then |
| + | local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)") |
| + | if args then |
| + | local function dcode(s) if (string.sub(s,1,3) == "-n#") then s = string.sub(s,4,-1);local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s; |
| + | end |
| + | for num in string.gfind( args, "%s-(%d+)%s-" ) do |
| + | if num then num = tonumber(num) end |
| + | if num and message[user.sName][num] then |
| + | local t = message[user.sName][num] |
| + | local msg, sep,set = "\r\n\r\n\t\t\t\t\t\t\tMessage #"..num.."\r\n", string.rep( "=", 100 ), string.rep("- ", 85) |
| + | msg = msg..sep.."\r\n\r\nFrom: "..dcode(t.who).."\tTime: "..t.when.."\t\tMessage follows\r\n"..set.."[Message start]\r\n"..dcode(t.message).."\r\n"..set.."[Message end]\r\n"..sep |
| + | SendBack( user, msg, Bot, true ) |
| + | if t.read == 0 then t.read = 1; savemsg(); end |
| + | else |
| + | SendBack( user, "Nachricht #"..num.." existiert nicht!", Bot, how ) |
| + | end |
| + | end |
| + | else |
| + | SendBack( user, "Falscher syntax! Schreibe: !"..cmdread.." . Mehrere Zahlen mit Leerzeichen trennen.", Bot, how ) |
| + | end |
| + | else |
| + | SendBack( user, "Deine Mailbox ist leer.", Bot, how ) |
| + | end |
| + | cls(); return 1; |
| + | end |
| + | |
| + | --- save msg |
| + | |
| + | function savemsg() |
| + | local function parse(tbl) |
| + | local str, tab ="", string.rep( "\t", 9) |
| + | local function fquot(s) return string.format( "%q", s) end |
| + | local function ncode( s ) if (s ~= "") and (string.sub(s,1,3) ~= "-n#") then local t = {}; for i = 1, string.len(s) do t[i] = string.byte(string.sub(s,i,i)); end; return "-n#"..table.concat(t, "#"); end; return s; end |
| + | for a, t in tbl do |
| + | str = str.."\t\t{ ["..fquot("read").."] = "..t.read..", ["..fquot("who").."] = "..fquot(ncode(t.who))..", ["..fquot("when").."] = "..fquot(t.when)..",\n\t\t["..fquot("message").."] = "..fquot(ncode(t.message)).." },\n" |
| + | end |
| + | return str |
| + | end |
| + | local f = io.open ( "offline.dat", "w+" ) |
| + | local s = "message = {" |
| + | for name, t in message do |
| + | s = s.."\n\t["..string.format( "%q", string.gsub( name, "\"", "\"")).."] = {\n"..parse(t).."\t}," |
| + | end; |
| + | f:write(s.."\n}") |
| + | f:close() |
| + | end |
| + | |
| + | function SendBack( user, msg, who, pm ) |
| + | if pm then user:SendPM ( who, msg ); else user:SendData( who, msg ); end |
| + | end |
| + | |
| + | function NewUserConnected(user) |
| + | if user.bUserCommand then |
| + | user:SendData("$UserCommand 1 3 :Weimarnetz-Mailserver:\\INBOX$<%[mynick]> !inbox||") |
| + | user:SendData("$UserCommand 1 3 :Weimarnetz-Mailserver:\\poste eine Nachricht$<%[mynick]> !postmsg %[line:Enter and :]||") |
| + | user:SendData("$UserCommand 1 3 :Weimarnetz-Mailserver:\\lese eine Nachricht$<%[mynick]> !readmsg %[line:Enter Nr of Post you would read:]||") |
| + | user:SendData("$UserCommand 1 3 :Weimarnetz-Mailserver:\\lösche eine Nachricht$<%[mynick]> !delmsg %[line:Enter Nr of Post you would delete:]||") |
| + | user:SendData(":Weimarnetz-Mailserver:", "Neues Rechts-Click Menu für Weimarnetz-Mailserver steht zur Verfügung..") |
| + | end |
| + | |
| + | if not washere[user.sName] then washere[user.sName] = 1 end |
| + | if message[user.sName] then |
| + | local cnt=0 |
| + | for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end |
| + | if (cnt > 0) then SendBack( user, "Du hast "..cnt.." neue Nachrichten. Schreibe !"..cmdibox.." um in Deine Mailbox zu schauen!", Bot, true ); end |
| + | end |
| + | end |
| + | |
| + | function ChatArrival(user,data) |
| + | local data = string.sub( data, 1, -2 ) |
| + | local _,_,cmd = string.find(data,"%b<>%s+[!+.#?](%S+)") |
| + | if cmd then return parsecmds( user, data, string.lower(cmd) ); end |
| + | end |
| + | |
| + | function ToArrival(user,data) |
| + | if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then |
| + | local data = string.sub( data, 1, -2 ) |
| + | local _,_,cmd = string.find(data,"%$%b<>%s+[!+.#?](%S+)") |
| + | if cmd then return parsecmds( user, data, string.lower(cmd), true ) end |
| + | return 1 |
| + | end |
| + | end |
| + | |
| + | function parsecmds( user, data, cmd, how ) |
| + | local t = { |
| + | [cmdpost] = { postmsg, { user, data, how } }, |
| + | [cmdread] = { readmsg, { user, data, how } }, |
| + | [cmdibox] = { inbox, { user, how } }, |
| + | [cmddbox] = { delmsg, { user, data, how } }, |
| + | } |
| + | if t[cmd] then |
| + | return t[cmd][1]( unpack(t[cmd][2]) ) |
| + | end |
| + | end |
| + | |
| + | function UserDisconnected(user) |
| + | if not washere[user.sName] then washere[user.sName] = 1; end |
| + | end |
| + | |
| + | function OnExit() |
| + | savemsg() |
| + | local f = io.open( "washere.lst", "w+") |
| + | for a,b in washere do f:write(a.."\n"); end |
| + | f:close() |
| + | end |
| + | |
| + | OpDisconnected=UserDisconnected |
| + | OpConnected=NewUserConnected |
| + | </pre> |