mod_spox 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CHANGELOG +31 -1
  2. data/LICENSE +674 -0
  3. data/README.rdoc +73 -0
  4. data/bin/mod_spox +28 -28
  5. data/data/mod_spox/extras/AOLSpeak.rb +2 -3
  6. data/data/mod_spox/extras/AutoKick.rb +10 -23
  7. data/data/mod_spox/extras/AutoMode.rb +12 -23
  8. data/data/mod_spox/extras/Bash.rb +55 -0
  9. data/data/mod_spox/extras/Bouncer.rb +85 -57
  10. data/data/mod_spox/extras/Bullshit.rb +1 -1
  11. data/data/mod_spox/extras/Bytes.rb +1 -2
  12. data/data/mod_spox/extras/Confess.rb +27 -29
  13. data/data/mod_spox/extras/DCC.rb +11 -20
  14. data/data/mod_spox/extras/DevWatch.rb +21 -23
  15. data/data/mod_spox/extras/DownForEveryoneOrJustMe.rb +47 -0
  16. data/data/mod_spox/extras/EightBall.rb +1 -1
  17. data/data/mod_spox/extras/FML.rb +35 -0
  18. data/data/mod_spox/extras/Headers.rb +31 -50
  19. data/data/mod_spox/extras/Karma.rb +81 -29
  20. data/data/mod_spox/extras/Logger.rb +2 -2
  21. data/data/mod_spox/extras/LolSpeak.rb +1 -2
  22. data/data/mod_spox/extras/PhpCli.rb +138 -8
  23. data/data/mod_spox/extras/PhpFuncLookup.rb +20 -23
  24. data/data/mod_spox/extras/Pinger.rb +1 -1
  25. data/data/mod_spox/extras/Quotes.rb +8 -10
  26. data/data/mod_spox/extras/RegexTracker.rb +2 -4
  27. data/data/mod_spox/extras/Roulette.rb +20 -27
  28. data/data/mod_spox/extras/RubyCli.rb +93 -0
  29. data/data/mod_spox/extras/Search.rb +17 -3
  30. data/data/mod_spox/extras/Seen.rb +150 -0
  31. data/data/mod_spox/extras/SlashdotHeadlineGenerator.rb +500 -0
  32. data/data/mod_spox/extras/Talk.rb +2 -4
  33. data/data/mod_spox/extras/Topten.rb +10 -12
  34. data/data/mod_spox/extras/TracTicket.rb +3 -5
  35. data/data/mod_spox/extras/Translate.rb +20 -22
  36. data/data/mod_spox/extras/Twitter.rb +118 -33
  37. data/data/mod_spox/extras/UrbanDictionary.rb +8 -17
  38. data/data/mod_spox/extras/Weather.rb +1 -2
  39. data/data/mod_spox/plugins/Authenticator.rb +93 -98
  40. data/data/mod_spox/plugins/Banner.rb +26 -56
  41. data/data/mod_spox/plugins/Helper.rb +5 -6
  42. data/data/mod_spox/plugins/Initializer.rb +4 -14
  43. data/data/mod_spox/plugins/Joiner.rb +1 -1
  44. data/data/mod_spox/plugins/Nicker.rb +13 -0
  45. data/data/mod_spox/plugins/Parter.rb +2 -2
  46. data/data/mod_spox/plugins/Permissions.rb +60 -0
  47. data/data/mod_spox/plugins/PluginLoader.rb +7 -12
  48. data/data/mod_spox/plugins/Ponger.rb +51 -0
  49. data/data/mod_spox/plugins/Quitter.rb +1 -2
  50. data/data/mod_spox/plugins/Servers.rb +57 -0
  51. data/data/mod_spox/plugins/Status.rb +3 -2
  52. data/data/mod_spox/plugins/Triggers.rb +9 -9
  53. data/lib/mod_spox/Bot.rb +109 -33
  54. data/lib/mod_spox/BotConfig.rb +2 -2
  55. data/lib/mod_spox/ConfigurationWizard.rb +12 -12
  56. data/lib/mod_spox/Database.rb +1 -4
  57. data/lib/mod_spox/Exceptions.rb +26 -0
  58. data/lib/mod_spox/Helpers.rb +29 -68
  59. data/lib/mod_spox/Loader.rb +23 -24
  60. data/lib/mod_spox/Logger.rb +19 -17
  61. data/lib/mod_spox/MessageFactory.rb +50 -24
  62. data/lib/mod_spox/Pipeline.rb +21 -7
  63. data/lib/mod_spox/Plugin.rb +27 -3
  64. data/lib/mod_spox/PluginManager.rb +28 -15
  65. data/lib/mod_spox/PriorityQueue.rb +69 -0
  66. data/lib/mod_spox/Socket.rb +93 -51
  67. data/lib/mod_spox/Sockets.rb +76 -63
  68. data/lib/mod_spox/Timer.rb +21 -141
  69. data/lib/mod_spox/Version.rb +14 -0
  70. data/lib/mod_spox/handlers/BadNick.rb +1 -1
  71. data/lib/mod_spox/handlers/Bounce.rb +5 -5
  72. data/lib/mod_spox/handlers/Created.rb +13 -5
  73. data/lib/mod_spox/handlers/Handler.rb +12 -3
  74. data/lib/mod_spox/handlers/Invite.rb +14 -8
  75. data/lib/mod_spox/handlers/Join.rb +24 -20
  76. data/lib/mod_spox/handlers/Kick.rb +22 -13
  77. data/lib/mod_spox/handlers/Mode.rb +42 -36
  78. data/lib/mod_spox/handlers/Motd.rb +4 -0
  79. data/lib/mod_spox/handlers/Names.rb +66 -39
  80. data/lib/mod_spox/handlers/Nick.rb +20 -14
  81. data/lib/mod_spox/handlers/Part.rb +25 -8
  82. data/lib/mod_spox/handlers/Ping.rb +11 -5
  83. data/lib/mod_spox/handlers/Pong.rb +9 -5
  84. data/lib/mod_spox/handlers/Privmsg.rb +25 -17
  85. data/lib/mod_spox/handlers/Quit.rb +13 -8
  86. data/lib/mod_spox/handlers/Topic.rb +4 -0
  87. data/lib/mod_spox/handlers/Welcome.rb +16 -24
  88. data/lib/mod_spox/handlers/Who.rb +64 -48
  89. data/lib/mod_spox/handlers/Whois.rb +92 -60
  90. data/lib/mod_spox/messages/incoming/Nick.rb +2 -2
  91. data/lib/mod_spox/messages/incoming/Privmsg.rb +1 -1
  92. data/lib/mod_spox/messages/incoming/Whois.rb +1 -0
  93. data/lib/mod_spox/messages/internal/EstablishConnection.rb +1 -1
  94. data/lib/mod_spox/messages/internal/PluginsReady.rb +10 -0
  95. data/lib/mod_spox/messages/internal/QueueSocket.rb +8 -0
  96. data/lib/mod_spox/messages/internal/Reconnect.rb +8 -0
  97. data/lib/mod_spox/messages/internal/UnqueueSocket.rb +8 -0
  98. data/lib/mod_spox/migrations/002_persistent_sigs.rb +14 -0
  99. data/lib/mod_spox/migrations/003_auth_restructure.rb +31 -0
  100. data/lib/mod_spox/migrations/004_mode_index_fix.rb +18 -0
  101. data/lib/mod_spox/migrations/005_nick_mode_nopark.rb +18 -0
  102. data/lib/mod_spox/models/Auth.rb +16 -46
  103. data/lib/mod_spox/models/AuthMask.rb +13 -0
  104. data/lib/mod_spox/models/Channel.rb +46 -27
  105. data/lib/mod_spox/models/Config.rb +10 -19
  106. data/lib/mod_spox/models/Group.rb +20 -8
  107. data/lib/mod_spox/models/Models.rb +1 -1
  108. data/lib/mod_spox/models/Nick.rb +105 -113
  109. data/lib/mod_spox/models/NickMode.rb +23 -9
  110. data/lib/mod_spox/models/Server.rb +12 -1
  111. data/lib/mod_spox/models/Setting.rb +12 -16
  112. data/lib/mod_spox/models/Signature.rb +28 -8
  113. data/tests/BotHolder.rb +24 -0
  114. data/tests/handlers/tc_BadNick.rb +21 -0
  115. data/tests/handlers/tc_Created.rb +24 -0
  116. data/tests/handlers/tc_Invite.rb +50 -0
  117. data/tests/handlers/tc_Join.rb +33 -0
  118. data/tests/handlers/tc_Kick.rb +32 -0
  119. data/tests/handlers/tc_Mode.rb +85 -0
  120. data/tests/handlers/tc_Names.rb +35 -0
  121. data/tests/handlers/tc_Nick.rb +55 -0
  122. data/tests/handlers/tc_Part.rb +44 -0
  123. data/tests/handlers/tc_Ping.rb +40 -0
  124. data/tests/handlers/tc_Pong.rb +28 -0
  125. data/tests/handlers/tc_Privmsg.rb +85 -0
  126. data/tests/handlers/tc_Quit.rb +40 -0
  127. data/tests/handlers/tc_Who.rb +50 -0
  128. data/tests/handlers/tc_Whois.rb +61 -0
  129. data/tests/models/tc_Auth.rb +34 -0
  130. data/tests/models/tc_Channel.rb +52 -0
  131. data/tests/models/tc_Config.rb +19 -0
  132. data/tests/models/tc_Nick.rb +142 -0
  133. data/tests/models/tc_NickMode.rb +40 -0
  134. data/tests/models/tc_Setting.rb +21 -0
  135. data/tests/models/tc_Signature.rb +14 -0
  136. data/tests/run_tests.rb +4 -0
  137. metadata +284 -212
  138. data/README +0 -36
  139. data/lib/mod_spox/Cache.rb +0 -57
  140. data/lib/mod_spox/Monitors.rb +0 -84
  141. data/lib/mod_spox/Pool.rb +0 -164
  142. data/lib/mod_spox/models/AuthGroup.rb +0 -16
  143. data/lib/mod_spox/models/ChannelMode.rb +0 -14
  144. data/lib/mod_spox/models/NickChannel.rb +0 -45
  145. data/lib/mod_spox/models/NickGroup.rb +0 -16
@@ -7,7 +7,7 @@ class Bullshit < ModSpox::Plugin
7
7
  include ModSpox::Models
8
8
  def initialize(pipeline)
9
9
  super(pipeline)
10
- Signature.find_or_create(:signature => 'bullshit', :plugin => name, :method => 'bullshit', :description => 'Web economy bullshit generator')
10
+ add_sig(:sig => 'bullshit', :method => :bullshit, :desc => 'Web economy bullshit generator')
11
11
  @bs = [[ "aggregate","architect","benchmark","brand","cultivate","deliver","deploy","disintermediate","drive","e-enable","embrace","empower","enable","engage","engineer","enhance","envisioneer","evolve","expedite","exploit","extend","facilitate","generate","grow","harness","implement","incentivize","incubate","innovate","integrate","iterate","leverage","matrix","maximize","mesh","monetize","morph","optimize","orchestrate","productize","recontextualize","redefine","reintermediate","reinvent","repurpose","revolutionize","scale","seize","strategize","streamline","syndicate","synergize","synthesize","target","transform","transition","unleash","utilize","visualize","whiteboard" ],
12
12
  [ "24/365","24/7","B2B","B2C","back-end","best-of-breed","bleeding-edge","bricks-and-clicks","clicks-and-mortar","collaborative","compelling","cross-platform","cross-media","customized","cutting-edge","distributed","dot-com","dynamic","e-business","efficient","end-to-end","enterprise","extensible","frictionless","front-end","global","granular","holistic","impactful","innovative","integrated","interactive","intuitive","killer","leading-edge","magnetic","mission-critical","next-generation","one-to-one","open-source","out-of-the-box","plug-and-play","proactive","real-time","revolutionary","rich","robust","scalable","seamless","sexy","sticky","strategic","synergistic","transparent","turn-key","ubiquitous","user-centric","value-added","vertical","viral","virtual","visionary","web-enabled","wireless","world-class" ],
13
13
  [ "action-items","applications","architectures","bandwidth","channels","communities","content","convergence","deliverables","e-business","e-commerce","e-markets","e-services","e-tailers","experiences","eyeballs","functionalities","infomediaries","infrastructures","initiatives","interfaces","markets","methodologies","metrics","mindshare","models","networks","niches","paradigms","partnerships","platforms","portals","relationships","ROI","synergies","web-readiness","schemas","solutions","supply-chains","systems","technologies","users","vortals","web services" ]]
