mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 13:01:07 -05:00
Rename WTE plugin to TranslateParty
This is probably less mean to the translator developers that we're hacking a free API of.
This commit is contained in:
parent
7c3c90ee37
commit
0c9a0ee92d
@ -1,13 +1,13 @@
|
|||||||
##WTE - Worst Translations Ever!
|
## Translate Party
|
||||||
|
|
||||||
**Note: This plugin requires Python 3!**
|
**Note: This plugin requires Python 3!**
|
||||||
|
|
||||||
WTE is a plugin that sticks text through multiple rounds of Google Translate, in order to get
|
Translate party sticks text through multiple rounds of Google Translate, in order to get
|
||||||
some interesting results. It automatically picks a list of languages to go through, and translates
|
some amusing results. It automatically picks a list of languages to go through, and translates
|
||||||
back and forth between them quite a few times. This guarantees that the result will be different
|
back and forth between them quite a few times. This guarantees that the result will be different
|
||||||
every time.
|
every time.
|
||||||
|
|
||||||
Any source language [supported by Google Translate](https://translate.google.com/about/intl/en_ALL/#supportedLangs)
|
Any source language [supported by Google Translate](https://cloud.google.com/translate/v2/translate-reference#supported_languages)
|
||||||
is allowed, since auto-detection is used to translate text back to your desired language. This can be set via `config plugins.wte.language`, and defaults to English (`en`).
|
is allowed, since auto-detection is used to translate text back to your desired language. This can be set via `config plugins.wte.language`, and defaults to English (`en`).
|
||||||
|
|
||||||
Samples:
|
Samples:
|
@ -32,7 +32,7 @@ import supybot.conf as conf
|
|||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
try:
|
try:
|
||||||
from supybot.i18n import PluginInternationalization
|
from supybot.i18n import PluginInternationalization
|
||||||
_ = PluginInternationalization('WTE')
|
_ = PluginInternationalization('TranslateParty')
|
||||||
except:
|
except:
|
||||||
# Placeholder that allows to run the plugin on a bot
|
# Placeholder that allows to run the plugin on a bot
|
||||||
# without the i18n module
|
# without the i18n module
|
||||||
@ -44,14 +44,14 @@ def configure(advanced):
|
|||||||
# user or not. You should effect your configuration by manipulating the
|
# user or not. You should effect your configuration by manipulating the
|
||||||
# registry as appropriate.
|
# registry as appropriate.
|
||||||
from supybot.questions import expect, anything, something, yn
|
from supybot.questions import expect, anything, something, yn
|
||||||
conf.registerPlugin('WTE', True)
|
conf.registerPlugin('TranslateParty', True)
|
||||||
|
|
||||||
|
|
||||||
WTE = conf.registerPlugin('WTE')
|
TranslateParty = conf.registerPlugin('TranslateParty')
|
||||||
conf.registerChannelValue(WTE, 'verbose',
|
conf.registerChannelValue(TranslateParty, 'verbose',
|
||||||
registry.Boolean(True, _("""Determines whether
|
registry.Boolean(True, _("""Determines whether
|
||||||
verbose output (list of languages used, etc.) will be used.""")))
|
verbose output (list of languages used, etc.) will be used.""")))
|
||||||
conf.registerChannelValue(WTE, 'language',
|
conf.registerChannelValue(TranslateParty, 'language',
|
||||||
registry.String('en', _("""Determines what the output language
|
registry.String('en', _("""Determines what the output language
|
||||||
of 'wte' will be. This should be one of Google Translate's supported
|
of 'wte' will be. This should be one of Google Translate's supported
|
||||||
language codes as listed at:
|
language codes as listed at:
|
@ -43,19 +43,19 @@ except ImportError: # Python 2
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from supybot.i18n import PluginInternationalization
|
from supybot.i18n import PluginInternationalization
|
||||||
_ = PluginInternationalization('WTE')
|
_ = PluginInternationalization('TranslateParty')
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Placeholder that allows to run the plugin on a bot
|
# Placeholder that allows to run the plugin on a bot
|
||||||
# without the i18n module
|
# without the i18n module
|
||||||
_ = lambda x:x
|
_ = lambda x:x
|
||||||
|
|
||||||
class WTE(callbacks.Plugin):
|
class TranslateParty(callbacks.Plugin):
|
||||||
"""Worst Translations Ever! plugin. Translates text through
|
"""Worst Translations Ever! plugin. Translates text through
|
||||||
multiple rounds of Google Translate to get amazing results!"""
|
multiple rounds of Google Translate to get amazing results!"""
|
||||||
threaded = True
|
threaded = True
|
||||||
|
|
||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
self.__parent = super(WTE, self)
|
self.__parent = super(TranslateParty, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
self.langs = {
|
self.langs = {
|
||||||
'af': 'Afrikaans',
|
'af': 'Afrikaans',
|
||||||
@ -166,24 +166,23 @@ class WTE(callbacks.Plugin):
|
|||||||
args = {"sl": sourceLang, "tl": targetLang, 'q': text}
|
args = {"sl": sourceLang, "tl": targetLang, 'q': text}
|
||||||
url = "https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&"+ \
|
url = "https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&"+ \
|
||||||
urlencode(args)
|
urlencode(args)
|
||||||
self.log.debug("WTE: Using URL %s", url)
|
self.log.debug("TranslateParty: Using URL %s", url)
|
||||||
headers = {'User-Agent': ('Mozilla/5.0 (X11; Linux i586; rv:31.0) '
|
headers = {'User-Agent': ('Mozilla/5.0 (X11; Linux i586; rv:31.0) '
|
||||||
'Gecko/20100101 Firefox/31.0')}
|
'Gecko/20100101 Firefox/31.0')}
|
||||||
try:
|
try:
|
||||||
data = utils.web.getUrlFd(url, headers).read().decode("utf-8")
|
data = utils.web.getUrlFd(url, headers).read().decode("utf-8")
|
||||||
except utils.web.Error as e:
|
except utils.web.Error as e:
|
||||||
self.log.exception("WTE: getTranslation errored (probably malformed or too long text)")
|
self.log.exception("TranslateParty: getTranslation errored (probably malformed or too long text)")
|
||||||
return text
|
return text
|
||||||
data = self._jsonRepair(data)
|
data = self._jsonRepair(data)
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
return ''.join(x[0] for x in data[0])
|
return ''.join(x[0] for x in data[0])
|
||||||
|
|
||||||
@wrap(['text'])
|
@wrap(['text'])
|
||||||
def wte(self, irc, msg, args, text):
|
def tp(self, irc, msg, args, text):
|
||||||
"""wte <text>
|
"""tp <text>
|
||||||
|
|
||||||
Worst Translations Ever! plugin. Translates <text> through
|
Translates <text> through multiple rounds of Google Translate to get amusing results.
|
||||||
multiple rounds of Google Translate to get amazing results!
|
|
||||||
"""
|
"""
|
||||||
outlang = self.registryValue('language', msg.args[0])
|
outlang = self.registryValue('language', msg.args[0])
|
||||||
if outlang not in self.langs:
|
if outlang not in self.langs:
|
||||||
@ -195,7 +194,7 @@ class WTE(callbacks.Plugin):
|
|||||||
# in that it gives interesting results but doesn't spam Google's API
|
# in that it gives interesting results but doesn't spam Google's API
|
||||||
# (and risk getting blocked) too much.
|
# (and risk getting blocked) too much.
|
||||||
ll = random.sample(self.langs.keys(), random.randint(4,8))
|
ll = random.sample(self.langs.keys(), random.randint(4,8))
|
||||||
self.log.debug(format("WTE: Using %i languages: %L "
|
self.log.debug(format("TranslateParty: Using %i languages: %L "
|
||||||
"(outlang %s)", len(ll), ll, outlang))
|
"(outlang %s)", len(ll), ll, outlang))
|
||||||
|
|
||||||
# For every language in this list, translate the text given from
|
# For every language in this list, translate the text given from
|
||||||
@ -214,6 +213,6 @@ class WTE(callbacks.Plugin):
|
|||||||
"(output language %s)", len(ll), languages, outlang))
|
"(output language %s)", len(ll), languages, outlang))
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
|
||||||
Class = WTE
|
Class = TranslateParty
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2014, James Lu
|
# Copyright (c) 2014,2016 James Lu
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -31,18 +31,18 @@
|
|||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
from sys import version_info
|
from sys import version_info
|
||||||
|
|
||||||
class WTETestCase(PluginTestCase):
|
class TranslatePartyTestCase(PluginTestCase):
|
||||||
plugins = ('WTE',)
|
plugins = ('TranslateParty',)
|
||||||
|
|
||||||
@unittest.skipIf(version_info[0] < 3,
|
@unittest.skipIf(version_info[0] < 3,
|
||||||
"Not supported on Python 2 (severe Unicode handling problems)")
|
"Not supported on Python 2 (severe Unicode handling problems)")
|
||||||
@unittest.skipUnless(network, "Network-based tests have been disabled via "
|
@unittest.skipUnless(network, "Network-based tests have been disabled via "
|
||||||
"--no-network")
|
"--no-network")
|
||||||
def testWTE(self):
|
def testTranslateParty(self):
|
||||||
inp = "The quick brown fox jumps over the lazy dog."
|
inp = "The quick brown fox jumps over the lazy dog."
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
m = self.getMsg("wte %s" % inp)
|
m = self.getMsg("tp %s" % inp)
|
||||||
print('\nWTE Input: %s\nWTE Response: %s' % (inp, m.args[1]))
|
print('\nTranslateParty Input: %s\nWTE Response: %s' % (inp, m.args[1]))
|
||||||
assert m, 'No response found.'
|
assert m, 'No response found.'
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
Loading…
x
Reference in New Issue
Block a user