mod_spox 0.1.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG +36 -0
  2. data/INSTALL +2 -2
  3. data/README +0 -1
  4. data/bin/mod_spox +51 -12
  5. data/data/mod_spox/extras/AOLSpeak.rb +5 -18
  6. data/data/mod_spox/extras/AutoKick.rb +44 -23
  7. data/data/mod_spox/extras/AutoMode.rb +2 -5
  8. data/data/mod_spox/extras/AutoRejoin.rb +21 -0
  9. data/data/mod_spox/extras/Bouncer.rb +10 -10
  10. data/data/mod_spox/extras/Bytes.rb +12 -0
  11. data/data/mod_spox/extras/Confess.rb +131 -52
  12. data/data/mod_spox/extras/DCC.rb +189 -0
  13. data/data/mod_spox/extras/DevWatch.rb +32 -33
  14. data/data/mod_spox/extras/FloodKicker.rb +129 -0
  15. data/data/mod_spox/extras/GoogleIt.rb +13 -0
  16. data/data/mod_spox/extras/Headers.rb +31 -4
  17. data/data/mod_spox/extras/Karma.rb +103 -49
  18. data/data/mod_spox/extras/Logger.rb +45 -30
  19. data/data/mod_spox/extras/LolSpeak.rb +1 -1
  20. data/data/mod_spox/extras/NickServ.rb +83 -0
  21. data/data/mod_spox/extras/PhpCli.rb +12 -15
  22. data/data/mod_spox/extras/PhpFuncLookup.rb +57 -25
  23. data/data/mod_spox/extras/Quotes.rb +5 -4
  24. data/data/mod_spox/extras/RegexTracker.rb +160 -0
  25. data/data/mod_spox/extras/Roulette.rb +22 -23
  26. data/data/mod_spox/extras/Search.rb +3 -2
  27. data/data/mod_spox/extras/Slashdot.rb +35 -0
  28. data/data/mod_spox/extras/Topten.rb +5 -5
  29. data/data/mod_spox/extras/TracTicket.rb +68 -0
  30. data/data/mod_spox/extras/Translate.rb +69 -30
  31. data/data/mod_spox/extras/Twitter.rb +372 -0
  32. data/data/mod_spox/extras/UrbanDictionary.rb +21 -12
  33. data/data/mod_spox/extras/Weather.rb +1 -1
  34. data/data/mod_spox/plugins/Authenticator.rb +63 -30
  35. data/data/mod_spox/plugins/Banner.rb +164 -151
  36. data/data/mod_spox/plugins/Helper.rb +18 -7
  37. data/data/mod_spox/plugins/PluginLoader.rb +46 -22
  38. data/data/mod_spox/plugins/PoolConfig.rb +52 -0
  39. data/data/mod_spox/plugins/Quitter.rb +1 -1
  40. data/data/mod_spox/plugins/Status.rb +28 -0
  41. data/lib/mod_spox/Action.rb +20 -3
  42. data/lib/mod_spox/BaseConfig.rb +1 -0
  43. data/lib/mod_spox/Bot.rb +98 -75
  44. data/lib/mod_spox/BotConfig.rb +14 -6
  45. data/lib/mod_spox/ConfigurationWizard.rb +94 -105
  46. data/lib/mod_spox/Database.rb +33 -13
  47. data/lib/mod_spox/Helpers.rb +67 -38
  48. data/lib/mod_spox/Loader.rb +25 -5
  49. data/lib/mod_spox/Logger.rb +20 -62
  50. data/lib/mod_spox/MessageFactory.rb +34 -25
  51. data/lib/mod_spox/Monitors.rb +5 -0
  52. data/lib/mod_spox/Pipeline.rb +40 -51
  53. data/lib/mod_spox/Plugin.rb +40 -9
  54. data/lib/mod_spox/PluginManager.rb +46 -38
  55. data/lib/mod_spox/Pool.rb +129 -143
  56. data/lib/mod_spox/Socket.rb +41 -50
  57. data/lib/mod_spox/Sockets.rb +211 -0
  58. data/lib/mod_spox/Timer.rb +86 -69
  59. data/lib/mod_spox/handlers/BadNick.rb +1 -1
  60. data/lib/mod_spox/handlers/Created.rb +1 -1
  61. data/lib/mod_spox/handlers/Handler.rb +9 -0
  62. data/lib/mod_spox/handlers/Invite.rb +1 -1
  63. data/lib/mod_spox/handlers/Join.rb +2 -2
  64. data/lib/mod_spox/handlers/Kick.rb +1 -1
  65. data/lib/mod_spox/handlers/LuserChannels.rb +1 -1
  66. data/lib/mod_spox/handlers/LuserOp.rb +1 -1
  67. data/lib/mod_spox/handlers/LuserUnknown.rb +1 -1
  68. data/lib/mod_spox/handlers/Mode.rb +2 -2
  69. data/lib/mod_spox/handlers/MyInfo.rb +1 -1
  70. data/lib/mod_spox/handlers/Names.rb +1 -1
  71. data/lib/mod_spox/handlers/Nick.rb +20 -3
  72. data/lib/mod_spox/handlers/NickInUse.rb +3 -3
  73. data/lib/mod_spox/handlers/Notice.rb +5 -15
  74. data/lib/mod_spox/handlers/Part.rb +1 -1
  75. data/lib/mod_spox/handlers/Ping.rb +1 -1
  76. data/lib/mod_spox/handlers/Pong.rb +1 -1
  77. data/lib/mod_spox/handlers/Privmsg.rb +2 -2
  78. data/lib/mod_spox/handlers/Quit.rb +1 -1
  79. data/lib/mod_spox/handlers/Topic.rb +2 -1
  80. data/lib/mod_spox/handlers/Welcome.rb +3 -3
  81. data/lib/mod_spox/handlers/Who.rb +9 -7
  82. data/lib/mod_spox/handlers/Whois.rb +29 -16
  83. data/lib/mod_spox/handlers/YourHost.rb +1 -1
  84. data/lib/mod_spox/messages/incoming/Privmsg.rb +38 -19
  85. data/lib/mod_spox/messages/internal/DCCListener.rb +12 -0
  86. data/lib/mod_spox/messages/internal/DCCRequest.rb +12 -0
  87. data/lib/mod_spox/messages/internal/DCCSocket.rb +19 -0
  88. data/lib/mod_spox/messages/internal/StatusRequest.rb +2 -1
  89. data/lib/mod_spox/messages/outgoing/Privmsg.rb +21 -5
  90. data/lib/mod_spox/migrations/001_initialize_models.rb +115 -0
  91. data/lib/mod_spox/models/Auth.rb +24 -16
  92. data/lib/mod_spox/models/AuthGroup.rb +4 -3
  93. data/lib/mod_spox/models/Channel.rb +20 -12
  94. data/lib/mod_spox/models/ChannelMode.rb +2 -2
  95. data/lib/mod_spox/models/Config.rb +11 -3
  96. data/lib/mod_spox/models/Group.rb +6 -1
  97. data/lib/mod_spox/models/Nick.rb +93 -33
  98. data/lib/mod_spox/models/NickChannel.rb +8 -6
  99. data/lib/mod_spox/models/NickGroup.rb +16 -0
  100. data/lib/mod_spox/models/NickMode.rb +3 -3
  101. data/lib/mod_spox/models/Server.rb +6 -2
  102. data/lib/mod_spox/models/Setting.rb +12 -6
  103. data/lib/mod_spox/models/Signature.rb +7 -13
  104. data/lib/mod_spox/models/Trigger.rb +1 -1
  105. metadata +125 -100
