def listIgnores(channel, sender): """Lists all currently ignored nicks.""" if len(dbQuery('SELECT nick FROM ignores')) <= 0: sendMessage(channel, "I'm listening to everyone!") return ignores = [] for (nick, issuer, issuetime) in dbQuery("SELECT nick, issuer, issuetime FROM ignores"): ignores.append("%s: set by %s on %s" % (nick, issuer, time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(issuetime)))) try: url = paste('\n'.join(ignores)) sendMessage(channel, "The following people are currently ignored: %s" % url) except Exception as e: sendMessage(channel, "Uploading list of ignored people failed: %s" % (e,))
def process_results(channel, sender, results_data): """Process the resulting data of a search and present it""" max_num_urls_displayed = 1 search_parameters = results_data["search_parameters"] post_numbers = results_data["post_numbers"] total_time = results_data["total_time"] if len(post_numbers) <= 0: sendMessage(channel, "{0}: No results for {1} on {2}".format(sender, search_parameters["string"], search_parameters["user_board"])) else: post_template = "https://boards.4chan.org/{0}/thread/{1}" urls = [post_template.format(search_parameters["board"], post_num) for post_num in post_numbers] if len(urls) > max_num_urls_displayed: message = paste('\n'.join(urls)) else: message = " ".join(urls[:max_num_urls_displayed]) sendMessage(channel, "{0}: {1} | Search time {2:.2f}s | {3} matches".format(sender, message, total_time, len(urls)))
def help(channel, sender, command): """Provides help on the bot's commands.""" msg_lines = [] if command == None: msg_lines.append("The following commands are available:") for function in functionList(): syntax = function.syntax if function.description: description = "|| " + function.description else: description = "" if function.restricted: admin_command = "(admin command)" else: admin_command = "" # If there is no syntax for the command documented, then why use it? if syntax is not None: command_line = "{} {} {}".format(syntax, description, admin_command) msg_lines.append(command_line) msg_lines.append("You can use `help <command>` for specific help.") msg = "\n\n".join(msg_lines) url = pastebins.paste(msg) sendMessage(channel, "{}: {}".format(sender, url)) else: for function in functionList(): if matchFormat(command, function.format) != None: helpProvided = False if function.description != None: sendMessage(sender, "%s: %s" % (function.name, function.description)) helpProvided = True if function.syntax != None: sendMessage(sender, "syntax: %s" % function.syntax) helpProvided = True if helpProvided: return sendMessage(sender, "I have no help on that topic.")