rubyserv-iirc/main.rb

97 lines
2.4 KiB
Ruby

# Copyright (C) 2022 Noisytoot <ron@noisytoot.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
require "timeout"
require "redis"
require "iirc"
require "./eval"
require "./shell"
class OperBot < IIRC::IRCv3Bot
include IIRC::Batteries
include IIRC::Formatting
include Eval
include Shell
def redis
@redis ||= Redis.new
end
def eval_prefix
redis.get('eval.prefix') || "] "
end
def shell_prefix
redis.get('eval.prefix.shell') || "$ "
end
def eval_timeout
timeout = redis.get('eval.timeout')
if timeout then timeout.to_i else 15 end
end
def supported_caps
[
'cap-notify', 'away-notify', 'invite-notify', 'account-notify',
'extended-join', 'chghost', 'setname', 'multi-prefix', 'batch',
'labeled-response', 'message-tags', 'server-time', 'account-tag',
'solanum.chat/oper', 'letspiss.net/hiddenoper', 'letspiss.net/id'
] + redis.lrange('ircv3.capabilities', 0, -1)
end
def on_001(evt)
for cap in supported_caps
cap! cap
end
end
def on_cap(evt)
if evt.args[1].upcase == 'NEW'
for cap in evt.args[2].split(' ')
if supported_caps.include? cap
cap! cap
end
end
end
end
def reload
load __FILE__
load './eval.rb'
load './shell.rb'
end
def autojoin_channels
([ENV['IRC_JOIN']] + redis.lrange('autojoin.channels', 0, -1)).compact
end
end
class IIRC::Event
def from_oper?
tags.key? 'solanum.chat/oper' or tags.key? 'letspiss.net/hiddenoper'
end
end
if __FILE__ == $0 and not defined? STARTED
STARTED = true
OperBot.run ENV['IRC_HOST'] || 'localhost',
ENV['IRC_PORT'] || 6697,
nick: ENV['IRC_NICK'],
username: ENV['IRC_USERNAME'] || ENV['IRC_NICK'],
realname: ENV['IRC_REALNAME'] || ENV['IRC_NICK'],
ssl_context: IIRC::SSL.no_verify
end