@@ -0,0 +1,129 @@
1
+ class FloodKicker
2
+ def initialize(pipeline)
3
+ super
4
+ flood = Models::Auth.find_or_create(:name => 'flood')
5
+ @watched = []
6
+ @channels = Setting.filter(:name => :floodkicker).first
7
+ @channels = [] if @channels.nil?
8
+ @channels.each do |c|
9
+ @watched << c[:channel]
10
+ end
11
+ @data = {}
12
+ @pipeline.hook(self, :listener, :Incoming_Privmsg)
13
+ add_sig(:sig => 'floodkick enable(\s \S+)?', :method => :add_channel, :group => flood,
14
+ :desc => 'Add channel to flood kicker', :params => [:channel])
15
+ add_sig(:sig => 'floodkick disable(\s \S+)?', :method => :remove_channel, :group => flood,
16
+ :desc => 'Remove channel from flood kicker', :params => [:channel])
17
+ add_sig(:sig => 'floodkick lines(\s \d+)?', :method => :max_lines, :group => flood,
18
+ :desc => 'Maximum number of lines in allowed time', :params => [:lines])
19
+ add_sig(:sig => 'floodkick seconds(\s \d+)?', :method => :max_seconds, :group => flood,
20
+ :desc => 'Maximum number of seconds for allowed lines', :params => [:seconds])
21
+ add_sig(:sig => 'floodkick status(\s \S+)?', :method => :status, :desc => 'Show parameters for given channel',
22
+ :params => [:channel])
23
+ end
24
+ # @channels -> {:channel => chan.pk, :lines => \d+, :seconds => \d+}
25
+
26
+ def add_channel(m, params)
27
+ chan = params[:channel] ? Models::Channel.locate(params[:channel].strip) : m.channel
28
+ unless(watched_channels_ids.include?(chan.pk))
29
+ @channels << {:channel => chan.pk, :lines => 5, :seconds => 1}
30
+ save_channels
31
+ reply m.replyto, "Flood kicker is now enabled for: #{chan.name}"
32
+ else
33
+ reply m.replyto, "\2Error:\2 Flood kicker is already enabled for: #{chan.name}"
34
+ end
35
+ end
36
+
37
+ def remove_channel(m, params)
38
+ chan = params[:channel] ? Models::Channel.locate(params[:channel].strip) : m.channel
39
+ if(watched_channels_ids.include?(chan.pk))
40
+ @channels.delete(get_chan(chan.pk))
41
+ save_channels
42
+ reply m.replyto, "Flood kicker is now disabled for: #{chan.name}"
43
+ else
44
+ reply m.replyto, "Flood kicker is not enabled for: #{chan.name}"
45
+ end
46
+ end
47
+
48
+ def max_lines(m, params)
49
+ lines = params[:lines] ? params[:lines].to_i : nil
50
+ chan = get_chan(m.channel.pk)
51
+ unless(chan.nil?)
52
+ if(lines.nil? || lines == 0)
53
+ reply m.replyto, "Flood kicker lines for this channel currently set at: #{chan[:lines]} lines"
54
+ else
55
+ chan[:lines] = lines
56
+ save_channels
57
+ reply m.replyto, "Flood kicker lines updated to: #{lines} lines"
58
+ end
59
+ else
60
+ reply m.replyto, "\2Error:\2 Flood kicker is not enabled in this channel"
61
+ end
62
+ end
63
+
64
+ def max_seconds(m, params)
65
+ seconds = params[:seconds] ? params[:seconds].to_i : nil
66
+ chan = get_chan(m.channel.pk)
67
+ unless(chan.nil?)
68
+ if(seconds.nil? || seconds == 0)
69
+ reply m.replyto, "Flood kicker seconds for this channel currently set at: #{chan[:seconds]} seconds"
70
+ else
71
+ chan[:seconds] = seconds
72
+ save_channels
73
+ reply m.replyto, "Flood kicker seconds updated to: #{seconds} seconds"
74
+ end
75
+ else
76
+ reply m.replyto, "\2Error:\2 Flood kicker is not enabled in this channel"
77
+ end
78
+ end
79
+
80
+ def listener(m)
81
+ if(@watched.include?(m.channel.pk))
82
+ log_message(m)
83
+ if(kick_nick?(m.nick, m.channel))
84
+ chan = get_chan(m.channel.pk)
85
+ @pipeline << Messages::Outgoing::Kick.new(m.nick, m.channel, "Flooding. (exceeded #{chan[:lines]} lines in #{chan[:seconds]} seconds)")
86
+ end
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def log_message(m)
93
+ @data[m.channel.pk] = {} unless @data.has_key?(m.channel.pk)
94
+ @data[m.channel.pk][m.nick.pk] = [] unless @data[m.channel.pk].has_key?(m.nick.pk)
95
+ @data[m.channel.pk][m.nick.pk] << {:time => Time.now, :message => m.message}
96
+ @data[m.channel.pk][m.nick.pk].shift until @data[m.channel.pk][m.nick.pk].size <= get_chan(m.channel.pk)[:lines]
97
+ end
98
+
99
+ def kick_nick?(nick, channel)
100
+ chan = get_chan(channel.pk)
101
+ if(@data[channel.pk].has_key?(nick.pk) && @data[channel.pk][nick.pk].size == chan[:lines])
102
+ return @data[channel.pk][nick.pk][@data[channel.pk][nick.pk].size - 1][:time].to_i - @data[channel.pk][nick.pk][0].to_i >= chan[:seconds].to_i
103
+ else
104
+ return false
105
+ end
106
+ end
107
+
108
+ def save_channels
109
+ s = Models::Setting.find_or_create(:name => 'floodkicker')
110
+ s.value = @channels
111
+ s.save
112
+ @watched.clear
113
+ @channels.each{|c| @watched << c.pk}
114
+ end
115
+
116
+ def watched_channels
117
+ @channels.collect{|c| Models::Channel[c[:channel]]}
118
+ end
119
+
120
+ def watched_channels_ids
121
+ @channels.collect{|c| c[:channel]}
122
+ end
123
+
124
+ def get_chan(pk)
125
+ @channels.each do |c|
126
+ return c if c[:channel] == pk
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,13 @@
1
+ class GoogleIt < ModSpox::Plugin
2
+ def initialize(pipeline)
3
+ super
4
+ add_sig(:sig => 'googleit (.+)', :method => :git, :description => 'Let me google that for you', :params => [:term])
5
+ end
6
+
7
+ def git(m, params)
8
+ link = "http://www.letmegooglethatforyou.com/?q=#{URI.escape(params[:term])}"
9
+ output = ["Oh please, let me google: \2#{params[:term]}\2 for you."]
10
+ output << "\2Result:\2 #{Helpers.tinyurl(link)}"
11
+ reply m.replyto, output
12
+ end
13
+ end
@@ -5,11 +5,30 @@ class Headers < ModSpox::Plugin
5
5
 
