├── nickData.template.yaml ├── .gitignore ├── README.md ├── seen.template.yaml ├── ping.rb ├── slap.rb ├── rfc.rb ├── tinyurl.rb ├── bot.rb ├── seen.rb ├── nick.rb └── order.rb /nickData.template.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | somenick: Some Name 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #YAML Files 2 | nickData.yaml 3 | seen.yaml 4 | order.html 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a simple bot built using the Ruby Cinch IRC framework 2 | -------------------------------------------------------------------------------- /seen.template.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | somenick: 3 | - '2014-03-20 09:31:25' 4 | - "said some thing" 5 | -------------------------------------------------------------------------------- /ping.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | 3 | require 'cinch' 4 | 5 | class Ping 6 | include Cinch::Plugin 7 | @help="." 8 | match(/^\.$/,{:use_prefix => false}) 9 | def execute(m) 10 | m.reply ".." 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /slap.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | 3 | require 'cinch' 4 | 5 | class Slap 6 | include Cinch::Plugin 7 | @help="!slap" 8 | match(/slap (.+)/)#,{:use_prefix => false}) 9 | def execute(m,user) 10 | m.reply "*#{m.bot.nick} slaps #{user}" 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /rfc.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | 3 | require 'cinch' 4 | 5 | class Rfc 6 | include Cinch::Plugin 7 | @help="!rfcXXXX" 8 | match(/(rfc[0-9]+)/)#,{:use_prefix => false}) 9 | def execute(m,rfc) 10 | rfc.downcase! 11 | m.reply " https://tools.ietf.org/html/#{rfc}" 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /tinyurl.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | 3 | require 'cinch' 4 | require 'net/http' 5 | require 'uri' 6 | 7 | 8 | class Tinyurl 9 | include Cinch::Plugin 10 | @help="!tiny" 11 | match(/tiny (http.+)/) 12 | def execute(m,url) 13 | if(!url.include?("tinyurl")) 14 | tinyurl=Net::HTTP.get(URI.parse("http://tinyurl.com/api-create.php?url=#{url}")) 15 | m.reply tinyurl 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /bot.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'cinch' 3 | require './nick.rb' 4 | require './ping.rb' 5 | require './slap.rb' 6 | require './tinyurl.rb' 7 | require './seen.rb' 8 | require './order.rb' 9 | 10 | bot = Cinch::Bot.new do 11 | configure do |c| 12 | c.server = "irc.freenode.org" 13 | c.channels = ["#somechan"] 14 | c.nick = "botname" 15 | c.plugins.plugins = [Ping,Slap,Tinyurl,Nick,Seen,Order] 16 | end 17 | 18 | on :message, "!help" do |m| 19 | @help=[] 20 | @bot.plugins.each do |plugin| 21 | help = plugin.class.instance_variable_get(:@help) 22 | if help!=' ' 23 | @help.push(help) 24 | end 25 | end 26 | m.reply @help.join(', ') 27 | end 28 | 29 | end 30 | 31 | bot.start 32 | 33 | -------------------------------------------------------------------------------- /seen.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | require 'cinch' 3 | require 'date' 4 | require 'time' 5 | require 'yaml' 6 | 7 | class Seen 8 | include Cinch::Plugin 9 | @help="!seen" 10 | match(/(.+)/,{:use_prefix => false}) 11 | 12 | def initialize(*args) 13 | super 14 | @last=YAML.load_file( 'seen.yaml') 15 | puts "@last is #{@last}" 16 | if(@last==nil) 17 | @last={} 18 | end 19 | end 20 | 21 | 22 | def time_in_words(minutes) 23 | case 24 | when minutes < 1 25 | "less than a minute" 26 | when minutes < 50 27 | if minutes > 1 28 | "#{minutes} minutes" 29 | else 30 | "#{minutes} minute" 31 | end 32 | when minutes < 90 33 | "about one hour" 34 | when minutes < 1080 35 | "#{(minutes / 60).round} hours" 36 | when minutes < 1440 37 | "one day" 38 | when minutes < 2880 39 | "about one day" 40 | else 41 | "#{(minutes / 1440).round} days" 42 | end 43 | end 44 | 45 | 46 | def execute(m,arg) 47 | if( arg =~ /^!seen (.+)$/ ) 48 | curtime=Time.now() 49 | if @last[$1.downcase] != nil 50 | oldtime=Time.parse(@last[$1.downcase][0]) 51 | timediff=curtime-oldtime 52 | # puts timediff 53 | if timediff<60 54 | timediff=0 55 | else 56 | timediff=(timediff/60).to_i 57 | end 58 | m.reply "#{$1} was last seen #{time_in_words(timediff)} ago saying: #{@last[$1.downcase][1]}" 59 | else 60 | m.reply "I haven't seen #{$1} since I last joined the channel" 61 | end 62 | else 63 | @last[m.user.nick.downcase]=[Time.now.strftime("%Y-%m-%d %H:%M:%S"),arg] 64 | File.open( 'seen.yaml', 'w' ) do |out| 65 | YAML.dump( @last, out ) 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /nick.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | require 'yaml' 3 | require 'cinch' 4 | 5 | class Nick 6 | 7 | include Cinch::Plugin 8 | @help="!nick" 9 | match /nick (.+)/ 10 | @nickData={} 11 | @nameIndex={} 12 | 13 | def storeData() 14 | File.open("./nickData.yaml", "w") do |file| 15 | file.puts YAML::dump(@nickData) 16 | file.puts "" 17 | end 18 | end 19 | 20 | def loadData() 21 | $/="\n\n" 22 | dataArray=[] 23 | @nickData={} 24 | @nameIndex={} 25 | File.open("./nickData.yaml", "r").each do |object| 26 | dataArray << YAML::load(object) 27 | end 28 | dataArray.each do |hash| 29 | hash.each do |k,v| 30 | @nickData[k]=v 31 | @nameIndex[v]=k 32 | end 33 | end 34 | end 35 | 36 | def initialize(*args) 37 | super 38 | loadData() 39 | end 40 | 41 | def execute(m,cmdstr) 42 | output="" 43 | cmd,val = cmdstr.split(' ',2) 44 | if(val==nil && cmd!='reload') 45 | val=cmd 46 | cmd='get' 47 | end 48 | 49 | if(cmd=='reload') 50 | @nickData={} 51 | @nameIndex={} 52 | loadData() 53 | output="nick data reloaded" 54 | elsif(cmd=='get') 55 | if(@nickData[m.user.nick]!=nil) 56 | if(@nickData[val]!=nil || @nameIndex[val]!=nil) 57 | if(@nickData[val]!=nil) 58 | output=val+" is "+@nickData[val] 59 | else 60 | output=val+" is "+@nameIndex[val] 61 | end 62 | else 63 | output="Sorry. I don't know who that is." 64 | end 65 | else 66 | output="Show me yours first. !nick set your name" 67 | end 68 | elsif(cmd=='set') 69 | if val==m.user.nick 70 | output="#{m.user.nick}, I dont think so. Try again" 71 | else 72 | @nickData[m.user.nick]=val 73 | @nameIndex[val]=m.user.nick 74 | storeData() 75 | output="Thanks "+m.user.nick+". Now I know who you are." 76 | end 77 | else 78 | output="What's that now? I don't understand." 79 | end 80 | m.reply "#{m.user.nick}, #{output}" 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /order.rb: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/ruby 2 | require 'cinch' 3 | require 'date' 4 | require 'time' 5 | require 'yaml' 6 | 7 | class Order 8 | include Cinch::Plugin 9 | @help="!order" 10 | match(/(.+)/,{:use_prefix => false}) 11 | 12 | def initialize(*args) 13 | super 14 | @slack=false 15 | @open=false 16 | @orders={} 17 | end 18 | 19 | 20 | def time_in_words(minutes) 21 | case 22 | when minutes < 1 23 | "less than a minute" 24 | when minutes < 50 25 | if minutes > 1 26 | "#{minutes} minutes" 27 | else 28 | "#{minutes} minute" 29 | end 30 | when minutes < 90 31 | "about one hour" 32 | when minutes < 1080 33 | "#{(minutes / 60).round} hours" 34 | when minutes < 1440 35 | "one day" 36 | when minutes < 2880 37 | "about one day" 38 | else 39 | "#{(minutes / 1440).round} days" 40 | end 41 | end 42 | 43 | 44 | def execute(m,arg) 45 | if( arg =~ /^!order (.+)$/ ) 46 | original_order = $1 47 | if($1=="help") 48 | m.reply("!order [open|close|check|what you want to order]") 49 | return 50 | elsif($1=="open") 51 | if(@open==true) 52 | m.reply("there is already an order open") 53 | else 54 | @open=true 55 | @orders={} 56 | File.open('index.html','w') {|f| f.write("") } 57 | if(@slack) 58 | m.reply("ordering is now open , order with: !order foo with a shot of bar please") 59 | else 60 | m.reply("ordering is now open, order with: !order foo with a shot of bar please") 61 | end 62 | end 63 | return 64 | elsif($1=="close") 65 | @open=false 66 | m.reply("this order has been closed") 67 | File.open('index.html', 'w' ) do |f| 68 | f.puts "coffeebot order" 69 | @orders.each do |nick,order| 70 | f.puts "#{nick}: #{order}
" 71 | end 72 | f.puts "" 73 | end 74 | m.reply("view at http://coffeebot.uphreak.com/") 75 | return 76 | elsif(@open!=true) 77 | m.reply("sorry, there is no open order") 78 | return 79 | elsif($1=="check") 80 | nick=m.user.nick.downcase 81 | if (@orders[nick]!=nil) 82 | order=@orders[nick][0..-5] #trim
83 | m.reply("#{nick}, I have you down for '#{order}'.") 84 | else 85 | m.reply("#{nick}, you have not ordered anything yet.") 86 | end 87 | elsif($1=="") 88 | m.reply("you can't ask to order nothing") 89 | return 90 | elsif($1 =~ /^for=([^ ]+) (.+)$/) 91 | @orders[$1.downcase]="#{$2}
" 92 | else 93 | @orders[m.user.nick.downcase]="#{original_order}
" 94 | end 95 | elsif( arg =~/^!order$/) 96 | if(@open==true) 97 | m.reply("there is an open order, use !order something, to place yours") 98 | else 99 | m.reply("there is no order, open one with !order open") 100 | end 101 | end 102 | 103 | end 104 | end 105 | --------------------------------------------------------------------------------