1
0
Fork 0
mirror of https://github.com/nishiki/botish.git synced 2024-10-26 23:23:17 +00:00

add config file

This commit is contained in:
Adrien Waksberg 2017-04-19 21:46:53 +02:00
parent b4d303747b
commit e695a12882
3 changed files with 23 additions and 24 deletions

View file

@ -10,32 +10,20 @@ options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: botish --host irc.freenode.net --channel "test" [options]'
opts.on('-c', '--channel CHANNEL') do |channel|
options[:channel] = channel
end
opts.on('-H', '--host HOST') do |host|
options[:host] = host
opts.on('-c', '--config PATH') do |path|
options[:config_file] = path
end
opts.on('-h', '--help') do
puts opts
exit 0
end
opts.on('-p', '--port PORT') do |port|
options[:port] = port.to_i
end
opts.on('-u', '--user USER') do |user|
options[:user] = user
end
end.parse!
Dir["#{File.expand_path('../../modules', __FILE__)}/*"].each do |f|
require_relative f
end
botish = Botish::Botish.new(options[:host], options[:channel], options[:user], options[:port])
botish = Botish::Botish.new(options[:config_file])
botish.connect
botish.listen

7
config.yml.example Normal file
View file

@ -0,0 +1,7 @@
---
host: irc.freenode.net
port: 6667
user: botish
channels:
- test
- test2

View file

@ -1,15 +1,17 @@
#!/usr/bin/ruby
require 'yaml'
require 'socket'
require 'botish/base'
module Botish
class Botish < Base
def initialize(host, channel, user, port)
@host = host
@channel = channel
@user = user || 'botish'
@port = port || 6667
def initialize(config_file)
config = YAML.load_file(config_file)
@host = config['host']
@channels = config['channels']
@user = config['user'] || 'botish'
@port = config['port'] || 6667
end
def connect
@ -24,8 +26,10 @@ module Botish
break if msg.include?('End of /MOTD command.')
end
send_msg("JOIN #{@channel}")
send_msg("PRIVMSG #{@channel} :Je suis là :')")
@channels.each do |channel|
send_msg("JOIN ##{channel}")
send_msg("PRIVMSG ##{channel} :Je suis là :')")
end
end
def listen
@ -43,8 +47,8 @@ module Botish
when /^PING (?<host>.+)/
send_msg("PONG #{Regexp.last_match('host')}")
when /^:(?<user>[[:alpha:]]+)([^ ]+)? PRIVMSG #{@channel} :#{@user}: ping/
send_msg("PRIVMSG #{@channel} :#{Regexp.last_match('user')}: pong")
when /^:(?<user>[[:alpha:]]+)([^ ]+)? PRIVMSG (?<channel>#[[:alpha:]]+) :#{@user}: ping/
send_msg("PRIVMSG #{Regexp.last_match('channel')} :#{Regexp.last_match('user')}: pong")
when /^:(?<user>[[:alpha:]]+)([^ ]+)? PRIVMSG (?<channel>#?[[:alpha:]]+) :#{@user}: (?<command>[[:lower:]]+)( (?<args>.+))?/
command = Regexp.last_match('command')