#!/usr/bin/env python

# !! DO NOT EDIT THIS FILE, SETTINGS ARE STORED IN THE SETTINGS FOLDER !! #

"""
    settings.py - Funnybot Setting Handler.
    Copyright (C) 2011-2013  The FunnyBot Team

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
"""

# !! DO NOT EDIT THIS FILE, SETTINGS ARE STORED IN THE SETTINGS FOLDER !! #

from core import funnylog as logger

# Global settings object for accessing/modifying settings
class setting(object):
	# Initialize the object
	def __init__(self,loadfromfile=False,**settingargs):
		#check to see if core settings were passed in the init
		if settingargs:
			self.coresettings = settingargs
		else:
			self.coresettings = dict()
		self.modsettings = dict()
		self.funcsettings = dict()
	
	
	def get(self,name, type='core', modname=None, funcname=None):
		if type == 'core':
			if name in self.coresettings:
				return self.coresettings[name]
			else:
				# error goes here for looking up a non-existent core setting
				pass
		elif type == 'module':
			if modname in self.modsettings:
				if name in self.modsettings[modname]:
					return self.modsettings[modname][name]
				else:
					# error goes here for looking up non-existant module setting
					pass
			else:
				# error goes here for looking up non-existant module
				pass
		elif type == 'function':
			if funcname in self.funcsettings:
				if name in self.funcsettings[funcname]:
					return self.funcsettings[funcname][name]
				else:
					# error goes here for looking up non-existant module setting
					pass
			else:
				# error goes here for looking up non-existant module
				pass
		
		# None shall pass...
		return None
	
	def getCore(self,name):
		return self.get(name=name)
	
	def getMod(self,name,module):
		return self.get(name=name,type='module',modname=module)
	
	def getFunc(self,name,function):
		return self.get(name=name,type='function',funcname=function)
	
	def set(self,name, value, type='core', modname=None, funcname=None):
		oldval = None
		if type == 'core':
			if name in self.coresettings:
				oldval = self.coresetting[name]
			self.coresettings[name] = value
		elif type == 'module':
			if modname in self.modsettings:
				if name in self.modsettings[modname]:
					oldval = self.modsettings[modname][name]
				self.modsettings[modname][name] = value
			else:
				# error goes here for looking up non-existant module
				pass
		elif type == 'function':
			if funcname in self.funcsettings:
				if name in self.funcsettings[funcname]:
					oldval = self.funcsettings[funcname][name]
				self.funcsettings[funcname][name] = value
			else:
				# error goes here for looking up non-existant module
				pass
		
		# Send the oldval back from where it came...
		return oldval

	def setCore(self,name,value):
		return self.set(name=name,value=value,type='core')
	
	def setMod(self,name,value,module):
		return self.set(name=name,value=value,type='module',modname=module)
	
	def setFunc(self,name,value,function):
		return self.set(name=name,value=value,type='function',funcname=function)

