chronicle_bot/Rakefile
Bill Niblock ce06aa568b Refactor for ActiveRecord and Config Files
Update Custom Commands to leverage ActiveRecord and save commands to a
database. By default, it will use SQLite. Configuration for this (and
potential configuration for PostgreSQL and MySQL) live in
`config/db.yml`. Inculde a Rakefile for handling DB creation and
migrations.

Rakefile: Add Rakefile to handle running the bot, and DB management
Gemfile: Update with new gem dependencies
db/migrate/*: ActiveRecord migrations for Custom Command
custom_commands.rb: Update to leverage ActiveRecord

Leverage the Rakefile to start the bot, removing the binary file. Update
the Dockerfile to also leverage the Rakefile.

Dockerfile: Update to use Rakefile, and install new dependencies
chronicle: Remove unnecessary start file

Refactor the `chronicle_bot` file into `chronicle` and `matrix`

chronicle.rb: General Chronicle setup
matrix.rb: Start a Matrix-specific bot

Update the bot to read configuration from files, instead of either the
environment, or hard-coded values.

config/db.yml: Database configuration
config/bot.yml: General bot configuration

Update the README to reflect the above change with regards to running
the bot either using the Rakefile, or using a Docker container.
2021-02-27 19:55:43 -05:00

59 lines
1.5 KiB
Ruby

namespace :chronicle do
desc 'Start the bot'
task :start do
require 'active_record'
require_relative 'lib/chronicle'
db_config = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(db_config)
bot_config = YAML::load(File.open('config/bot.yml'))
Chronicle::Config.load_config(bot_config)
Chronicle.start
end
end
namespace :db do
require 'active_record'
require 'yaml'
Dir[File.join(__dir__, 'db', 'migrate', '*.rb')].each do |file|
require file
end
task :connect do
connection_details = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(connection_details)
end
desc "Create a new database"
task :create do
connection_details = YAML::load(File.open('config/database.yml'))
if connection_details["adapter"] == 'sqlite3'
if File.exists?(connection_details["database"])
puts 'DB already exists'
else
File.open(connection_details["database"], 'w+') {}
end
else
ActiveRecord::Base.establish_connection(connection_details)
ActiveRecord::Base.connection.create_database(
connection_details["database"]
)
end
end
desc "Run the migrations"
task :migrate => 'db:connect' do
# ActiveRecord::MigrationContext.new('db/migrate/').migrate()
CreateCustomCommands.migrate(:up)
end
desc "Clear the database"
task :drop => 'db:connect' do
# ActiveRecord::Migration.migrate(:down)
CreateCustomCommands.migrate(:down)
end
end