Add 'Lyrics/' from commit 'dbedb06a5ade8f0fee309e0d0f641c62da8296a5'

git-subtree-dir: Lyrics
git-subtree-mainline: 00a3eda667
git-subtree-split: dbedb06a5a
This commit is contained in:
oddluck 2019-02-14 13:31:03 -05:00
commit 3551587ecd
5 changed files with 143 additions and 0 deletions

6
Lyrics/README.md Normal file
View File

@ -0,0 +1,6 @@
# Lyrics
Limnoria plugin to return song lyrics by artist, song title from lyric-api.herokuapp.com
command: lyric artist, song title
requirements: limnoria, python 3, requests

42
Lyrics/__init__.py Normal file
View File

@ -0,0 +1,42 @@
###
# Copyright (c) 2019 oddluck
# All rights reserved.
#
#
###
"""
Advice: Uses Advice API to retrieve information
"""
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.authors.unknown
# 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__ = ''
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
Lyrics = config.Lyrics

29
Lyrics/config.py Normal file
View File

@ -0,0 +1,29 @@
###
# Copyright (c) 2019, oddluck
# All rights reserved.
#
#
###
import supybot.conf as conf
import supybot.registry as registry
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('Lyrics')
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('Lyrics', True)
Lyrics = conf.registerPlugin('Lyrics')

50
Lyrics/plugin.py Normal file
View File

@ -0,0 +1,50 @@
###
# Copyright (c) 2019 oddluck
# All rights reserved.
#
#
###
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 supybot.ircmsgs as ircmsgs
import requests
import html
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('Weed')
except ImportError:
# Placeholder that allows to run the plugin on a bot
# without the i18n module
_ = lambda x: x
class Lyrics(callbacks.Plugin):
"""Retrieves song lyrics"""
threaded = True
def lyric(self, irc, msg, args, lyric):
"""<artist, song title>
Get song lyrics. search must be formatted as artist, song title.
"""
channel = msg.args[0]
lyrics = None
if ',' in lyric:
query = lyric.split(', ')
else:
irc.reply("Searches must be formatted as artist, song title")
query = None
if query:
data = requests.get("https://lyric-api.herokuapp.com/api/find/{0}/{1}".format(query[0], query[1])).json()
lyrics = html.unescape(data['lyric']).replace('\n\n', '. ').replace('?\n', '? ').replace('!\n', '! ').replace('.\n', '. ').replace(',\n', ', ').replace('...\n', '... ').replace('\n', ', ')
if lyrics:
irc.reply(lyrics)
else:
irc.reply("Nothing found.")
lyric = wrap(lyric, ['text'])
Class = Lyrics

16
Lyrics/test.py Normal file
View File

@ -0,0 +1,16 @@
###
# Copyright (c) 2019, oddluck
# All rights reserved.
#
#
###
from supybot.test import *
class LyricsTestCase(PluginTestCase):
plugins = ('Lyrics',)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: