mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
attempt plugin category
This commit is contained in:
parent
5e9101242b
commit
dfdc2dcde5
@ -27,6 +27,7 @@ class PluginValues(BASE):
|
|||||||
"""
|
"""
|
||||||
__tablename__ = 'plugin_values'
|
__tablename__ = 'plugin_values'
|
||||||
plugin = Column(String(255), primary_key=True)
|
plugin = Column(String(255), primary_key=True)
|
||||||
|
category = Column(String(255), primary_key=True)
|
||||||
key = Column(String(255), primary_key=True)
|
key = Column(String(255), primary_key=True)
|
||||||
value = Column(String(255))
|
value = Column(String(255))
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ class SpiceDB(object):
|
|||||||
|
|
||||||
# PLUGIN FUNCTIONS
|
# PLUGIN FUNCTIONS
|
||||||
|
|
||||||
def set_plugin_value(self, plugin, key, value):
|
def set_plugin_value(self, plugin, key, value, category='default'):
|
||||||
"""Sets the value for a given key to be associated with the plugin."""
|
"""Sets the value for a given key to be associated with the plugin."""
|
||||||
plugin = Identifier(plugin).lower()
|
plugin = Identifier(plugin).lower()
|
||||||
value = json.dumps(value, ensure_ascii=False)
|
value = json.dumps(value, ensure_ascii=False)
|
||||||
@ -224,6 +225,7 @@ class SpiceDB(object):
|
|||||||
try:
|
try:
|
||||||
result = session.query(PluginValues) \
|
result = session.query(PluginValues) \
|
||||||
.filter(PluginValues.plugin == plugin)\
|
.filter(PluginValues.plugin == plugin)\
|
||||||
|
.filter(PluginValues.category == category)\
|
||||||
.filter(PluginValues.key == key) \
|
.filter(PluginValues.key == key) \
|
||||||
.one_or_none()
|
.one_or_none()
|
||||||
# PluginValues exists, update
|
# PluginValues exists, update
|
||||||
@ -232,7 +234,7 @@ class SpiceDB(object):
|
|||||||
session.commit()
|
session.commit()
|
||||||
# DNE - Insert
|
# DNE - Insert
|
||||||
else:
|
else:
|
||||||
new_pluginvalue = PluginValues(plugin=plugin, key=key, value=value)
|
new_pluginvalue = PluginValues(plugin=plugin, category=category, key=key, value=value)
|
||||||
session.add(new_pluginvalue)
|
session.add(new_pluginvalue)
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError:
|
except SQLAlchemyError:
|
||||||
@ -241,13 +243,14 @@ class SpiceDB(object):
|
|||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def get_plugin_value(self, plugin, key):
|
def get_plugin_value(self, plugin, key, category='default'):
|
||||||
"""Retrieves the value for a given key associated with a plugin."""
|
"""Retrieves the value for a given key associated with a plugin."""
|
||||||
plugin = Identifier(plugin).lower()
|
plugin = Identifier(plugin).lower()
|
||||||
session = self.ssession()
|
session = self.ssession()
|
||||||
try:
|
try:
|
||||||
result = session.query(PluginValues) \
|
result = session.query(PluginValues) \
|
||||||
.filter(PluginValues.plugin == plugin)\
|
.filter(PluginValues.plugin == plugin)\
|
||||||
|
.filter(PluginValues.category == category)\
|
||||||
.filter(PluginValues.key == key) \
|
.filter(PluginValues.key == key) \
|
||||||
.one_or_none()
|
.one_or_none()
|
||||||
if result is not None:
|
if result is not None:
|
||||||
@ -259,13 +262,14 @@ class SpiceDB(object):
|
|||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def delete_plugin_value(self, plugin, key):
|
def delete_plugin_value(self, plugin, key, category='default'):
|
||||||
"""Deletes the value for a given key to be associated with the plugin."""
|
"""Deletes the value for a given key to be associated with the plugin."""
|
||||||
plugin = Identifier(plugin).lower()
|
plugin = Identifier(plugin).lower()
|
||||||
session = self.ssession()
|
session = self.ssession()
|
||||||
try:
|
try:
|
||||||
result = session.query(PluginValues) \
|
result = session.query(PluginValues) \
|
||||||
.filter(PluginValues.plugin == plugin)\
|
.filter(PluginValues.plugin == plugin)\
|
||||||
|
.filter(PluginValues.category == category)\
|
||||||
.filter(PluginValues.key == key) \
|
.filter(PluginValues.key == key) \
|
||||||
.one_or_none()
|
.one_or_none()
|
||||||
# PluginValues exists, delete
|
# PluginValues exists, delete
|
||||||
@ -278,7 +282,7 @@ class SpiceDB(object):
|
|||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def adjust_plugin_value(self, plugin, key, value):
|
def adjust_plugin_value(self, plugin, key, value, category='default'):
|
||||||
"""Sets the value for a given key to be associated with the plugin."""
|
"""Sets the value for a given key to be associated with the plugin."""
|
||||||
plugin = Identifier(plugin).lower()
|
plugin = Identifier(plugin).lower()
|
||||||
value = json.dumps(value, ensure_ascii=False)
|
value = json.dumps(value, ensure_ascii=False)
|
||||||
@ -286,6 +290,7 @@ class SpiceDB(object):
|
|||||||
try:
|
try:
|
||||||
result = session.query(PluginValues) \
|
result = session.query(PluginValues) \
|
||||||
.filter(PluginValues.plugin == plugin)\
|
.filter(PluginValues.plugin == plugin)\
|
||||||
|
.filter(PluginValues.category == category)\
|
||||||
.filter(PluginValues.key == key) \
|
.filter(PluginValues.key == key) \
|
||||||
.one_or_none()
|
.one_or_none()
|
||||||
# ChannelValue exists, update
|
# ChannelValue exists, update
|
||||||
@ -294,7 +299,7 @@ class SpiceDB(object):
|
|||||||
session.commit()
|
session.commit()
|
||||||
# DNE - Insert
|
# DNE - Insert
|
||||||
else:
|
else:
|
||||||
new_pluginvalue = PluginValues(plugin=plugin, key=key, value=float(value))
|
new_pluginvalue = PluginValues(plugin=plugin, category=category, key=key, value=float(value))
|
||||||
session.add(new_pluginvalue)
|
session.add(new_pluginvalue)
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError:
|
except SQLAlchemyError:
|
||||||
@ -303,7 +308,7 @@ class SpiceDB(object):
|
|||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def adjust_plugin_list(self, plugin, key, entries, adjustmentdirection):
|
def adjust_plugin_list(self, plugin, key, entries, adjustmentdirection, category='default'):
|
||||||
"""Sets the value for a given key to be associated with the plugin."""
|
"""Sets the value for a given key to be associated with the plugin."""
|
||||||
plugin = Identifier(plugin).lower()
|
plugin = Identifier(plugin).lower()
|
||||||
if not isinstance(entries, list):
|
if not isinstance(entries, list):
|
||||||
@ -313,6 +318,7 @@ class SpiceDB(object):
|
|||||||
try:
|
try:
|
||||||
result = session.query(PluginValues) \
|
result = session.query(PluginValues) \
|
||||||
.filter(PluginValues.plugin == plugin)\
|
.filter(PluginValues.plugin == plugin)\
|
||||||
|
.filter(PluginValues.category == category)\
|
||||||
.filter(PluginValues.key == key) \
|
.filter(PluginValues.key == key) \
|
||||||
.one_or_none()
|
.one_or_none()
|
||||||
# ChannelValue exists, update
|
# ChannelValue exists, update
|
||||||
@ -337,7 +343,7 @@ class SpiceDB(object):
|
|||||||
for entry in entries:
|
for entry in entries:
|
||||||
while entry in values:
|
while entry in values:
|
||||||
values.remove(entry)
|
values.remove(entry)
|
||||||
new_pluginvalue = PluginValues(plugin=plugin, key=key, value=values)
|
new_pluginvalue = PluginValues(plugin=plugin, category=category, key=key, value=values)
|
||||||
session.add(new_pluginvalue)
|
session.add(new_pluginvalue)
|
||||||
session.commit()
|
session.commit()
|
||||||
except SQLAlchemyError:
|
except SQLAlchemyError:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user