def addquote(pg_conn, cur, lrrbot, conn, event, respond_to, name, date, quote): """ Command: !addquote (NAME) [DATE] QUOTE Command: !addquote (NAME) QUOTE Command: !addquote [DATE] QUOTE Command: !addquote QUOTE Section: quotes Add a quotation with optional attribution to the quotation database. """ if date: try: date = utils.strtodate(date) except ValueError: return conn.privmsg(respond_to, "Could not add quote due to invalid date.") cur.execute( """ INSERT INTO quotes (quote, attrib_name, attrib_date) VALUES (%s, %s, %s) RETURNING qid """, (quote, name, date)) qid, = next(cur) quote_msg = "New quote #{qid}: \"{quote}\"".format(qid=qid, quote=quote) if name: quote_msg += " —{name}".format(name=name) if date: quote_msg += " [{date!s}]".format(date=date) conn.privmsg(respond_to, quote_msg)
def addquote(pg_conn, cur, lrrbot, conn, event, respond_to, name, date, quote): """ Command: !addquote (NAME) [DATE] QUOTE Command: !addquote (NAME) QUOTE Command: !addquote [DATE] QUOTE Command: !addquote QUOTE Section: quotes Add a quotation with optional attribution to the quotation database. """ if date: try: date = utils.strtodate(date) except ValueError: return conn.privmsg(respond_to, "Could not add quote due to invalid date.") cur.execute(""" INSERT INTO quotes (quote, attrib_name, attrib_date) VALUES (%s, %s, %s) RETURNING qid """, (quote, name, date)) qid, = next(cur) quote_msg = "New quote #{qid}: \"{quote}\"".format(qid=qid, quote=quote) if name: quote_msg += " —{name}".format(name=name) if date: quote_msg += " [{date!s}]".format(date=date) conn.privmsg(respond_to, quote_msg)
def modquote(pg_conn, cur, lrrbot, conn, event, respond_to, qid, name, date, quote): """ Command: !modquote QID (NAME) [DATE] QUOTE Command: !modquote QID (NAME) QUOTE Command: !modquote QID [DATE] QUOTE Command: !modquote QID QUOTE Section: quotes Modify an existing quotation with optional attribution. All fields are updated and/or deleted in case they're omitted. """ if date: try: date = utils.strtodate(date) except ValueError: return conn.privmsg(respond_to, "Could not modify quote due to invalid date.") cur.execute( """ UPDATE quotes SET quote = %s, attrib_name = %s, attrib_date = %s WHERE qid = %s AND NOT deleted """, (quote, name, date, qid)) if cur.rowcount == 1: quote_msg = "Modified quote #{qid}: \"{quote}\"".format(qid=qid, quote=quote) if name: quote_msg += " —{name}".format(name=name) if date: quote_msg += " [{date!s}]".format(date=date) conn.privmsg(respond_to, quote_msg) else: conn.privmsg(respond_to, "Could not modify quote.")
def modquote(pg_conn, cur, lrrbot, conn, event, respond_to, qid, name, date, quote): """ Command: !modquote QID (NAME) [DATE] QUOTE Command: !modquote QID (NAME) QUOTE Command: !modquote QID [DATE] QUOTE Command: !modquote QID QUOTE Section: quotes Modify an existing quotation with optional attribution. All fields are updated and/or deleted in case they're omitted. """ if date: try: date = utils.strtodate(date) except ValueError: return conn.privmsg(respond_to, "Could not modify quote due to invalid date.") cur.execute(""" UPDATE quotes SET quote = %s, attrib_name = %s, attrib_date = %s WHERE qid = %s AND NOT deleted """, (quote, name, date, qid)) if cur.rowcount == 1: quote_msg = "Modified quote #{qid}: \"{quote}\"".format(qid=qid, quote=quote) if name: quote_msg += " —{name}".format(name=name) if date: quote_msg += " [{date!s}]".format(date=date) conn.privmsg(respond_to, quote_msg) else: conn.privmsg(respond_to, "Could not modify quote.")