Skip to content

Commit

Permalink
core: basic skeleton of User class + expansion of Room to allow for that
Browse files Browse the repository at this point in the history
  • Loading branch information
Annika committed May 22, 2020
1 parent d7d60cc commit d5cac12
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
8 changes: 7 additions & 1 deletion config-example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"username": "",
"password": "",
"loglevel": 2
"loglevel": 2,
"sysops": [],
"broadcastRank": "+",
"addfactRank": "+",
"hostgameRank": "%",
"manageRank": "#",
"roomRanksInOrder": ["+", "%", "@", "*", "#"]
}
5 changes: 3 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
################################################

CONFIG_PATH = 'config.json'
CONFIG_VARS = ['username', 'password', 'loglevel']
CONFIG_VARS = ['username', 'password', 'loglevel', 'sysops', 'broadcastRank',
'addfactRank', 'hostgameRank', 'manageRank', 'roomRanksInOrder']

def loadConfig():
configData = json.load(open(CONFIG_PATH, 'r'))
Expand All @@ -22,5 +23,5 @@ def loadConfig():
returnValue.append(configData[configItem])
return returnValue

username, password, loglevel = loadConfig()
username, password, loglevel, sysops, broadcastRank, addfactRank, hostgameRank, manageRank, roomRanksInOrder = loadConfig()
# the order of these needs to be the same as in CONFIG_VARS
31 changes: 30 additions & 1 deletion core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,47 @@ def toID(string):
## Room Class ##
################


class Room():
def __init__(self, name):
self.auth = self.updateAuth()
self.id = toID(name)

def updateAuth(self):
'''Updates the auth list for the room. Returns the auth list'''
log("W: Room.updateAuth() isn't implemented yet")
return {'+': [], '%': [], '@': [], '#': []}
self.auth = {'+': [], '%': [], '@': [], '*', '#': []}
return self.auth

def say(self, message):
'''Sends the `message` to the room'''
log("W: Room.say() isn't implemented yet")

def leave(self):
'''Leaves the room'''
log("W: Room.leave() isn't implemented yet")

def usersWithRankGreaterThan(self, rank):
'''returns a list of userids for the roomauth whose room rank is greater than the given `rank`'''
userIDList = []
for rank in config.roomRanksInOrder[config.roomRanksInOrder.index(rank):]:
if rank in self.auth:
userIDList.extend(self.auth[rank])
return userIDList

class User():
def __init__(self, name):
self.name = name
self.id = toID(name)
self.isAdmin = self.id in config.sysops

def can(self, action, room):
'''returns True if the user can do the action and False otherwise'''
if action not in ['broadcast', 'addfact', 'hostgame', 'manage', 'admin']:
log("E: User.can(): {action} isn't a valid action".format(action=action))
return ((action === 'broadcast' and self.id in room.usersWithRankGreaterThan(config.broadcastRank)) or
(action === 'addfact' and self.id in room.usersWithRankGreaterThan(config.addfactRank)) or
(action === 'hostgame' and self.id in room.usersWithRankGreaterThan(config.hostgameRank)) or
(action === 'manage' and self.id in room.usersWithRankGreaterThan(config.manageRank)) or
self.isAdmin)

0 comments on commit d5cac12

Please sign in to comment.