This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/plugins/answers.py
2013-02-07 03:58:00 +13:00

14 lines
No EOL
475 B
Python

from util import hook, web, text
@hook.command
def answer(inp):
".answer <query> -- find the answer to a question on Yahoo! Answers"
query = "SELECT Subject, ChosenAnswer, Link FROM answers.search WHERE query=@query LIMIT 1"
result = web.query(query, {"query": inp.strip()}).one()
short_url = web.isgd(result["Link"])
answer = text.truncate_str(result["ChosenAnswer"], 80)
return u"\x02{}\x02 {} - {}".format(result["Subject"], answer, short_url)