6
6
  def initialize(pipeline)
7
7
  super(pipeline)
8
+ admin = Models::Group.find_or_create(:name => 'headers')
8
9
  Models::Signature.find_or_create(:signature => 'headers (https?:\/\/\S+)', :plugin => name, :method => 'fetch_headers',
9
10
  :description => 'Fetch HTTP headers').params = [:url]
11
+ Models::Signature.find_or_create(:signature => 'headers max (\d+)', :plugin => name, :method => 'set_max',
12
+ :group_id => admin.pk, :description => 'Set maximum number of headers to return').params = [:max]
13
+ Models::Signature.find_or_create(:signature => 'headers max', :plugin => name, :method => 'show_max',
14
+ :group_id => admin.pk, :description => 'Show maximum number of headers to return ')
10
15
  @lock = Mutex.new
16
+ @max = Models::Config[:headers_max]
17
+ @max = @max.nil? ? 0 : @max.to_i
11
18
  end
12
19
 
20
+ def set_max(message, params)
21
+ record = Models::Config.find_or_create(:name => 'headers_max')
22
+ record.value = params[:max].to_i
23
+ record.save
24
+ @max = params[:max].to_i
25
+ reply message.replyto, "Max headers returned set to: #{params[:max].to_i}"
26
+ end
27
+
28
+ def show_max(message, params)
29
+ reply message.replyto, "Maximum headers returned: #{@max == 0 ? 'no limit' : @max}"
30
+ end
31
+
13
32
  def fetch_headers(message, params)
