2011-07-19 7 views
1

私は(非常に)初心者のプログラマーで、どのような種類のチャットルームが使用されているかにかなり依存している非常に単純なチャットルームのボットを書くことが可能かどうかは疑問です。ブラウザの内容に基づいて基本的なチャットボット/自動レスポンダを作成する方法は?

シナリオは、私の友人が、いくつかの仲間のためだけに基本的なチャットルーム(https://blueimp.net/ajax/)を設定しているということですが、私は "bot"アカウントを作りたいクライアントマシン(鉱山)にのみ存在します。したがって、特定の文字列のブラウザを(ページを再ロードすることなく)継続的にチェックし、それが検出された場合はそれに応答します。例のように、たぶん彼らは!ボットソフトとタイプし、それは歌の推薦と共に戻ってくるでしょう。

私はApplescriptがこれを行う簡単な方法だと思っていました。誰もが私を始めさせるのに役立つだろうか?私が言ったように、私は初心者ですので、心に留めてください。これを学習体験として使用しようとしていて、書籍やチュートリアルではなく、特定のシナリオに対する解決策を考え出すことでベストを尽くします。

基本的に、流れのようなものになります:

  • 文字列 2秒ごとに(それがリフレッシュするAjaxベース、必要ません...ただ、ブラウザウィンドウ自体を確認してください)
  • の確認ウェブページ
  • 文字列が見つかった場合、応答 +

を入力して最初のテキストフィールドに返信私はこれではありません知っていますチャットボットを作る最も効率的な方法ですが、私はこのシナリオを使って、アプリケーションがローカルで互いにどのようにやりとりするかを理解するのを助けようとしています。 :)

答えて

0

私はあなたにこのコードを与えることでStackOverflowの書かれていないルールを破っているわけではありませんが、このAppleScriptコードを試してみてください(ブラウザウィンドウ全体がチャットボックスこの)必要に応じて:

repeat 
    tell application "Safari" --or whatever browser you use 
     set the message to "" 
     repeat until the message contains "something" --replace 'something' with the string you want to search for 
      set the message to (the text of document 1) as string --all text on the page 
     end repeat 
    end tell 
    tell application "System Events" 
     tell process "Safari" 
      select text box 1 of document 1 --assuming the chat box is the only text box on the page; if not, determine which number the chat box is. 
      --Text boxes are numbered starting at 1 and ending at the last text box. The 'search' goes from left to right, once the right edge of the window is reached, the search goes down until it reaches the next box. 
      --Once you determine the text box's number, change the 'text box 1' to 'text box [number]', where [number] is the text box's number. 
      keystroke "response" --replace 'respose' with the reply you want to send back 
     end tell 
    end tell 
    delay 2 --wait 2 seconds so the script doesn't spam the chat box 
end repeat 

これが何らかの理由で動作しないおよび/またはご質問があれば、ちょうど頼みます。 :)

関連する問題