@@ -2,8 +2,7 @@ class Bytes < ModSpox::Plugin
2
2
  include Models
3
3
  def initialize(args)
4
4
  super
5
- Signature.find_or_create(:signature => 'bytes (\d+)', :plugin => name, :method => 'convert',
6
- :description => 'Convert bytes to human readable string').params = [:bytes]
5
+ add_sig(:sig => 'bytes (\d+)', :method => :convert, :desc => 'Convert bytes to human readable string', :params => [:bytes])
7
6
  end
8
7
 
9
8
  def convert(message, params)
@@ -10,12 +10,6 @@ class Confess < ModSpox::Plugin
10
10
 
11
11
  def initialize(pipeline)
12
12
  super(pipeline)
13
- begin
14
- require 'htmlentities'
15
- rescue Object => boom
16
- Logger.warn('Error: This plugin requires the HTMLEntities gem. Please install and reload plugin.')
17
- raise Exceptions::BotException.new("Missing required HTMLEntities library")
18
- end
19
13
  begin
20
14
  Confession.db = Sequel.sqlite(BotConfig[:userpath] + '/confessions.db')
21
15
  rescue Object => boom
@@ -23,25 +17,19 @@ class Confess < ModSpox::Plugin
23
17
  raise Exceptions::BotException.new("Failed to create database: #{boom}")
24
18
  end
25
19
  Confession.build_confession && Confession.create_table unless Confession.table_exists?
