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.
61 lines
1.3 KiB
Ruby
Executable file
61 lines
1.3 KiB
Ruby
Executable file
# frozen_string_literal: true
|
|
|
|
require 'active_record'
|
|
require 'faraday'
|
|
require 'json'
|
|
require 'logger'
|
|
require 'matrix_sdk'
|
|
require 'yaml'
|
|
|
|
require_relative './matrix'
|
|
|
|
# Require any addons
|
|
Dir[File.join(__dir__, 'addons', '*.rb')].each do |file|
|
|
require file
|
|
end
|
|
|
|
# Chronicle Bot
|
|
module Chronicle
|
|
# A filter to simplify syncs
|
|
BOT_FILTER = {
|
|
presence: { types: [] },
|
|
account_data: { types: [] },
|
|
room: {
|
|
ephemeral: { types: [] },
|
|
state: {
|
|
types: ['m.room.*'],
|
|
lazy_load_members: true
|
|
},
|
|
timeline: {
|
|
types: ['m.room.message']
|
|
},
|
|
account_data: { types: [] }
|
|
}
|
|
}.freeze
|
|
|
|
# Establish configuration for Chronicle
|
|
module Config
|
|
class << self
|
|
# Matrix connection configuration attributes
|
|
attr_accessor :matrix_homeserver, :matrix_access_token
|
|
|
|
# Logging configuration attributes
|
|
attr_accessor :log_file, :log_verbose
|
|
end
|
|
|
|
# Load a configuration Hash, and store in "module variables"
|
|
#
|
|
# @param config [Hash] a configuration hash
|
|
def self.load_config(config)
|
|
@matrix_homeserver = config["matrix"]["homeserver"]
|
|
@matrix_access_token = config["matrix"]["token"]
|
|
|
|
@log_file = config["log"]["file"]
|
|
@log_verbose = config["log"]["debug"]
|
|
end
|
|
end
|
|
|
|
def self.start()
|
|
Chronicle::Matrix.start
|
|
end
|
|
end
|