2016-07-14 10:37:07 +00:00
|
|
|
from objects import glob
|
|
|
|
|
2016-09-02 15:45:10 +00:00
|
|
|
class channel:
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
A chat channel
|
|
|
|
"""
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
def __init__(self, name, description, publicRead, publicWrite, temp, hidden):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Create a new chat channel object
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
name -- channel name
|
|
|
|
description -- channel description
|
|
|
|
publicRead -- bool, if true channel can be read by everyone, if false it can be read only by mods/admins
|
|
|
|
publicWrite -- bool, same as public read but relative to write permissions
|
2016-07-15 09:46:44 +00:00
|
|
|
temp -- if True, channel will be deleted when there's no one in the channel
|
|
|
|
hidden -- if True, channel won't be shown in channels list
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
2016-08-17 14:41:05 +00:00
|
|
|
self.name = name
|
|
|
|
self.description = description
|
|
|
|
self.publicRead = publicRead
|
|
|
|
self.publicWrite = publicWrite
|
2016-07-14 10:37:07 +00:00
|
|
|
self.moderated = False
|
|
|
|
self.temp = temp
|
|
|
|
self.connectedUsers = [999] # Fokabot is always connected to every channels (otherwise it doesn't show up in IRC users list)
|
2016-07-15 09:46:44 +00:00
|
|
|
self.hidden = hidden
|
2016-07-14 10:37:07 +00:00
|
|
|
|
|
|
|
# Client name (#spectator/#multiplayer)
|
|
|
|
self.clientName = self.name
|
|
|
|
if self.name.startswith("#spect_"):
|
|
|
|
self.clientName = "#spectator"
|
|
|
|
elif self.name.startswith("#multi_"):
|
|
|
|
self.clientName = "#multiplayer"
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
def userJoin(self, userID):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Add a user to connected users
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
userID -- user ID that joined the channel
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
2016-08-17 14:41:05 +00:00
|
|
|
if userID not in self.connectedUsers:
|
|
|
|
self.connectedUsers.append(userID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
def userPart(self, userID):
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Remove a user from connected users
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
userID -- user ID that left the channel
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
2016-08-17 14:41:05 +00:00
|
|
|
if userID in self.connectedUsers:
|
|
|
|
self.connectedUsers.remove(userID)
|
2016-07-14 10:37:07 +00:00
|
|
|
|
|
|
|
# Remove temp channels if empty or there's only fokabot connected
|
|
|
|
l = len(self.connectedUsers)
|
|
|
|
if self.temp == True and ((l == 0) or (l == 1 and 999 in self.connectedUsers)):
|
|
|
|
glob.channels.removeChannel(self.name)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def getConnectedUsers(self):
|
|
|
|
"""
|
|
|
|
Get connected user IDs list
|
|
|
|
|
|
|
|
return -- connectedUsers list
|
|
|
|
"""
|
|
|
|
return self.connectedUsers
|
|
|
|
|
|
|
|
def getConnectedUsersCount(self):
|
|
|
|
"""
|
|
|
|
Count connected users
|
|
|
|
|
|
|
|
return -- connected users number
|
|
|
|
"""
|
|
|
|
return len(self.connectedUsers)
|