26
- Signature.find_or_create(:signature => 'confess', :plugin => name, :method => 'confess',
27
- :description => 'Print a confession')
28
- Signature.find_or_create(:signature => 'confess (?!score|count|fetcher|\+\+|\-\-)(.+)?', :plugin => name, :method => 'confess',
29
- :description => 'Print a confession').params = [:term]
30
- Signature.find_or_create(:signature => 'confess(\+\+|\-\-) ?(\d+)?', :plugin => name, :method => 'score',
31
- :description => 'Score a confession').params = [:score, :id]
32
- Signature.find_or_create(:signature => 'confess score (\d+)', :plugin => name, :method => 'show_score',
33
- :description => 'Show a confession\'s score').params = [:id]
34
- Signature.find_or_create(:signature => 'confess count', :plugin => name, :method => 'count',
35
- :description => 'Current count of cached confessions')
36
- Signature.find_or_create(:signature => 'confess fetcher (start|stop)', :plugin => name, :method => 'fetcher',
37
- :description => 'Turn confession fetcher on or off', :group_id => Group.filter(:name => 'admin').first.pk).params = [:status]
38
- Config[:confess] = 'nofetch' if Config[:confess].nil?
20
+ add_sig(:sig => 'confess', :method => :confess, :desc => 'Print a confession')
21
+ add_sig(:sig => 'confess (?!score|count|fetcher|\+\+|\-\-)(.+)?', :method => :confess, :desc => 'Print a confession', :params => [:term])
22
+ add_sig(:sig => 'confess(\+\+|\-\-) ?(\d+)?', :method => :score, :desc => 'Score a confession', :params => [:score, :id])
23
+ add_sig(:sig => 'confess score (\d+)', :method => :show_score, :desc => 'Show a confession\'s score', :params => [:id])
24
+ add_sig(:sig => 'confess count', :method => :count, :desc => 'Current count of cached confessions')
25
+ add_sig(:sig => 'confess fetcher (start|stop)', :method => :fetcher, :desc => 'Turn confession fetcher on or off', :group => Group.filter(:name => 'admin').first, :params => [:status])
26
+ add_sig(:sig => 'confess count (.+)', :method => :count_matches, :desc => 'Show number entries matching search', :params => [:query])
27
+ Config.set(:confess, 'nofetch') if Config.val(:confess).nil?
39
28
  @last_confession = {}
40
29
  @fetch = false
41
- @coder = HTMLEntities.new
42
30
  @timer = {:action => nil, :id => nil}
43
31
  @lock = Mutex.new
44
- start_fetcher if Config[:confess] == 'fetch'
32
+ start_fetcher if Config.val(:confess) == 'fetch'
45
33
  end
46
34
 
47
35
  def destroy
@@ -85,6 +73,16 @@ class Confess < ModSpox::Plugin
85
73
  end
86
74
  end
87
75
 
76
+ def count_matches(m, params)
77
+ begin
78
+ @lock.synchronize do
79
+ reply m.replyto, "Number of matches for \2#{params[:query]}\2: #{Confession.search(params[:query]).size}"
80
+ end
81
+ rescue Object => boom
82
+ error m.replyto, "Failed to count matches. Reason: #{boom}"
83
+ end
84
+ end
85
+
88
86
  def show_score(message, params)
89
87
  pk = nil
90
88
  score = nil
@@ -115,11 +113,11 @@ class Confess < ModSpox::Plugin
115
113
  if(c)
116
114
  @lock.synchronize do
117
115
  if(params[:score] == '++')
118
- c.update_with_params(:positive => c.positive.to_i + 1)
116
+ c.update(:positive => c.positive.to_i + 1)
119
117
  else
120
- c.update_with_params(:negative => c.negative.to_i + 1)
118
+ c.update(:negative => c.negative.to_i + 1)
121
119
  end
122
- c.update_with_params(:score => ((c.positive.to_f) / (c.positive.to_f + c.negative.to_f)) * 100.0)
120
+ c.update(:score => ((c.positive.to_f) / (c.positive.to_f + c.negative.to_f)) * 100.0)
123
121
  end
124
122
  else
125
123
  reply message.replyto, "\2Error:\2 Failed to find confession to score"
@@ -136,16 +134,16 @@ class Confess < ModSpox::Plugin
136
134
 
137
135
  def fetcher(message, params)
138
136
  if(params[:status] == 'start')
139
- if(Config[:confess] == 'fetch')
137
+ if(Config.val(:confess) == 'fetch')
140
138
  reply message.replyto, 'Confession fetcher is already running'
141
139
  else
142
- Config[:confess] = 'fetch'
140
+ Config.set(:confess, 'fetch')
143
141
  reply message.replyto, 'Confession fetcher is now running'
144
142
  start_fetcher
145
143
  end
146
144
  else
147
- if(Config[:confess] == 'fetch')
148
- Config[:confess] = 'nofetch'
145
+ if(Config.val(:confess) == 'fetch')
146
+ Config.set(:confess, 'nofetch')
149
147
  stop_fetcher
150
148
  reply message.replyto, 'Confession fetcher has been stopped'
151
149
  else
@@ -165,7 +163,7 @@ class Confess < ModSpox::Plugin
165
163
  Logger.info("Match found: #{match[0]}")
166
164
  conf = CGI::unescapeHTML(match[0])
167
165
  conf = conf.gsub(/<.+?>/, ' ').gsub(/[\r\n]/, '').gsub(/\s+/, ' ')