14
33
  @lock.synchronize do
15
34
  secure = false
@@ -28,22 +47,30 @@ class Headers < ModSpox::Plugin
28
47
  location = $1
29
48
  page = $2
30
49
  else
31
- location = params[:url]
50
+ location = params[:url].gsub(/\/$/, '')
32
51
  page = '/'
33
52
  end
34
53
  begin
35
54
  reply message.replyto, "Connecting to: #{location} on port: #{port} retrieving: #{page}"
36
55
  con = Net::HTTP.new(location, port)
37
56
  con.use_ssl = secure
38
- response = con.get(page, nil)
57
+ response = con.get(page)
39
58
  output = ["Response code: #{response.code}"]
59
+ count = 0
40
60
  response.each{|key,val|
41
- output << "#{key}: #{val}"
61
+ output << "#{key.slice(0..50)}: #{val.slice(0..200)}"
62
+ count += 1
63
+ break if @max != 0 && count >= @max
42
64
  }
43
- output << "Header listing complete"
65
+ if(count >= @max && @max != 0)
66
+ output << 'Maximum header limit reached.'
67
+ else
68
+ output << 'Header listing complete'
69
+ end
44
70
  reply message.replyto, output
45
71
  rescue Object => boom
46
72
  reply message.replyto, "Error retrieving headers: #{boom}"
73
+ Logger.warn("#{boom}\n#{boom.backtrace.join("\n")}")
47
74
  end
48
75
  end
49
76
  end
@@ -7,20 +7,27 @@ class Karma < ModSpox::Plugin
7
7
  Datatype::Karma.create_table unless Datatype::Karma.table_exists?
8
8
  Datatype::Alias.create_table unless Datatype::Alias.table_exists?
9
9
  alias_group = Models::Group.find_or_create(:name => 'alias')
