Sha256: b8dee567186131e054731cd5aa92b89b2f0a74ed9a9b1ddb79a63cdaf5b4b569

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

hook(type: :ujoin) do |dat|
  dat[:plug].users[dat[:nick]] = {} unless dat[:plug].users[dat[:nick]]
  u = dat[:plug].users[dat[:nick]]
  u[:nick] = dat[:nick]
  u[:user] = dat[:user]
  u[:host] = dat[:host]

  unless dat[:plug].chans[dat[:channel]]
    dat[:plug].chans[dat[:channel]] = {}
    dat[:plug].chans[dat[:channel]][:users] = []
  end

  dat[:plug].chans[dat[:channel]][:users] << u[:nick] unless
    dat[:plug].chans[dat[:channel]][:users].include? u[:nick]
end

hook(type: :upart) do |dat|
  dat[:plug].users[dat[:nick]] = {} unless dat[:plug].users[dat[:nick]]
  u = dat[:plug].users[dat[:nick]]
  u[:nick] = dat[:nick]
  u[:user] = dat[:user]
  u[:host] = dat[:host]

  unless dat[:plug].chans[dat[:channel]]
    dat[:plug].chans[dat[:channel]] = {}
    dat[:plug].chans[dat[:channel]][:users] = []
  end

  dat[:plug].chans[dat[:channel]][:users].delete u[:nick] if
    dat[:plug].chans[dat[:channel]][:users].include? u[:nick]

  if dat[:nick] == dat[:plug].nick && /requested by .*/.match(dat[:message])
    dat[:plug].join(dat[:channel])
  elsif dat[:nick] == dat[:plug].nick
    dat[:plug].chans.delete(dat[:channel])
  end
end

hook(type: :uquit) do |dat|
  dat[:plug].chans.each do |k, chan|
    if chan[:users] and chan[:users].include? dat[:nick]
      emit(dat.merge(type: :uquitc, channel: k))
      chan[:users].delete(dat[:nick])
    end
  end
  dat[:plug].users.delete(dat[:nick])
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
protonbot-0.3.7 lib/protonbot/core_plugin/hooks/joinpart.rb
protonbot-0.3.6 lib/protonbot/core_plugin/hooks/joinpart.rb