168
- conf = @coder.decode(conf)
166
+ conf = Helpers.convert_entities(conf)
169
167
  Logger.info("Match turned into: #{conf}")
170
168
  if conf.length < 300
171
169
  begin
@@ -8,30 +8,21 @@ class DCC < ModSpox::Plugin
8
8
  super
9
9
  group = Group.find_or_create(:name => 'dcc')
10
10
  admin = Group.find_or_create(:name => 'admin')
11
- Signature.find_or_create(:signature => 'file list(\s(.+))?', :plugin => name, :method => 'file_list',
12
- :description => 'List available DCC files', :group_id => group.pk).params = [:pattern]
13
- Signature.find_or_create(:signature => 'file get (.+)', :plugin => name, :method => 'file_get',
14
- :description => 'Download file', :group_id => group.pk).params = [:filename]
15
- Signature.find_or_create(:signature => 'file ports (\d+)-(\d+)', :plugin => name, :method => 'set_ports',
16
- :description => 'Set allowed DCC ports', :group_id => admin.pk).params = [:start, :end]
17
- Signature.find_or_create(:signature => 'file adddir (.+)', :plugin => name, :method => 'add_dir',
18
- :description => 'Add directory to file list', :group_id => admin.pk).params = [:dir]
19
- Signature.find_or_create(:signature => 'file rmdir (\d+)', :plugin => name, :method => 'rm_dir',
20
- :description => 'Remove directory from file list', :group_id => admin.pk).params = [:dir]
21
- Signature.find_or_create(:signature => 'file show dir', :plugin => name, :method => 'show_dirs',
22
- :description => 'Show directories available to file list', :group_id => admin.pk)
23
- Signature.find_or_create(:signature => 'file show ports', :plugin => name, :method => 'show_ports',
24
- :description => 'Show allowed ports', :group_id => admin.pk)
25
- Signature.find_or_create(:signature => 'file max wait(\s(\d+))?', :plugin => name, :method => 'max_wait',
26
- :description => 'Show/set timeout for accepting files', :group_id => admin.pk).params = [:wait]
27
- Signature.find_or_create(:signature => 'dcc chat', :plugin => name, :method => 'dcc_chat',
28
- :description => 'Start a DCC chat with the bot (useful if behind firewall', :group_id => group.pk)
11
+ add_sig(:sig => 'file list(\s(.+))?', :method => :file_list, :desc => 'List available DCC files', :group => group, :params => [:pattern])
12
+ add_sig(:sig => 'file get (.+)', :method => :file_get, :desc => 'Download file', :group => group, :params => [:filename])
13
+ add_sig(:sig => 'file ports (\d+)-(\d+)', :method => :set_ports, :desc => 'Set allowed DCC ports', :group => admin, :params => [:start, :end])
14
+ add_sig(:sig => 'file adddir (.+)', :method => :add_dir, :desc => 'Add directory to file list', :group => admin, :params => [:dir])
15
+ add_sig(:sig => 'file rmdir (\d+)', :method => :rm_dir, :desc => 'Remove directory from file list', :group => admin, :params => [:dir])
16
+ add_sig(:sig => 'file show dir', :method => :show_dirs, :desc => 'Show directories available to file list', :group => admin)
17
+ add_sig(:sig => 'file show ports', :method => :show_ports, :desc => 'Show allowed ports', :group => admin)
18
+ add_sig(:sig => 'file max wait(\s(\d+))?', :method => :max_wait, :desc => 'Show/set timeout for accepting files', :group => admin, :params => [:wait])
19
+ add_sig(:sig => 'dcc chat', :method => :dcc_chat, :desc => 'Start a DCC chat with the bot (useful if behind firewall', :group => group)
29
20
  @servers = {}
30
- @ports = Setting[:dcc_ports]
21
+ @ports = Setting.val(:dcc_ports)
31
22
  @ports = {:start => 49152, :end => 65535} if @ports.nil?
32
23
  @dirs = Setting.find_or_create(:name => 'dcc_dirs').value
33
24
  @dirs = [] unless @dirs.is_a?(Array)
34
- @max_wait = Setting[:dcc_max_wait]
25
+ @max_wait = Setting.val(:dcc_max_wait)
35
26
  @max_wait = @max_wait.nil? ? 60 : @max_wait.to_i
36
27
  end
37
28
 
@@ -8,27 +8,24 @@ class DevWatch < ModSpox::Plugin
8
8
  def initialize(pipeline)
9
9
  super(pipeline)
10
10
  admin = Group.filter(:name => 'admin').first
