Class: NickPlugin

Inherits:
CrazyDoll::Plugin show all
Defined in:
lib/crazy_doll/plugins/nick_plugin.rb

Instance Attribute Summary

Attributes inherited from CrazyDoll::Plugin

#line, #opts, #params

Instance Method Summary collapse

Methods inherited from CrazyDoll::Plugin

#c, config, #config, #current_channel, #current_nick, #custom_messages, #custom_messages_chan, #custom_messages_priv, #get, #initialize, #join, #parse_message, #post, #register_events, #register_keys, #reply, #reply_to, #reply_to_a_channel?, #say, #talked_with_me?

Constructor Details

This class inherits a constructor from CrazyDoll::Plugin

Instance Method Details

#change_nickObject



71
72
73
74
75
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 71

def change_nick
  return reply "I'm already using my correct nick." if current_nick == config.nick.name
  set_current_nick
  identify
end

#gen_random_nickObject



35
36
37
38
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 35

def gen_random_nick
  letters = [*97..122].map { |x| x.chr }
  OpenStruct.new({ :name => 8.times.map { letters.shuffle[0] }.join, :user => 'CrazyDoll', :real_name => 'CrazyDoll Bot' })
end

#get_err_unavailresourceObject



48
49
50
51
52
53
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 48

def get_err_unavailresource
  if opts.extra == c.nick.name
    set_current_nick
    identify
  end
end

#get_nickObject



63
64
65
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 63

def get_nick
  c.nick.name = opts.new_nick
end

#get_pingObject



59
60
61
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 59

def get_ping
  post PONG, opts.from
end

#get_rpl_welcomeObject



55
56
57
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 55

def get_rpl_welcome
  identify
end

#get_versionObject



67
68
69
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 67

def get_version
  post NOTICE, opts.from.nick, "\x01VERSION CrazyDoll IRC Bot v.#{CrazyDoll::VERSION}\x01"
end

#identify(pass = nil) ⇒ Object



40
41
42
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 40

def identify(pass=nil)
  say 'NickServ', "IDENTIFY #{pass||c.nick.password}" if pass or (not c.random_nick and c.nick.password)
end

#initObject



10
11
12
13
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 10

def init
  c.identified  = false
  c.random_nick = true
end

#send_nick(nick = nil) ⇒ Object



27
28
29
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 27

def send_nick(nick=nil)
  post NICK, nick || c.nick.name
end

#send_user(user = nil, real_name = nil) ⇒ Object



31
32
33
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 31

def send_user(user=nil, real_name=nil)
  post USER, user||c.nick.user, "0", "*", real_name||c.nick.real_name
end

#set_current_nickObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 15

def set_current_nick
  if c.random_nick?
    c.nick        = config.nick
    c.random_nick = false
  else
    c.nick        = gen_random_nick
    c.random_nick = true
  end
  send_nick
  send_user
end

#sys_socket_startObject



44
45
46
# File 'lib/crazy_doll/plugins/nick_plugin.rb', line 44

def sys_socket_start
  set_current_nick
end