def switch_rename(self, lhs, rhs): try: slot_name = valid_slot(lhs) new_name = valid_slot(rhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name).first() if not slot: self.error("Radio slot not found.") return if self.character.radio.filter(key__iexact=new_name).exclude(id=slot.id).count(): self.error("That name would conflict with another slot.") return slot.key = new_name slot.save() self.sys_msg("Slot renamed to: %s" % new_name)
def switch_broadcast(self, lhs, rhs): try: slot_name = valid_slot(lhs) except ValueError as err: self.error(unicode(err)) return if not rhs: self.error("What will you say?") return slot = self.character.radio.filter(key__istartswith=slot_name).first() chan = slot.frequency.channel chan.msg(rhs, senders=self.character, slot=slot)
def switch_ungag(self, lhs, rhs): try: slot_name = valid_slot(lhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name).first() if not slot: self.error("Radio slot not found.") return slot.ungag() self.sys_msg("Radio slot un-gagged.")
def switch_off(self, lhs, rhs): try: slot_name = valid_slot(lhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name, on=True).first() if not slot: self.error("Radio slot not found. Are any of your slots on?") return slot.switch_off() self.sys_msg("Radio slot de-activated.")
def switch_freq(self, lhs, rhs): try: slot_name = valid_slot(lhs) freq_name = valid_freq(rhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name).first() if not slot: self.error("Radio slot not found.") return freq, created = RadioFrequency.objects.get_or_create(key=freq_name) if created: freq.setup() slot.tune(freq) self.sys_msg("You have tuned into %s on Slot '%s'!" % (freq_name, slot_name))
def switch_init(self, lhs, rhs): try: slot_name = valid_slot(lhs) freq_name = valid_freq(rhs) except ValueError as err: self.error(unicode(err)) return if self.character.radio.filter(key__iexact=freq_name): self.error("You already have a slot by that name. Use /rename if you wish to change its name or /freq to re-tune it.") return freq, created = RadioFrequency.objects.get_or_create(key=freq_name) if created: freq.setup() self.character.radio.create(key=slot_name, frequency=freq) freq.channel.connect(self.character) self.sys_msg("You have tuned into %s on Slot '%s'!" % (freq_name, slot_name))
def switch_title(self, lhs, rhs): try: slot_name = valid_slot(lhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name).first() if not slot: self.error("Radio slot not found.") return if rhs: slot.title = sanitize_string(rhs) slot.save(update_fields=['title']) self.sys_msg("Title changed to: %s" % rhs) else: slot.title = None slot.save(update_fields=['title']) self.sys_msg("Title cleared.")
def switch_color(self, lhs, rhs): try: slot_name = valid_slot(lhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name).first() if not slot: self.error("Radio slot not found.") return if rhs: if len(ANSIString('|%s' % rhs)) != 0: self.error("That is not a valid color code.") return slot.color = sanitize_string(rhs) slot.save(update_fields=['color']) self.sys_msg("Color changed to: %s" % rhs) else: slot.color = None slot.save(update_fields=['color']) self.sys_msg("Color cleared.")
def switch_codename(self, lhs, rhs): try: slot_name = valid_slot(lhs) except ValueError as err: self.error(unicode(err)) return slot = self.character.radio.filter(key__istartswith=slot_name).first() if not slot: self.error("Radio slot not found.") return if rhs: if Character.objects.filter_family(db_key__iexact=rhs).count(): self.error("Cannot set your codename to an existing character's name.") return slot.codename = sanitize_string(rhs) slot.save(update_fields=['codename']) self.sys_msg("Codename changed to: %s" % rhs) else: slot.codename = None slot.save(update_fields=['codename']) self.sys_msg("Codename cleared.")