10
- Models::Signature.find_or_create(:signature => 'karma (\S+)', :plugin => name, :method => 'score', :description => 'Returns karma for given thing').params = [:thing]
11
- Models::Signature.find_or_create(:signature => 'karma reset (\S+)', :plugin => name, :method => 'reset',
10
+ Models::Signature.find_or_create(:signature => 'karma (?!(fight|alias|dealias|aliases|reset) (\S+|\(.+?\)) ?(\S+|\(.+?\))?$)(\S+|\(.+?\))', :plugin => name, :method => 'score', :description => 'Returns karma for given thing').params = [:crap, :crap2, :crap3, :thing]
11
+ Models::Signature.find_or_create(:signature => 'karma reset (\S+|\(.+?\))', :plugin => name, :method => 'reset',
12
12
  :group_id => Models::Group.filter(:name => 'admin').first.pk, :description => 'Reset a karma score').params = [:thing]
13
- Models::Signature.find_or_create(:signature => 'karma alias (\S+) (\S+)', :plugin => name, :method => 'aka',
13
+ Models::Signature.find_or_create(:signature => 'karma alias (\S+|\(.+?\)) (\S+|\(.+?\))', :plugin => name, :method => 'aka',
14
14
  :group_id => alias_group.pk, :description => 'Alias a karma object to another karma object').params = [:thing, :thang]
15
- Models::Signature.find_or_create(:signature => 'karma dealias (\S+) (\S+)', :plugin => name, :method => 'dealias',
15
+ Models::Signature.find_or_create(:signature => 'karma dealias (\S+|\(.+?\)) (\S+|\(.+?\))', :plugin => name, :method => 'dealias',
16
16
  :group_id => alias_group.pk, :description => 'Remove a karma alias').params = [:thing, :otherthing]
17
- Models::Signature.find_or_create(:signature => 'karma aliases (\S+)', :plugin => name, :method => 'show_aliases',
17
+ Models::Signature.find_or_create(:signature => 'karma aliases (\S+|\(.+?\))', :plugin => name, :method => 'show_aliases',
18
18
  :description => 'Show all aliases for given thing').params = [:thing]
19
- Models::Signature.find_or_create(:signature => 'karma fight (\S+) (\S+)', :plugin => name, :method => 'fight',
19
+ Models::Signature.find_or_create(:signature => 'karma fight (\S+|\(.+?\)) (\S+|\(.+?\))', :plugin => name, :method => 'fight',
20
20
  :description => 'Make two karma objects fight').params = [:thing, :thang]
21
+ add_sig(:sig => 'antikarma (\S+|\(.+?\))', :method => :antikarma, :desc => 'Show things antikarma', :params => [:thing])
21
22
  @pipeline.hook(self, :check, :Incoming_Privmsg)
22
23
  @thing_maxlen = 32
23
24
  @karma_regex = /(\(.{1,#@thing_maxlen}?\)|\S{1,#@thing_maxlen})([+-]{2})(?:\s|$)/
25
+ @eggs = {}
26
+ @eggs[:chameleon] = []
27
+ @eggs[:chameleon] << 'Karma karma karma karma karma chameleon You come and go You come and go Loving would be easy if your colors were like my dream Red, gold and green Red, gold and green'
28
+ @eggs[:chameleon] << 'Didn\'t hear your wicked words every day And you used to be so sweet I heard you say That my love was an addiction When we cling our love is strong When you go youre gone forever You string along You string along'
29
+ @eggs[:chameleon] << 'Every day is like a survival You\'re my lover not my rival Every day is like a survival You\'re my lover not my rival'
30
+ @eggs[:chameleon] << 'I\'m a man without conviction I\'m a man who doesnt know How to sell a contradication You come and go You come and go'
24
31
  end
25
32
 
26
33
  def check(message)
@@ -28,7 +35,7 @@ class Karma < ModSpox::Plugin
28
35
  message.message.scan(@karma_regex) do |match|
29
36
  thing, adj = match
30
37
  thing.downcase!
31
- thing = thing[1..-2] if thing[0..0] == '(' && thing[-1..1] == ')'
38
+ thing = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
32
39
  adj = adj == '++' ? +1 : -1
33
40
  things = [thing]
34
41
  karma = Datatype::Karma.find_or_create(:thing => thing, :channel_id => message.target.pk)
@@ -44,81 +51,128 @@ class Karma < ModSpox::Plugin
44
51
  end
45
52
  end
46
53
  end
47
-
54
+
48
55
  def score(message, params)
49
56
  return unless message.is_public?
50
- karma = Datatype::Karma.filter(:thing => params[:thing].downcase, :channel_id => message.target.pk).first
57
+ thing = params[:thing]
58
+ orig = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
59
+ orig = thing if orig.nil?
60
+ thing = orig.downcase
61
+ karma = Datatype::Karma.filter(:thing => thing, :channel_id => message.target.pk).first
51
62
  if(karma)
52
- @pipeline << Privmsg.new(message.replyto, "Karma for \2#{params[:thing]}\2 is #{Datatype::Alias.score_object(karma.pk)}")
63
+ @pipeline << Privmsg.new(message.replyto, "Karma for \2#{orig}\2 is #{Datatype::Alias.score_object(karma.pk)}")
53
64
  else
54
- @pipeline << Privmsg.new(message.replyto, "\2Error:\2 #{params[:thing]} has no karma")
65
+ @pipeline << Privmsg.new(message.replyto, "\2Error:\2 #{orig} has no karma")
66
+ end
67
+ if(@eggs.has_key?(params[:thing].downcase.to_sym))
68
+ @pipeline << Messages::Internal::TimerAdd.new(self, rand(5) + 1, nil, true){ egg(params[:thing].downcase, message) }
55
69
  end
56
70
  end
57
-
71
+
72
+ def antikarma(message, params)
73
+ return unless message.is_public?
74
+ thing = params[:thing]
75
+ orig = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
76
+ orig = thing if orig.nil?
77
+ thing = orig.downcase
78
+ karma = Datatype::Karma.filter(:thing => thing, :channel_id => message.target.pk).first
79
+ if(karma)
80
+ @pipeline << Privmsg.new(message.replyto, "Anti-Karma for \2#{orig}\2 is #{0 - Datatype::Alias.score_object(karma.pk).to_i}")
81
+ else
82
+ @pipeline << Privmsg.new(message.replyto, "\2Error:\2 #{orig} has no anti-karma")
83
+ end
84
+ end
85
+
58
86
  def reset(message, params)
59
- params[:thing].downcase!
87
+ sthing = params[:thing].downcase
88
+ sthing = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
60
89
  return unless message.is_public?
61
- karma = Datatype::Karma.filter(:thing => params[:thing], :channel_id => message.target.pk).first
90
+ karma = Datatype::Karma.filter(:thing => sthing, :channel_id => message.target.pk).first
62
91
  if(karma)
63
92
  karma.update_with_params(:score => 0)
64
93
  @pipeline << Privmsg.new(message.replyto, "Karma for \2#{karma.thing}\2 has been reset")
65
94
  else
66
- @pipeline << Privmsg.new(message.replyto, "\2Error:\2 #{params[:thing]} has no karma")
67
- end
95
+ @pipeline << Privmsg.new(message.replyto, "\2Error:\2 #{sthing} has no karma")
96
+ end
68
97
  end
69
-
98
+
70
99
  def fight(message, params)
71
- thing = Datatype::Karma.find_or_create(:thing => params[:thing].downcase)
72
- thang = Datatype::Karma.find_or_create(:thing => params[:thang].downcase)
73
- thing_score = Datatype::Alias.score_object(thing.pk)
74
- thang_score = Datatype::Alias.score_object(thang.pk)
75
- winner = thing_score > thang_score ? params[:thing] : params[:thang]
76
- loser = thing_score > thang_score ? params[:thang] : params[:thing]
100
+ thing = params[:thing]
101
+ thang = params[:thang]
102
+ thing = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
103
+ thang = thang[1..-2] if thang[0..0] == '(' && thang[-1..-1] == ')'
104
+ rthing = Datatype::Karma.find_or_create(:thing => thing.downcase, :channel_id => message.target.pk)
105
+ rthang = Datatype::Karma.find_or_create(:thing => thang.downcase, :channel_id => message.target.pk)
106
+ thing_score = Datatype::Alias.score_object(rthing.pk)
107
+ thang_score = Datatype::Alias.score_object(rthang.pk)
108
+ winner = thing_score > thang_score ? thing : thang
109
+ loser = thing_score > thang_score ? thang : thing
77
110
  distance = (thing_score - thang_score).abs
78
- reply message.replyto, "\2KARMA FIGHT RESULTS:\2 \2#{winner}\2 has beaten \2#{loser}\2 by a #{distance} point lead"
111
+ output = "\2KARMA FIGHT RESULTS:\2 "
112
+ if(distance > 0)
113
+ reply message.replyto, "\2#{winner}\2 #{winner[-1] == 's' || winner[-1] == 115 ? 'have' : 'has'} beaten \2#{loser}\2 #{distance > 50 ? 'like a redheaded step child' : ''} (+#{distance} points)"
114
+ else
115
+ reply message.replyto, "\2#{winner}\2 #{winner[-1] == 's' || winner[-1] == 115 ? 'have' : 'has'} tied \2#{loser}\2"
116
+ end
79
117
  end
80
-
118
+
81
119
  def aka(message, params)
82
- thing = Datatype::Karma.find_or_create(:thing => params[:thing].downcase, :channel_id => message.target.pk)
83
- thang = Datatype::Karma.find_or_create(:thing => params[:thang].downcase, :channel_id => message.target.pk)
120
+ thing = params[:thing].downcase
121
+ thang = params[:thang].downcase
122
+ thing = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
123
+ thang = thang[1..-2] if thang[0..0] == '(' && thang[-1..-1] == ')'
124
+ thing = Datatype::Karma.find_or_create(:thing => thing, :channel_id => message.target.pk)
125
+ thang = Datatype::Karma.find_or_create(:thing => thang, :channel_id => message.target.pk)
84
126
  if(Datatype::Alias.filter('(thing_id = ? AND aka_id = ?) OR (thing_id = ? AND aka_id = ?)', thing.pk, thang.pk, thang.pk, thing.pk).first)
85
- reply message.replyto, "\2Error:\2 #{params[:thing]} is already aliased to #{params[:thang]}"
127
+ reply message.replyto, "\2Error:\2 #{thing.thing} is already aliased to #{thang.thing}"
86
128
  else
87
129
  Datatype::Alias.find_or_create(:thing_id => thing.pk, :aka_id => thang.pk)
88
- reply message.replyto, "\2Karma Alias:\2 #{params[:thing]} is now aliased to #{params[:thang]}"
130
+ reply message.replyto, "\2Karma Alias:\2 #{thing.thing} is now aliased to #{thang.thing}"
89
131
  end
90
132
  end
91
-
133
+
92
134
  def dealias(message, params)
93
- thing = Datatype::Karma.filter(:thing => params[:thing].downcase, :channel_id => message.target.pk).first
94
- otherthing = Datatype::Karma.filter(:thing => params[:otherthing].downcase, :channel_id => message.target.pk).first
135
+ sthing = params[:thing].downcase
136
+ sotherthing = params[:otherthing].downcase
137
+ sthing = sthing[1..-2] if sthing[0..0] == '(' && sthing[-1..-1] == ')'
138
+ sotherthing = sotherthing[1..-2] if sotherthing[0..0] == '(' && sotherthing[-1..-1] == ')'
139
+ thing = Datatype::Karma.filter(:thing => sthing, :channel_id => message.target.pk).first
140
+ otherthing = Datatype::Karma.filter(:thing => sotherthing, :channel_id => message.target.pk).first
95
141
  if(thing && otherthing)
96
142
  set = Datatype::Alias.filter('(thing_id = ? AND aka_id = ?) OR (thing_id = ? AND aka_id = ?)', thing.pk, otherthing.pk, otherthing.pk, thing.pk)
97
143
  if(set.size < 1)
98
- reply message.replyto, "\2Error:\2 No alias found between #{params[:thing]} and #{params[:otherthing]}"
144
+ reply message.replyto, "\2Error:\2 No alias found between #{thing.thing} and #{otherthing.thing}"
99
145
  else
100
146
  set.destroy
101
- reply message.replyto, "#{params[:thing]} has been successfully dealiased from #{params[:otherthing]}"
147
+ reply message.replyto, "#{thing.thing} has been successfully dealiased from #{otherthing.thing}"
102
148
  end
103
149
  else
104
- reply message.replyto, "\2Error:\2 No alias found between #{params[:thing]} and #{params[:otherthing]}"
150
+ reply message.replyto, "\2Error:\2 No alias found between #{sthing} and #{sotherthing}"
105
151
  end
106
152
  end
107
-
153
+
108
154
  def show_aliases(message, params)
109
- thing = Datatype::Karma.filter(:thing => params[:thing].downcase, :channel_id => message.target.pk).first
155
+ thing = params[:thing].downcase
156
+ thing = thing[1..-2] if thing[0..0] == '(' && thing[-1..-1] == ')'
157
+ thing = Datatype::Karma.filter(:thing => thing, :channel_id => message.target.pk).first
110
158
  if(thing)
111
159
  things = []
112
160
  Datatype::Alias.get_aliases(thing.pk).each do |id|
113
161
  things << Datatype::Karma[id].thing
114
162
  end
115
163
  if(things.empty?)
116
- reply message.replyto, "#{params[:thing]} is not currently aliased"
164
+ reply message.replyto, "#{thing.thing} is not currently aliased"
117
165
  else
118
- reply message.replyto, "#{params[:thing]} is currently aliased to: #{things.join(', ')}"
166
+ reply message.replyto, "#{thing.thing} is currently aliased to: #{things.join(', ')}"
119
167
  end
120
168
  else
121
- reply message.replyto, "\2Error:\2 #{params[:thing]} has never been used and has no aliases"
169
+ reply message.replyto, "\2Error:\2 #{thing.thing} has never been used and has no aliases"
170
+ end
171
+ end
172
+
173
+ def egg(karma, message)
174
+ if(karma.downcase == 'chameleon')
175
+ reply message.replyto, @eggs[:chameleon][rand(@eggs[:chameleon].size - 1)]
122
176
  end
123
177
  end
124
178
 
@@ -131,7 +185,7 @@ class Karma < ModSpox::Plugin
131
185
  foreign_key :channel_id, :table => :channels
132
186
  index [:thing, :channel_id], :unique => true
133
187
  end
134
-
188
+
135
189
  def channel
136
190
  ModSpox::Models::Channel[channel_id]
137
191
  end
@@ -142,15 +196,15 @@ class Karma < ModSpox::Plugin
142
196
  foreign_key :thing_id, :null => false
143
197
  foreign_key :aka_id, :null => false
144
198
  end
145
-
199
+
146
200
  def thing
147
201
  Karma[thing_id]
148
202
  end
149
-
203
+
150
204
  def aka
151
205
  Karma[aka_id]
152
206
  end
153
-
207
+
154
208
  def Alias.score_object(object_id)
155
209
  Alias.create_lock unless class_variable_defined?(:@@lock)
156
210
  @@objects = []
@@ -160,16 +214,16 @@ class Karma < ModSpox::Plugin
160
214
  end
161
215
  return score
162
216
  end
163
-
217
+
164
218
  def Alias.get_aliases(object_id)
165
219
  Alias.score_object(object_id)
166
220
  objs = @@objects.dup
167
221
  objs.delete(object_id)
168
222
  return objs
169
223
  end
170
-
224
+
171
225
  private
172
-
226
+
173
227
  def Alias.sum_objects(object_id)
174
228
  return 0 if @@objects.include?(object_id)
175
229
  @@objects << object_id
@@ -183,11 +237,11 @@ class Karma < ModSpox::Plugin
183
237
  end
184
238
  return score
185
239
  end
186
-
240
+
187
241
  def Alias.create_lock
188
242
  @@lock = Mutex.new
189
243
  end
190
-
244
+
191
245
  end
192
246
  end
193
247
  end
@@ -31,11 +31,11 @@ class ChatLogger < ModSpox::Plugin
31
31
  type = 'action' if message.is_action?
32
32
  target = message.target.is_a?(Sequel::Model) ? message.target : Helpers.find_model(message.target)
33
33
  if(target.is_a?(Models::Channel))
34
- PublicLog.new(:message => message.message, :type => type, :sender => me.pk,
35
- :channel => target.pk, :received => Time.now).save
34
+ PublicLog.new(:message => message.message, :type => type, :sender_id => me.pk,
35
+ :channel_id => target.pk, :received => Time.now).save
36
36
  else
37
- PrivateLog.new(:message => message.message, :type => type, :sender => me.pk,
38
- :receiver => target.pk, :received => Time.now).save
37
+ PrivateLog.new(:message => message.message, :type => type, :sender_id => me.pk,
38
+ :receiver_id => target.pk, :received => Time.now).save
39
39
  end
40
40
  end
41
41
 
@@ -43,30 +43,30 @@ class ChatLogger < ModSpox::Plugin
43
43
  type = message.is_a?(Messages::Incoming::Privmsg) ? 'privmsg' : 'notice'
44
44
  type = 'action' if message.is_action?
45
45
  if(message.is_public?)
46
- PublicLog.new(:message => message.message, :type => type, :sender => message.source.pk,
47
- :channel => message.target.pk, :received => message.time).save
46
+ PublicLog.new(:message => message.message, :type => type, :sender_id => message.source.pk,
47
+ :channel_id => message.target.pk, :received => message.time).save
48
48
  else
49
- PrivateLog.new(:message => message.message, :type => type, :sender => message.source.pk,
50
- :receiver => message.target.pk, :received => message.time).save
49
+ PrivateLog.new(:message => message.message, :type => type, :sender_id => message.source.pk,
50
+ :receiver_id => message.target.pk, :received => message.time).save
51
51
  end
52
52
  end
53
53
 
54
54
  def log_join(message)
55
- PublicLog.new(:type => 'join', :sender => message.nick.pk, :channel => message.channel.pk, :received => message.time).save
55
+ PublicLog.new(:type => 'join', :sender_id => message.nick.pk, :channel_id => message.channel.pk, :received => message.time).save
56
56
  end
57
57
 
58
58
  def log_part(message)
59
- PublicLog.new(:message => message.reason, :type => 'part', :sender => message.nick.pk,
60
- :channel => message.channel.pk, :received => message.time).save
59
+ PublicLog.new(:message => message.reason, :type => 'part', :sender_id => message.nick.pk,
60
+ :channel_id => message.channel.pk, :received => message.time).save
61
61
  end
62
62
 
63
63
  def log_quit(message)
64
- PublicLog.new(:message => message.message, :type => 'quit', :sender => message.nick.pk, :received => message.time).save
64
+ PublicLog.new(:message => message.message, :type => 'quit', :sender_id => message.nick.pk, :received => message.time).save
65
65
  end
66
66
 
67
67
  def log_kick(message)
68
- PublicLog.new(:message => "#{message.kickee.pk}|#{message.reason}", :type => 'kick', :sender => message.kicker.pk,
69
- :channel => message.channel.pk, :received => message.time).save
68
+ PublicLog.new(:message => "#{message.kickee.pk}|#{message.reason}", :type => 'kick', :sender_id => message.kicker.pk,
69
+ :channel_id => message.channel.pk, :received => message.time).save
70
70
  end
71
71
 
72
72
  # TODO: Fix this
@@ -83,27 +83,27 @@ class ChatLogger < ModSpox::Plugin
83
83
  def seen(m, p)
84
84
  nick = Helpers.find_model(p[:nick], false)
85
85
  if(nick.is_a?(Models::Nick))
86
- record = PublicLog.filter(:sender => nick.pk).order(:received).last
87
- record_p = PrivateLog.filter(:sender => nick.pk).order(:received).last
86
+ record = PublicLog.filter(:sender_id => nick.pk).order(:received).last
87
+ record_p = PrivateLog.filter(:sender_id => nick.pk).order(:received).last
88
88
  record = record_p if !record || (record_p && record && record_p.received > record.received)
89
89
  if(record)
90
90
  if(record.is_a?(PublicLog))
91
91
  case record.values[:type]
92
92
  when 'join'
93
- message = "joining #{Channel[record.channel].name}"
93
+ message = "joining #{record.channel.name}"
94
94
  when 'part'
95
- message = "parting #{Channel[record.channel].name} with the message: #{record.message}"
95
+ message = "parting #{record.channel.name} with the message: #{record.message}"
96
96
  when 'privmsg'
97
- message = "in #{Channel[record.channel].name} saying: #{record.message}"
97
+ message = "in #{record.channel.name} saying: #{record.message}"
98
98
  when 'action'
99
- message = "in #{Channel[record.channel].name} saying: * #{p[:nick]} #{record.message}"
99
+ message = "in #{record.channel.name} saying: * #{p[:nick]} #{record.message}"
100
100
  when 'notice'
101
- message = "in #{Channel[record.channel].name} saying: #{record.message}"
101
+ message = "in #{record.channel.name} saying: #{record.message}"
102
102
  when 'kick'
103
103
  if(record.message =~ /^([0-9]+)\|/)
104
104
  kickee = Nick[$1.to_i]
105
105
  reason = $2
106
- message = "kicking #{kickee.nick} from #{Channel[record.channel].name} (#{record.message})"
106
+ message = "kicking #{kickee.nick} from #{record.channel.name} (#{record.message})"
107
107
  end
108
108
  end
109
109
  else
@@ -121,8 +121,8 @@ class ChatLogger < ModSpox::Plugin
121
121
  def spoke(m, p)
122
122
  nick = Helpers.find_model(p[:nick], false)
123
123
  if(nick.is_a?(Models::Nick))
124
- record = PublicLog.filter(:sender => nick.pk).filter("type in ('privmsg', 'action')").order(:received).last
125
- record_p = PrivateLog.filter(:sender => nick.pk).order(:received).last
124
+ record = PublicLog.filter(:sender_id => nick.pk).filter("type in ('privmsg', 'action')").order(:received).last
125
+ record_p = PrivateLog.filter(:sender_id => nick.pk).order(:received).last
126
126
  record = record_p if !record || (record_p && record && record_p.received > record.received)
127
127
  if(record)
128
128
  if(record.is_a?(PublicLog))
@@ -145,9 +145,16 @@ class ChatLogger < ModSpox::Plugin
145
145
  text :type, :null => false, :default => 'privmsg'
146
146
  boolean :action, :null => false, :default => false
147
147
  timestamp :received, :null => false
148
- foreign_key :sender, :table => :nicks
149
- foreign_key :receiver, :table => :nicks
150
- index :message, :type => :full_text
148
+ foreign_key :sender_id, :table => :nicks
149
+ foreign_key :receiver_id, :table => :nicks
150
+ end
151
+
152
+ def sender
153
+ Models::Nick[sender_id]
154
+ end
155
+
156
+ def receiver
157
+ Models::Nick[receiver_id]
151
158
  end
152
159
  end
153
160
 
@@ -158,10 +165,18 @@ class ChatLogger < ModSpox::Plugin
158
165
  text :type, :null => false, :default => 'privmsg'
159
166
  boolean :action, :null => false, :default => false
160
167
  timestamp :received, :null => false
161
- foreign_key :sender, :table => :nicks
162
- foreign_key :channel, :table => :channels
163
- index :message, :type => :full_text
168
+ foreign_key :sender_id, :table => :nicks
169
+ foreign_key :channel_id, :table => :channels
170
+ end
171
+
172
+ def sender
173
+ Models::Nick[sender_id]
174
+ end
175
+
176
+ def channel
177
+ Models::Channel[channel_id]
164
178
  end
179
+
165
180
  end
166
181
 
167
182
  end
@@ -8,7 +8,7 @@ class LolSpeak < ModSpox::Plugin
8
8
  begin
9
9
  require 'lolspeak'
10
10
  rescue Object => boom
11
- Logger.log('Error: This plugins requires the lolspeak gem. Please install gem and reload plugin.')
11
+ Logger.warn('Error: This plugins requires the lolspeak gem. Please install gem and reload plugin.')
12
12
  raise BotException.new("Failed to initialize plugin. Missing lolspeak gem.")
13
13
  end
14
14
  Signature.find_or_create(:signature => 'lolspeak (.+)', :plugin => name, :method => 'translate',