11
- Signature.find_or_create(:signature => 'devwatch (on|off) (\S+)', :plugin => name, :method => 'enable_watch', :group_id => admin.pk,
12
- :description => 'Turn development watcher on/off in given channel').params = [:status, :channel]
13
- Signature.find_or_create(:signature => 'devwatch list', :plugin => name, :method => 'watch_list', :group_id => admin.pk,
14
- :description => 'List all channels on the development watch list')
15
- Signature.find_or_create(:signature => 'devwatch url ?(\S+)?', :plugin => name, :method => 'set_url', :group_id => admin.pk,
16
- :description => 'Set URL for development RSS feed').params = [:url]
17
- Signature.find_or_create(:signature => 'devwatch interval ?(\d+)?', :plugin => name, :method => 'set_interval', :group_id => admin.pk,
18
- :description => 'Set time interval for notifications').params = [:time]
19
- if(Setting[:devwatch].nil?)
11
+ add_sig(:sig => 'devwatch (on|off) (\S+)', :method => :enable_watch, :group => admin, :desc => 'Turn development watcher on/off in given channel', :params => [:status, :channel])
12
+ add_sig(:sig => 'devwatch list', :method => :watch_list, :group => admin, :desc => 'List all channels on the development watch list')
13
+ add_sig(:sig => 'devwatch url ?(\S+)?', :method => :set_url, :group => admin, :desc => 'Set URL for development RSS feed', :params => [:url])
14
+ add_sig(:sig => 'devwatch interval ?(\d+)?', :method => :set_interval, :group => admin, :desc => 'Set time interval for notifications', :params => [:time])
15
+ if(Setting.val(:devwatch).nil?)
20
16
  Setting.find_or_create(:name => 'devwatch').value = {:channels => [], :interval => 300}
21
17
  end
22
18
  @original = nil
23
19
  @new = nil
24
20
  @timer = {:action => nil, :id => nil}
25
21
  start_auto
22
+ check_updates
26
23
  end
27
24
 
28
25
  def enable_watch(message, params)
29
26
  channel = Channel.filter(:name => params[:channel]).first
30
27
  if(channel)
31
- vals = Setting[:devwatch]
28
+ vals = Setting.val(:devwatch)
32
29
  if(params[:status] == 'on')
33
30
  vals[:channels] << channel.pk unless vals[:channels].include?(channel.pk)
34
31
  reply(message.replyto, "#{channel.name} is now on the development watch list")
@@ -44,25 +41,25 @@ class DevWatch < ModSpox::Plugin
44
41
  end
45
42
 
46
43
  def watch_list(message, params)
47
- if(Setting[:devwatch][:channels].empty?)
44
+ if(Setting.val(:devwatch)[:channels].empty?)
48
45
  reply(message.replyto, "No channels currently on the development watch list")
49
46
  else
50
47
  chans = []
51
- Setting[:devwatch][:channels].each{|id| chans << Channel[id].name}
48
+ Setting.val(:devwatch)[:channels].each{|id| chans << Channel[id].name}
52
49
  reply(message.replyto, "Channels on development watch list: #{chans.join(', ')}")
53
50
  end
54
51
  end
55
52
 
56
53
  def set_url(message, params)
57
54
  if(params[:url])
58
- vals = Setting[:devwatch]
55
+ vals = Setting.val(:devwatch)
59
56
  vals[:url] = params[:url]
60
57
  reply(message.replyto, "OK")
61
58
  Setting.filter(:name => 'devwatch').first.value = vals
62
59
  update_auto
63
60
  else
64
- if(Setting[:devwatch].has_key?(:url))
65
- reply(message.replyto, "\2Devwatch URL:\2 #{Setting[:devwatch][:url]}")
61
+ if(Setting.val(:devwatch).has_key?(:url))
62
+ reply(message.replyto, "\2Devwatch URL:\2 #{Setting.val(:devwatch)[:url]}")
66
63
  else
67
64
  reply(message.replyto, "\2Error:\2 No URL set for devwatch")
68
65
  end
@@ -71,7 +68,7 @@ class DevWatch < ModSpox::Plugin
71
68
 
72
69
  def set_interval(message, params)
73
70
  if(params[:time])
74
- vals = Setting[:devwatch]
71
+ vals = Setting.val(:devwatch)
75
72
  vals[:interval] = params[:time].to_i
76
73
  Setting.filter(:name => 'devwatch').first.value = vals
77
74
  if(@timer[:action].nil?)
@@ -81,13 +78,13 @@ class DevWatch < ModSpox::Plugin
81
78
  end
82
79
  reply(message.replyto, "Devwatch announcement interval reset to: #{Helpers.format_seconds(params[:time].to_i)}")
83
80
  else
84
- reply(message.replyto, "Devwatch announcement interval set to: #{Helpers.format_seconds(Setting[:devwatch][:interval].to_i)}")
81
+ reply(message.replyto, "Devwatch announcement interval set to: #{Helpers.format_seconds(Setting.val(:devwatch)[:interval].to_i)}")
85
82
  end
86
83
  end
87
84
 
88
85
  def check_updates
