Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ redis_url = redis://localhost:6379/0
redis_prefix = botbot-
plugin_dirs = /home/skull/dev/botbot-plugins
plugin_blacklist =
lang = en

[Links]
mode = whitelist
Expand Down
22 changes: 22 additions & 0 deletions ircbot/plugins/translate.py
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"])
Copy link
Collaborator

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

Copy link
Contributor Author

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

api_response = requests.get(translate_url).text
api_json = json.loads(api_response)
print(api_json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you print this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

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))
31 changes: 0 additions & 31 deletions ircbot/plugins/translate_ru.py

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ traitlets==4.0.0
urbandictionary==1.1
dnspython==1.15.0
raven==6.4.0
langdetect==1.0.7