Remove WTE plugin, as Google broke the API :(

This commit is contained in:
James Lu 2015-04-14 17:08:58 -07:00
parent 59b0b5c991
commit 14d98f1736
7 changed files with 0 additions and 351 deletions

View File

@ -75,7 +75,3 @@ Most of these plugins also have their own READMEs in their folders; you can usua
##### [Weather](Weather/README.md)
- My fork of [reticulatingspline's Weather](https://github.com/reticulatingspline/Weather) plugin. [Source](https://github.com/GLolol/Supybot-Weather)
##### [WTE](WTE/README.md)
- Worst Translations Ever! plugin. Translates text through multiple rounds of Google Translate to get some interesting results!
- Due to lingering issues with Unicode handling in Python 2, **Python 3 is strongly recommended** for those using this plugin.

View File

@ -1,28 +0,0 @@
##WTE - Worst Translations Ever!
**Due to lingering issues with Unicode handling in Python 2, Python 3 is strongly recommended for those using this plugin!**
WTE is a plugin that 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
back and forth between them quite a few times. This guarantees that the result will be different
every time.
Any source language [supported by Google Translate](https://translate.google.com/about/intl/en_ALL/#supportedLangs)
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:
```
<GLolol> %wte This text will be scrambled to near perfection.
<@Atlas> This message was standing almost completely.
```
```
<@Ere> Atlas, wte Mi ne scias la koloro de la hundo FK plugilo, cxar de tio, kio okazis en Islando
<@Atlas> My dick plows Aludra star name I do not know the color of cotton, Iceland
```
```
<GLolol> %wte An evil monster lurks beneath the forest.
<@Atlas> Error Evil Xasa woude.
```

View File

@ -1,70 +0,0 @@
###
# Copyright (c) 2014, James Lu
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
"""
Add a description of the plugin (to be presented to the user inside the wizard)
here. This should describe *what* the plugin does.
"""
import supybot
import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
__version__ = ""
# XXX Replace this with an appropriate author or supybot.Author instance.
__author__ = supybot.Author('James Lu', 'GLolol',
'GLolol@overdrive.pw')
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = 'https://github.com/GLolol/SupyPlugins/'
from . import config
from . import plugin
from imp import reload
# In case we're being reloaded.
reload(config)
reload(plugin)
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!
if world.testing:
from . import test
Class = plugin.Class
configure = config.configure
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -1,61 +0,0 @@
###
# Copyright (c) 2014, James Lu
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import supybot.conf as conf
import supybot.registry as registry
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('WTE')
except:
# Placeholder that allows to run the plugin on a bot
# without the i18n module
_ = lambda x:x
def configure(advanced):
# This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified themself as an advanced
# user or not. You should effect your configuration by manipulating the
# registry as appropriate.
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('WTE', True)
WTE = conf.registerPlugin('WTE')
conf.registerChannelValue(WTE, 'verbose',
registry.Boolean(False, _("""Determines whether
verbose output (list of languages used, etc.) will be used.""")))
conf.registerChannelValue(WTE, 'language',
registry.String('en', _("""Determines what the output language
of 'wte' will be. This should be one of Google Translate's language
codes as listed at:
https://cloud.google.com/translate/v2/using_rest#language-params""")))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -1 +0,0 @@
# Stub so local is a module, used for third-party modules

View File

@ -1,140 +0,0 @@
###
# Copyright (c) 2014, James Lu
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import random
import json
try: # Python 3
from urllib.parse import urlencode
except ImportError: # Python 2
from urllib import urlencode
from string import printable
from sys import version_info
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('WTE')
except ImportError:
# Placeholder that allows to run the plugin on a bot
# without the i18n module
_ = lambda x:x
class WTE(callbacks.Plugin):
"""Worst Translations Ever! plugin. Translates text through
multiple rounds of Google Translate to get amazing results!"""
threaded = True
def __init__(self, irc):
self.__parent = super(WTE, self)
self.__parent.__init__(irc)
if version_info[0] < 3:
self.log.warning("WTE: Due to Unicode handling issues, "
"Unicode characters will be stripped from this plugin's "
"input/output. For optimal results, please upgrade the "
"bot to Python 3.")
self.langs = ('sw', 'sv', 'is', 'et', 'te', 'tr', 'mr', 'nl', 'sl',
'id', 'gu', 'hi', 'az', 'hmn', 'ko', 'da', 'bg', 'lo', 'so', 'tl',
'hu', 'ca', 'cy', 'bs', 'ka', 'vi', 'eu', 'ms', 'fr', 'no', 'hy',
'ro', 'ru', 'th', 'it', 'ta', 'sq', 'ceb', 'bn', 'de', 'zh-CN',
'be', 'lt', 'ne', 'fi', 'pa', 'iw', 'km', 'mt', 'ht', 'mi', 'lv',
'jw', 'sr', 'ar', 'ig', 'ha', 'pt', 'ga', 'af', 'zu', 'la', 'el',
'cs', 'uk', 'ja', 'hr', 'kn', 'gl', 'mk', 'fa', 'sk', 'mn', 'es',
'ur', 'pl', 'eo', 'yo', 'en', 'yi')
def _jsonRepair(self, data):
while ',,' in data:
data = data.replace(',,', ',null,')
while '[,' in data:
data = data.replace('[,', '[')
return data
def getTranslation(self, irc, sourceLang, targetLang, text):
args = {"client": "t", "sl": sourceLang, "tl": targetLang}
if version_info[0] < 3:
# Python 2's Unicode handling is just horrible. I've tried a
# dozen different combinations of encoding and decoding and they
# all fail with a stupid, useless UnicodeDecodeError. We're
# just going to strip all non-ASCII characters until
# this stupid issue gets fixed. -GLolol
args['q'] = filter(lambda x: x in printable, text)
else:
args['q'] = text
url = "https://translate.google.com/translate_a/t?"+ \
urlencode(args)
self.log.debug("WTE: Using URL %s", url)
headers = {'User-Agent': ('Mozilla/5.0 (X11; Linux i586; rv:31.0) '
'Gecko/20100101 Firefox/31.0')}
try:
data = utils.web.getUrlFd(url, headers).read().decode("utf-8")
except utils.web.Error as e:
irc.error(str(e), Raise=True)
data = self._jsonRepair(data)
data = json.loads(data)
return ''.join(x[0] for x in data[0])
def wte(self, irc, msg, args, text):
"""wte <text>
Worst Translations Ever! plugin. Translates <text> through
multiple rounds of Google Translate to get amazing results!
"""
outlang = self.registryValue('language', msg.args[0])
if outlang not in self.langs:
irc.error("Unrecognized output language. Please set "
"'config plugins.wte.language' correctly.", Raise=True)
ll = random.sample(self.langs, random.randint(5,10))
self.log.debug(format("WTE: Using %i languages: %L "
"(outlang %s)", len(ll), ll, outlang))
for targetlang in ll:
text = self.getTranslation(irc, "auto", targetlang, text)
text = self.getTranslation(irc, "auto", outlang, text)
text = text.strip()
if not text:
s = ("Error encoding/decoding response. If you are using "
"Python 2, it is recommended to upgrade to "
"Python 3 to suppress these kinds of errors, as there "
"are some lingering issues handling Unicode on "
"versions of Python 2.")
irc.error(s, Raise=True)
if self.registryValue("verbose", msg.args[0]):
irc.reply(format("Translated through \x02%i\x02 languages: %L "
"(outlang %s)",
len(ll), ll, outlang))
irc.reply(text)
wte = wrap(wte, ['text'])
Class = WTE
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -1,47 +0,0 @@
###
# Copyright (c) 2014, James Lu
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from supybot.test import *
from sys import version_info
class WTETestCase(PluginTestCase):
plugins = ('WTE',)
@unittest.skipIf(version_info[0] < 3,
"Not supported on Python 2 (severe Unicode handling problems)")
@unittest.skipUnless(network, "Network-based tests have been disabled via "
"--no-network")
def testWTE(self):
inp = "The quick brown fox jumps over the lazy dog."
m = self.getMsg("wte %s" % inp)
print('\nWTE Input: %s\nWTE Response: %s' % (inp, m.args[1]))
assert m, 'No response found.'
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: