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.
- data/CHANGELOG +36 -0
- data/INSTALL +2 -2
- data/README +0 -1
- data/bin/mod_spox +51 -12
- data/data/mod_spox/extras/AOLSpeak.rb +5 -18
- data/data/mod_spox/extras/AutoKick.rb +44 -23
- data/data/mod_spox/extras/AutoMode.rb +2 -5
- data/data/mod_spox/extras/AutoRejoin.rb +21 -0
- data/data/mod_spox/extras/Bouncer.rb +10 -10
- data/data/mod_spox/extras/Bytes.rb +12 -0
- data/data/mod_spox/extras/Confess.rb +131 -52
- data/data/mod_spox/extras/DCC.rb +189 -0
- data/data/mod_spox/extras/DevWatch.rb +32 -33
- data/data/mod_spox/extras/FloodKicker.rb +129 -0
- data/data/mod_spox/extras/GoogleIt.rb +13 -0
- data/data/mod_spox/extras/Headers.rb +31 -4
- data/data/mod_spox/extras/Karma.rb +103 -49
- data/data/mod_spox/extras/Logger.rb +45 -30
- data/data/mod_spox/extras/LolSpeak.rb +1 -1
- data/data/mod_spox/extras/NickServ.rb +83 -0
- data/data/mod_spox/extras/PhpCli.rb +12 -15
- data/data/mod_spox/extras/PhpFuncLookup.rb +57 -25
- data/data/mod_spox/extras/Quotes.rb +5 -4
- data/data/mod_spox/extras/RegexTracker.rb +160 -0
- data/data/mod_spox/extras/Roulette.rb +22 -23
- data/data/mod_spox/extras/Search.rb +3 -2
- data/data/mod_spox/extras/Slashdot.rb +35 -0
- data/data/mod_spox/extras/Topten.rb +5 -5
- data/data/mod_spox/extras/TracTicket.rb +68 -0
- data/data/mod_spox/extras/Translate.rb +69 -30
- data/data/mod_spox/extras/Twitter.rb +372 -0
- data/data/mod_spox/extras/UrbanDictionary.rb +21 -12
- data/data/mod_spox/extras/Weather.rb +1 -1
- data/data/mod_spox/plugins/Authenticator.rb +63 -30
- data/data/mod_spox/plugins/Banner.rb +164 -151
- data/data/mod_spox/plugins/Helper.rb +18 -7
- data/data/mod_spox/plugins/PluginLoader.rb +46 -22
- data/data/mod_spox/plugins/PoolConfig.rb +52 -0
- data/data/mod_spox/plugins/Quitter.rb +1 -1
- data/data/mod_spox/plugins/Status.rb +28 -0
- data/lib/mod_spox/Action.rb +20 -3
- data/lib/mod_spox/BaseConfig.rb +1 -0
- data/lib/mod_spox/Bot.rb +98 -75
- data/lib/mod_spox/BotConfig.rb +14 -6
- data/lib/mod_spox/ConfigurationWizard.rb +94 -105
- data/lib/mod_spox/Database.rb +33 -13
- data/lib/mod_spox/Helpers.rb +67 -38
- data/lib/mod_spox/Loader.rb +25 -5
- data/lib/mod_spox/Logger.rb +20 -62
- data/lib/mod_spox/MessageFactory.rb +34 -25
- data/lib/mod_spox/Monitors.rb +5 -0
- data/lib/mod_spox/Pipeline.rb +40 -51
- data/lib/mod_spox/Plugin.rb +40 -9
- data/lib/mod_spox/PluginManager.rb +46 -38
- data/lib/mod_spox/Pool.rb +129 -143
- data/lib/mod_spox/Socket.rb +41 -50
- data/lib/mod_spox/Sockets.rb +211 -0
- data/lib/mod_spox/Timer.rb +86 -69
- data/lib/mod_spox/handlers/BadNick.rb +1 -1
- data/lib/mod_spox/handlers/Created.rb +1 -1
- data/lib/mod_spox/handlers/Handler.rb +9 -0
- data/lib/mod_spox/handlers/Invite.rb +1 -1
- data/lib/mod_spox/handlers/Join.rb +2 -2
- data/lib/mod_spox/handlers/Kick.rb +1 -1
- data/lib/mod_spox/handlers/LuserChannels.rb +1 -1
- data/lib/mod_spox/handlers/LuserOp.rb +1 -1
- data/lib/mod_spox/handlers/LuserUnknown.rb +1 -1
- data/lib/mod_spox/handlers/Mode.rb +2 -2
- data/lib/mod_spox/handlers/MyInfo.rb +1 -1
- data/lib/mod_spox/handlers/Names.rb +1 -1
- data/lib/mod_spox/handlers/Nick.rb +20 -3
- data/lib/mod_spox/handlers/NickInUse.rb +3 -3
- data/lib/mod_spox/handlers/Notice.rb +5 -15
- data/lib/mod_spox/handlers/Part.rb +1 -1
- data/lib/mod_spox/handlers/Ping.rb +1 -1
- data/lib/mod_spox/handlers/Pong.rb +1 -1
- data/lib/mod_spox/handlers/Privmsg.rb +2 -2
- data/lib/mod_spox/handlers/Quit.rb +1 -1
- data/lib/mod_spox/handlers/Topic.rb +2 -1
- data/lib/mod_spox/handlers/Welcome.rb +3 -3
- data/lib/mod_spox/handlers/Who.rb +9 -7
- data/lib/mod_spox/handlers/Whois.rb +29 -16
- data/lib/mod_spox/handlers/YourHost.rb +1 -1
- data/lib/mod_spox/messages/incoming/Privmsg.rb +38 -19
- data/lib/mod_spox/messages/internal/DCCListener.rb +12 -0
- data/lib/mod_spox/messages/internal/DCCRequest.rb +12 -0
- data/lib/mod_spox/messages/internal/DCCSocket.rb +19 -0
- data/lib/mod_spox/messages/internal/StatusRequest.rb +2 -1
- data/lib/mod_spox/messages/outgoing/Privmsg.rb +21 -5
- data/lib/mod_spox/migrations/001_initialize_models.rb +115 -0
- data/lib/mod_spox/models/Auth.rb +24 -16
- data/lib/mod_spox/models/AuthGroup.rb +4 -3
- data/lib/mod_spox/models/Channel.rb +20 -12
- data/lib/mod_spox/models/ChannelMode.rb +2 -2
- data/lib/mod_spox/models/Config.rb +11 -3
- data/lib/mod_spox/models/Group.rb +6 -1
- data/lib/mod_spox/models/Nick.rb +93 -33
- data/lib/mod_spox/models/NickChannel.rb +8 -6
- data/lib/mod_spox/models/NickGroup.rb +16 -0
- data/lib/mod_spox/models/NickMode.rb +3 -3
- data/lib/mod_spox/models/Server.rb +6 -2
- data/lib/mod_spox/models/Setting.rb +12 -6
- data/lib/mod_spox/models/Signature.rb +7 -13
- data/lib/mod_spox/models/Trigger.rb +1 -1
- 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
|
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
|
-
|
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
|
11
|
-
Models::Signature.find_or_create(:signature => 'karma reset (\S
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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#{
|
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 #{
|
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 =>
|
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 #{
|
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 =
|
72
|
-
thang =
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
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 =
|
83
|
-
thang =
|
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 #{
|
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 #{
|
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
|
-
|
94
|
-
|
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 #{
|
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, "#{
|
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 #{
|
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 =
|
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, "#{
|
164
|
+
reply message.replyto, "#{thing.thing} is not currently aliased"
|
117
165
|
else
|
118
|
-
reply message.replyto, "#{
|
166
|
+
reply message.replyto, "#{thing.thing} is currently aliased to: #{things.join(', ')}"
|
119
167
|
end
|
120
168
|
else
|
121
|
-
reply message.replyto, "\2Error:\2 #{
|
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, :
|
35
|
-
:
|
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, :
|
38
|
-
:
|
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, :
|
47
|
-
:
|
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, :
|
50
|
-
:
|
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', :
|
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', :
|
60
|
-
:
|
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', :
|
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', :
|
69
|
-
:
|
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(:
|
87
|
-
record_p = PrivateLog.filter(:
|
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 #{
|
93
|
+
message = "joining #{record.channel.name}"
|
94
94
|
when 'part'
|
95
|
-
message = "parting #{
|
95
|
+
message = "parting #{record.channel.name} with the message: #{record.message}"
|
96
96
|
when 'privmsg'
|
97
|
-
message = "in #{
|
97
|
+
message = "in #{record.channel.name} saying: #{record.message}"
|
98
98
|
when 'action'
|
99
|
-
message = "in #{
|
99
|
+
message = "in #{record.channel.name} saying: * #{p[:nick]} #{record.message}"
|
100
100
|
when 'notice'
|
101
|
-
message = "in #{
|
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 #{
|
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(:
|
125
|
-
record_p = PrivateLog.filter(:
|
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 :
|
149
|
-
foreign_key :
|
150
|
-
|
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 :
|
162
|
-
foreign_key :
|
163
|
-
|
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.
|
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',
|