def addquote(self): adder = self.lastsender if not self.values: self.chat("No") return text = ' '.join(self.values) quote = Quote(adder=adder, text=text, date=datetime.utcnow(), random=random.random()) quote.save()
def addquote(self): adder = self.lastsender if not self.values: self.chat("No") return text = ' '.join(self.values) quote = Quote(adder=adder, text=text, date=datetime.utcnow(), random=random.random()) quote.save() return 'Quote saved'
def randomquote(self): rand = random.random() if not Quote.objects: self.chat("no quotes") return q = random.choice(Quote.objects) # We can use this way if the QDB gets big. This comes from the # official MongoDB cookbook. We can use the random field for the # search function below too. For that, need to query on the text and # random. if False: q = Quote.objects(random__gte=rand).first() if not q: q = Quote.objects(random__lte=rand).first() if q: return q.text else: return "Couldn't find a quote for some reason"
def countquote(self): if not self.values: self.chat("Enter a search term") return term = ' '.join(self.values) if len(term) <= 1: self.chat("Enter a bigger search term") return quotes = Quote.objects(text__icontains=term) if not quotes: self.chat("No quotes found") else: total = len(quotes) self.chat("Found %d quotes" % total)
def quote(self): if not self.values: self.chat("Enter a search term") return term = ' '.join(self.values) if len(term) <= 1: self.chat("Enter a bigger search term") return quotes = Quote.objects(text__icontains=term) if not quotes: self.chat("No quotes found") else: total = len(quotes) if total > 1: q = random.choice(quotes) else: q = quotes.first() self.chat(q.text)