def gethelpmessage(messagename): if messagename: helpmessage = yadon.ReadRowFromTable(settings.helpmessagestablename, "message_help_" + messagename) #Default message if no parameter is given else: helpmessage = yadon.ReadRowFromTable(settings.helpmessagestablename, "message_help") #Use {cp} for command prefix and {pd} for parameter delimiter if helpmessage: return helpmessage[0].replace("{cp}", settings.commandprefix).replace("{pd}", settings.paramdelim).replace("\\n", "\n").replace("\\t", "\t") else: return None
def getuserlevel(self, userid): try: return int( yadon.ReadRowFromTable(settings.userlevelstablename, str(userid))[0]) except (TypeError, IndexError, ValueError): return settings.defaultuserlevel
def updatesetting(self, variable, value, authlevel=settings.defaultuserlevel): try: oldvalue = getattr(settings, variable) except AttributeError: return try: settinglevel = int( yadon.ReadRowFromTable(settings.settingstablename, variable, named_columns=True)["Tier"]) except (IndexError, ValueError, TypeError): settinglevel = settings.maxuserlevel if settinglevel > authlevel: return value = value.replace("\n", "\\n").replace("\t", "\\t") yadon.WriteRowToTable(settings.settingstablename, variable, { "Value": value, "Tier": settinglevel }, named_columns=True) try: if float(value) % 1 == 0: value = int(value) else: value = float(value) except ValueError: value = value.replace("\\n", "\n").replace("\\t", "\t") setattr(settings, variable, value) return oldvalue
def updatesetting(variable, value, authlevel=1): try: oldvalue = getattr(settings, variable) except AttributeError: return try: settinglevel = int( yadon.ReadRowFromTable(settings.settingstablename, variable)[1]) except (IndexError, ValueError): settinglevel = 1 if settinglevel > authlevel: return value = value.replace("\n", "\\n").replace("\t", "\\t") yadon.WriteRowToTable(settings.settingstablename, variable, [value, settinglevel]) try: if float(value) % 1 == 0: value = int(value) else: value = float(value) except ValueError: value = value.replace("\\n", "\n").replace("\\t", "\t") setattr(settings, variable, value) return oldvalue
def removesetting(variable, authlevel=1): try: value = getattr(settings, variable) except AttributeError: return try: settinglevel = int(yadon.ReadRowFromTable(settings.settingstablename, variable)[1]) except (IndexError, ValueError): settinglevel = 1 if settinglevel > authlevel: return yadon.RemoveRowFromTable(settings.settingstablename, variable) delattr(settings, variable) return value
def removesetting(self, variable, authlevel=settings.defaultuserlevel): try: value = getattr(settings, variable) except AttributeError: return try: settinglevel = int( yadon.ReadRowFromTable(settings.settingstablename, variable, named_columns=True)["Tier"]) except (IndexError, ValueError): settinglevel = settings.maxuserlevel if settinglevel > authlevel: return yadon.RemoveRowFromTable(settings.settingstablename, variable, named_columns=True) delattr(settings, variable) return value
async def customresponse(context, *args, **kwargs): response = yadon.ReadRowFromTable(settings.customresponsestablename, context["command"]) if response: return await koduck.sendmessage(context["message"], sendcontent=response[0])