commit 3370e78c508d538a5865da21b67b78ffb95f2552 Author: Alexander Munch-Hansen Date: Thu Dec 14 23:47:33 2017 +0100 initial commit diff --git a/cat_facts/bot.rb b/cat_facts/bot.rb new file mode 100644 index 0000000..48e3b5e --- /dev/null +++ b/cat_facts/bot.rb @@ -0,0 +1,33 @@ +require 'cinch' + + +file = File.open "cat_facts.html", "r" +a = file.read.split "") + end +end + +l.delete_at 0 +done = l.collect do |s| + if s.include? "id" + s.slice( s.index(">") + 1 .. s.index("<") - 1 ) + end +end + +bot = Cinch::Bot.new do + configure do |c| + c.nick = 'CatFacts^' + c.server = 'server' + c.port = port + c.channels = ['#bot-test'] + c.ssl.use = true + end + + on :message, /(?i)(.*).*cat.*/ do |m| + m.reply done.sample + end +end + +bot.start diff --git a/cat_facts/cat_facts.txt b/cat_facts/cat_facts.txt new file mode 100644 index 0000000..6186ea0 --- /dev/null +++ b/cat_facts/cat_facts.txt @@ -0,0 +1,2 @@ +Unlike dogs, cats do not have a sweet tooth. Scientists believe this is due to a mutation in a key taste receptor# +When a cat chases its prey, it keeps its head level. Dogs and humans bob their heads up and down# diff --git a/coin_flip_bot/flip-a-coin.rb b/coin_flip_bot/flip-a-coin.rb new file mode 100644 index 0000000..7b530be --- /dev/null +++ b/coin_flip_bot/flip-a-coin.rb @@ -0,0 +1,33 @@ +# coding: utf-8 +require 'cinch' + +bot = Cinch::Bot.new do + configure do |c| + c.nick = 'MrRollBot' + c.server = 'irc.guava.space' + c.port = 6697 + c.channels = ['#bot-test', '#chat'] + c.ssl.use = true + end + + on :message, /^!roll/ do |m| + random_int = rand(0..100).to_s + m.params[1].match /^!roll ([0-9]*)-([0-9]*)/ do |numbers| + if not numbers[1].nil? then + random_int = rand(numbers[1].to_i..numbers[2].to_i).to_s + end + end + m.reply random_int + end + + on :message, /!coin/ do |m| + probs = rand(1..10).to_i + if probs < 5 then + m.reply "Heads" + else + m.reply "Tails" + end + end +end + +bot.start diff --git a/table_bot/put_table_back.rb b/table_bot/put_table_back.rb new file mode 100644 index 0000000..94d147a --- /dev/null +++ b/table_bot/put_table_back.rb @@ -0,0 +1,22 @@ +# coding: utf-8 +require 'cinch' + +bot = Cinch::Bot.new do + configure do |c| + c.nick = 'GoodTable' + c.server = 'irc.guava.space' + c.port = 6697 + c.channels = ['#bot-test'] + c.ssl.use = true + end + + on :message, '(╯°□°)╯︵ ┻━┻' do |m| + m.reply '┯━┯ノ(º₋ºノ) plz be kind to table' + end + + on :message, 'ಠ_ಠ' do |m| + m.reply '( ͡° ͜ʖ ͡°)' + end +end + +bot.start diff --git a/taylor_bot/DictionaryGenerator.rb b/taylor_bot/DictionaryGenerator.rb new file mode 100644 index 0000000..57430aa --- /dev/null +++ b/taylor_bot/DictionaryGenerator.rb @@ -0,0 +1,36 @@ +class DictionaryGenerator + attr_reader :dictionary, :depth + + def initialize( depth ) + @dictionary = {} + @capitalized_words = [] + @depth = depth + @split_words = /(\.\s+)|(\.$)|([?!])|[\s]+/ + @split_sentence = /(?<=[.!?])\s+/ + end + + def add_word_to_dict( keyword, followedby ) + @dictionary[keyword] ||= [] + @dictionary[keyword] << followedby + end + + def insert_text( text ) + input_sentences = text.split @split_sentence + + if input_sentences.empty? then raise "insert_text called without input" end + + unless input_sentences[-1].strip[-1].match /[.!?]/ then + input_sentences[-1] = input_sentences[-1].strip + '.' + end + + input_sentences.each do |sentence| + + sentence.split(@split_words).each_cons(@depth + 1) do |words| + words = words.collect { |s| s.gsub(/["()]/, "") } + self.add_word_to_dict words[0..-2], words[-1] + end + end + end + +end + diff --git a/taylor_bot/SentenceGenerator.rb b/taylor_bot/SentenceGenerator.rb new file mode 100644 index 0000000..c9c9814 --- /dev/null +++ b/taylor_bot/SentenceGenerator.rb @@ -0,0 +1,50 @@ +class NullObject + def method_missing (*args, &block) + self + end + def nil?; true; end + def to_str; end + def to_ary; []; end +end + +NULL_OBJECT = NullObject.new + +class SentenceGenerator + + def initialize(dictionary) + @dictionary = dictionary + @depth = @dictionary.depth + end + + def random_word(last_word) + @dictionary.dictionary.fetch(last_word, NULL_OBJECT).sample + end + + def is_terminator?(symbol) + (symbol =~ /[!?]/ || symbol == '.') + end + + + # Ugly way of making sure the key starts with a capital letter + def random_capitalized_word + random_choice = ["temp"] + until random_choice[0] =~ /[A-Z]/ + words = @dictionary.dictionary.keys + random_choice = words[rand(words.length)] + end + random_choice + end + + def generate_sentence() + sentence = [] + maximum_length = 30 + wordcount = 0 + sentence.concat(random_capitalized_word) + until (is_terminator?(sentence.last[-1])) || wordcount > maximum_length + wordcount += 1 + word = random_word(sentence.last(@depth)) + sentence << word + end + sentence.join(' ') + end +end diff --git a/taylor_bot/taylor_bot.rb b/taylor_bot/taylor_bot.rb new file mode 100644 index 0000000..b517763 --- /dev/null +++ b/taylor_bot/taylor_bot.rb @@ -0,0 +1,39 @@ +require 'cinch' +require_relative 'DictionaryGenerator' +require_relative 'SentenceGenerator' +require_relative 'config' + + +love_file = File.open("love_story.txt","r").read +our_file = File.open("our_song.txt","r").read +shouldve_file = File.open('shouldve_said_no.txt','r').read + +text = love_file + our_file + shouldve_file + +@dictionary = DictionaryGenerator.new(2) +@dictionary.insert_text text + +sentenceGen = SentenceGenerator.new(@dictionary) +puts "-------------------------------------" +puts sentenceGen.generate_sentence +puts "-------------------------------------" + + + bot = Cinch::Bot.new do + configure do |c| + c.nick = 'TaylorSwift' + c.server = SERVER_ADDRESS + c.port = PORT + c.channels = CHANNELS + c.ssl.use = true + end + + on :message, /.*(?i)(.).*taylor.*/ do |m| + to_reply = sentenceGen.generate_sentence + sec_to_sleep = to_reply.size * 0.01+1 + sleep(sec_to_sleep) + m.reply to_reply + end + end + + bot.start