-
Notifications
You must be signed in to change notification settings - Fork 10
change translate to translate any messages not in the channel lang #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import requests | ||
| import json | ||
|
|
||
| from langdetect import detect, detect_langs | ||
| from ircbot import bot | ||
|
|
||
|
|
||
| def translate(bot, text): | ||
| api_key = bot.config['Yandex']['translate_key'] | ||
| lang = detect(text) | ||
| translate_url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key={}&text={}&lang={}-{}".format(api_key, text, lang, bot.config["System"]["lang"]) | ||
| api_response = requests.get(translate_url).text | ||
| api_json = json.loads(api_response) | ||
| print(api_json) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you print this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an edited version of the previous function solely for translating russian, in the original it had been printed so i left it
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it serves a purpose any more and could probably be taken out
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return api_json['text'][0] | ||
|
|
||
|
|
||
| @bot.hook() | ||
| def message_hook(bot, channel, sender, message): | ||
| # gibberish messages are still assigned a language, however the level of confidence is always less than 0.9 | ||
| if detect(message) != bot.config["System"]["lang"] and float(str(detect_langs(message)[0])[3:]) < 0.9: | ||
| bot.message(channel, "translation: {}").format(translate(bot, message)) | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,4 @@ traitlets==4.0.0 | |
| urbandictionary==1.1 | ||
| dnspython==1.15.0 | ||
| raven==6.4.0 | ||
| langdetect==1.0.7 | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this line pass the linter? Looks rather long to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah whole thing got passed