def run_command(self, data, args): db = mbdb.MBDatabase("*", "*", "127.0.0.1") c = db.new_connection() arg_name = args[0][:10] try: (word_id, word) = c.get_random_starting_word(arg_name) except: c.close() return name = c.get_proper_case(arg_name) for x in range(0, 16): try: (word_id, word2) = c.get_random_next_word(arg_name, word_id) if word_id == 206158430271: break word += " %s" % word2 except: break sentence = "" if name: sentence = "%s> %s" % (name, word) else: sentence = "%s> %s" % (arg_name, word) c.close() print sentence self.bot.get_conn().send_freq("1337", sentence)
def main(): FILENAME = "session.log" db = mbdb.MBDatabase('*', '*', '127.0.0.1') c = db.new_connection() f = open(FILENAME) lines = f.readlines() rgx = re.compile(r"^\s+([^<].+?)> ([^\?].*?)$") lengths = [] wordsToId = {} playersToId = {} for l in lines: if l[0] != " ": continue match = rgx.match(l) if not match: continue name = str(match.group(1).decode("ascii", "ignore")) blurb = str(match.group(2).decode("ascii", "ignore")) c.log_chat(name, blurb) c.close()
def run_command(self, data, args): db = mbdb.MBDatabase("*", "*", "127.0.0.1") c = db.new_connection() try: message = c.get_rand_message(args[0]) if message: self.bot.get_conn().send_freq("1337", message) except Exception, e: print e
import mbdb import sys db = mbdb.MBDatabase('*', '*', "127.0.0.1") c = db.new_connection() arg_name = sys.argv[1][:10] try: (word_id, word) = c.get_random_starting_word(arg_name) except: c.close() name = c.get_proper_case(arg_name) for x in range(0, 16): try: (word_id, word2) = c.get_random_next_word(arg_name, word_id) if word_id == 206158430271: break word += " %s" % word2 except: break sentence = "" if name: sentence = "%s> %s" % (name, word) else: sentence = "%s> %s" % (arg_name, word) c.close() print sentence
def main(): FILENAME = "session.log" db = mbdb.MBDatabase('*', '*', '127.0.0.1') c = db.new_connection() f = open(FILENAME) lines = f.readlines() rgx = re.compile(r"^\s+([^<].+?)> ([^\?].*?)$") lengths = [] wordsToId = {} playersToId = {} current_player_id = 1 current_word_id = 1 for l in lines: if l[0] != " ": continue match = rgx.match(l) if not match: continue name = str(match.group(1).decode("ascii", "ignore")) blurb = str(match.group(2).decode("ascii", "ignore")) arr_words = blurb.split(' ') player_id = current_player_id try: player_id = playersToId[name] except KeyError: current_player_id += 1 playersToId[name] = player_id c.insert_player_row(player_id, name) starting = 1 for i_w in range(len(arr_words) - 1): word_a = arr_words[i_w] word_b = "" if i_w < len(arr_words) - 1: word_b = arr_words[i_w + 1] if len(word_a) > 32 or len(word_b) > 32: continue word_a_id = current_word_id try: word_a_id = wordsToId[word_a] except KeyError: current_word_id += 1 wordsToId[word_a] = word_a_id c.insert_word_row(word_a_id, word_a) word_b_id = current_word_id try: word_b_id = wordsToId[word_b] except KeyError: current_word_id += 1 wordsToId[word_b] = word_b_id c.insert_word_row(word_b_id, word_b) c.insert_conv_row(player_id, word_a_id, word_b_id, starting) starting = 0 c.close()
def run_command(self, data, args): db = mbdb.MBDatabase("*", "*", "127.0.0.1") c = db.new_connection() player_data = {} player_confidence = {} current_total_bigram_count = 0 words = args[0].split(" ") first = True for i in range(0, len(words)): word_a = words[i] word_b = "" if i + 1 < len(words): word_b = words[i + 1] elif not first: break bigram_data = c.get_bigram_count(word_a, word_b) first = False tot_count = 0 tot_bigram_count = 0 for (k, v) in bigram_data: tot_count += c.get_player_line_count(k) tot_bigram_count += v current_total_bigram_count += tot_bigram_count for (player_id, n_lines) in bigram_data: line_count = c.get_player_line_count(player_id) try: player_data[player_id] *= (n_lines * 1000 / line_count) * ( n_lines * 1000 / tot_count) * (n_lines * 100 / tot_bigram_count) player_confidence[player_id] = ( player_confidence[player_id][0] + n_lines, player_confidence[player_id][1] + tot_bigram_count) except KeyError: player_data[player_id] = (n_lines * 1000 / line_count) * ( n_lines * 1000 / tot_count) * (n_lines * 100 / tot_bigram_count) player_confidence[player_id] = (n_lines, current_total_bigram_count) for player_id in player_data: player_data[player_id] *= c.get_player_line_count(player_id) try: max_player_id = max(player_data.iteritems(), key=operator.itemgetter(1))[0] max_name = c.get_player_name(max_player_id) max_player_confidence = player_confidence[max_player_id][ 0] / player_confidence[max_player_id][1] self.bot.get_conn().send_freq( "1337", "%s said %s (%s%% confidence)" % (max_name, args[0], 100 * round(max_player_confidence, 4))) print "%s said %s (%s%% confidence)" % ( max_name, args[0], 100 * round(max_player_confidence, 4)) except Exception, e: print e
import mbdb import sys db = mbdb.MBDatabase("*", "*", "127.0.0.1") c = db.new_connection() t = c.get_rand_message(" ".join(sys.argv[1:])) print t c.close()