def findquote(pg_conn, cur, lrrbot, conn, event, respond_to, query): """ Command: !findquote QUERY Section: quotes Search for a quote in the quote database. """ row = utils.pick_random_row( cur, """ SELECT qid, quote, attrib_name, attrib_date FROM quotes WHERE TO_TSVECTOR('english', quote) @@ PLAINTO_TSQUERY('english', %s) AND NOT deleted """, (query, )) if row is None: return conn.privmsg(respond_to, "Could not find any matching quotes.") qid, quote, name, date = row quote_msg = "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 get_tweet(conn, cur, lrrbot, user, data): if user is not None and lrrbot.is_mod_nick(user): mode = utils.weighted_choice([(0, 10), (1, 4), (2, 1)]) if mode == 0: # get random !advice return random.choice(storage.data['responses']['advice']['response']) elif mode == 1: # get a random !quote row = utils.pick_random_row(cur, """ SELECT qid, quote, attrib_name, attrib_date FROM quotes WHERE NOT deleted """) if row is None: return None qid, quote, name, date = row quote_msg = "\"{quote}\"".format(quote=quote) if name: quote_msg += " —{name}".format(name=name) return quote_msg else: # get a random statistic show, game_id, stat = utils.weighted_choice( ((show, game_id, stat), math.log(count)) for show in storage.data['shows'] for game_id in storage.data['shows'][show]['games'] for stat in storage.data['stats'] for count in [storage.data['shows'][show]['games'][game_id]['stats'].get(stat)] if count ) game = storage.data['shows'][show]['games'][game_id] count = game['stats'][stat] display = storage.data['stats'][stat].get("singular", stat) if count == 1 else storage.data['stats'][stat].get("plural", stat + "s") return "%d %s for %s on %s" % (count, display, commands.game.game_name(game), commands.show.show_name(show)) return None
def quote(pg_conn, cur, lrrbot, conn, event, respond_to, qid, attrib): """ Command: !quote Command: !quote ATTRIB Section: quotes Post a randomly selected quotation, optionally filtered by attribution. --command Command: !quote ID Section: quotes Post the quotation with the specified ID. """ if qid: where, params = """ WHERE qid = %s AND NOT deleted """, (int(qid), ) elif attrib: where, params = """ WHERE LOWER(attrib_name) LIKE %s AND NOT deleted """, ("%" + attrib.lower().replace('\\', '\\\\').replace('%', '\\%').replace( '_', '\\_') + "%", ) else: where, params = """ WHERE NOT deleted """, () row = utils.pick_random_row( cur, """ SELECT qid, quote, attrib_name, attrib_date FROM quotes %s """ % where, params) if row is None: conn.privmsg(respond_to, "Could not find any matching quotes.") return qid, quote, name, date = row quote_msg = "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 quote(pg_conn, cur, lrrbot, conn, event, respond_to, qid, attrib): """ Command: !quote Command: !quote ATTRIB Section: quotes Post a randomly selected quotation, optionally filtered by attribution. --command Command: !quote ID Section: quotes Post the quotation with the specified ID. """ if qid: where, params = """ WHERE qid = %s AND NOT deleted """, (int(qid),) elif attrib: where, params = """ WHERE LOWER(attrib_name) LIKE %s AND NOT deleted """, ("%" + attrib.lower().replace('\\','\\\\').replace('%','\\%').replace('_','\\_') + "%",) else: where, params = """ WHERE NOT deleted """, () row = utils.pick_random_row(cur, """ SELECT qid, quote, attrib_name, attrib_date FROM quotes %s """ % where, params) if row is None: conn.privmsg(respond_to, "Could not find any matching quotes.") return qid, quote, name, date = row quote_msg = "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 get_tweet(conn, cur, lrrbot, user, data): if user is not None and lrrbot.is_mod_nick(user): mode = utils.weighted_choice([(0, 10), (1, 4), (2, 1)]) if mode == 0: # get random !advice return random.choice( storage.data['responses']['advice']['response']) elif mode == 1: # get a random !quote row = utils.pick_random_row( cur, """ SELECT qid, quote, attrib_name, attrib_date FROM quotes WHERE NOT deleted """) if row is None: return None qid, quote, name, date = row quote_msg = "\"{quote}\"".format(quote=quote) if name: quote_msg += " —{name}".format(name=name) return quote_msg else: # get a random statistic show, game_id, stat = utils.weighted_choice( ((show, game_id, stat), math.log(count)) for show in storage.data['shows'] for game_id in storage.data['shows'][show]['games'] for stat in storage.data['stats'] for count in [ storage.data['shows'][show]['games'][game_id]['stats'].get( stat) ] if count) game = storage.data['shows'][show]['games'][game_id] count = game['stats'][stat] display = storage.data['stats'][stat].get( "singular", stat) if count == 1 else storage.data['stats'][stat].get( "plural", stat + "s") return "%d %s for %s on %s" % (count, display, commands.game.game_name(game), commands.show.show_name(show)) return None
def findquote(pg_conn, cur, lrrbot, conn, event, respond_to, query): """ Command: !findquote QUERY Section: quotes Search for a quote in the quote database. """ row = utils.pick_random_row(cur, """ SELECT qid, quote, attrib_name, attrib_date FROM quotes WHERE TO_TSVECTOR('english', quote) @@ PLAINTO_TSQUERY('english', %s) AND NOT deleted """, (query, )) if row is None: return conn.privmsg(respond_to, "Could not find any matching quotes.") qid, quote, name, date = row quote_msg = "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)