diff --git a/Weed/README.md b/Weed/README.md new file mode 100644 index 0000000..c389410 --- /dev/null +++ b/Weed/README.md @@ -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 diff --git a/Weed/__init__.py b/Weed/__init__.py new file mode 100644 index 0000000..fc853c9 --- /dev/null +++ b/Weed/__init__.py @@ -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: diff --git a/Weed/config.py b/Weed/config.py new file mode 100644 index 0000000..3017fbb --- /dev/null +++ b/Weed/config.py @@ -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: + diff --git a/Weed/plugin.py b/Weed/plugin.py new file mode 100644 index 0000000..da9e998 --- /dev/null +++ b/Weed/plugin.py @@ -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): + """ + 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 diff --git a/Weed/test.py b/Weed/test.py new file mode 100644 index 0000000..7581c07 --- /dev/null +++ b/Weed/test.py @@ -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: +