Add 'Weed/' from commit '511b6d24d2f6c2a0e816772e991f96b5574d8307'
git-subtree-dir: Weed git-subtree-mainline:de94aa5422
git-subtree-split:511b6d24d2
This commit is contained in:
commit
a92f4ded1d
|
@ -0,0 +1,6 @@
|
|||
# Weed
|
||||
Limnoria plugin to fetch cannabis (marijuana) strain information from the strain api (strains.evanbusse.com)
|
||||
|
||||
obtain an api key from http://strains.evanbusse.com/
|
||||
|
||||
config plugins.weed.strain_api your_key_here
|
|
@ -0,0 +1,45 @@
|
|||
###
|
||||
# Copyright (c) 2019 oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
"""
|
||||
Weed: Uses Weed 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
|
||||
configure = config.configure
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
|
@ -0,0 +1,35 @@
|
|||
###
|
||||
# Copyright (c) 2019, oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('Weed')
|
||||
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('Weed', True)
|
||||
|
||||
|
||||
Weed = conf.registerPlugin('Weed')
|
||||
|
||||
conf.registerGlobalValue(Weed, 'strain_api',
|
||||
registry.String('', _("""Strain API Key""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
###
|
||||
# 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 json
|
||||
import re
|
||||
|
||||
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 Weed(callbacks.Plugin):
|
||||
"""Uses API to retrieve information"""
|
||||
threaded = True
|
||||
|
||||
def strain(self, irc, msg, args, strain):
|
||||
"""<strain>
|
||||
Searches API based on user input
|
||||
"""
|
||||
|
||||
response1 = None
|
||||
response2 = None
|
||||
channel = msg.args[0]
|
||||
strain = re.sub('[^\w\:\"\#\-\.\' ]', '', strain).casefold()
|
||||
strain_api = self.registryValue('strain_api')
|
||||
|
||||
url = "http://strainapi.evanbusse.com/{0}/strains/search/name/{1}".format(strain_api, strain)
|
||||
|
||||
data = requests.get(url).json()
|
||||
|
||||
for item in data:
|
||||
if item['desc'] is not None and item['name'].casefold() == strain:
|
||||
id = item['id']
|
||||
name = ircutils.bold(item['name'])
|
||||
type = ircutils.bold(item['race'])
|
||||
desc = item['desc']
|
||||
url2 = "http://strainapi.evanbusse.com/{0}/strains/data/flavors/{1}".format(strain_api, id)
|
||||
data2 = requests.get(url2).json()
|
||||
flavor1 = data2[0]
|
||||
flavor2 = data2[1]
|
||||
flavor3 = data2[2]
|
||||
response1 = "{0} | {1} | Flavors: {2}, {3}, {4} | {5}".format(name, type, flavor1, flavor2, flavor3, desc)
|
||||
break
|
||||
for item in data:
|
||||
if item['desc'] is not None and item['name'].casefold() != strain:
|
||||
id = item['id']
|
||||
name = ircutils.bold(item['name'])
|
||||
type = ircutils.bold(item['race'])
|
||||
desc = item['desc']
|
||||
url2 = "http://strainapi.evanbusse.com/{0}/strains/data/flavors/{1}".format(strain_api, id)
|
||||
data2 = requests.get(url2).json()
|
||||
flavor1 = data2[0]
|
||||
flavor2 = data2[1]
|
||||
flavor3 = data2[2]
|
||||
response2 = "{0} | {1} | Flavors: {2}, {3}, {4} | {5}".format(name, type, flavor1, flavor2, flavor3, desc)
|
||||
break
|
||||
if response1 != None:
|
||||
irc.reply(response1)
|
||||
elif response1 == None and response2 != None:
|
||||
irc.reply(response2)
|
||||
else:
|
||||
irc.reply('No results found, what have you been smoking?')
|
||||
|
||||
strain = wrap(strain, ['text'])
|
||||
|
||||
Class = Weed
|
|
@ -0,0 +1,16 @@
|
|||
###
|
||||
# Copyright (c) 2019, oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
|
||||
class WeedTestCase(PluginTestCase):
|
||||
plugins = ('Weed',)
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
Reference in New Issue