I make a chat assistant on the site (chat bot, if you like), and ran into the problem of checking the keyword (the "! Help" commands). Perform a check in the timer. Wrote a primitive variant with the search for a keyword in the source code recorded in StringList :
find:='!help'; SrcCode.Clear; SrcCode.Add(GetHtml(WB_Doc)); for i:=0 to SrcCode.Count - 1 do if pos(find, SrcCode.Strings[i]) > 0 then begin Label1.Caption:='Ключевое слово найдено'; SpeedButton2.Click; end else Label1.Caption:='Ничего'; It works, but as expected, at intervals of every 3 seconds, I get a message stating that the keyword has been found and the response to the chat request is being executed.
I decided to dig in the direction of searching for a keyword in the page elements:
DocChat: IHTMLElementCollection; chatElement: IHTMLElement; DocChat:=(webbrowser1.Document as IHTMLDocument2).all.tags('span') as IHTMLElementCollection; for i:=0 to DocChat.Length-1 do begin chatElement:=DocChat.item(i,0)as IHTMLElement; if (chatElement.className='message') and (chatElement.innerText='!help') then begin Label1.Caption:='Ключевое слово найдено'; SpeedButton2.Click; end else Label1.Caption:='Ничего'; end; But success in this matter was not. Not searched. If, in this case, the search was performed, the effect would still be the same (every 3 seconds “Keyword found”).
Please tell me how you can implement the search for the "! Help" command in the timer, without a looping problem. Those. How a new message appears with a keyword - run once:
Label1.Caption:='Ключевое слово найдено'; SpeedButton2.Click; if the keyword is received again, execute the same commands again.
PS On the "html" page in the chat there is a div with the class chat-line , in it there is a span with the class timestamp , which records the time of the published comment (12:45) and another span , with the class message , which contains the comment itself. I think it can be used somehow, but comments with the team can be sent several times a minute, so this information is unlikely to help.
UPD: As for the sequence number, I do not quite know how the assignment code should be for the found keyword of the sequence number and the response is no more than 1 time. It should be borne in mind that through the n-th number of comments in the chat, older messages disappear from the source code.
UPD: Help please, I honestly do not know how to solve this problem.