WIP: cleanup #11
99
plugin.py
99
plugin.py
@ -28,19 +28,13 @@
|
|||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
from humanize import ordinal
|
|
||||||
from supybot import utils, plugins, ircutils, callbacks, world, conf, log
|
from supybot import utils, plugins, ircutils, callbacks, world, conf, log
|
||||||
from supybot.commands import *
|
from supybot.commands import *
|
||||||
|
|
||||||
|
|
||||||
from num2words import num2words
|
from num2words import num2words
|
||||||
import dateutil.parser
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -53,12 +47,6 @@ except ImportError:
|
|||||||
|
|
||||||
filename = conf.supybot.directories.data.dirize("Tripsit.db")
|
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"]
|
insufflated = ["Insufflation", "Insufflation-IR", "Insufflation-XR"]
|
||||||
|
|
||||||
METHODS = {
|
METHODS = {
|
||||||
@ -75,6 +63,7 @@ METHODS = {
|
|||||||
"smoked": ["Smoked"]
|
"smoked": ["Smoked"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Tripsit(callbacks.Plugin):
|
class Tripsit(callbacks.Plugin):
|
||||||
"""Harm-Reduction tools from tripsit's tripbot and the tripsitwiki"""
|
"""Harm-Reduction tools from tripsit's tripbot and the tripsitwiki"""
|
||||||
threaded = True
|
threaded = True
|
||||||
@ -109,55 +98,6 @@ class Tripsit(callbacks.Plugin):
|
|||||||
world.flushers.remove(self._flushDb)
|
world.flushers.remove(self._flushDb)
|
||||||
self.__parent.die()
|
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):
|
def set(self, irc, msg, args, timezone):
|
||||||
"""<timezone>
|
"""<timezone>
|
||||||
|
|
||||||
@ -170,7 +110,7 @@ class Tripsit(callbacks.Plugin):
|
|||||||
if nick in self.db:
|
if nick in self.db:
|
||||||
self.db[nick]['timezone'] = timezone
|
self.db[nick]['timezone'] = timezone
|
||||||
else:
|
else:
|
||||||
self.db[nick] = {'timezone': timezone }
|
self.db[nick] = {'timezone': timezone}
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except pytz.UnknownTimeZoneError:
|
except pytz.UnknownTimeZoneError:
|
||||||
irc.error(_('Unknown timezone'), Raise=True)
|
irc.error(_('Unknown timezone'), Raise=True)
|
||||||
@ -185,31 +125,12 @@ class Tripsit(callbacks.Plugin):
|
|||||||
[--ago] and [ROA] fields are optional
|
[--ago] and [ROA] fields are optional
|
||||||
"""
|
"""
|
||||||
opts = dict(opts)
|
opts = dict(opts)
|
||||||
# r = requests.get(url_drug, params={"name": name}).json()
|
|
||||||
found_method = False
|
found_method = False
|
||||||
onset = None
|
onset = None
|
||||||
# if not r['err']:
|
|
||||||
# drug = r['data'][0]
|
|
||||||
# drug_name = drug['pretty_name']
|
|
||||||
# method_keys = ['value']
|
|
||||||
methods = []
|
methods = []
|
||||||
if method:
|
if method:
|
||||||
methods = [method.lower()]
|
methods = [method.lower()]
|
||||||
methods = METHODS.get(methods[0], methods)
|
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
|
drug_and_method = name
|
||||||
if method:
|
if method:
|
||||||
if not found_method:
|
if not found_method:
|
||||||
@ -229,7 +150,7 @@ class Tripsit(callbacks.Plugin):
|
|||||||
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
|
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
|
||||||
dose_td_s = dose_td.total_seconds()
|
dose_td_s = dose_td.total_seconds()
|
||||||
time = time - dose_td
|
time = time - dose_td
|
||||||
doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method }
|
doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method}
|
||||||
doses = self.db[nick].get('doses')
|
doses = self.db[nick].get('doses')
|
||||||
if doses:
|
if doses:
|
||||||
doses.append(doseLog)
|
doses.append(doseLog)
|
||||||
@ -246,7 +167,7 @@ class Tripsit(callbacks.Plugin):
|
|||||||
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
|
dose_td = datetime.timedelta(hours=int(ago[0:2]), minutes=int(ago[2:4]))
|
||||||
dose_td_s = dose_td.total_seconds()
|
dose_td_s = dose_td.total_seconds()
|
||||||
time = time - dose_td
|
time = time - dose_td
|
||||||
doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method }
|
doseLog = {'time': time, 'dose': dose, 'drug': name, 'method': method}
|
||||||
doses = [doseLog]
|
doses = [doseLog]
|
||||||
self.db[nick] = {'timezone': timezone, 'doses': doses}
|
self.db[nick] = {'timezone': timezone, 'doses': doses}
|
||||||
|
|
||||||
@ -261,7 +182,6 @@ class Tripsit(callbacks.Plugin):
|
|||||||
# re=":-( This is currently not available, sorry. Exception ID T0T4LLYFCK3D."
|
# re=":-( This is currently not available, sorry. Exception ID T0T4LLYFCK3D."
|
||||||
irc.reply(re)
|
irc.reply(re)
|
||||||
|
|
||||||
|
|
||||||
@wrap([optional('positiveInt')])
|
@wrap([optional('positiveInt')])
|
||||||
def undose(self, irc, msg, args, entry):
|
def undose(self, irc, msg, args, entry):
|
||||||
"""<n>
|
"""<n>
|
||||||
@ -328,8 +248,8 @@ class Tripsit(callbacks.Plugin):
|
|||||||
dose_time = lastdose['time']
|
dose_time = lastdose['time']
|
||||||
timezone = self.db[nick]['timezone']
|
timezone = self.db[nick]['timezone']
|
||||||
tz = pytz.timezone(str(timezone))
|
tz = pytz.timezone(str(timezone))
|
||||||
time = datetime.datetime.now(tz=tz)
|
time = datetime.datetime.now(tz = tz)
|
||||||
since_dose = time - dose_time
|
since_dose= time - dose_time
|
||||||
since_dose_seconds = since_dose.total_seconds()
|
since_dose_seconds = since_dose.total_seconds()
|
||||||
if history:
|
if history:
|
||||||
history = num2words(history, to='ordinal')
|
history = num2words(history, to='ordinal')
|
||||||
@ -345,7 +265,6 @@ class Tripsit(callbacks.Plugin):
|
|||||||
"""<n>
|
"""<n>
|
||||||
|
|
||||||
retrieves your <n> last logged doses
|
retrieves your <n> last logged doses
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if history > 20:
|
if history > 20:
|
||||||
irc.error("you can't retrieve more than 20 doses")
|
irc.error("you can't retrieve more than 20 doses")
|
||||||
@ -355,7 +274,7 @@ class Tripsit(callbacks.Plugin):
|
|||||||
try:
|
try:
|
||||||
rangecheck = self.db[nick]['doses'][-int(history)]
|
rangecheck = self.db[nick]['doses'][-int(history)]
|
||||||
irc.reply(f"Your last {history} doses logged are:", private=True)
|
irc.reply(f"Your last {history} doses logged are:", private=True)
|
||||||
for number in range(history,0,-1):
|
for number in range(history, 0, -1):
|
||||||
lastdose = self.db[nick]['doses'][-int(number)]
|
lastdose = self.db[nick]['doses'][-int(number)]
|
||||||
dose = lastdose['dose']
|
dose = lastdose['dose']
|
||||||
drug = lastdose['drug']
|
drug = lastdose['drug']
|
||||||
@ -378,8 +297,6 @@ class Tripsit(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.error(f'No doses saved for {nick}')
|
irc.error(f'No doses saved for {nick}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@wrap(["something"])
|
@wrap(["something"])
|
||||||
def amountdosed(self, irc, msg, args, drug):
|
def amountdosed(self, irc, msg, args, drug):
|
||||||
"""<drug>
|
"""<drug>
|
||||||
@ -393,7 +310,7 @@ class Tripsit(callbacks.Plugin):
|
|||||||
doselogs = self.db[nick]['doses']
|
doselogs = self.db[nick]['doses']
|
||||||
for doselog in doselogs:
|
for doselog in doselogs:
|
||||||
if doselog["drug"] == drug:
|
if doselog["drug"] == drug:
|
||||||
for i,c in enumerate(doselog["dose"]):
|
for i, c in enumerate(doselog["dose"]):
|
||||||
if not c.isdigit():
|
if not c.isdigit():
|
||||||
break
|
break
|
||||||
num += int(doselog["dose"][:i])
|
num += int(doselog["dose"][:i])
|
||||||
|
Loading…
Reference in New Issue
Block a user