beerbot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ # The files in this directory are part of BeerBot, a a ruby irc bot library.
2
+ # Copyright (C) 2014 Daniel Bush
3
+ # This program is distributed under the terms of the GNU
4
+ # General Public License. A copy of the license should be
5
+ # enclosed with this project in the file LICENSE. If not
6
+ # see <http://www.gnu.org/licenses/>.
7
+
8
+ module BeerBot
9
+
10
+ # Config should be loaded with the json from a config file before
11
+ # initialisation of the system.
12
+ #
13
+ # It should be available to things like bot modules eg
14
+ # BeerBot::Config['datadir']
15
+ #
16
+
17
+ Config = {}
18
+
19
+ class << Config
20
+
21
+ def load config
22
+ self.reject!{true}
23
+ self.merge!(config)
24
+ end
25
+
26
+ def validate!
27
+ if not self['datadir'] then
28
+ raise "'datadir' not set in config."
29
+ end
30
+ if not self['moduledir'] then
31
+ raise "'moduledir' not set in config."
32
+ end
33
+ unless File.exists?(self['datadir']) then
34
+ raise "datadir:'#{self['datadir']}' doesn't exist."
35
+ end
36
+ unless File.exists?(self['moduledir']) then
37
+ raise "config['moduledir']=#{@module_path} doesn't exist, make one (bot modules will go here)!"
38
+ end
39
+ end
40
+
41
+ # Return path for module data dir -- a place where the module can
42
+ # stash data.
43
+
44
+ def module_data name,&block
45
+ self.validate!
46
+ datadir = self['datadir']
47
+ path = File.join(datadir,'modules',name)
48
+ if not File.exists?(path) then
49
+ FileUtils.mkdir_p(path)
50
+ end
51
+ if block_given? then
52
+ Dir.chdir(path) {
53
+ block.call(path)
54
+ }
55
+ else
56
+ path
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,153 @@
1
+ # The files in this directory are part of BeerBot, a a ruby irc bot library.
2
+ # Copyright (C) 2013,2014 Daniel Bush
3
+ # This program is distributed under the terms of the GNU
4
+ # General Public License. A copy of the license should be
5
+ # enclosed with this project in the file LICENSE. If not
6
+ # see <http://www.gnu.org/licenses/>.
7
+
8
+ require 'set'
9
+ require 'rubygems'
10
+ require 'pry'
11
+ require 'json'
12
+ require_relative 'BeerBot'
13
+
14
+ # Run the irc bot.
15
+ #
16
+ # This class creates and coordinates all the high level components
17
+ # needed to run beerbot over irc.
18
+ #
19
+ # See bin/* .
20
+
21
+ module BeerBot; end
22
+
23
+ class BeerBot::RunIRC
24
+
25
+ Utils = BeerBot::Utils
26
+ IRCWorld = BeerBot::Utils::IRCWorld
27
+ InOut = BeerBot::Utils::InOut
28
+ IRCConnection = BeerBot::IRCConnection
29
+ IRC = BeerBot::Protocol::IRC
30
+ Bot = BeerBot::Bot
31
+ IRCDispatcher = BeerBot::Dispatchers::IRCDispatcher
32
+ Scheduler = BeerBot::Scheduler
33
+
34
+ attr_accessor :config,:bot,:scheduler,:dispatcher,:world,:conn,:postq,:parse,:more
35
+
36
+ # Initialize all parts of the system here.
37
+ #
38
+ # config should be a hash, normally BeerBot::Config.
39
+ #
40
+ # Note BeerBot::Config should be loaded before we initialize here.
41
+
42
+ def initialize config
43
+
44
+ @path = File.expand_path(File.dirname(__FILE__)+'/..')
45
+ @module_path = config['moduledir']
46
+ @config = config
47
+
48
+ # Create the bot.
49
+ @bot = Bot.new(@module_path,config['modules'])
50
+
51
+ # Dispatcher which receives messages and interacts with the bot.
52
+ @dispatcher = IRCDispatcher.new(
53
+ @bot,
54
+ config['nick'],
55
+ prefix:config['cmd_prefix'],
56
+ world:@world
57
+ )
58
+
59
+ # Set up scheduler (this doesn't start it yet)...
60
+ @scheduler = Scheduler.instance(config['timezone'])
61
+ # Create a world associated with this irc connection.
62
+ # (lists channels and users we know about)
63
+ @world = IRCWorld.new(config['nick'])
64
+
65
+ # Create but don't open the irc connection.
66
+ @conn = IRCConnection.new(
67
+ nick:config['nick'],
68
+ server:config['server'])
69
+
70
+ # Dispatcher thread takes stuff from @conn queue and processes
71
+ # it...
72
+
73
+ @dispatcher_thread = InOut.new(inq:@conn.queue,outq:@conn.writeq) {|input|
74
+ str,raw = input
75
+ replies = @dispatcher.receive(str)
76
+ }
77
+ @dispatcher_thread.start!
78
+
79
+ # Schedule dispatcher thread.
80
+ #
81
+ # These are responses that were prepared and scheduled earlier and
82
+ # which also need to be dispatched.
83
+
84
+ @scheduler_thread = InOut.new(inq:@scheduler.queue,outq:@conn.writeq) {|cron_job|
85
+ puts "<< scheduler #{cron_job.inspect}"
86
+ puts "<< scheduler #{@scheduler.time}"
87
+ IRC.to_irc(cron_job.job)
88
+ }
89
+ @scheduler_thread.start!
90
+
91
+ # Set up a repl in a separate thread.
92
+ #
93
+ # In pry, you can then do:
94
+ # @conn.writeq.enq IRC.join('#chan1')
95
+ # @conn.write IRC.join('#chan1')
96
+
97
+ Pry.config.prompt = Proc.new {|_| "pry> "}
98
+ @pry_thread = Thread.new {
99
+ binding.pry
100
+ }
101
+
102
+ # Do stuff once we've identified with the irc server...
103
+ #
104
+ # Join channels.
105
+ # Start the scheduler.
106
+
107
+ @conn.ready? {
108
+ channels = config['channels']
109
+ if channels then
110
+ channels.each{|chan|
111
+ self.join(chan)
112
+ }
113
+ end
114
+ @scheduler.start
115
+ }
116
+ end
117
+
118
+ # Start the connection.
119
+
120
+ def start
121
+ @conn.open.join
122
+ end
123
+
124
+ # Convenience method to say something to channel or someone.
125
+
126
+ def say to,msg
127
+ @conn.writeq.enq(IRC.msg(to,msg))
128
+ end
129
+
130
+ # Convenience method to do something (/me).
131
+
132
+ def action to,msg
133
+ @conn.writeq.enq(IRC.action(to,msg))
134
+ end
135
+
136
+ # Convenience method to join a channel.
137
+
138
+ def join chan
139
+ @conn.writeq.enq(IRC.join(chan))
140
+ end
141
+
142
+ # Reload @bot using module list 'modules'.
143
+ #
144
+ # You could use
145
+
146
+ def reload! modules=[]
147
+ @config['modules'] = modules
148
+ @bot = Bot.new(@module_path,modules)
149
+ @dispatcher.bot = @bot
150
+ end
151
+
152
+ end
153
+
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beerbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Bush
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: CronR
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: '["Out of the box you get an irc bot, but beerbot could be so much more...",
84
+ ["Daniel Bush"]]'
85
+ email: dlb.id.au@gmail.com
86
+ executables:
87
+ - run-irc.rb
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - lib/BeerBot/00.utils/DataFile.rb
92
+ - lib/BeerBot/00.utils/InOut.rb
93
+ - lib/BeerBot/00.utils/More.rb
94
+ - lib/BeerBot/00.utils/paramExpand.rb
95
+ - lib/BeerBot/00.utils/utils.rb
96
+ - lib/BeerBot/00.utils/world/IRCWorld.rb
97
+ - lib/BeerBot/00.utils/world/World.rb
98
+ - lib/BeerBot/01.connect/Connection.rb
99
+ - lib/BeerBot/01.connect/IRCConnection.rb
100
+ - lib/BeerBot/01.protocols/botmsg.rb
101
+ - lib/BeerBot/01.protocols/irc.rb
102
+ - lib/BeerBot/02.bot/bot.rb
103
+ - lib/BeerBot/03.more/BotMsgMore.rb
104
+ - lib/BeerBot/06.dispatchers/irc.rb
105
+ - lib/BeerBot/70.scheduler/scheduler.rb
106
+ - lib/BeerBot/Config.rb
107
+ - lib/BeerBot.rb
108
+ - lib/RunIRC.rb
109
+ - bin/run-irc.rb
110
+ homepage: http://github.com/danielbush/BeerBot
111
+ licenses:
112
+ - GPL
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.1.10
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: An ruby 2.0 bot
134
+ test_files: []