irc-qik-bot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ .bundle
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ indev
20
+ tests
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'xml-motor'
data/README ADDED
@@ -0,0 +1,60 @@
1
+ ======================================================================
2
+ ____ _ __ ___ ,, ,, ,, ,, ,,
3
+ || ||)) // ' __ // \\_ || ||// _ || ====
4
+ _||_ ||\\ \\_, \\_//\\ || ||\\ ||)) (()) ||_
5
+
6
+ ======================================================================
7
+ IRC-Qik-Bot version 0.0.1 beta
8
+ ======================================================================
9
+
10
+ IRC ~ Automated Babbling Bot
11
+
12
+ How To Install:
13
+ $ gem install irc-qik-bot --no-ri --no-rdoc
14
+
15
+ How To Use:
16
+
17
+ ## configure defaults for irc-qik-bot
18
+ WIP $ irc-qik-bot config
19
+ ## directly starts at default channel
20
+ $ irc-qik-bot chat
21
+ ## would join the provided server at default provided channel in config
22
+ $ irc-qik-bot irc.freenode.net
23
+ ## would join provided server, channel with default nick
24
+ $ irc-qik-bot irc.freenode.net, ruby
25
+ ## would join with all provided config
26
+ $ irc-qik-bot irc.freenode.net, ruby, qbot
27
+
28
+ ## configs can also be provided as ENV variables
29
+ $ IRC="irc.freenode.com" CHANNEL="#ruby" NICK="qbot" irc-qik-bot
30
+
31
+ ======================================================================
32
+
33
+ usage currently require the 'bot nick' to be used;
34
+ will also pin it to conventional !command
35
+
36
+ Current Features:
37
+ [+] basic IRC Network, Channel Connector
38
+ [+] Help ~ 'qbot: help'
39
+ [+] Babbler ~ 'qbot: babble'
40
+ [+] Quote ~ 'qbot: quote'
41
+ [+] URL Un-Shortener ~ 'qbot: unshort http://SHORT_URL'
42
+ [+] google ~ 'qbot: google search term'
43
+ [+] YAML Config Support
44
+
45
+ ======================================================================
46
+
47
+ Future Roadmap:
48
+ [+] whois
49
+ [+] nslookup
50
+ [+] ycombinator
51
+ [+] twitter
52
+ [+] reddit
53
+ [+] slashdot
54
+ [+] stackoverflow
55
+ [+] github
56
+
57
+ ======================================================================
58
+ http://github.com/abhishekkr
59
+ http://www.twitter.com/abionic
60
+ ======================================================================
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require 'rake'
6
+
7
+ namespace :lint do
8
+
9
+ desc 'remove tailing whitespace'
10
+ task :notail do
11
+ Dir.glob(File.join Dir.pwd, '*.rb').each do |fyl|
12
+ %x{sed -i 's/\ *$//g' #{fyl}}
13
+ end
14
+ Dir.glob(File.join Dir.pwd, '*', '*.rb').each do |fyl|
15
+ %x{sed -i 's/\ *$//g' #{fyl}}
16
+ end
17
+ Dir.glob(File.join Dir.pwd, '*', '*', '*.rb').each do |fyl|
18
+ %x{sed -i 's/\ *$//g' #{fyl}}
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join File.dirname(File.expand_path __FILE__), '..', 'lib', 'irc-qik-bot.rb'
3
+
4
+ # Start the IRC QikBot at given IRC="irc.network" CHANNEL="#channel" NICK="mynick"
5
+
6
+ if ARGV.size > 0
7
+ if ARGV[0].match(/chat/)
8
+ IRC::Qikbot.chat
9
+ else
10
+ server = ARGV[0]
11
+ channel = ARGV[1]
12
+ nick = ARGV[2]
13
+ IRC::Qikbot.chat server, channel, nick
14
+ end
15
+ else
16
+ print "IRC Server : #{ENV['IRC']} "
17
+ irc = ENV['IRC'] || STDIN.gets
18
+ print "Join #Channel: #{ENV['CHANNEL']} "
19
+ channel = ENV['CHANNEL'] || STDIN.gets
20
+ print "IRC NickName : #{ENV['NICK']} "
21
+ nick = ENV['NICK'] || STDIN.gets
22
+ IRC::Qikbot.chat irc.chomp, channel.chomp, nick.chomp
23
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'irc-qik-bot/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'irc-qik-bot'
7
+ s.version = IRC::Qikbot::VERSION
8
+ s.authors = ['abhishekkr']
9
+ s.email = ['abhikumar163@gmail.com']
10
+ s.homepage = 'http://abhishekkr.github.com/irc-qik-bot'
11
+ s.summary = %q{a babbling IRC Bot very quick to setup and act ;) aiming to be intelligent}
12
+ s.description = %q{pure socket no framework :: IRC Qik Bot ~ its a babbling IRC Bot very quick to setup and act ;) aiming to be intelligent...
13
+ Current Features: https://github.com/abhishekkr/irc-qik-bot/blob/master/README
14
+ }
15
+
16
+ s.rubyforge_project = 'irc-qik-bot'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.require_paths = ["lib"]
21
+
22
+ s.executables = %w( irc-qik-bot )
23
+
24
+ s.add_runtime_dependency 'xml-motor', '>= 0.1.6'
25
+ s.add_development_dependency 'xml-motor', '>= 0.1.6'
26
+ end
@@ -0,0 +1,33 @@
1
+ # irc-qik-bot
2
+
3
+ irc_libs = File.join(File.dirname(File.expand_path __FILE__), 'irc-qik-bot', 'irc-motor.rb')
4
+ Dir.glob(irc_libs).each do |lib|
5
+ require lib
6
+ end
7
+
8
+ module IRC
9
+ module Qikbot
10
+
11
+ def self.chat(irc_svr = nil, irc_chanl = nil, irc_nick = nil)
12
+ begin
13
+ if irc_svr.nil?
14
+ cnf = IRC::Motor.ymlconf["network"]["default"]
15
+ irc_svr = cnf["server"]
16
+ irc_chanl = cnf["channel"]
17
+ irc_nick = cnf["nick"]
18
+ elsif irc_chanl.nil?
19
+ cnf = IRC::Motor.ymlconf["network"][irc_svr]["default"]
20
+ irc_chanl = cnf["channel"]
21
+ irc_nick = cnf["nick"]
22
+ elsif irc_nick.nil?
23
+ irc_nick = IRC::Motor.ymlconf["network"][irc_svr][irc_chanl]["nick"]
24
+ end
25
+ IRC::Motor.connect irc_svr
26
+ IRC::Motor.join_channel irc_chanl, irc_nick
27
+ IRC::Motor.in_channel
28
+ rescue
29
+ puts "\n\n\n\nOUCH!!!\n\n\n"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,61 @@
1
+ # irc-handler-channel
2
+
3
+ module IRC
4
+ module Handlers
5
+ module Channel
6
+
7
+ def self.response(irc_motor, irc_stream)
8
+ p irc_stream
9
+ msg = irc_stream.split(":#{irc_motor.nick}:")[1]
10
+ if irc_stream.match(/^PING :(.+)$/i)
11
+ puts "[ Server ping ]"
12
+ irc_motor.ircsend "PONG :#{$1}"
13
+ elsif !msg.nil?
14
+ puts "","*"*10,msg,"*"*10,""
15
+ cmd = msg.chomp.split.first
16
+ if cmd.match(/(hi|hello|hey).*/i)
17
+ privmsg irc_motor, "Hello to you too"
18
+ elsif cmd.match(/(unshort|google|whois).*/i)
19
+ privmsg irc_motor, "just a moment, I'm looking it up"
20
+ privmsg irc_motor, w3c_lookup(msg.strip)
21
+ elsif cmd.match(/(babble|help|quote).*/i)
22
+ privmsg irc_motor, babble(msg.strip)
23
+ else
24
+ privmsg irc_motor, "Waddya want x("
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.babble(ircmd)
30
+ if ircmd.match(/^babble(.*)$/i)
31
+ return IRC::AutoBabble.babble("#{$1}")
32
+ elsif ircmd.match(/^quote(.*)$/i)
33
+ return IRC::AutoBabble.quote("#{$1}")
34
+ elsif ircmd.match(/^help(.*)$/i)
35
+ return IRC::AutoBabble.helper("#{$1}")
36
+ end
37
+ "BaaBaaBooBoo, try help."
38
+ end
39
+
40
+ def self.w3c_lookup(ircmd)
41
+ if ircmd.match(/^google (.+)$/i)
42
+ return IRC::WWW.google("#{$1}") || "Google seems busy for the while :("
43
+ elsif ircmd.match(/^unshort (.+)$/i)
44
+ return IRC::WWW.unshort("#{$1}") || "Un-shortener Service Un-available for the moment"
45
+ elsif ircmd.match(/^whois (.+)$/i)
46
+ return IRC::WWW.whois("#{$1}") || "WHOIS Service Un-available for the moment"
47
+ end
48
+ "Can't understand your Web lookup, try help."
49
+ end
50
+
51
+ def self.privmsg(irc_motor, msglines)
52
+ msglines = msglines.split("\n")
53
+ for_time = (msglines.size/5).to_i + 0.5
54
+ msglines.each do |msg|
55
+ sleep 0.5
56
+ irc_motor.ircsend "PRIVMSG #{irc_motor.channel} :#{msg}"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "socket"
4
+
5
+ module IRC
6
+ module Handlers
7
+ module Socket
8
+
9
+ def self.tcp_connect(server, port)
10
+ begin
11
+ return TCPSocket.open server, port
12
+ rescue
13
+ return nil
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # irc-handlers
2
+
3
+ irc_libs = File.join(File.dirname(File.expand_path __FILE__), '*', '*.rb')
4
+ Dir.glob(irc_libs).each do |lib|
5
+ require lib
6
+ end
7
+
8
+ module IRC
9
+ module Handlers
10
+
11
+ def self.socket(server, port)
12
+ IRC::Handlers::Socket.tcp_connect server, port
13
+ end
14
+
15
+ def self.channel(irc_motor, irc_stream)
16
+ IRC::Handlers::Channel.response irc_motor, irc_stream
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,78 @@
1
+ # irc-motor
2
+
3
+
4
+ irc_libs = File.join(File.dirname(File.expand_path __FILE__), '*.rb')
5
+ Dir.glob(irc_libs).each do |lib|
6
+ require lib
7
+ end
8
+
9
+ module IRC
10
+ module Motor
11
+
12
+ def self.nick(nick=nil)
13
+ @nick = nick unless nick.nil?
14
+ @nick
15
+ end
16
+
17
+ def self.channel(channel=nil)
18
+ @channel = channel unless channel.nil?
19
+ @channel
20
+ end
21
+
22
+ def self.connect(server, port="6667")
23
+ @irc = IRC::Handlers.socket server, port
24
+ end
25
+
26
+ def self.ircsend(msg)
27
+ return err("No IRC Connection Found") unless @irc
28
+ @irc.send "#{msg}\n", 0
29
+ end
30
+
31
+ def self.join_channel(irc_chanl, irc_nick="qbot")
32
+ channel irc_chanl
33
+ nick irc_nick
34
+ ircsend "USER irc qik bot :#{ENV['USERNAME']} qbot"
35
+ ircsend "NICK #{nick}"
36
+ ircsend "JOIN #{channel}"
37
+ end
38
+
39
+ def self.in_channel
40
+ while true
41
+ ready = select([@irc, $stdin], nil)
42
+ next if !ready
43
+ for status in ready[0]
44
+ if status == $stdin then
45
+ admin_input
46
+ elsif status == @irc then
47
+ channel_input
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def self.admin_input
54
+ return if $stdin.eof
55
+ irc_command = $stdin.gets
56
+ ircsend irc_command
57
+ end
58
+
59
+ def self.channel_input
60
+ return if @irc.eof
61
+ irc_stream = @irc.gets
62
+ IRC::Handlers.channel self, irc_stream
63
+ end
64
+
65
+ def self.ymlconf
66
+ require 'yaml'
67
+ resource_dir = File.expand_path File.join(File.dirname(__FILE__), '..', '..', 'resource')
68
+ irc_yaml = File.join resource_dir, 'irc.yaml'
69
+ YAML.load_file irc_yaml
70
+ end
71
+
72
+ if ENV["VERBOSE"]=="1"
73
+ def self.err(msg)
74
+ STDERR.puts "ERROR: #{msg}"
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module IRC
4
+ module AutoBabble
5
+
6
+ def self.babble(args)
7
+ dat = from_file "resource/babble_data"
8
+ return dat unless dat.nil?
9
+ "Babbler is drunk enough to babble more."
10
+ end
11
+
12
+ def self.quote(args)
13
+ dat = from_file "resource/babble_quotes"
14
+ return dat unless dat.nil?
15
+ "Philosopher is still thinking."
16
+ end
17
+
18
+ def self.helper(args)
19
+ return <<-IRC_QIKBOT_HELP
20
+ *******************************
21
+ | IRC-Qikbot |
22
+ | its Qik, Easy, Extensible |
23
+ | \\ Command-Set: |
24
+ | |> hi/hey/hello |
25
+ | |> babble BABBLE_ABOUT |
26
+ | |> quote |
27
+ | |> unshort http://SHORTURL |
28
+ | |> google SEARCH_TERMS |
29
+ | talk to me, with my name |
30
+ | like |
31
+ | > qbot: google irc-bot |
32
+ *******************************
33
+ IRC_QIKBOT_HELP
34
+ end
35
+
36
+ private
37
+ def self.from_file(fylname)
38
+ begin
39
+ fylname = File.join(File.dirname(File.expand_path __FILE__), '..', '..', '..', fylname)
40
+ babble = File.open(fylname, "r") do |fyl|
41
+ fyl.readlines[rand0m]
42
+ end
43
+ return babble
44
+ rescue
45
+ return "Babbler cannot read its babble-o-paedia."
46
+ end
47
+ end
48
+
49
+ def self.rand0m
50
+ (rand * 10).to_i
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "net/http"
5
+ require "net/https"
6
+ require "uri"
7
+ require "xml-motor"
8
+
9
+ module IRC
10
+ module WWW
11
+
12
+ def self.google(search_terms, item_count = 1)
13
+ http_requester("http://www.google.com/search?q=#{search_terms.split.join("+")}", "div.div.cite").first.split("<").collect{|y| y.split(">")}.collect{|z| z[1]}.join
14
+ end
15
+
16
+ def self.unshort(short_url)
17
+ http_requester("http://webhoudini.appspot.com/unshort_url?url=#{short_url}", "h3.a").join
18
+ end
19
+
20
+ def self.whois(short_url)
21
+ http_requester("http://whois.domaintools.com/#{short_url}", "div", "class='whois_record'").join
22
+ end
23
+
24
+ def self.http_requester(httpurl, node, attribs=nil)
25
+ begin
26
+ uri = URI.parse(httpurl)
27
+ http = Net::HTTP.new(uri.host, uri.port)
28
+ case httpurl[5] #checking if https is there
29
+ when ?s then http.use_ssl = true
30
+ else http.use_ssl = false
31
+ end
32
+ #http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
33
+ request = Net::HTTP::Get.new(uri.request_uri)
34
+ response = http.request(request)
35
+ rescue
36
+ response = nil
37
+ end
38
+ XMLMotor.get_node_from_content response.body, node, attribs
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ # irc-qik-bot::version
2
+
3
+ module IRC
4
+ module Qikbot
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ I never forget, neither do I forgive.
2
+ A good word is more powerful than entire world, it's the one driving them.
3
+ Do not lie, you are increasing the overhead for the facts you keep.
4
+ Truth is the most lean knowledge management technique.
5
+ When knowledge is the engine, curosity is your power.
6
+ Hacking your way out is a good thing, just don't forget the documenting it.
7
+ A Hack is a new way to solve an old problem.
8
+ Ear is the root cause of fEar.
9
+ Do not keep babbling, it is injurious to health.
@@ -0,0 +1,9 @@
1
+ I never forget, neither do I forgive.
2
+ A good word is more powerful than entire world, it's the one driving them.
3
+ Do not lie, you are increasing the overhead for the facts you keep.
4
+ Truth is the most lean knowledge management technique.
5
+ When knowledge is the engine, curosity is your power.
6
+ Hacking your way out is a good thing, just don't forget the documenting it.
7
+ A Hack is a new way to solve an old problem.
8
+ Ear is the root cause of fEar.
9
+ Do not keep babbling, it is injurious to health.
@@ -0,0 +1,17 @@
1
+ network:
2
+ default:
3
+ server : "irc.freenode.com"
4
+ channel: "#qikbot"
5
+ nick : "qbot"
6
+ "irc.freenode.com":
7
+ default:
8
+ channel: "#qikbot"
9
+ nick: "qbot"
10
+ "#ruby":
11
+ nick: "quby"
12
+ "#puppet":
13
+ nick: "master-o-p"
14
+ "#regex":
15
+ nick: "reg-x"
16
+ "#qikbot":
17
+ nick: "qbot"
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irc-qik-bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - abhishekkr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xml-motor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: xml-motor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.6
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.6
46
+ description: ! 'pure socket no framework :: IRC Qik Bot ~ its a babbling IRC Bot very
47
+ quick to setup and act ;) aiming to be intelligent...
48
+
49
+ Current Features: https://github.com/abhishekkr/irc-qik-bot/blob/master/README
50
+
51
+ '
52
+ email:
53
+ - abhikumar163@gmail.com
54
+ executables:
55
+ - irc-qik-bot
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - README
63
+ - Rakefile
64
+ - bin/irc-qik-bot
65
+ - irc-qik-bot.gemspec
66
+ - lib/irc-qik-bot.rb
67
+ - lib/irc-qik-bot/handlers/irc-handlers-channel.rb
68
+ - lib/irc-qik-bot/handlers/irc-handlers-socket.rb
69
+ - lib/irc-qik-bot/irc-handlers.rb
70
+ - lib/irc-qik-bot/irc-motor.rb
71
+ - lib/irc-qik-bot/utils/irc-auto-babble.rb
72
+ - lib/irc-qik-bot/utils/irc-www.rb
73
+ - lib/irc-qik-bot/version.rb
74
+ - resource/babble_data
75
+ - resource/babble_quotes
76
+ - resource/irc.yaml
77
+ homepage: http://abhishekkr.github.com/irc-qik-bot
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
90
+ - 0
91
+ hash: -4275890795173266833
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ segments:
99
+ - 0
100
+ hash: -4275890795173266833
101
+ requirements: []
102
+ rubyforge_project: irc-qik-bot
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: a babbling IRC Bot very quick to setup and act ;) aiming to be intelligent
107
+ test_files: []