Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This file is part of Merlin.
- # Merlin is the Copyright (C)2008-2009 of Robin K. Hansen, Elliot Rosemarine, Andreas Jacobsen.
- # Individual portions may be copyright by individual contributors, and
- # are included in this collective work with permission of the copyright
- # owners.
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- from Core.db import session
- from Core.maps import Galaxy, Planet, Alliance, Intel
- from Core.loadable import loadable
- options = ['alliance', 'nick', 'fakenick', 'defwhore', 'covop', 'scanner', 'dists', 'bg', 'gov', 'relay', 'reportchan', 'comment']
- @loadable.module("half")
- class intel(loadable):
- """View or set intel for a planet. Valid options: """
- __doc__ += ", ".join(options)
- usage = " x.y[.z] [option=value]+"
- paramre = loadable.coordre
- def execute(self, message, user, params):
- if params.group(3) is None:
- galaxy = Galaxy.load(*params.group(1,2))
- if galaxy is None:
- message.alert("No galaxy with coords %s:%s" % params.group(1,2))
- return
- prev = []
- for planet in galaxy.planets:
- if planet.intel is not None:
- reply = "#%s"%(planet.z,)
- if planet.intel.nick:
- reply += " %s"%(planet.intel.nick,)
- if planet.alliance:
- reply += " [%s]"%(planet.alliance.name[:3],)
- prev.append(reply)
- if len(prev):
- reply ="Intel %d:%d - "%(galaxy.x,galaxy.y,)
- reply+="Score (%d) Value (%d) Size (%d)"%(galaxy.score_rank,galaxy.value_rank,galaxy.size_rank)
- reply+=" - "
- reply+=" - ".join(prev)
- message.reply(reply)
- else:
- message.reply("No information stored for %s:%s" % (galaxy.x, galaxy.y,))
- return
- planet = Planet.load(*params.group(1,2,3))
- if planet is None:
- message.alert("No planet with coords %s:%s:%s" % params.group(1,2,3))
- return
- if planet.intel is None:
- planet.intel = Intel()
- if user.is_member():
- params = self.split_opts(message.get_msg())
- for opt, val in params.items():
- if opt == "alliance":
- if val in self.nulls:
- planet.intel.alliance = None
- continue
- alliance = Alliance.load(val)
- if alliance is None:
- message.alert("No alliances match %s" % (val,))
- continue
- planet.intel.alliance = alliance
- if (opt in options) and (val in self.nulls):
- setattr(planet.intel, opt, None)
- continue
- if opt in ("nick","fakenick","bg","gov","reportchan"):
- setattr(planet.intel, opt, val)
- if opt in ("defwhore","covop","scanner","relay"):
- if val in self.true:
- setattr(planet.intel, opt, True)
- if val in self.false:
- setattr(planet.intel, opt, False)
- if opt == "dists":
- try:
- planet.intel.dists = int(val)
- except ValueError:
- pass
- if opt == "comment":
- planet.intel.comment = message.get_msg().split("comment=")[1]
- session.commit()
- message.reply(("Information stored for %s:%s:%s -"+str(planet.intel) if str(planet.intel) else "No information stored for %s:%s:%s") % (planet.x, planet.y, planet.z,))
Add Comment
Please, Sign In to add comment