Give servers and nicknames basic locale support

This commit is contained in:
Ben 2019-06-07 00:36:21 +01:00
parent 7de38bcf18
commit 23b0838c81
5 changed files with 12 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import config
from houdini.houdini import Houdini
from houdini import ConflictResolution
from houdini import Language
if __name__ == '__main__':
logger = logging.getLogger('houdini')
@ -21,6 +22,8 @@ if __name__ == '__main__':
help='Cache expiry (seconds)', type=int)
parser.add_argument('-P', '--plugins', action='store',
nargs='*', help='Plugins to load')
parser.add_argument('-l', '--language', action='store', help='Houdini language',
choices=['En', 'Fr', 'Pt', 'Es', 'De', 'Ru'])
boot_modes = parser.add_mutually_exclusive_group()
boot_modes.add_argument('-W', '--world', action='store_true', help='Run server in world mode')
@ -115,11 +118,12 @@ if __name__ == '__main__':
if server['World']:
server.update({
'Id': args.id or config.servers[args.server]['Id'],
'Language': getattr(Language, args.language) if args.language else config.servers[args.server]['Language'],
'Capacity': args.capacity or config.servers[args.server]['Capacity'],
'CacheExpiry': args.cache_expiry or config.servers[args.server]['CacheExpiry']
})
server['logging'] = logging
server['Logging'] = logging
factory_instance = Houdini(args.server,
database=database,

View File

@ -1,4 +1,5 @@
from houdini import ConflictResolution
from houdini import Language
database = {
'Address': 'localhost',
@ -39,6 +40,7 @@ servers = {
'Id': '100',
'Address': '0.0.0.0',
'Port': 9875,
'Language': Language.En,
'World': True,
'Capacity': 200,
'CacheExpiry': 3600,

View File

@ -15,7 +15,7 @@ class ConflictResolution(enum.Enum):
Exception = 2
class Language(enum.Enum):
class Language(enum.IntEnum):
En = 1
Pt = 2
Fr = 4

View File

@ -66,6 +66,9 @@ class Penguin(db.Model):
rejection_de = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
rejection_ru = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
def safe_nickname(self, language_bitmask):
return self.nickname if self.approval & language_bitmask else "P" + str(self.id)
@property
def approval(self):
return int('{}{}0{}{}{}{}'.format(self.approval_ru * 1, self.approval_de * 1, self.approval_es * 1,

View File

@ -45,7 +45,7 @@ class Penguin(Spheniscidae):
@property
def nickname(self):
return self.data.nickname if self.data.approval else "P" + self.data.id
return self.data.safe_nickname(self.server.server_config['Language'])
async def load(self):
if self.data: