pep.py/objects/channelList.py

65 lines
2.0 KiB
Python
Raw Normal View History

2016-10-02 20:48:14 +00:00
from common.log import logUtils as log
2016-05-18 17:12:46 +00:00
from objects import channel
2016-10-02 20:48:14 +00:00
from objects import glob
2016-04-19 17:40:59 +00:00
2016-09-02 15:45:10 +00:00
class channelList:
def __init__(self):
self.channels = {}
2016-04-19 17:40:59 +00:00
def loadChannels(self):
"""
Load chat channels from db and add them to channels list
:return:
2016-04-19 17:40:59 +00:00
"""
# Get channels from DB
channels = glob.db.fetchAll("SELECT * FROM bancho_channels")
# Add each channel if needed
for i in channels:
if i["name"] not in self.channels:
publicRead = True if i["public_read"] == 1 else False
publicWrite = True if i["public_write"] == 1 else False
self.addChannel(i["name"], i["description"], publicRead, publicWrite)
2016-07-15 09:46:44 +00:00
def addChannel(self, name, description, publicRead, publicWrite, temp = False, hidden = False):
2016-04-19 17:40:59 +00:00
"""
Add a channel to channels list
2016-04-19 17:40:59 +00:00
:param name: channel name
:param description: channel description
:param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
:param publicWrite: same as public read, but regards writing permissions
:param temp: if True, this channel will be deleted when there's no one in this channel
:param hidden: if True, thic channel won't be shown in channels list
:return:
2016-04-19 17:40:59 +00:00
"""
2016-07-15 09:46:44 +00:00
self.channels[name] = channel.channel(name, description, publicRead, publicWrite, temp, hidden)
log.info("Created channel {}".format(name))
2016-04-19 17:40:59 +00:00
def addTempChannel(self, name):
"""
Add a temporary channel (like #spectator or #multiplayer), gets deleted when there's no one in the channel
2016-07-15 09:46:44 +00:00
and it's hidden in channels list
:param name: channel name
:return: True if the channel was created, otherwise False
"""
if name in self.channels:
return False
2016-07-15 09:46:44 +00:00
self.channels[name] = channel.channel(name, "Chat", True, True, True, True)
log.info("Created temp channel {}".format(name))
def removeChannel(self, name):
"""
Removes a channel from channels list
:param name: channel name
:return:
"""
if name not in self.channels:
log.debug("{} is not in channels list".format(name))
return
self.channels.pop(name)
log.info("Removed channel {}".format(name))