🏡 index : ~doyle/dave.git

author dave <dave@ip-172-26-11-212.eu-west-2.compute.internal> 2019-03-30 15:39:58.0 +00:00:00
committer dave <dave@ip-172-26-11-212.eu-west-2.compute.internal> 2019-03-30 15:39:58.0 +00:00:00
commit
f5a8ed0da4de042a35d0142b903490550d8a05c3 [patch]
tree
b1b50003d3f7ac0a6c19d1ba1a6c028c50c55cfc
parent
19d28d61623f226c486b88fcd1356daa163da8d9
download
f5a8ed0da4de042a35d0142b903490550d8a05c3.tar.gz

better quote ergonomics



Diff

 dave/modules/quote.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/dave/modules/quote.py b/dave/modules/quote.py
index 71f353a..c1ab448 100644
--- a/dave/modules/quote.py
+++ a/dave/modules/quote.py
@@ -1,12 +1,15 @@
"""Quote system"""
from sqlalchemy.exc import SQLAlchemyError
import dave.module
import dave.config
import uuid
import random
import os
from dave.models import Quote
from twisted.words.protocols.irc import assembleFormattedText, attributes as A

random.seed(os.urandom(64))

@dave.module.help("Syntax: aq [quote] (-- attribute). Add a quote.")
@dave.module.command(["aq", "addquote"], "(.*?)(?: (?:--|—) ?(.+?))?$")
@dave.module.ratelimit(1, 2)
@@ -31,15 +34,11 @@
    if not query.count():
        bot.reply(source, sender, "No quotes found.")
        return

    row = query.offset(
        random.randrange(query.count())
    ).first()

    attr = " by " + row.attributed if row.attributed else ""
    row = query.offset(random.randrange(query.count())).first()

    bot.reply(source, sender, assembleFormattedText(A.normal[
        A.bold[row.quote], attr
        "<{}> ".format(row.attributed.strip()) if row.attributed else "", A.bold[row.quote]
    ]))

@dave.module.help("Syntax: fq [search]. Search for a quote.")
@@ -59,13 +58,13 @@
        bot.reply(source, sender, "No results for query.")

    if len(quotes) > 3:
        bot.reply(source, sender, "Your query yielded too many results ({}), here's a " \
        bot.reply(source, sender, "Your query returned too many results ({}), here's a " \
                                  "random sample:".format(len(quotes)))
        quotes = random.sample(quotes, 3)

    for quote in quotes:
        bot.reply(source, sender, assembleFormattedText(A.normal[
            A.bold[quote.quote], " by ", (quote.attributed or quote.added_by)
            "<{}> ".format(quote.attributed.strip()) if quote.attributed else "", A.bold[quote.quote], " (added by {})".format(quote.added_by)
        ]))

@dave.module.help("Syntax: dq [uuid]. Allow the quote owner to delete a quote.")