Receive Adium messages in Applescript
I'm trying to write a simple chat bot for Adium, that will post "lol" and "haha" and answer basic questions in annoying group chats that some people keep adding me to.
I've covered the "lol" part with a few simple send and delay commands in a repeat, but I need to do some interaction as well.
Answer "yes" to anything with a question mark for example...Believe me or not, such a simple bot would pass a Turing Test for those conversations.
Opening the Adium dictionary does not reveal any obvious way of getting messages, nor does the Growl dictionary.
I did found out that I can run a script every time a message is received, Is there a way to get access to the sent message?
Adium pref http://media.ruk.ca/images/adiumpreferences.png
My code:
tell application "Adium"
activate
set theChat to the active chat
send theChat message "Hi"
delay 5
send theChat message "How's life?"
delay 10
repeat 10 times
send theChat message "Realy?"
开发者_StackOverflowdelay 5
send theChat message "Lol :P"
delay 15
send theChat message "Haha XD"
delay 15
send theChat message "Yes1!!1"
delay 20
send theChat message "I like it! :D"
delay 10
end repeat
send theChat message "Bye!"
tell theChat to close
end tell
You can pipe to a script using Pipe Event as well now.
Based on review of the current Adium sourcecode and a search for current and past items in the Adium bug tracker and wiki which contain both "applescript" and "message" as substrings, this does not appear to be possible when using only AppleScript in Adium 1.0 through 1.3.10 (latest at time of writing). It seems to have been possible with plain AppleScript in Adium 0.89.1, but the volunteer developers are not yet convinced that adding this feature back is worth the effort.
To access the message content in AppleScript right now probably requires writing an Adium Xtra to forward the information. Examples of Xtra plugins that access the text of last message include Challenge/Response or SpamFilter. The sourcecode for SpamFilter is available on BitBucket, so you could conceivably modify it to send message contents to an AppleScript.
EDIT: Since I posted my response, user 'zostay' has spotted a new Adium Xtra called "Pipe Event". It allows sending the text of an event to a script in exactly the manner I envisioned when I wrote my second paragraph, so I'm up-voting zostay's answer. Sourcecode is also available.
精彩评论