def _configure(self, config): BaseChatManager._configure(self, config) try: otherBots = stringToList(config.setdefault('other_bots', "none")) self._otherBots = map(int, otherBots) except ValueError: raise FatalError("Error configuring WalkieTalkieRepeater: " "other_bots must be list of integers (userIds)") try: self._numPlayersForFreqChange = int(config.setdefault( 'num_players_to_change', 3)) self._freqChangeTimeout = int(config.setdefault('change_timeout', 10)) except ValueError: raise FatalError("Error configuring WalkieTalkieRepeater: " "num_players_to_change and change_timeout must " "be integral") self._format = config.setdefault('format', "[[%username%]] %text%") self._emoteFormat = config.setdefault('emote_format', "[[%username% %text%]]") self._key = str(config.setdefault('key', random.randint(0,999999))) if self._key.strip() == "": config['key'] = random.randint(0,999999) self._key = str(config['key'])
def _processAddMessageTemplate(self, message): uid = message.uid text = message.text failMessage = self.newMessage(uid, "Your kmail was not in a valid format.") m = self._messageMatcher.search(text) if m is None: return failMessage newMessages = self._messageExtractor.findall(m.group("messageSection")) if not newMessages: return failMessage messageName = "m{}".format(int(_epochTime())) newMessage = {'last': 0, 'hard': False, 'order': [], 'index': 0} try: newMessage['mode'] = self._modes[m.group("mode")] newMessage['period'] = int(m.group("period")) newMessage['offset'] = int(m.group("offset")) newMessage['channels'] = stringToList(m.group("channels")) newMessage['description'] = m.group("description") newMessage['messages'] = { "m{}".format(k): v for k, v in enumerate(newMessages) } days = int(m.group("expires")) newMessage['expires'] = _epochTime() + days * 24 * 60 * 60 except (KeyError, IndexError, ValueError): return failMessage self._messages[messageName] = newMessage return self.newMessage( uid, "Your announcement {} has been added.".format(messageName))
def _processAddMessageTemplate(self, message): uid = message.uid text = message.text failMessage = self.newMessage(uid, "Your kmail was not in a valid format.") m = self._messageMatcher.search(text) if m is None: return failMessage newMessages = self._messageExtractor.findall(m.group("messageSection")) if not newMessages: return failMessage messageName = "m{}".format(int(_epochTime())) newMessage = {'last': 0, 'hard': False, 'order': [], 'index': 0} try: newMessage['mode'] = self._modes[m.group("mode")] newMessage['period'] = int(m.group("period")) newMessage['offset'] = int(m.group("offset")) newMessage['channels'] = stringToList(m.group("channels")) newMessage['description'] = m.group("description") newMessage['messages'] = {"m{}".format(k): v for k,v in enumerate(newMessages)} days = int(m.group("expires")) newMessage['expires'] = _epochTime() + days * 24 * 60 * 60 except (KeyError, IndexError, ValueError): return failMessage self._messages[messageName] = newMessage return self.newMessage(uid, "Your announcement {} has been added." .format(messageName))
def _configure(self, config): self._daysUntilBoot = int(config.setdefault('boot_after_days', 180)) safeRanks = stringToList( config.setdefault('safe_ranks', "rank1, rank2")) safeTitles = stringToList( config.setdefault('safe_titles', "DO NOT DELETE, " "DO NOT ERASE")) self._safeRanks = map(_rankTransform, safeRanks) self._safeTitles = map(_rankTransform, safeTitles) self._bootMessage = toTypeOrNone( config.setdefault('boot_message', "none")) self._simulate = stringToBool(config.setdefault('simulate', "false")) self._immediate = stringToBool( config.setdefault('run_immediately', "false")) try: self._bootFrequencyDays = int( config.setdefault('boot_every_n_days', 1)) except ValueError: raise FatalError("ClanRankModule: boot_every_n_days must " "be integral") rules = config.setdefault( 'rules', { 'Normal Member': { 'demotion_allowed': "false", 'min_karma': 0, 'min_days_until_next_promotion': 7, 'min_days_in_clan': 0, 'next_rank': 'Rank2' }, 'Rank2': { 'demotion_allowed': "true", 'min_karma': 0, 'min_days_until_next_promotion': 0, 'min_days_in_clan': 0, 'next_rank': "none" } }) for rule in rules.values(): rule.setdefault('demotion_allowed', True) rule.setdefault('min_karma', 0) rule.setdefault('min_days_until_next_promotion', 0) rule.setdefault('min_days_in_clan', 0) rule.setdefault('next_rank', "none") self._ruleConfig = rules
def _configure(self, config): self._clanOnly = map( str.lower, stringToList(config.get('clan_only_channels', "clan,hobopolis," "slimetube,dread"))) self.log("Chat log clan only channels: {}" .format(', '.join(self._clanOnly))) config['clan_only_channels'] = listToString(self._clanOnly)
def _configure(self, config): for k, v in config.items(): if isinstance(v, dict): modeStr = v.setdefault('mode', 'cycle').lower() periodStr = v.setdefault('period', 1440) try: period = int(periodStr) except ValueError: raise FatalError( "Invalid period specified: {}".format(periodStr)) offsetStr = v.setdefault('offset', 'random') try: offset = int(offsetStr) except ValueError: if offsetStr.lower() != "random": raise FatalError( ("Invalid offset: {}, must be " "integer or 'random'").format(offsetStr)) else: offset = random.randint(0, period) try: mode = self._modes[modeStr] except IndexError: raise FatalError( "Invalid mode specified: {}".format(modeStr)) channels = stringToList(v.setdefault('channel', 'clan,')) messages = {} for key_, val_ in v.items(): if key_.lower().startswith("message"): try: keyVal = "message{:06d}".format(int(key_[7:])) except ValueError: raise FatalError(("Invalid message name: {}; " "messages must be message1, " "message2, ...").format(key_)) messages[keyVal] = val_ self._messages[k] = { 'mode': mode, 'period': period, 'channels': channels, 'messages': messages, 'offset': offset, 'order': [], 'index': 0, 'hard': True, 'last': 0, 'expires': 0, 'description': "" }
def _configure(self, config): for k,v in config.items(): if isinstance(v, dict): modeStr = v.setdefault('mode', 'cycle').lower() periodStr = v.setdefault('period', 1440) try: period = int(periodStr) except ValueError: raise FatalError("Invalid period specified: {}" .format(periodStr)) offsetStr = v.setdefault('offset', 'random') try: offset = int(offsetStr) except ValueError: if offsetStr.lower() != "random": raise FatalError(("Invalid offset: {}, must be " "integer or 'random'") .format(offsetStr)) else: offset = random.randint(0, period) try: mode = self._modes[modeStr] except IndexError: raise FatalError("Invalid mode specified: {}" .format(modeStr)) channels = stringToList(v.setdefault('channel', 'clan,')) messages = {} for key_,val_ in v.items(): if key_.lower().startswith("message"): try: keyVal = "message{:06d}".format(int(key_[7:])) except ValueError: raise FatalError(("Invalid message name: {}; " "messages must be message1, " "message2, ...") .format(key_)) messages[keyVal] = val_ self._messages[k] = {'mode': mode, 'period': period, 'channels': channels, 'messages': messages, 'offset': offset, 'order': [], 'index': 0, 'hard': True, 'last': 0, 'expires': 0, 'description': ""}
def _configure(self, config): try: self._notifyPercent = map(int, stringToList( config.setdefault('update-percent', "25,50,75,90,100"))) except ValueError: raise FatalError("update-percent must be a list of integers") try: self._perror = float(config.setdefault("p_error", "0.001")) if not 0 < self._perror < 1: raise ValueError() except ValueError: raise FatalError("p_error must be a float between 0 and 1")
def _configure(self, config): self._command = map( str.lower, stringToList(config.get('command', 'UNCONFIGURED'))) config['command'] = listToString(self._command) self._helpText = config.setdefault('helptext', 'UNCONFIGURED') ruleDict = config.get('text', {}) ruleDict.setdefault('__default__', "Ask me about: %keywords%.") ruleDict.setdefault('__error__', "I don't know anything about %arg%.") ruleDict.setdefault('__unique__', "I don't have a unique match for %arg%.") config['text'] = ruleDict for keyword,rule in ruleDict.items(): self._rules[keyword.strip().lower()] = rule.decode('string_escape') self.debugLog("Added {} keyword-rules.".format(len(self._rules)))
def _configure(self, config): self._command = map( str.lower, stringToList(config.get('command', 'UNCONFIGURED'))) config['command'] = listToString(self._command) self._helpText = config.setdefault('helptext', 'UNCONFIGURED') ruleDict = config.get('text', {}) ruleDict.setdefault('__default__', "Ask me about: %keywords%.") ruleDict.setdefault('__error__', "I don't know anything about %arg%.") ruleDict.setdefault('__unique__', "I don't have a unique match for %arg%.") config['text'] = ruleDict for keyword, rule in ruleDict.items(): self._rules[keyword.strip().lower()] = rule.decode('string_escape') self.debugLog("Added {} keyword-rules.".format(len(self._rules)))
def _configure(self, config): BaseChatManager._configure(self, config) try: otherBots = stringToList(config.setdefault('other_bots', "none")) self._otherBots = map(int, otherBots) except ValueError: raise FatalError("Error configuring WalkieTalkieRepeater: " "other_bots must be list of integers (userIds)") try: self._numPlayersForFreqChange = int( config.setdefault('num_players_to_change', 3)) self._freqChangeTimeout = int( config.setdefault('change_timeout', 10)) except ValueError: raise FatalError("Error configuring WalkieTalkieRepeater: " "num_players_to_change and change_timeout must " "be integral") self._format = config.setdefault('format', "[[%username%]] %text%") self._emoteFormat = config.setdefault('emote_format', "[[%username% %text%]]") self._key = str(config.setdefault('key', random.randint(0, 999999))) if self._key.strip() == "": config['key'] = random.randint(0, 999999) self._key = str(config['key'])