8000 Added fully fledged OPER handling. · Pull Request #257 · cinchrb/cinch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 13, 2019. It is now read-only.
8000

Added fully fledged OPER handling. #257

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/cinch/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class Bot < User
# @since 2.0.0
attr_reader :handlers

# The bot's OPER state.
# @return [Boolean]
attr_accessor :is_oper

# The bot's modes.
#
# @return [Array<String>]
Expand Down Expand Up @@ -235,6 +239,7 @@ def quit(message = nil)
# `@config.plugins.plugins`?
# @return [void]
def start(plugins = true)
@is_oper = false
@reconnects = 0
@plugins.register_plugins(@config.plugins.plugins) if plugins

Expand Down
3 changes: 2 additions & 1 deletion lib/cinch/configuration/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Cinch
class Configuration
# @since 2.0.0
class Bot < Configuration
KnownOptions = [:server, :port, :ssl, :password, :nick, :nicks,
KnownOptions = [:server, :port, :ssl, :password, :nick, :nicks, :oper,
:realname, :user, :messages_per_second, :server_queue_size,
:strictness, :message_split_start, :message_split_end,
:max_messages, :plugins, :channels, :encoding, :reconnect, :max_reconnect_delay,
Expand All @@ -22,6 +22,7 @@ def self.default_config
:realname => "cinch",
:user => "cinch",
:modes => [],
:oper => nil,
:messages_per_second => nil,
:server_queue_size => nil,
:strictness => :forgiving,
Expand Down
14 changes: 13 additions & 1 deletion lib/cinch/irc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def setup_ssl(socket)
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
@bot.loggers.info "Using SSL with #{@bot.config.server}:#{@bot.config.port}"

@socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
@socket.sync = true
@socket.connect
Expand Down Expand Up @@ -611,6 +610,9 @@ def on_001(msg, events)
# Ensure that we know our real, possibly truncated or otherwise
# modified nick.
@bot.set_nick msg.params.first
if !@bot.config.oper.nil? && @bot.config.oper["user"] != "" && @bot.config.oper["pass"] != ""
@bot.oper @bot.config.oper["pass"], @bot.config.oper["user"]
end
end

# @since 2.0.0
Expand Down Expand Up @@ -817,6 +819,12 @@ def on_368(msg, events)
msg.channel.mark_as_synced(:bans)
end

def on_381(msg, events)
@bot.is_oper = true
update_whois(@bot, {:oper? => true})
events << [:oper]
end

def on_386(msg, events)
# RPL_QLIST
unless @in_lists.include?(:owners)
Expand Down Expand Up @@ -873,6 +881,10 @@ def on_671(msg, events)
update_whois(user, {:secure? => true})
end

def on_464(msg, events)
events << [:oper_fail]
end

# @since 2.0.0
def on_730(msg, events)
# RPL_MONONLINE
Expand Down
0