def func(self): """Executes goals cmd""" try: if not self.args: self.list_goals() elif "create" in self.switches: self.create_goal() else: try: goal = self.goals.get(id=self.lhslist[0]) except (Goal.DoesNotExist, ValueError, IndexError): raise CommandError( "You do not have a goal by that number.") if not self.switches: self.msg(goal.display()) elif self.check_switches(self.field_switches): self.update_goal_field(goal) elif "rfr" in self.switches: self.request_review(goal) else: raise CommandError("Invalid switch.") except CommandError as err: self.msg(err) else: self.mark_command_used()
def close_ticket(self, ticket): """Closes a ticket""" if not self.rhs: raise CommandError("You must provide a result.") update = ticket.goal_update if update.result: raise CommandError( "Update already has a result written. Close the ticket with @job." ) update.result = self.rhs update.save() resolve_ticket(self.caller.player_ob, ticket, "Result: %s" % self.rhs) self.msg("You have closed the ticket and set the result to: %s" % self.rhs)
def update_goal_field(self, goal): """Updates a field for a goal""" args = self.rhs or "" target_name = self.rhs field = list(set(self.switches) & set(self.field_switches))[0] old = getattr(goal, field) if field == "status": args = self.get_value_for_choice_field_string( Goal.STATUS_CHOICES, args) old = goal.get_status_display() elif field == "scope": args = self.get_value_for_choice_field_string( Goal.SCOPE_CHOICES, args) old = goal.get_scope_display() elif field == "plot": try: args = self.caller.dompc.plots.get(id=args) target_name = args except (Plot.DoesNotExist, ValueError): raise CommandError("No plot by that ID.") setattr(goal, field, args) goal.save() msg = "Old value was: %s\n" % old msg += "%s set to: %s" % (field.capitalize(), target_name) self.msg(msg)
def create_goal(self): try: summary, desc = self.args.split("/", 1) if not desc: raise ValueError except ValueError: raise CommandError( 'You must provide a summary and a description of your goal.') goal = self.goals.create(summary=summary, description=desc) self.msg('You have created a new goal: ID #%s.' % goal.id)
def request_review(self, goal): """Submits a ticket asking for a review of progress toward their goal""" from datetime import datetime, timedelta past_thirty_days = datetime.now() - timedelta(days=30) recent = GoalUpdate.objects.filter( goal__in=self.goals.all(), db_date_created__gt=past_thirty_days).first() beat = None if recent: raise CommandError( "You submitted a request for review for goal %s too recently." % recent.goal.id) try: summary, ooc_message = self.rhs.split("/") except (AttributeError, ValueError): raise CommandError( "You must provide both a short story summary of what your character did or attempted to " "do in order to make progress toward their goal, and an OOC message to staff, telling " "them of your intent for results you would like and anything else that seems " "relevant.") if len(self.lhslist) > 1: try: beat = PlotUpdate.objects.filter( plot__in=self.caller.dompc.plots.all()).get( id=self.lhslist[1]) except (PlotUpdate.DoesNotExist, ValueError): raise CommandError("No beat by that ID.") update = goal.updates.create(beat=beat, player_summary=summary) ticket = create_ticket( self.caller.player_ob, self.rhs, plot=goal.plot, beat=beat, goal_update=update, queue_slug="Goals", ) self.msg( "You have sent in a request for review for goal %s. Ticket ID is %s." % (goal.id, ticket.id))
def func(self): """Executes GMgoals command""" try: if not self.args: return self.list_tickets() try: ticket = self.tickets.get(id=self.lhs) except Ticket.DoesNotExist: raise CommandError("No ticket found by that ID.") if not self.switches: return self.msg(ticket.display()) if "close" in self.switches: return self.close_ticket(ticket) except CommandError as err: self.msg(err)