mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-27 05:21:10 -05:00
accountsdb: store users case-insensitively by default
This commit is contained in:
parent
9504ee446a
commit
f3bfd9ff73
@ -1,4 +1,4 @@
|
|||||||
# Autogenerated by update-modules.py on Wed Jan 2 19:43:14 2019 - DO NOT EDIT THIS COPY DIRECTLY!
|
# Autogenerated by update-modules.py on Sat Mar 9 11:14:30 2019 - DO NOT EDIT THIS COPY DIRECTLY!
|
||||||
###
|
###
|
||||||
# Copyright (c) 2019, James Lu <james@overdrivenetworks.com>
|
# Copyright (c) 2019, James Lu <james@overdrivenetworks.com>
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
@ -58,7 +58,7 @@ class AccountsDB():
|
|||||||
ident@host if they are not logged in.
|
ident@host if they are not logged in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE):
|
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE, case_sensitive=False):
|
||||||
"""
|
"""
|
||||||
Loads the existing database, creating a new one in memory if none
|
Loads the existing database, creating a new one in memory if none
|
||||||
exists.
|
exists.
|
||||||
@ -66,6 +66,7 @@ class AccountsDB():
|
|||||||
self.db = {}
|
self.db = {}
|
||||||
self._plugin_name = plugin_name
|
self._plugin_name = plugin_name
|
||||||
self.filename = conf.supybot.directories.data.dirize(filename)
|
self.filename = conf.supybot.directories.data.dirize(filename)
|
||||||
|
self.case_sensitive = case_sensitive
|
||||||
|
|
||||||
self.addressing_mode = addressing_mode
|
self.addressing_mode = addressing_mode
|
||||||
|
|
||||||
@ -75,6 +76,13 @@ class AccountsDB():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug('%s: Unable to load database, creating '
|
log.debug('%s: Unable to load database, creating '
|
||||||
'a new one: %s', self._plugin_name, e)
|
'a new one: %s', self._plugin_name, e)
|
||||||
|
else:
|
||||||
|
if not case_sensitive:
|
||||||
|
for key, val in self.db.copy().items():
|
||||||
|
if not key.islower():
|
||||||
|
log.debug('%s: case-shifting key %s to %s', self._plugin_name, key, key.lower())
|
||||||
|
self.db[key.lower()] = val
|
||||||
|
del self.db[key]
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Exports the database to a file."""
|
"""Exports the database to a file."""
|
||||||
@ -103,11 +111,18 @@ class AccountsDB():
|
|||||||
def set(self, prefix, newId):
|
def set(self, prefix, newId):
|
||||||
"""Sets a user ID given the user's prefix."""
|
"""Sets a user ID given the user's prefix."""
|
||||||
user = self._get_key(prefix)
|
user = self._get_key(prefix)
|
||||||
|
|
||||||
|
if not self.case_sensitive:
|
||||||
|
user = user.lower()
|
||||||
self.db[user] = newId
|
self.db[user] = newId
|
||||||
|
|
||||||
def get(self, prefix):
|
def get(self, prefix):
|
||||||
"""Sets a user ID given the user's prefix."""
|
"""Sets a user ID given the user's prefix."""
|
||||||
user = self._get_key(prefix)
|
|
||||||
|
|
||||||
|
user = self._get_key(prefix)
|
||||||
|
log.debug('%s: looking up prefix %s; got user %s', self._plugin_name, prefix, user)
|
||||||
|
|
||||||
|
if not self.case_sensitive:
|
||||||
|
user = user.lower()
|
||||||
# Automatically returns None if entry does not exist
|
# Automatically returns None if entry does not exist
|
||||||
return self.db.get(user)
|
return self.db.get(user)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Autogenerated by update-modules.py on Wed Jan 2 19:43:14 2019 - DO NOT EDIT THIS COPY DIRECTLY!
|
# Autogenerated by update-modules.py on Sat Mar 9 11:14:30 2019 - DO NOT EDIT THIS COPY DIRECTLY!
|
||||||
###
|
###
|
||||||
# Copyright (c) 2019, James Lu <james@overdrivenetworks.com>
|
# Copyright (c) 2019, James Lu <james@overdrivenetworks.com>
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
@ -58,7 +58,7 @@ class AccountsDB():
|
|||||||
ident@host if they are not logged in.
|
ident@host if they are not logged in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE):
|
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE, case_sensitive=False):
|
||||||
"""
|
"""
|
||||||
Loads the existing database, creating a new one in memory if none
|
Loads the existing database, creating a new one in memory if none
|
||||||
exists.
|
exists.
|
||||||
@ -66,6 +66,7 @@ class AccountsDB():
|
|||||||
self.db = {}
|
self.db = {}
|
||||||
self._plugin_name = plugin_name
|
self._plugin_name = plugin_name
|
||||||
self.filename = conf.supybot.directories.data.dirize(filename)
|
self.filename = conf.supybot.directories.data.dirize(filename)
|
||||||
|
self.case_sensitive = case_sensitive
|
||||||
|
|
||||||
self.addressing_mode = addressing_mode
|
self.addressing_mode = addressing_mode
|
||||||
|
|
||||||
@ -75,6 +76,13 @@ class AccountsDB():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug('%s: Unable to load database, creating '
|
log.debug('%s: Unable to load database, creating '
|
||||||
'a new one: %s', self._plugin_name, e)
|
'a new one: %s', self._plugin_name, e)
|
||||||
|
else:
|
||||||
|
if not case_sensitive:
|
||||||
|
for key, val in self.db.copy().items():
|
||||||
|
if not key.islower():
|
||||||
|
log.debug('%s: case-shifting key %s to %s', self._plugin_name, key, key.lower())
|
||||||
|
self.db[key.lower()] = val
|
||||||
|
del self.db[key]
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Exports the database to a file."""
|
"""Exports the database to a file."""
|
||||||
@ -103,11 +111,18 @@ class AccountsDB():
|
|||||||
def set(self, prefix, newId):
|
def set(self, prefix, newId):
|
||||||
"""Sets a user ID given the user's prefix."""
|
"""Sets a user ID given the user's prefix."""
|
||||||
user = self._get_key(prefix)
|
user = self._get_key(prefix)
|
||||||
|
|
||||||
|
if not self.case_sensitive:
|
||||||
|
user = user.lower()
|
||||||
self.db[user] = newId
|
self.db[user] = newId
|
||||||
|
|
||||||
def get(self, prefix):
|
def get(self, prefix):
|
||||||
"""Sets a user ID given the user's prefix."""
|
"""Sets a user ID given the user's prefix."""
|
||||||
user = self._get_key(prefix)
|
|
||||||
|
|
||||||
|
user = self._get_key(prefix)
|
||||||
|
log.debug('%s: looking up prefix %s; got user %s', self._plugin_name, prefix, user)
|
||||||
|
|
||||||
|
if not self.case_sensitive:
|
||||||
|
user = user.lower()
|
||||||
# Automatically returns None if entry does not exist
|
# Automatically returns None if entry does not exist
|
||||||
return self.db.get(user)
|
return self.db.get(user)
|
||||||
|
@ -57,7 +57,7 @@ class AccountsDB():
|
|||||||
ident@host if they are not logged in.
|
ident@host if they are not logged in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE):
|
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE, case_sensitive=False):
|
||||||
"""
|
"""
|
||||||
Loads the existing database, creating a new one in memory if none
|
Loads the existing database, creating a new one in memory if none
|
||||||
exists.
|
exists.
|
||||||
@ -65,6 +65,7 @@ class AccountsDB():
|
|||||||
self.db = {}
|
self.db = {}
|
||||||
self._plugin_name = plugin_name
|
self._plugin_name = plugin_name
|
||||||
self.filename = conf.supybot.directories.data.dirize(filename)
|
self.filename = conf.supybot.directories.data.dirize(filename)
|
||||||
|
self.case_sensitive = case_sensitive
|
||||||
|
|
||||||
self.addressing_mode = addressing_mode
|
self.addressing_mode = addressing_mode
|
||||||
|
|
||||||
@ -74,6 +75,13 @@ class AccountsDB():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug('%s: Unable to load database, creating '
|
log.debug('%s: Unable to load database, creating '
|
||||||
'a new one: %s', self._plugin_name, e)
|
'a new one: %s', self._plugin_name, e)
|
||||||
|
else:
|
||||||
|
if not case_sensitive:
|
||||||
|
for key, val in self.db.copy().items():
|
||||||
|
if not key.islower():
|
||||||
|
log.debug('%s: case-shifting key %s to %s', self._plugin_name, key, key.lower())
|
||||||
|
self.db[key.lower()] = val
|
||||||
|
del self.db[key]
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Exports the database to a file."""
|
"""Exports the database to a file."""
|
||||||
@ -102,11 +110,18 @@ class AccountsDB():
|
|||||||
def set(self, prefix, newId):
|
def set(self, prefix, newId):
|
||||||
"""Sets a user ID given the user's prefix."""
|
"""Sets a user ID given the user's prefix."""
|
||||||
user = self._get_key(prefix)
|
user = self._get_key(prefix)
|
||||||
|
|
||||||
|
if not self.case_sensitive:
|
||||||
|
user = user.lower()
|
||||||
self.db[user] = newId
|
self.db[user] = newId
|
||||||
|
|
||||||
def get(self, prefix):
|
def get(self, prefix):
|
||||||
"""Sets a user ID given the user's prefix."""
|
"""Sets a user ID given the user's prefix."""
|
||||||
user = self._get_key(prefix)
|
|
||||||
|
|
||||||
|
user = self._get_key(prefix)
|
||||||
|
log.debug('%s: looking up prefix %s; got user %s', self._plugin_name, prefix, user)
|
||||||
|
|
||||||
|
if not self.case_sensitive:
|
||||||
|
user = user.lower()
|
||||||
# Automatically returns None if entry does not exist
|
# Automatically returns None if entry does not exist
|
||||||
return self.db.get(user)
|
return self.db.get(user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user