expanded subcommands
This commit is contained in:
commit
0b37281fb3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__
|
71
__init__.py
Normal file
71
__init__.py
Normal file
@ -0,0 +1,71 @@
|
||||
###
|
||||
# Copyright (c) 2020, mogad0n
|
||||
# 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.
|
||||
|
||||
###
|
||||
|
||||
"""
|
||||
PsychonautWiki: Queries the Psychonautwiki api
|
||||
"""
|
||||
|
||||
import sys
|
||||
import supybot
|
||||
from supybot import world
|
||||
|
||||
# Use this for the version of this plugin.
|
||||
__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
|
||||
if sys.version_info >= (3, 4):
|
||||
from importlib import reload
|
||||
else:
|
||||
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:
|
56
config.py
Normal file
56
config.py
Normal file
@ -0,0 +1,56 @@
|
||||
###
|
||||
# Copyright (c) 2020, mogad0n
|
||||
# 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 import conf, registry
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('PsychonautWiki')
|
||||
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('PsychonautWiki', True)
|
||||
|
||||
|
||||
PsychonautWiki = conf.registerPlugin('PsychonautWiki')
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(PsychonautWiki, 'someConfigVariableName',
|
||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
1
local/__init__.py
Normal file
1
local/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# Stub so local is a module, used for third-party modules
|
192
plugin.py
Normal file
192
plugin.py
Normal file
@ -0,0 +1,192 @@
|
||||
###
|
||||
# Copyright (c) 2020, mogad0n
|
||||
# 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 import utils, plugins, ircutils, callbacks
|
||||
from supybot.commands import *
|
||||
import requests
|
||||
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('PsychonautWiki')
|
||||
except ImportError:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x: x
|
||||
|
||||
url = "https://api.psychonautwiki.org/graphql"
|
||||
|
||||
|
||||
class PsychonautWiki(callbacks.Plugin):
|
||||
"""Queries the Psychonautwiki api"""
|
||||
threaded = True
|
||||
|
||||
|
||||
@wrap(['something', optional('something')])
|
||||
def psywiki(self, irc, msg, args, name, category):
|
||||
"""<drug> <category>
|
||||
fetches data on drug from psychonautwiki. Categories currently supported are name, dose, duration
|
||||
"""
|
||||
categories = ['name', 'summary', 'dose', 'duration', 'effects', 'addictionPotential', 'crossTolerances', 'toxicity']
|
||||
query = { 'query' : 'query getdruginfo($name: String){substances(query: $name) {name summary toxicity addictionPotential crossTolerances effects { name } roas {name dose {units threshold heavy common { min max } light { min max } strong { min max }} duration {afterglow { min max units } comeup { min max units } duration { min max units } offset { min max units } onset { min max units }peak { min max units }total { min max units }}}}}', 'variables': {'name': name}}
|
||||
r = requests.post(url=url, json=query).json()
|
||||
|
||||
def format_dose(dose, unit):
|
||||
if dose == 'N/A':
|
||||
return 'N/A'
|
||||
else:
|
||||
return f"{dose['min']}-{dose['max']} {unit}"
|
||||
|
||||
def format_duration(duration, unit):
|
||||
if duration == 'N/A':
|
||||
return "N/A"
|
||||
else:
|
||||
return f"{duration['min']}-{duration['max']} {unit}"
|
||||
|
||||
if r['data']:
|
||||
formatted_doses = []
|
||||
formatted_duration = []
|
||||
formatted_effects = []
|
||||
substance = r['data']['substances'][0]
|
||||
drug_name = substance['name']
|
||||
summary = substance['summary']
|
||||
toxicity = substance['toxicity']
|
||||
addictionPotential = substance['addictionPotential']
|
||||
crossTolerances = substance['crossTolerances']
|
||||
effects = substance['effects']
|
||||
for effect in effects:
|
||||
formatted_effects.append(effect['name'])
|
||||
roas = substance['roas']
|
||||
for roa in roas:
|
||||
if roa['dose']['threshold'] is not None:
|
||||
threshold = roa['dose']['threshold']
|
||||
else:
|
||||
threshold = 'N/A'
|
||||
if roa['dose']['heavy'] is not None:
|
||||
heavy = roa['dose']['heavy']
|
||||
else:
|
||||
heavy = 'N/A'
|
||||
if roa['dose']['light'] is not None:
|
||||
light = roa['dose']['light']
|
||||
else:
|
||||
light = 'N/A'
|
||||
if roa['dose']['common'] is not None:
|
||||
common = roa['dose']['common']
|
||||
else:
|
||||
common = 'N/A'
|
||||
if roa['dose']['strong'] is not None:
|
||||
strong = roa['dose']['strong']
|
||||
else:
|
||||
strong = 'N/A'
|
||||
unit_dose = roa['dose']['units']
|
||||
formatted_doses.append(f"{roa['name']} threshold: {threshold}{unit_dose} light: {format_dose(light, unit_dose)} common: {format_dose(common, unit_dose)} strong: {format_dose(strong, unit_dose)} heavy: {heavy}{unit_dose}")
|
||||
if roa['duration']['afterglow'] is not None:
|
||||
afterglow = roa['duration']['afterglow']
|
||||
unit_afterglow = roa['duration']['afterglow']['units']
|
||||
else:
|
||||
afterglow = 'N/A'
|
||||
unit_afterglow = 'N/A'
|
||||
if roa['duration']['comeup'] is not None:
|
||||
comeup = roa['duration']['comeup']
|
||||
unit_comeup = roa['duration']['comeup']['units']
|
||||
else:
|
||||
comeup = 'N/A'
|
||||
unit_comeup = 'N/A'
|
||||
|
||||
if roa['duration']['offset'] is not None:
|
||||
offset = roa['duration']['offset']
|
||||
unit_offset = roa['duration']['offset']['units']
|
||||
else:
|
||||
offset = 'N/A'
|
||||
unit_offset = 'N/A'
|
||||
|
||||
if roa['duration']['peak'] is not None:
|
||||
peak = roa['duration']['peak']
|
||||
unit_peak = roa['duration']['peak']['units']
|
||||
else:
|
||||
peak = 'N/A'
|
||||
unit_peak = 'N/A'
|
||||
|
||||
if roa['duration']['onset'] is not None:
|
||||
onset = roa['duration']['onset']
|
||||
unit_onset = roa['duration']['onset']['units']
|
||||
else:
|
||||
onset = 'N/A'
|
||||
unit_onset = 'N/A'
|
||||
|
||||
if roa['duration']['total'] is not None:
|
||||
total = roa['duration']['total']
|
||||
unit_total = roa['duration']['total']['units']
|
||||
else:
|
||||
total = 'N/A'
|
||||
unit_total = 'N/A'
|
||||
|
||||
# if roa['duration']['duration'] in not None:
|
||||
# duration = roa['duration']['duration']
|
||||
# unit_duration = roa['duration']['duration']['units']
|
||||
# else:
|
||||
# duration = 'N/A'
|
||||
# unit_duration = 'N/A'
|
||||
|
||||
formatted_duration.append(f"{roa['name']} onset: {format_duration(onset, unit_onset)} comeup: {format_duration(comeup, unit_comeup)} peak: {format_duration(peak, unit_peak)} offset: {format_duration(offset, unit_offset)} afterglow: {format_duration(afterglow, unit_afterglow)} total: {format_duration(total, unit_total)}")
|
||||
if category in categories and category == 'name':
|
||||
re = drug_name
|
||||
elif category in categories and category == 'summary':
|
||||
re = drug_name + ' ' + summary
|
||||
elif category in categories and category == 'addictionPotential':
|
||||
re = drug_name + ' ' + addictionPotential
|
||||
elif category in categories and category == 'toxicity':
|
||||
if toxicity is None:
|
||||
re = 'N/A'
|
||||
else:
|
||||
re = drug_name + ' ' + ', '.join(toxicity)
|
||||
elif category in categories and category == 'crossTolerances':
|
||||
if crossTolerances is None:
|
||||
re = 'N/A'
|
||||
else:
|
||||
re = drug_name + ' ' + ', '.join(crossTolerances)
|
||||
elif category in categories and category == 'effects':
|
||||
re = drug_name + ' ' + ', '.join(formatted_effects)
|
||||
elif category in categories and category == 'dose':
|
||||
re = drug_name + ' ' + ' | '.join(formatted_doses)
|
||||
elif category in categories and category == 'duration':
|
||||
re = drug_name + ' ' + ' | '.join(formatted_duration)
|
||||
else:
|
||||
re = drug_name + ' ' + ', '.join(categories)
|
||||
else:
|
||||
re = "Unknown Substance"
|
||||
irc.reply(re)
|
||||
|
||||
|
||||
|
||||
Class = PsychonautWiki
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
38
test.py
Normal file
38
test.py
Normal file
@ -0,0 +1,38 @@
|
||||
###
|
||||
# Copyright (c) 2020, mogad0n
|
||||
# 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 *
|
||||
|
||||
|
||||
class PsychonautWikiTestCase(PluginTestCase):
|
||||
plugins = ('PsychonautWiki',)
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
Loading…
Reference in New Issue
Block a user