def cmd_del_quote(self, number, user, tags): num2 = number.lstrip('#') try: rownum = int(num2) db.run("DELETE FROM quotes WHERE id=?", rownum) self.send("Deleted!") except ValueError: self.send("Uh that's not a number")
def _quote_random(self): quotes = db.run(""" SELECT id, quote, user FROM quotes WHERE id IN (SELECT id FROM quotes ORDER BY random() LIMIT 1) """) if quotes: self._send_quote(quotes[0])
def try_custom_command(self, cmd): rows = db.run("SELECT name, response FROM commands WHERE name=?", cmd) if rows: name, response = rows[0] self.send(response) else: print(f"no command named {cmd}")
def _quote_by_search(self, query): search = f'%{query}%' quotes = db.run( "SELECT id, quote, user FROM quotes WHERE quote LIKE ? ORDER BY random()", search) if quotes: self._send_quote(quotes[0]) else: self.send("I don't know that quote.")
def cmd_add_message(self, message_def, user, tags): if tags['mod']: if ' ' not in message_def: self.send( "Tell me what the response to that command should be.") return name, response = message_def.split(' ', 1) name = name.lstrip('!') try: db.new_row( "INSERT INTO commands (name, response) VALUES (?, ?)", name, response) self.send(f"Added command !{name}.") except db.IntegrityError: db.run("DELETE FROM commands WHERE name=?", name) db.new_row( "INSERT INTO commands (name, response) VALUES (?, ?)", name, response) self.send(f"Redefined command !{name}.") else: self.complain_no_permission(user)
def _quote_by_rownum(self, rownum): quotes = db.run("SELECT id, quote, user FROM quotes WHERE id=?", rownum) if quotes: self._send_quote(quotes[0])