89
- if(Setting[:devwatch].has_key?(:url) && Setting[:devwatch][:channels].size > 0)
90
- src = open(Setting[:devwatch][:url])
86
+ if(Setting.val(:devwatch).has_key?(:url) && Setting.val(:devwatch)[:channels].size > 0)
87
+ src = open(Setting.val(:devwatch)[:url])
91
88
  doc = REXML::Document.new(src.read)
92
89
  if @original.nil?
93
90
  doc.elements.each('rss/channel/item') do |item|
@@ -102,7 +99,7 @@ class DevWatch < ModSpox::Plugin
102
99
  end
103
100
  end
104
101
 
105
- def print_new
102
+ def print_new(max=5)
106
103
  new_items = Array.new
107
104
  # run through the list until we hit a duplicate #
108
105
  i = 1
@@ -115,11 +112,12 @@ class DevWatch < ModSpox::Plugin
115
112
  new_items << "#{item.elements['title'].text}: #{item.elements['link'].text}"
116
113
  end
117
114
  i += 1
115
+ break if i > max
118
116
  end
119
117
  @original = new_orig.nil? ? @original : new_orig
120
118
  if new_items.size > 0
121
119
  new_items.reverse!
122
- Setting[:devwatch][:channels].each do |id|
120
+ Setting.val(:devwatch)[:channels].each do |id|
123
121
  channel = Channel[id]
124
122
  new_items.each do |item|
125
123
  reply(channel, item)
@@ -143,8 +141,8 @@ class DevWatch < ModSpox::Plugin
143
141
  end
144
142
 
145
143
  def start_auto
146
- if(@timer[:action].nil? && Setting[:devwatch].has_key?(:url) && Setting[:devwatch][:channels].size > 0)
147
- m = Messages::Internal::TimerAdd.new(self, Setting[:devwatch][:interval].to_i){ check_updates }
144
+ if(@timer[:action].nil? && Setting.val(:devwatch).has_key?(:url) && Setting.val(:devwatch)[:channels].size > 0)
145
+ m = Messages::Internal::TimerAdd.new(self, Setting.val(:devwatch)[:interval].to_i){ check_updates }
148
146
  @timer[:id] = m.id
149
147
  @pipeline << m
150
148
  end
@@ -0,0 +1,47 @@
1
+ # ex: set ts=4 et:
2
+ require "net/http"
3
+
4
+ # downforeveryoneorjustme.com website-upness-checker plugin
5
+ # by pizza
6
+
7
+ class DownForEveryoneOrJustMe < ModSpox::Plugin
8
+
9
+ def initialize(pipeline)
10
+ super
11
+ add_sig(:sig => 'down ((?:(?:[a-z0-9][a-z0-9-]*)\.)+[a-z]+)',
12
+ :method => :down,
13
+ :desc => 'Check website status',
14
+ :params => [:domain])
15
+ @site = 'http://downforeveryoneorjustme.com/'
16
+ end
17
+
18
+ def down(m, params)
19
+ begin
20
+ # check for valid domain
21
+ domain = params[:domain].downcase
22
+ url = @site + domain
23
+ reply m.replyto, get_text(domain, url)
24
+ rescue Object => boom
25
+ error m.replyto, "Failed to fetch. #{boom}"
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def get_text(domain, url)
32
+ begin
33
+ t = "#{domain} appears "
34
+ data = Net::HTTP.get_response(URI.parse(url)).body
35
+ if /is up/.match(data)
36
+ t = t + "up"
37
+ else
38
+ t = t + "down"
39
+ end
40
+ return t
41
+ rescue Object => boom
42
+ Logger.error(boom)
43
+ raise boom
44
+ end
45
+ end
46
+ end
47
+
@@ -4,7 +4,7 @@ class EightBall < ModSpox::Plugin
4
4
 
5
5
  def initialize(pipeline)
6
6
  super
