Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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'
Ejemplo n.º 3
0
    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"
Ejemplo n.º 4
0
    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"
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)