示例#1
0
 def register(self):
     thread = self.r.get_submission(submission_id = self.recruit_id,comment_sort = "new")
     cmnts = praw.helpers.flatten_tree(thread.comments)
     users = self.user_info.keys()
     for cmnt in cmnts:
         author = str(cmnt.author).lower()
         if author not in users:
             base = False #is the user actually setting their base here
             parts = cmnt.body.split("\n")
             try:
                 for part in parts:
                     if "$$" in part:
                         base = readTerritory(part)
                         if base not in self.lands:
                             base = "midnightmarsh"
                             cmnt.reply("No base set, defaulting to the [Midnight Marsh](/r/MidnightMarsh)")
                             log.warning("%s tried to set their base to a non-existent territory: %s" % (author,base))
             except ValueError:
                 base = "midnightmarsh"
                 #cmnt.reply("No base set, defaulting to the [Midnight Marsh](/r/MidnightMarsh)")
                 log.warning("%s messed up the registrationg command: %s" % (author,cmnt.body))
             if base:
                 print ("Adding new user %s to user_info with citizenship in %s!" % (author,base))
                 log.info("Adding new user %s to user_info with citizenship in %s!" % (author,base))
                 self.user_info[author]={"food": 0, "material": 0, "luxury": 0,
                                         "last_produced":0.0,"last_creation":0,
                                         "producing":"material","home":base}
                 cmnt.reply("You have now registered as a citizen in %s!\
                            By default, you are producing material goods." % base)
     self.data["user_info"] = self.user_info
示例#2
0
def parseRequest(request):
    """Parse the request Chromabot sends, and return the proper buff as
    a float, or None if an error occurs. Request should be any string
    form of the territory name. /r/AreusAntris, Areus Antris, 
    areusantris, and all others should work equally well."""
    
    #convert the territory Reo sends into one guaranteed to be readable
    territory = readTerritory(request)

    #make sure that the json file works, first. If it doesn't, return
    #an error to Chromabot instead the API will take care of errors
    #without Reo needing to code anything else.
    chromaData = None
    with open("EconomyInfo.json",'r') as f:
        chromaData = json.load(f)
    
    #check to see if the request is a valid one
    if territory in chromaData['LandInfo'].keys():
        return chromaData['LandInfo'][territory]['DEFbuff']
    else:
        return None