def describeComponentOverview(self, doFullSentence, masterPronoun):
         description = ""
         # May only describe components if they exist
         if not len(self.components.keys()) == 0:
                 if doFullSentence:
                         # Begin with pronoun
                         description = utils.getPronoun(self.gender, 'subject') + " "
                 else:
                         # Full sentence not required
                         description += random.choice(", and ", ", which ")
                 # Describe possession
                 description += random.choice(["is made up of", "is composed of", "has"]) + " "
                 # Track components listed so last 
                 keyCount = 0
                 for key, value in self.components.items():
                         keyCount += 1
                         description += utils.intToWord(len(value)) + " " + utils.pluralise(str(type(value[0]).__name__), len(value))
                         if len(self.components.keys()) > 1 and keyCount+1 == len(self.components.keys()):
                                 # insert a connector before last component
                                 description += " and "
                         elif not keyCount == len(self.components.keys()):
                                 # comma separate components
                                 description += ", "
                         description += ". "
                 if doFullSentence:
                         description = string.capitalize(description)
         return description
예제 #2
0
    async def reasons(self, ctx: Context, karma: clean_content):
        karma_stripped = karma.lstrip("@")

        # Get the karma from the database
        karma_item = (db_session.query(KarmaModel).filter(
            func.lower(KarmaModel.name) == func.lower(karma_stripped)).first())

        if karma_item:
            # Set the karma item's name to be the same as in the database
            karma_stripped = karma_item.name
            # Get all of the changes that have some reason
            karma_changes = (db_session.query(KarmaChange).filter(
                KarmaChange.karma_id == karma_item.id,
                KarmaChange.reason is not None,
            ).all())
            # Flatten the reasons into a single list and sort it alphabetically
            reasons = sorted(
                (r for r in (change.reason
                             for change in karma_changes) if r is not None),
                key=str.casefold,
            )

            # If there's at least one reason
            if reasons:
                reasons_plural = pluralise(reasons, "reason")

                bullet_points = "\n".join(f" • {reason}\n"
                                          for reason in reasons)
                result = f'The {reasons_plural} for "{karma_stripped}" are as follows:\n\n{bullet_points}'
            else:
                result = f"There are no reasons down for that karma topic! :frowning:"

            file = None
            fp = None
            if len(result) > 2000:
                # Create a new temporary file that isn't deleted until we say
                with tempfile.NamedTemporaryFile(delete=False) as fp:
                    fp.write(result.encode("utf8"))

                # Wait for the file to close before accessing it (Windows NT limitation)
                file = File(fp.name, filename=f"{karma_stripped}.txt")
                result = f'There are too many reasons for "{karma_stripped}" to fit in a Discord message!'

            await ctx.send(result, file=file)

            # Delete temporary file (if any) after message is sent
            if fp:
                os.remove(fp.name)
        else:
            # The item hasn't been karma'd
            result = f"\"{karma_stripped}\" hasn't been karma'd yet. :cry:"
            await ctx.send(result)
예제 #3
0
global whitespace

iPrint("\nLet's Describe Something!\n", True)

print("Creating a cube...")
box = geometry.Cube()
box.setNoun("box")
box.addColours(["red", "orange"])
box.describe()
#wsWrapper(box.printComponentTree)

print("Creating a rabbit...")
rabbit = creatures.Creature()
rabbit.setNoun("rabbit")
rabbit.addColours(["brown"])
rabbit.describe()

print("Creating a humanoid...")
percy = creatures.Humanoid()
percy.setNoun("human")
percy.setName("percy")
percy.addColours(["pink"])
percy.describe()

# Sentence building tests
noun = "turkey"
tNum = 1
for tNum in range(0,12):
        print("There "+utils.isOrAre(tNum)+" "+utils.intToWord(tNum)+" "+utils.pluralise(noun, tNum)+" on my lawn.")