mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 04:51:08 -05:00
Remove RhymeZone and TranslateParty, which never worked on Python 2
This commit is contained in:
parent
eddd8d2ae1
commit
a5fdbd771b
@ -83,10 +83,6 @@ Most of these plugins also have their own READMEs in their folders; you can usua
|
||||
##### [RelayNext](RelayNext/README.md)
|
||||
- Next generation relayer plugin, designed with two-way relays in mind.
|
||||
|
||||
##### RhymeZone
|
||||
- Fetches rhymes from http://rhymezone.com/.
|
||||
- Unsupported on Python 2 due to string encoding issues.
|
||||
|
||||
##### SedRegex
|
||||
- History replacer using sed-style expressions. Fork of [t3chguy's Replacer plugin](https://github.com/t3chguy/Limnoria-Plugins/tree/master/Replacer).
|
||||
|
||||
@ -97,10 +93,6 @@ Most of these plugins also have their own READMEs in their folders; you can usua
|
||||
- An alternative to Supybot's built-in DNS function, using the `host` DNS lookup utility on the host machine.
|
||||
* **Requires:** `host` DNS lookup binary (as in `/usr/bin/host`)
|
||||
|
||||
##### [TranslateParty](TranslateParty/README.md)
|
||||
- Translates text through Google Translate multiple times in order to get amusing results.
|
||||
- **Note: This plugin requires Python 3!**
|
||||
|
||||
##### Voteserv
|
||||
- A plugin for storing and manipulating votes/polls.
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
Fetches rhymes from http://rhymezone.com/.
|
@ -1,68 +0,0 @@
|
||||
###
|
||||
# Copyright (c) 2015, 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.
|
||||
|
||||
###
|
||||
|
||||
"""
|
||||
RhymeZone: Fetches rhymes from http://rhymezone.com/.
|
||||
"""
|
||||
|
||||
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__ = "2017.05.31"
|
||||
|
||||
# XXX Replace this with an appropriate author or supybot.Author instance.
|
||||
__author__ = supybot.Author('James Lu', 'GLolol', 'GLolol@overdrivenetworks.com')
|
||||
|
||||
# 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:
|
@ -1,57 +0,0 @@
|
||||
###
|
||||
# Copyright (c) 2015, 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('RhymeZone')
|
||||
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('RhymeZone', True)
|
||||
|
||||
|
||||
RhymeZone = conf.registerPlugin('RhymeZone')
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(RhymeZone, 'someConfigVariableName',
|
||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
@ -1 +0,0 @@
|
||||
# Stub so local is a module, used for third-party modules
|
@ -1,108 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# Copyright (c) 2015, 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
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('RhymeZone')
|
||||
except ImportError:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x: x
|
||||
|
||||
try:
|
||||
from bs4 import BeautifulSoup
|
||||
except ImportError:
|
||||
raise ImportError("Beautiful Soup 4 is required for this plugin: "
|
||||
"http://www.crummy.com/software/BeautifulSoup/bs4/"
|
||||
"doc/#installing-beautiful-soup")
|
||||
|
||||
class RhymeZone(callbacks.Plugin):
|
||||
"""Fetches rhymes from http://rhymezone.com/."""
|
||||
threaded = True
|
||||
|
||||
@wrap(['text'])
|
||||
def rhymes(self, irc, msg, args, word):
|
||||
"""<word/phrase>
|
||||
|
||||
Looks up rhymes for the word/phrase given on rhymezone.com.
|
||||
"""
|
||||
url = 'http://www.rhymezone.com/r/rhyme.cgi?typeofrhyme=perfect&%s' % utils.web.urlencode({'Word': word})
|
||||
data = utils.web.getUrl(url)
|
||||
soup = BeautifulSoup(data)
|
||||
|
||||
results = []
|
||||
|
||||
try:
|
||||
for tag in soup.find("div", {"id": "snippets_top"}).next_siblings:
|
||||
if tag.name == 'a': # It's a rhyme result!
|
||||
# Get rid of non-breaking spaces in IRC output
|
||||
result = tag.text.replace('\xa0', ' ').strip()
|
||||
|
||||
# Each page ends with a bunch of links, such as one to a
|
||||
# "words ending with xyz" page. Once we get here, there are no
|
||||
# results left, and we can break.
|
||||
if result.startswith('words ending with'):
|
||||
break
|
||||
|
||||
results.append(result)
|
||||
|
||||
elif tag.name == 'center': # These are usually used for headings
|
||||
|
||||
# Get the heading text, cut at the first newline
|
||||
text = tag.text.split('\n')[0]
|
||||
|
||||
# The dagger is used for a footnote about near-rhymes and how
|
||||
# they work; we don't need this.
|
||||
text = text.replace(' †', '').strip()
|
||||
|
||||
if text: # Ignore empty content
|
||||
# Add the results for this type to replies
|
||||
results.append(ircutils.bold(text))
|
||||
|
||||
except AttributeError:
|
||||
irc.error("Word or phrase not found.")
|
||||
|
||||
else:
|
||||
# Join, tweak the formatting, and reply
|
||||
s = ', '.join(results)
|
||||
s = s.replace(':\x02,', ':\x02')
|
||||
s = s.replace(':\x02 \x02', ':\x02 (none), \x02')
|
||||
irc.reply(s)
|
||||
|
||||
Class = RhymeZone
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
@ -1,43 +0,0 @@
|
||||
###
|
||||
# Copyright (c) 2015-2016, James Lu <glolol@overdrivenetworks.com>
|
||||
# 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 *
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
class RhymeZoneTestCase(PluginTestCase):
|
||||
plugins = ('RhymeZone',)
|
||||
|
||||
@unittest.skipUnless(network, 'Network-based tests have been disabled via --no-network.')
|
||||
@unittest.skipUnless(sys.version_info[0] >= 3, 'Not supported on Python 2.')
|
||||
def testRhymes(self):
|
||||
self.assertNotError('rhymes cat')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
@ -1,28 +0,0 @@
|
||||
## Translate Party
|
||||
|
||||
**Note: This plugin requires Python 3!**
|
||||
|
||||
Translate party sticks text through multiple rounds of Google Translate, in order to get
|
||||
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
|
||||
every time.
|
||||
|
||||
Any source language [supported by Google Translate](https://cloud.google.com/translate/docs/languages)
|
||||
is allowed, since auto-detection is used to translate text back to your desired language. The output language can be set via `config plugins.translateparty.language`, and defaults to English (`en`).
|
||||
|
||||
Samples:
|
||||
|
||||
```
|
||||
<GLolol> %tp This text will be scrambled to near perfection.
|
||||
<@Atlas> This message was standing almost completely.
|
||||
```
|
||||
|
||||
```
|
||||
<@Ere> %tp 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> %tp An evil monster lurks beneath the forest.
|
||||
<@Atlas> Error Evil Xasa woude.
|
||||
```
|
@ -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__ = "2017.05.31"
|
||||
|
||||
# XXX Replace this with an appropriate author or supybot.Author instance.
|
||||
__author__ = supybot.Author('James Lu', 'GLolol',
|
||||
'GLolol@overdrivenetworks.com')
|
||||
|
||||
# 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:
|
@ -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('TranslateParty')
|
||||
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('TranslateParty', True)
|
||||
|
||||
|
||||
TranslateParty = conf.registerPlugin('TranslateParty')
|
||||
conf.registerChannelValue(TranslateParty, 'verbose',
|
||||
registry.Boolean(True, _("""Determines whether
|
||||
verbose output (list of languages used, etc.) will be used.""")))
|
||||
conf.registerChannelValue(TranslateParty, 'language',
|
||||
registry.String('en', _("""Determines what the output language
|
||||
of 'wte' will be. This should be one of Google Translate's supported
|
||||
language codes as listed at:
|
||||
https://cloud.google.com/translate/v2/using_rest#language-params""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
@ -1 +0,0 @@
|
||||
# Stub so local is a module, used for third-party modules
|
@ -1,218 +0,0 @@
|
||||
###
|
||||
# Copyright (c) 2014-2015, 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
|
||||
raise ImportError('This plugin requires Python 3!')
|
||||
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('TranslateParty')
|
||||
except ImportError:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x:x
|
||||
|
||||
class TranslateParty(callbacks.Plugin):
|
||||
"""Translates text through multiple rounds of Google Translate to get amusing results!"""
|
||||
threaded = True
|
||||
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(TranslateParty, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.langs = {
|
||||
'af': 'Afrikaans',
|
||||
'sq': 'Albanian',
|
||||
'ar': 'Arabic',
|
||||
'hy': 'Armenian',
|
||||
'az': 'Azerbaijani',
|
||||
'eu': 'Basque',
|
||||
'be': 'Belarusian',
|
||||
'bn': 'Bengali',
|
||||
'bs': 'Bosnian',
|
||||
'bg': 'Bulgarian',
|
||||
'ca': 'Catalan',
|
||||
'ceb': 'Cebuano',
|
||||
'ny': 'Chichewa',
|
||||
'zh-CN': 'Chinese Simplified',
|
||||
'zh-TW': 'Chinese Traditional',
|
||||
'hr': 'Croatian',
|
||||
'cs': 'Czech',
|
||||
'da': 'Danish',
|
||||
'nl': 'Dutch',
|
||||
'en': 'English',
|
||||
'eo': 'Esperanto',
|
||||
'et': 'Estonian',
|
||||
'tl': 'Filipino',
|
||||
'fi': 'Finnish',
|
||||
'fr': 'French',
|
||||
'gl': 'Galician',
|
||||
'ka': 'Georgian',
|
||||
'de': 'German',
|
||||
'el': 'Greek',
|
||||
'gu': 'Gujarati',
|
||||
'ht': 'Haitian Creole',
|
||||
'ha': 'Hausa',
|
||||
'iw': 'Hebrew',
|
||||
'hi': 'Hindi',
|
||||
'hmn': 'Hmong',
|
||||
'hu': 'Hungarian',
|
||||
'is': 'Icelandic',
|
||||
'ig': 'Igbo',
|
||||
'id': 'Indonesian',
|
||||
'ga': 'Irish',
|
||||
'it': 'Italian',
|
||||
'ja': 'Japanese',
|
||||
'jw': 'Javanese',
|
||||
'kn': 'Kannada',
|
||||
'kk': 'Kazakh',
|
||||
'km': 'Khmer',
|
||||
'ko': 'Korean',
|
||||
'lo': 'Lao',
|
||||
'la': 'Latin',
|
||||
'lv': 'Latvian',
|
||||
'lt': 'Lithuanian',
|
||||
'mk': 'Macedonian',
|
||||
'mg': 'Malagasy',
|
||||
'ms': 'Malay',
|
||||
'ml': 'Malayalam',
|
||||
'mt': 'Maltese',
|
||||
'mi': 'Maori',
|
||||
'mr': 'Marathi',
|
||||
'mn': 'Mongolian',
|
||||
'my': 'Myanmar (Burmese)',
|
||||
'ne': 'Nepali',
|
||||
'no': 'Norwegian',
|
||||
'fa': 'Persian',
|
||||
'pl': 'Polish',
|
||||
'pt': 'Portuguese',
|
||||
'ma': 'Punjabi',
|
||||
'ro': 'Romanian',
|
||||
'ru': 'Russian',
|
||||
'sr': 'Serbian',
|
||||
'st': 'Sesotho',
|
||||
'si': 'Sinhala',
|
||||
'sk': 'Slovak',
|
||||
'sl': 'Slovenian',
|
||||
'so': 'Somali',
|
||||
'es': 'Spanish',
|
||||
'su': 'Sudanese',
|
||||
'sw': 'Swahili',
|
||||
'sv': 'Swedish',
|
||||
'tg': 'Tajik',
|
||||
'ta': 'Tamil',
|
||||
'te': 'Telugu',
|
||||
'th': 'Thai',
|
||||
'tr': 'Turkish',
|
||||
'uk': 'Ukrainian',
|
||||
'ur': 'Urdu',
|
||||
'uz': 'Uzbek',
|
||||
'vi': 'Vietnamese',
|
||||
'cy': 'Welsh',
|
||||
'yi': 'Yiddish',
|
||||
'yo': 'Yoruba',
|
||||
'zu': 'Zulu',
|
||||
}
|
||||
|
||||
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):
|
||||
"""
|
||||
Fetches translations from Google Translate, given the source language,
|
||||
target language, and text.
|
||||
"""
|
||||
args = {"sl": sourceLang, "tl": targetLang, 'q': text}
|
||||
url = "https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&"+ \
|
||||
urlencode(args)
|
||||
self.log.debug("TranslateParty: 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:
|
||||
self.log.exception("TranslateParty: getTranslation errored (probably malformed or too long text)")
|
||||
return text
|
||||
data = self._jsonRepair(data)
|
||||
data = json.loads(data)
|
||||
return ''.join(x[0] for x in data[0])
|
||||
|
||||
@wrap(['text'])
|
||||
def tp(self, irc, msg, args, text):
|
||||
"""tp <text>
|
||||
|
||||
Translates <text> through multiple rounds of Google Translate to get amusing 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)
|
||||
|
||||
# Randomly choose 4 to 8 languages from the list of supported languages.
|
||||
# The amount can be adjusted if you really wish - 4 to 8 is reasonable
|
||||
# in that it gives interesting results but doesn't spam Google's API
|
||||
# (and risk getting blocked) too much.
|
||||
ll = random.sample(self.langs.keys(), random.randint(4,8))
|
||||
self.log.debug(format("TranslateParty: Using %i languages: %L "
|
||||
"(outlang %s)", len(ll), ll, outlang))
|
||||
|
||||
# For every language in this list, translate the text given from
|
||||
# auto-detect into the target language, and replace the original text
|
||||
# with it.
|
||||
for targetlang in ll:
|
||||
text = self.getTranslation(irc, "auto", targetlang, text)
|
||||
text = self.getTranslation(irc, "auto", outlang, text)
|
||||
text = ircutils.stripFormatting(text)
|
||||
text = text.strip()
|
||||
|
||||
if self.registryValue("verbose", msg.args[0]):
|
||||
# Verbose output was requested, show the language codes AND
|
||||
# names that we translated through.
|
||||
languages = [ircutils.bold("%s [%s]" % (self.langs[lang], lang)) for lang in ll]
|
||||
irc.reply(format("Translated through \x02%i\x02 languages: %L "
|
||||
"(output language %s)", len(ll), languages, outlang))
|
||||
irc.reply(text)
|
||||
|
||||
Class = TranslateParty
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
@ -1,48 +0,0 @@
|
||||
###
|
||||
# Copyright (c) 2014,2016 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 TranslatePartyTestCase(PluginTestCase):
|
||||
plugins = ('TranslateParty',)
|
||||
|
||||
@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 testTranslateParty(self):
|
||||
inp = "The quick brown fox jumps over the lazy dog."
|
||||
for _ in range(2):
|
||||
m = self.getMsg("tp %s" % inp)
|
||||
print('\nTranslateParty Input: %s\nWTE Response: %s' % (inp, m.args[1]))
|
||||
assert m, 'No response found.'
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
Loading…
x
Reference in New Issue
Block a user