7
- Signature.find_or_create(:signature => '8ball .+\?$', :plugin => name, :method => 'eightball', :description => 'Ask the magic eightball a question')
7
+ add_sig(:sig => '8ball .+\?$', :method => :eightball, :desc => 'Ask the magic eightball a question')
8
8
  @responses = ['Ask Again Later',
9
9
  'Better Not Tell You Now',
10
10
  'Concentrate and Ask Again',
@@ -0,0 +1,35 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+
4
+ class FML < ModSpox::Plugin
5
+
6
+ def initialize(pipeline)
7
+ super
8
+ add_sig(:sig => 'fml( (love|money|kids|work|health|sex|miscellaneous))?', :method => :random, :desc => 'Fuck my life', :params => [:wspace, :category])
9
+ @site = 'http://api.betacie.com/view/'
10
+ @vars = ['key=readonly', 'language=en']
11
+ end
12
+
13
+ def random(m, params)
14
+ begin
15
+ t = params[:category] ? "#{params[:category].strip}/" : ''
16
+ reply m.replyto, get_text("#{t}random")
17
+ rescue Object => boom
18
+ error m.replyto, 'Failed to fetch.' + boom.to_s
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def get_text(thing)
25
+ data = Net::HTTP.get_response(URI.parse(@site+thing+'?'+@vars.join('&'))).body
26
+ doc = REXML::Document.new(data)
27
+ output = []
28
+ doc.elements.each('root/items/item/text') do |t|
29
+ output << Helpers.convert_entities(t.text)
30
+ end
31
+ raise 'Failed to fetch item from FML' if output.empty?
32
+ return output[rand(output.size)]
33
+ end
34
+
35
+ end
@@ -1,26 +1,22 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
+ require 'uri'
3
4
 
4
5
  class Headers < ModSpox::Plugin
5
6
 
6
7
  def initialize(pipeline)
7
8
  super(pipeline)
8
9
  admin = Models::Group.find_or_create(:name => 'headers')
9
- Models::Signature.find_or_create(:signature => 'headers (https?:\/\/\S+)', :plugin => name, :method => 'fetch_headers',
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
+ add_sig(:sig => 'headers ((https?:\/\/)?\S+)', :method => :fetch_headers, :desc => 'Fetch HTTP headers', :params => [:url])
11
+ add_sig(:sig => 'headers max (\d+)', :method => :set_max, :group => admin, :desc => 'Set maximum number of headers to return', :params => [:max])
12
+ add_sig(:sig => 'headers max', :method => :show_max, :group => admin, :desc => 'Show maximum number of headers to return ')
15
13
  @lock = Mutex.new
16
- @max = Models::Config[:headers_max]
14
+ @max = Models::Config.val(:headers_max)
17
15
  @max = @max.nil? ? 0 : @max.to_i
18
16
  end
19
17
 
20
18
  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
19
+ record = Models::Config.set(:headers_max, params[:max].to_i)
24
20
  @max = params[:max].to_i
25
21
  reply message.replyto, "Max headers returned set to: #{params[:max].to_i}"
26
22
  end
@@ -30,48 +26,33 @@ class Headers < ModSpox::Plugin
30
26
  end
31
27
 
32
28
  def fetch_headers(message, params)
33
- @lock.synchronize do
34
- secure = false
35
- if(params[:url] =~ /^http:/)
36
- port = 80
29
+ params[:url] = "http://#{params[:url]}" unless params[:url].slice(0..3).downcase == 'http'
30
+ uri = URI.parse(params[:url])
31
+ begin
32
+ path = uri.path.nil? || uri.path.empty? ? '/' : uri.path
33
+ path += "?#{uri.query}" unless uri.query.nil?
34
+ reply message.replyto, "Connecting to: #{uri.host} on port: #{uri.port} retrieving: #{path}"
35
+ con = Net::HTTP.new(uri.host, uri.port)
36
+ #con.secure = uri.scheme == 'https'
37
+ con.open_timeout = 5
38
+ con.read_timeout = 5
39
+ response = con.head(path)
40
+ output = ["Response code: #{response.code}"]
41
+ count = 0
42
+ response.each_capitalized{|key,val|
43
+ output << "#{key.slice(0..50)}: #{val.slice(0..200)}"
44
+ count += 1
45
+ break if @max != 0 && count >= @max
46
+ }
47
+ if(count >= @max && @max != 0)
48
+ output << 'Maximum header limit reached.'
37
49
  else
38
- port = 443
39
- secure = true
40
- end
41
- params[:url].gsub!(/^https?:\/\//, '')
42
- if(params[:url] =~ /:(\d+)/)
43
- port = $1.to_i
44
- params[:url].gsub!(/:(\d+)/, '')
45
- end
46
- if(params[:url] =~ /(.+?[a-zA-Z]{2,4})(\/.+)$/)
47
- location = $1
48
- page = $2
49
- else
50
- location = params[:url].gsub(/\/$/, '')
51
- page = '/'
52
- end
53
- begin
54
- reply message.replyto, "Connecting to: #{location} on port: #{port} retrieving: #{page}"
55
- con = Net::HTTP.new(location, port)
56
- con.use_ssl = secure
57
- response = con.get(page)
58
- output = ["Response code: #{response.code}"]
59
- count = 0
60
- response.each{|key,val|
61
- output << "#{key.slice(0..50)}: #{val.slice(0..200)}"
62
- count += 1
63
- break if @max != 0 && count >= @max
64
- }
65
- if(count >= @max && @max != 0)
66
- output << 'Maximum header limit reached.'
67
- else
68
- output << 'Header listing complete'
69
- end
70
- reply message.replyto, output
71
- rescue Object => boom
72
- reply message.replyto, "Error retrieving headers: #{boom}"
73
- Logger.warn("#{boom}\n#{boom.backtrace.join("\n")}")
50
+ output << 'Header listing complete'
74
51
  end
52
+ reply message.replyto, output
53
+ rescue Object => boom
54
+ reply message.replyto, "Error retrieving headers (#{uri.host}): #{boom}"
55
+ Logger.warn("Headers plugin error: #{boom}")
75
56
  end
76
57
  end
77
58