spicebot database is seperate from bot database

This commit is contained in:
deathbybandaid 2019-05-30 10:14:55 -04:00
parent b9eb5c02ed
commit 1c5e3e8212

View File

@ -25,9 +25,9 @@ class NickValues(BASE):
""" """
NickValues SQLAlchemy Class NickValues SQLAlchemy Class
""" """
__tablename__ = 'nick_values' __tablename__ = 'spice_nick_values'
nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True)
# category = 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))
@ -36,9 +36,9 @@ class ChannelValues(BASE):
""" """
ChannelValues SQLAlchemy Class ChannelValues SQLAlchemy Class
""" """
__tablename__ = 'channel_values' __tablename__ = 'spice_channel_values'
channel = Column(String(255), primary_key=True) channel = Column(String(255), primary_key=True)
# category = 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))
@ -47,9 +47,9 @@ class PluginValues(BASE):
""" """
PluginValues SQLAlchemy Class PluginValues SQLAlchemy Class
""" """
__tablename__ = 'plugin_values' __tablename__ = 'spice_plugin_values'
plugin = Column(String(255), primary_key=True) plugin = Column(String(255), primary_key=True)
# category = 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))
@ -58,7 +58,7 @@ class SpiceDB(object):
# NICK FUNCTIONS # NICK FUNCTIONS
def set_nick_value(self, nick, key, value): def set_nick_value(self, nick, key, value, category='default'):
"""Sets the value for a given key to be associated with the nick.""" """Sets the value for a given key to be associated with the nick."""
nick = Identifier(nick) nick = Identifier(nick)
value = json.dumps(value, ensure_ascii=False) value = json.dumps(value, ensure_ascii=False)
@ -67,6 +67,7 @@ class SpiceDB(object):
try: try:
result = session.query(NickValues) \ result = session.query(NickValues) \
.filter(NickValues.nick_id == nick_id) \ .filter(NickValues.nick_id == nick_id) \
.filter(NickValues.category == category)\
.filter(NickValues.key == key) \ .filter(NickValues.key == key) \
.one_or_none() .one_or_none()
# NickValue exists, update # NickValue exists, update
@ -75,7 +76,7 @@ class SpiceDB(object):
session.commit() session.commit()
# DNE - Insert # DNE - Insert
else: else:
new_nickvalue = NickValues(nick_id=nick_id, key=key, value=value) new_nickvalue = NickValues(nick_id=nick_id, category=category, key=key, value=value)
session.add(new_nickvalue) session.add(new_nickvalue)
session.commit() session.commit()
except SQLAlchemyError: except SQLAlchemyError:
@ -84,7 +85,7 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def get_nick_value(self, nick, key): def get_nick_value(self, nick, key, category='default'):
"""Retrieves the value for a given key associated with a nick.""" """Retrieves the value for a given key associated with a nick."""
nick = Identifier(nick) nick = Identifier(nick)
session = self.ssession() session = self.ssession()
@ -92,6 +93,7 @@ class SpiceDB(object):
result = session.query(NickValues) \ result = session.query(NickValues) \
.filter(Nicknames.nick_id == NickValues.nick_id) \ .filter(Nicknames.nick_id == NickValues.nick_id) \
.filter(Nicknames.slug == nick.lower()) \ .filter(Nicknames.slug == nick.lower()) \
.filter(NickValues.category == category)\
.filter(NickValues.key == key) \ .filter(NickValues.key == key) \
.one_or_none() .one_or_none()
if result is not None: if result is not None:
@ -103,7 +105,7 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def delete_nick_value(self, nick, key): def delete_nick_value(self, nick, key, category='default'):
"""Deletes the value for a given key to be associated with the nick.""" """Deletes the value for a given key to be associated with the nick."""
nick = Identifier(nick) nick = Identifier(nick)
nick_id = self.get_nick_id(nick) nick_id = self.get_nick_id(nick)
@ -111,6 +113,7 @@ class SpiceDB(object):
try: try:
result = session.query(NickValues) \ result = session.query(NickValues) \
.filter(NickValues.nick_id == nick_id) \ .filter(NickValues.nick_id == nick_id) \
.filter(NickValues.category == category)\
.filter(NickValues.key == key) \ .filter(NickValues.key == key) \
.one_or_none() .one_or_none()
# NickValue exists, delete # NickValue exists, delete
@ -123,7 +126,7 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def adjust_nick_value(self, nick, key, value): def adjust_nick_value(self, nick, key, value, category='default'):
"""Sets the value for a given key to be associated with the nick.""" """Sets the value for a given key to be associated with the nick."""
nick = Identifier(nick) nick = Identifier(nick)
value = json.dumps(value, ensure_ascii=False) value = json.dumps(value, ensure_ascii=False)
@ -132,6 +135,7 @@ class SpiceDB(object):
try: try:
result = session.query(NickValues) \ result = session.query(NickValues) \
.filter(NickValues.nick_id == nick_id) \ .filter(NickValues.nick_id == nick_id) \
.filter(NickValues.category == category)\
.filter(NickValues.key == key) \ .filter(NickValues.key == key) \
.one_or_none() .one_or_none()
# NickValue exists, update # NickValue exists, update
@ -140,7 +144,7 @@ class SpiceDB(object):
session.commit() session.commit()
# DNE - Insert # DNE - Insert
else: else:
new_nickvalue = NickValues(nick_id=nick_id, key=key, value=float(value)) new_nickvalue = NickValues(nick_id=nick_id, category=category, key=key, value=float(value))
session.add(new_nickvalue) session.add(new_nickvalue)
session.commit() session.commit()
except SQLAlchemyError: except SQLAlchemyError:
@ -149,7 +153,7 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def adjust_nick_list(self, nick, key, entries, adjustmentdirection): def adjust_nick_list(self, nick, key, entries, adjustmentdirection, category='default'):
"""Sets the value for a given key to be associated with the nick.""" """Sets the value for a given key to be associated with the nick."""
nick = Identifier(nick) nick = Identifier(nick)
if not isinstance(entries, list): if not isinstance(entries, list):
@ -160,6 +164,7 @@ class SpiceDB(object):
try: try:
result = session.query(NickValues) \ result = session.query(NickValues) \
.filter(NickValues.nick_id == nick_id) \ .filter(NickValues.nick_id == nick_id) \
.filter(NickValues.category == category)\
.filter(NickValues.key == key) \ .filter(NickValues.key == key) \
.one_or_none() .one_or_none()
# NickValue exists, update # NickValue exists, update
@ -184,7 +189,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_nickvalue = NickValues(nick_id=nick_id, key=key, value=values) new_nickvalue = NickValues(nick_id=nick_id, category=category, key=key, value=values)
session.add(new_nickvalue) session.add(new_nickvalue)
session.commit() session.commit()
except SQLAlchemyError: except SQLAlchemyError:
@ -195,7 +200,7 @@ class SpiceDB(object):
# CHANNEL FUNCTIONS # CHANNEL FUNCTIONS
def set_channel_value(self, channel, key, value): def set_channel_value(self, channel, key, value, category='default'):
"""Sets the value for a given key to be associated with the channel.""" """Sets the value for a given key to be associated with the channel."""
channel = Identifier(channel).lower() channel = Identifier(channel).lower()
value = json.dumps(value, ensure_ascii=False) value = json.dumps(value, ensure_ascii=False)
@ -203,6 +208,7 @@ class SpiceDB(object):
try: try:
result = session.query(ChannelValues) \ result = session.query(ChannelValues) \
.filter(ChannelValues.channel == channel)\ .filter(ChannelValues.channel == channel)\
.filter(ChannelValues.category == category)\
.filter(ChannelValues.key == key) \ .filter(ChannelValues.key == key) \
.one_or_none() .one_or_none()
# ChannelValue exists, update # ChannelValue exists, update
@ -211,7 +217,7 @@ class SpiceDB(object):
session.commit() session.commit()
# DNE - Insert # DNE - Insert
else: else:
new_channelvalue = ChannelValues(channel=channel, key=key, value=value) new_channelvalue = ChannelValues(channel=channel, category=category, key=key, value=value)
session.add(new_channelvalue) session.add(new_channelvalue)
session.commit() session.commit()
except SQLAlchemyError: except SQLAlchemyError:
@ -220,13 +226,14 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def get_channel_value(self, channel, key): def get_channel_value(self, channel, key, category='default'):
"""Retrieves the value for a given key associated with a channel.""" """Retrieves the value for a given key associated with a channel."""
channel = Identifier(channel).lower() channel = Identifier(channel).lower()
session = self.ssession() session = self.ssession()
try: try:
result = session.query(ChannelValues) \ result = session.query(ChannelValues) \
.filter(ChannelValues.channel == channel)\ .filter(ChannelValues.channel == channel)\
.filter(ChannelValues.category == category)\
.filter(ChannelValues.key == key) \ .filter(ChannelValues.key == key) \
.one_or_none() .one_or_none()
if result is not None: if result is not None:
@ -238,13 +245,14 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def delete_channel_value(self, channel, key): def delete_channel_value(self, channel, key, category='default'):
"""Sets the value for a given key to be associated with the channel.""" """Sets the value for a given key to be associated with the channel."""
channel = Identifier(channel).lower() channel = Identifier(channel).lower()
session = self.ssession() session = self.ssession()
try: try:
result = session.query(ChannelValues) \ result = session.query(ChannelValues) \
.filter(ChannelValues.channel == channel)\ .filter(ChannelValues.channel == channel)\
.filter(ChannelValues.category == category)\
.filter(ChannelValues.key == key) \ .filter(ChannelValues.key == key) \
.one_or_none() .one_or_none()
# ChannelValue exists, delete # ChannelValue exists, delete
@ -257,7 +265,7 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def adjust_channel_value(self, channel, key, value): def adjust_channel_value(self, channel, key, value, category='default'):
"""Sets the value for a given key to be associated with the channel.""" """Sets the value for a given key to be associated with the channel."""
channel = Identifier(channel).lower() channel = Identifier(channel).lower()
value = json.dumps(value, ensure_ascii=False) value = json.dumps(value, ensure_ascii=False)
@ -265,6 +273,7 @@ class SpiceDB(object):
try: try:
result = session.query(ChannelValues) \ result = session.query(ChannelValues) \
.filter(ChannelValues.channel == channel)\ .filter(ChannelValues.channel == channel)\
.filter(ChannelValues.category == category)\
.filter(ChannelValues.key == key) \ .filter(ChannelValues.key == key) \
.one_or_none() .one_or_none()
# ChannelValue exists, update # ChannelValue exists, update
@ -273,7 +282,7 @@ class SpiceDB(object):
session.commit() session.commit()
# DNE - Insert # DNE - Insert
else: else:
new_channelvalue = ChannelValues(channel=channel, key=key, value=float(value)) new_channelvalue = ChannelValues(channel=channel, category=category, key=key, value=float(value))
session.add(new_channelvalue) session.add(new_channelvalue)
session.commit() session.commit()
except SQLAlchemyError: except SQLAlchemyError:
@ -282,7 +291,7 @@ class SpiceDB(object):
finally: finally:
session.close() session.close()
def adjust_channel_list(self, channel, key, entries, adjustmentdirection): def adjust_channel_list(self, channel, key, entries, adjustmentdirection, category='default'):
"""Sets the value for a given key to be associated with the channel.""" """Sets the value for a given key to be associated with the channel."""
channel = Identifier(channel).lower() channel = Identifier(channel).lower()
if not isinstance(entries, list): if not isinstance(entries, list):
@ -292,6 +301,7 @@ class SpiceDB(object):
try: try:
result = session.query(ChannelValues) \ result = session.query(ChannelValues) \
.filter(ChannelValues.channel == channel)\ .filter(ChannelValues.channel == channel)\
.filter(ChannelValues.category == category)\
.filter(ChannelValues.key == key) \ .filter(ChannelValues.key == key) \
.one_or_none() .one_or_none()
# ChannelValue exists, update # ChannelValue exists, update
@ -316,7 +326,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_channelvalue = ChannelValues(channel=channel, key=key, value=values) new_channelvalue = ChannelValues(channel=channel, category=category, key=key, value=values)
session.add(new_channelvalue) session.add(new_channelvalue)
session.commit() session.commit()
except SQLAlchemyError: except SQLAlchemyError:
@ -327,7 +337,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)
@ -335,6 +345,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
@ -343,7 +354,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:
@ -352,13 +363,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:
@ -370,13 +382,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
@ -389,7 +402,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)
@ -397,6 +410,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
@ -405,7 +419,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:
@ -414,7 +428,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):
@ -424,6 +438,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
@ -448,7 +463,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: