def __init__(self, room, data = None): if not data: data = { 'moderate': { 'anything': False, 'spam': False, 'banword': False, 'stretching': False, 'caps': False, 'groupchats': False, 'urls': False }, 'allow games':False, 'tourwhitelist':[]} self.users = {} self.loading = True self.joinTime = int(time.time()) self.title = room self.isPM = room.lower() == 'pm' self.rank = ' ' self.allowGames = data['allow games'] self.tour = None self.activity = None self.tourwhitelist = data['tourwhitelist'] self.chatlog = deque({'user': None, 'message': '', 'timestamp': ''}, 20) self.moderation = ModerationHandler(data['moderate'], self)
def __init__(self, room, data=None): """Intializes room with preliminary information.""" if not data: data = { 'moderate': { 'room': room, 'anything': False, 'spam': False, 'banword': False, 'caps': False, 'stretching': False, 'groupchats': False, 'urls': False }, 'broadcastrank': ' ', 'allow games': False, 'tourwhitelist': [] } self.users = {} self.loading = True self.title = room self.broadcast_rank = data['broadcastrank'] self.isPM = room.lower() == 'pm' self.rank = ' ' self.moderation = ModerationHandler(data['moderate']) self.allowGames = data['allow games'] self.tour = None self.activity = None self.tourwhitelist = data['tourwhitelist'] self.chatlog = deque({'': -1}, 20) self.moderation.assignRoom(self)
def __init__(self, room, data=None): """Intializes room with preliminary information.""" if not data: data = { 'moderate': { 'room': room, 'anything': False, 'spam': False, 'banword': False, 'caps': False, 'stretching': False, 'groupchats': False, 'urls': False }, 'broadcastrank': ' ', 'allow games': False, 'tourwhitelist': []} self.users = {} self.loading = True self.title = room self.broadcast_rank = data['broadcastrank'] self.isPM = room.lower() == 'pm' self.rank = ' ' self.moderation = ModerationHandler(data['moderate']) self.allowGames = data['allow games'] self.tour = None self.activity = None self.tourwhitelist = data['tourwhitelist'] self.chatlog = deque({'': -1}, 20) self.moderation.assignRoom(self)
class Room: """ Contains all important information of a pokemon showdown room. Attributes: users: map, maps user ids to users. loading: Bool, if this room is still loading information. title: string, name of the room. rank: string, the rank of this bot in this room. isPM: bool, if this room is considered a private message. moderation: Bool, if this bot should moderate this room. allowGames: Bool, if this bot will allow games in this room. tour: Bool, if this bot will allow tours in this room. activity: Workshop object, if this room is a workshop. tourwhitelist: list of str, users who are not moderators but who have permission to start a tour. """ def __init__(self, room, data=None): """Intializes room with preliminary information.""" if not data: data = { 'moderate': { 'room': room, 'anything': False, 'spam': False, 'banword': False, 'caps': False, 'stretching': False, 'groupchats': False, 'urls': False }, 'broadcastrank': ' ', 'allow games': False, 'tourwhitelist': []} self.users = {} self.loading = True self.title = room self.broadcast_rank = data['broadcastrank'] self.isPM = room.lower() == 'pm' self.rank = ' ' self.moderation = ModerationHandler(data['moderate']) self.allowGames = data['allow games'] self.tour = None self.activity = None self.tourwhitelist = data['tourwhitelist'] self.chatlog = deque({'': -1}, 20) self.moderation.assignRoom(self) def doneLoading(self): """Set loading status to False""" self.loading = False def addUser(self, user): if self.moderation.isBannedFromRoom(user): return if user.id not in self.users: self.users[user.id] = user return True def removeUser(self, userid): """Removes user from this room.""" if userid in self.users: return self.users.pop(userid) def renamedUser(self, old, new): """updates user credentials.""" self.removeUser(old) self.addUser(new) def getUser(self, name): """Returns true if this user is in this room.""" if name in self.users: return self.users[name] def botHasBanPermission(self): return User.compareRanks(self.rank, '@') def logChat(self, user, message): """Logs the message unto our message queue""" self.chatlog.append({user.id: len(message)}) def isWhitelisted(self, user): """Returns true if this user is white listed for tours.""" return user.hasRank('@') or user in self.tourwhitelist def addToWhitelist(self, user): """Adds user to whitelist""" if user in self.tourwhitelist: return False self.tourwhitelist.append(user) return True def delFromWhitelist(self, target): """Returns true if the operation was succesful.""" if target not in self.tourwhitelist: return False self.tourwhitelist.remove(target) return True def createTour(self, ws, form, battleHandler): """Creates a tour with the specified format. Args: ws: websocket. form: string, type of format for this tournament. """ self.tour = Tournament(ws, self, form, battleHandler) def getTourWinner(self, msg): """Returns the winner of the current game. Args: msg:str, winning message from the tour. Returns: tuple (str,str) , represeting the user and the format won. """ things = json.loads(msg) winner = things['results'][0] if self.tour: self.tour.logWin(winner) return winner, things['format'] def endTour(self): """Ends the current tournament.""" self.tour = None
class Room: """ Contains all important information for a pokemon showdown room. The only variable of note is the activity object. This variable does not follow a strict typing as it can allow for several class types. What should be noted is that there can only be 1 instance of activity per room, so having a situation with a Workshop and RoomGame running at the same time is impossible. Attributes: users: map, maps user ids (str) to user objects. loading: Bool, if this room is still loading information. title: string, name of the room. rank: string, the rank of this bot in this room. isPM: Bool, if this room is considered a private message. moderation: ModerationHandler, handler object for moderating user content. allowGames: Bool, if this bot will allow games in this room. tour: Bool, if this bot will allow tours in this room. activity: GenericGame, object which implements the standard behaviour for a Game, all activities do not strictly have the same type. tourwhitelist: list of str, users who are not moderators but who have permission to start a tour. """ def __init__(self, room, data = None): if not data: data = { 'moderate': { 'anything': False, 'spam': False, 'banword': False, 'stretching': False, 'caps': False, 'groupchats': False, 'urls': False }, 'allow games':False, 'tourwhitelist':[]} self.users = {} self.loading = True self.joinTime = int(time.time()) self.title = room self.isPM = room.lower() == 'pm' self.rank = ' ' self.allowGames = data['allow games'] self.tour = None self.activity = None self.tourwhitelist = data['tourwhitelist'] self.chatlog = deque({'user': None, 'message': '', 'timestamp': ''}, 20) self.moderation = ModerationHandler(data['moderate'], self) def doneLoading(self): self.loading = False def isHistory(self, message): if not self.loading: return False if int(message[2]) > self.joinTime: self.loading = False return self.loading def addUser(self, user): if self.moderation.isBannedFromRoom(user): return if user.id not in self.users: self.users[user.id] = user return True def removeUser(self, userid): if userid in self.users: return self.users.pop(userid) def renamedUser(self, old, new): self.removeUser(old) self.addUser(new) def getUser(self, name): if name in self.users: return self.users[name] def botHasBanPermission(self): return User.compareRanks(self.rank, '@') def logChat(self, user, message, time): self.chatlog.append({'user': user, 'message': message, 'timestamp': time}) def isWhitelisted(self, user): return user.hasRank('%') or user.id in self.tourwhitelist def addToWhitelist(self, user): if user in self.tourwhitelist: return False self.tourwhitelist.append(user) return True def delFromWhitelist(self, target): if target not in self.tourwhitelist: return False self.tourwhitelist.remove(target) return True def createTour(self, ws, form, battleHandler): self.tour = Tournament(ws, self, form, battleHandler) def getTourWinner(self, msg): things = json.loads(msg) winner = things['results'][0] if self.tour: self.tour.logWin(winner) return winner, things['format'] def endTour(self): self.tour = None
class Room: """ Contains all important information of a pokemon showdown room. Attributes: users: map, maps user ids to users. loading: Bool, if this room is still loading information. title: string, name of the room. rank: string, the rank of this bot in this room. isPM: bool, if this room is considered a private message. moderation: Bool, if this bot should moderate this room. allowGames: Bool, if this bot will allow games in this room. tour: Bool, if this bot will allow tours in this room. activity: Workshop object, if this room is a workshop. tourwhitelist: list of str, users who are not moderators but who have permission to start a tour. """ def __init__(self, room, data=None): """Intializes room with preliminary information.""" if not data: data = { 'moderate': { 'room': room, 'anything': False, 'spam': False, 'banword': False, 'caps': False, 'stretching': False, 'groupchats': False, 'urls': False }, 'broadcastrank': ' ', 'allow games': False, 'tourwhitelist': [] } self.users = {} self.loading = True self.title = room self.broadcast_rank = data['broadcastrank'] self.isPM = room.lower() == 'pm' self.rank = ' ' self.moderation = ModerationHandler(data['moderate']) self.allowGames = data['allow games'] self.tour = None self.activity = None self.tourwhitelist = data['tourwhitelist'] self.chatlog = deque({'': -1}, 20) self.moderation.assignRoom(self) def doneLoading(self): """Set loading status to False""" self.loading = False def addUser(self, user): if self.moderation.isBannedFromRoom(user): return if user.id not in self.users: self.users[user.id] = user return True def removeUser(self, userid): """Removes user from this room.""" if userid in self.users: return self.users.pop(userid) def renamedUser(self, old, new): """updates user credentials.""" self.removeUser(old) self.addUser(new) def getUser(self, name): """Returns true if this user is in this room.""" if name in self.users: return self.users[name] def botHasBanPermission(self): return User.compareRanks(self.rank, '@') def logChat(self, user, message): """Logs the message unto our message queue""" self.chatlog.append({user.id: len(message)}) def isWhitelisted(self, user): """Returns true if this user is white listed for tours.""" return user.hasRank('@') or user in self.tourwhitelist def addToWhitelist(self, user): """Adds user to whitelist""" if user in self.tourwhitelist: return False self.tourwhitelist.append(user) return True def delFromWhitelist(self, target): """Returns true if the operation was succesful.""" if target not in self.tourwhitelist: return False self.tourwhitelist.remove(target) return True def createTour(self, ws, form, battleHandler): """Creates a tour with the specified format. Args: ws: websocket. form: string, type of format for this tournament. """ self.tour = Tournament(ws, self, form, battleHandler) def getTourWinner(self, msg): """Returns the winner of the current game. Args: msg:str, winning message from the tour. Returns: tuple (str,str) , represeting the user and the format won. """ things = json.loads(msg) winner = things['results'][0] if self.tour: self.tour.logWin(winner) return winner, things['format'] def endTour(self): """Ends the current tournament.""" self.tour = None