Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
bf26c3c63c | |||
d28f2032cd | |||
f53ddf450c | |||
bcb385d3e8 | |||
816ce22eca | |||
41f4e7d749 | |||
4c7f27393e | |||
fe1554b925 | |||
658302de4b |
153
plugin.py
153
plugin.py
@ -28,19 +28,13 @@
|
||||
|
||||
###
|
||||
|
||||
from humanize import ordinal
|
||||
from supybot import utils, plugins, ircutils, callbacks, world, conf, log
|
||||
from supybot.commands import *
|
||||
|
||||
|
||||
from num2words import num2words
|
||||
import dateutil.parser
|
||||
import json
|
||||
import requests
|
||||
import pickle
|
||||
import sys
|
||||
import datetime
|
||||
import time
|
||||
import pytz
|
||||
|
||||
try:
|
||||
@ -53,12 +47,6 @@ except ImportError:
|
||||
|
||||
filename = conf.supybot.directories.data.dirize("Tripsit.db")
|
||||
|
||||
|
||||
#url_drug = "http://tripbot.tripsit.me/api/tripsit/getDrug"
|
||||
#url_combo = "http://tripbot.tripsit.me/api/tripsit/getInteraction"
|
||||
url_drug = "http://172.16.24.2:1999/api/tripsit/getDrug"
|
||||
url_combo = "http://172.16.24.2:1999/api/tripsit/getInteraction"
|
||||
|
||||
insufflated = ["Insufflation", "Insufflation-IR", "Insufflation-XR"]
|
||||
|
||||
METHODS = {
|
||||
@ -75,6 +63,7 @@ METHODS = {
|
||||
"smoked": ["Smoked"]
|
||||
}
|
||||
|
||||
|
||||
class Tripsit(callbacks.Plugin):
|
||||
"""Harm-Reduction tools from tripsit's tripbot and the tripsitwiki"""
|
||||
threaded = True
|
||||
@ -109,55 +98,6 @@ class Tripsit(callbacks.Plugin):
|
||||
world.flushers.remove(self._flushDb)
|
||||
self.__parent.die()
|
||||
|
||||
@wrap(['something', optional('something')])
|
||||
def drug(self, irc, msg, args, name, category):
|
||||
"""<drug> [<category>]
|
||||
|
||||
fetches data on drug from tripsit wiki
|
||||
"""
|
||||
# category_list = []
|
||||
# r = requests.get(url_drug, params={"name": name}).json()
|
||||
# if not r['err']:
|
||||
# drug = r["data"][0]["pretty_name"]
|
||||
# properties = r["data"][0]["properties"]
|
||||
# for key in properties:
|
||||
# category_list.append(key)
|
||||
# if category is None:
|
||||
# re = drug + " Available categories are: " + ", ".join(category_list)
|
||||
# irc.reply(re)
|
||||
# else:
|
||||
# if category in properties.keys():
|
||||
# re = drug + " " + properties[category]
|
||||
# irc.reply(re)
|
||||
# else:
|
||||
# irc.error(f"Unknown category {drug} Available categories are: " + ", ".join(category_list))
|
||||
# else:
|
||||
# irc.error("unknown drug")
|
||||
irc.reply("This no longer works, try @psywiki " + name + " " + category)
|
||||
|
||||
# def combo(self, irc, msg, args, drugA, drugB):
|
||||
# """<drugA> <drugB>
|
||||
#
|
||||
# fetches known interactions between the substances provided.
|
||||
# """
|
||||
# r = requests.get(url_combo, params={f"drugA": drugA, f"drugB": drugB}).json()
|
||||
# if not r["err"] and r["data"][0]:
|
||||
# interaction = r["data"][0]
|
||||
# drug_a = interaction["interactionCategoryA"]
|
||||
# drug_b = interaction["interactionCategoryB"]
|
||||
# interaction_status = interaction["status"]
|
||||
# re = f"{drug_a} and {drug_b}: {interaction_status}"
|
||||
# if 'note' in interaction:
|
||||
# note = interaction["note"]
|
||||
# re += f'. Note: {note}'
|
||||
# irc.reply(re)
|
||||
# else:
|
||||
# irc.reply(re)
|
||||
# else:
|
||||
# irc.reply("Unknown combo (that doesn't mean it's safe). Known combos: lsd, mushrooms, dmt, mescaline, dox, nbomes, 2c-x, 2c-t-x, amt, 5-meo-xxt, cannabis, ketamine, mxe, dxm, pcp, nitrous, amphetamines, mdma, cocaine, caffeine, alcohol, ghb/gbl, opioids, tramadol, benzodiazepines, maois, ssris.")
|
||||
#
|
||||
# combo = wrap(combo, [("something"), ("something")])
|
||||
|
||||
def set(self, irc, msg, args, timezone):
|
||||
"""<timezone>
|
||||
|
||||
@ -185,31 +125,12 @@ class Tripsit(callbacks.Plugin):
|
||||
[--ago] and [ROA] fields are optional
|
||||
"""
|
||||
opts = dict(opts)
|
||||
# r = requests.get(url_drug, params={"name": name}).json()
|
||||
found_method = False
|
||||
onset = None
|
||||
# if not r['err']:
|
||||
# drug = r['data'][0]
|
||||
# drug_name = drug['pretty_name']
|
||||
# method_keys = ['value']
|
||||
methods = []
|
||||
if method:
|
||||
methods = [method.lower()]
|
||||
methods = METHODS.get(methods[0], methods)
|
||||
# method_keys += methods
|
||||
|
||||
# if 'formatted_onset' in drug:
|
||||
# match = list(set(method_keys)&
|
||||
# set(drug["formatted_onset"].keys()))
|
||||
# if match:
|
||||
# onset = drug["formatted_onset"][match[0]]
|
||||
# found_method = True
|
||||
# if match[0] in methods:
|
||||
# method = (match or [method])[0]
|
||||
#
|
||||
# if onset and "_unit" in drug["formatted_onset"]:
|
||||
# onset = "%s %s" % (
|
||||
# onset, drug["formatted_onset"]["_unit"])
|
||||
drug_and_method = name
|
||||
if method:
|
||||
if not found_method:
|
||||
@ -258,7 +179,6 @@ class Tripsit(callbacks.Plugin):
|
||||
re = utils.str.format("You dosed %s of %s at %s, %s ; %T ago", dose, drug_and_method, time.strftime("%c"), timezone, dose_td.total_seconds())
|
||||
if onset is not None:
|
||||
re += utils.str.format(". You should have/will start feeling effects %s from/after dosing", onset)
|
||||
# re=":-( This is currently not available, sorry. Exception ID T0T4LLYFCK3D."
|
||||
irc.reply(re)
|
||||
|
||||
|
||||
@ -340,23 +260,34 @@ class Tripsit(callbacks.Plugin):
|
||||
else:
|
||||
irc.error(f'No doses saved for {nick}')
|
||||
|
||||
@wrap(['positiveInt'])
|
||||
def listdose(self, irc, msg, args, history):
|
||||
"""<n>
|
||||
|
||||
retrieves your <n> last logged doses
|
||||
@wrap([getopts({'drug': 'something'}), 'positiveInt'])
|
||||
def listdose(self, irc, msg, args, opts, history):
|
||||
"""[--drug <drug>] <n>
|
||||
|
||||
Retrieves your <n> last logged doses, optionally filtered by drug.
|
||||
"""
|
||||
if history > 20:
|
||||
irc.error("you can't retrieve more than 20 doses")
|
||||
irc.error("You can't retrieve more than 20 doses.")
|
||||
return
|
||||
|
||||
opts = dict(opts)
|
||||
drug_filter = opts.get('drug')
|
||||
nick = msg.nick
|
||||
|
||||
if nick in self.db:
|
||||
doses = self.db[nick]['doses']
|
||||
if drug_filter:
|
||||
doses = [dose for dose in doses if dose['drug'].lower() == drug_filter.lower()]
|
||||
if len(doses) == 0:
|
||||
irc.error(f"No doses found for drug '{drug_filter}'.")
|
||||
return
|
||||
if drug_filter:
|
||||
irc.reply(f"Here are your last {history} dose(s) for drug '{drug_filter}':", private=True)
|
||||
else:
|
||||
irc.reply(f"Here are your last {history} dose(s):", private=True)
|
||||
try:
|
||||
rangecheck = self.db[nick]['doses'][-int(history)]
|
||||
irc.reply(f"Your last {history} doses logged are:", private=True)
|
||||
for number in range(history,0,-1):
|
||||
lastdose = self.db[nick]['doses'][-int(number)]
|
||||
for number in range(0, history):
|
||||
lastdose = doses[-(number + 1)]
|
||||
dose = lastdose['dose']
|
||||
drug = lastdose['drug']
|
||||
method = lastdose['method']
|
||||
@ -366,19 +297,45 @@ class Tripsit(callbacks.Plugin):
|
||||
time = datetime.datetime.now(tz=tz)
|
||||
since_dose = time - dose_time
|
||||
since_dose_seconds = since_dose.total_seconds()
|
||||
if number == 1:
|
||||
number = "The"
|
||||
else:
|
||||
number = num2words(number, to='ordinal')
|
||||
re = utils.str.format("::> %i last dose: Amount: %s of \x02%s\x0F via %s | datetime: %s %s | timedelta %T ", number, dose, drug, method, dose_time.strftime("%c"), timezone, since_dose_seconds)
|
||||
hours, remainder = divmod(since_dose_seconds, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
timedelta_str = f"{int(hours)} hours, {int(minutes)} minutes" if hours > 0 else f"{int(minutes)} minutes, {int(seconds)} seconds"
|
||||
number_str = "The" if number == 0 else num2words(number + 1, to='ordinal')
|
||||
re = utils.str.format(
|
||||
"✧ %s last dose: \x02Amount:\x0F %s of \x02%s\x0F \x02via\x0F %s | \x02Datetime:\x0F %s %s | \x02Time Since Last Dose:\x0F %s",
|
||||
number_str, dose, drug, method, dose_time.strftime("%Y-%m-%d %H:%M:%S"), timezone, timedelta_str
|
||||
)
|
||||
irc.reply(re, private=True)
|
||||
except IndexError:
|
||||
irc.error("You haven't logged that many doses")
|
||||
irc.error("You haven't logged that many doses.")
|
||||
return
|
||||
else:
|
||||
irc.error(f'No doses saved for {nick}')
|
||||
irc.error(f"No doses saved for {nick}.")
|
||||
|
||||
@wrap(["something"])
|
||||
def grepdose(self, irc, msg, args, drug):
|
||||
"""<drug>
|
||||
|
||||
pulls most recent dose for drug
|
||||
"""
|
||||
nick = msg.nick
|
||||
if nick in self.db:
|
||||
doselogs = self.db[nick]['doses']
|
||||
found = False
|
||||
for doselog in reversed(doselogs):
|
||||
if doselog['drug'] == drug:
|
||||
timezone = self.db[nick]['timezone']
|
||||
tz = pytz.timezone(str(timezone))
|
||||
now = datetime.datetime.now(tz=tz)
|
||||
since_dose = now - doselog['time']
|
||||
re = utils.str.format("You last dosed %s of %s via %s at %s %s, %T ago", doselog["dose"], doselog["drug"], doselog["method"], doselog["time"].strftime("%c"), timezone, since_dose.total_seconds())
|
||||
irc.reply(re)
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
irc.error(f"No doses saved for {drug}")
|
||||
else:
|
||||
irc.error(f"No doses saved for {nick}")
|
||||
|
||||
@wrap(["something"])
|
||||
def amountdosed(self, irc, msg, args, drug):
|
||||
|
Loading…
x
Reference in New Issue
Block a user