muzang-plugins 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +11 -0
  4. data/lib/muzang-plugins.rb +11 -0
  5. data/lib/muzang-plugins/helpers.rb +39 -0
  6. data/lib/muzang-plugins/muzang-eval.rb +51 -0
  7. data/lib/muzang-plugins/muzang-livereload.rb +19 -0
  8. data/lib/muzang-plugins/muzang-meme.rb +51 -0
  9. data/lib/muzang-plugins/muzang-motd.rb +21 -0
  10. data/lib/muzang-plugins/muzang-nerdpursuit.rb +95 -0
  11. data/lib/muzang-plugins/muzang-nerdpursuit/questions/algorithms/fastes_sorting_algorithm.json +14 -0
  12. data/lib/muzang-plugins/muzang-nerdpursuit/questions/algorithms/run_time_of_bst.json +14 -0
  13. data/lib/muzang-plugins/muzang-nerdpursuit/questions/bash/last_cmd_sub.json +13 -0
  14. data/lib/muzang-plugins/muzang-nerdpursuit/questions/bash/last_directory.json +14 -0
  15. data/lib/muzang-plugins/muzang-nerdpursuit/questions/bash/prefix_last_command.json +13 -0
  16. data/lib/muzang-plugins/muzang-nerdpursuit/questions/couchdb/new_database.json +10 -0
  17. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/attribute_selectors.json +14 -0
  18. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/background_image.json +15 -0
  19. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/float_left.json +14 -0
  20. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/hexadecimal_code.json +14 -0
  21. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/how_do_you_use_multiple_box_sha.json +15 -0
  22. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/media.json +14 -0
  23. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/position_fixed_support.json +14 -0
  24. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/position_property.json +15 -0
  25. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/release_date.json +14 -0
  26. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/roses.json +14 -0
  27. data/lib/muzang-plugins/muzang-nerdpursuit/questions/css/z-index_property.json +14 -0
  28. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/all_ur_base.json +14 -0
  29. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/answer_to_everything.json +14 -0
  30. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/club_mate_caffeine.json +14 -0
  31. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/ook_ook.json +15 -0
  32. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/prediction_gates.json +14 -0
  33. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/the_cake.json +15 -0
  34. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/to_which_year_marty_mcfly_wants.json +15 -0
  35. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/what_is_a_traditional_vulcan_sa.json +15 -0
  36. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/what_is_the_c_base.json +14 -0
  37. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/when_life_gives_you_lemons.json +14 -0
  38. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/where_are_the_characters_of_daw.json +15 -0
  39. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/which_character_in_star_trek_se.json +15 -0
  40. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/who_is_the_first_character_to_b.json +15 -0
  41. data/lib/muzang-plugins/muzang-nerdpursuit/questions/culture/yo_dawg.json +14 -0
  42. data/lib/muzang-plugins/muzang-nerdpursuit/questions/data/half_a_byte.json +14 -0
  43. data/lib/muzang-plugins/muzang-nerdpursuit/questions/flash/fps.json +14 -0
  44. data/lib/muzang-plugins/muzang-nerdpursuit/questions/flash/trace_something_in_as3.json +14 -0
  45. data/lib/muzang-plugins/muzang-nerdpursuit/questions/grafix/png.json +14 -0
  46. data/lib/muzang-plugins/muzang-nerdpursuit/questions/grafix/ps_save_for_web.json +14 -0
  47. data/lib/muzang-plugins/muzang-nerdpursuit/questions/grafix/screen_image_resolution.json +14 -0
  48. data/lib/muzang-plugins/muzang-nerdpursuit/questions/html/how_do_you_specify_html5_doctyp.json +15 -0
  49. data/lib/muzang-plugins/muzang-nerdpursuit/questions/html/img_tag.json +14 -0
  50. data/lib/muzang-plugins/muzang-nerdpursuit/questions/html/optional_html_tags.json +14 -0
  51. data/lib/muzang-plugins/muzang-nerdpursuit/questions/html/strict_doctype.json +14 -0
  52. data/lib/muzang-plugins/muzang-nerdpursuit/questions/http/HTCPCP.json +14 -0
  53. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/chrome_v8.json +10 -0
  54. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/fun_with_brackets.json +14 -0
  55. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/how_can_you_access_the_data_pas.json +15 -0
  56. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/jquery_sizzle.json +10 -0
  57. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/json.json +14 -0
  58. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/jsonp.json +14 -0
  59. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/nodetype_of_text_node.json +14 -0
  60. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/same_origin_policy.json +14 -0
  61. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/string_object_coercion_internals.json +14 -0
  62. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/typeof_arguments.json +14 -0
  63. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/valid_function_expression.json +14 -0
  64. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/what_s_4_2.json +15 -0
  65. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/what_s_typeof_null.json +12 -0
  66. data/lib/muzang-plugins/muzang-nerdpursuit/questions/javascript/who_created_jquery.json +14 -0
  67. data/lib/muzang-plugins/muzang-nerdpursuit/questions/php/invited-php.json +14 -0
  68. data/lib/muzang-plugins/muzang-nerdpursuit/questions/python/square_numbers_in_list.json +14 -0
  69. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/controller_action.json +14 -0
  70. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/folders.json +14 -0
  71. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/pluralize_person.json +14 -0
  72. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/rails_first_shown.json +14 -0
  73. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/rails_inventor.json +14 -0
  74. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/rake_about.json +11 -0
  75. data/lib/muzang-plugins/muzang-nerdpursuit/questions/rails/simple_format.json +14 -0
  76. data/lib/muzang-plugins/muzang-nerdpursuit/questions/regex/emails.json +14 -0
  77. data/lib/muzang-plugins/muzang-nerdpursuit/questions/regex/lazy.json +13 -0
  78. data/lib/muzang-plugins/muzang-nerdpursuit/questions/regex/min_max_quantifier.json +14 -0
  79. data/lib/muzang-plugins/muzang-nerdpursuit/questions/regex/negative_look_ahead.json +14 -0
  80. data/lib/muzang-plugins/muzang-nerdpursuit/questions/regex/prime.json +10 -0
  81. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/2_seconds.json +15 -0
  82. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/about_ruby.json +14 -0
  83. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/absolute_superclass_1.8.json +14 -0
  84. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/absolute_superclass_1.9.json +14 -0
  85. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/active_record_base.json +14 -0
  86. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_all_but_the_first.json +15 -0
  87. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_all_but_the_first_and_last .json +15 -0
  88. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_all_but_the_last.json +15 -0
  89. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_ampersand.json +14 -0
  90. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_get_and remove_first_element.json +15 -0
  91. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_get_and remove_last_element.json +15 -0
  92. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_pipe.json +14 -0
  93. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_splat.json +14 -0
  94. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/array_to_csv_string.json +15 -0
  95. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/backticks_in_ruby.json +15 -0
  96. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/base_object.json +14 -0
  97. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/best_language.json +14 -0
  98. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/bitwise_and.json +14 -0
  99. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/bitwise_or.json +14 -0
  100. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/class_inheritance.json +14 -0
  101. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/collect_alternative.json +14 -0
  102. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/comparsion.json +14 -0
  103. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/constants.json +14 -0
  104. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/date_format_month.json +10 -0
  105. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/divmod.json +14 -0
  106. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/enumerable.json +14 -0
  107. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/equality.json +13 -0
  108. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/falsy.json +14 -0
  109. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/fizzbuzz.json +15 -0
  110. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/garbarge_collector_in_19.json +15 -0
  111. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/global_variable_character.json +14 -0
  112. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/hash_with_indifferent_access.json +14 -0
  113. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/how_is_ruby_licensed.json +15 -0
  114. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/how_many_gems.json +14 -0
  115. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/instance_exec.json +10 -0
  116. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/kanji_converter.json +10 -0
  117. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/kernel-sprintf-2.json +14 -0
  118. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/kernel-sprintf.json +14 -0
  119. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/kernel.json +14 -0
  120. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/matz.json +14 -0
  121. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/method_used_for_comparisions.json +15 -0
  122. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/mixins_are_what.json +15 -0
  123. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/new_lambda_calling_syntax.json +13 -0
  124. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/new_lambda_constructing_syntax.json +10 -0
  125. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/nil.json +14 -0
  126. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/nil_id.json +15 -0
  127. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/nilclass.json +10 -0
  128. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/numeric_types.json +14 -0
  129. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/private_method_in_ruby.json +14 -0
  130. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/protected_method_in_ruby.json +15 -0
  131. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/quo.json +10 -0
  132. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/ranges_three_dots.json +14 -0
  133. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/return_value_or.json +14 -0
  134. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/rspec_controller_render_views.json +10 -0
  135. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/spaceship_operator.json +15 -0
  136. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/string_clean_whitespace.json +15 -0
  137. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/sum_things_up.json +15 -0
  138. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/symbol_identity_01.json +14 -0
  139. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/symbol_identity_02.json +14 -0
  140. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/symbol_identity_03.json +14 -0
  141. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/symbol_string_ids.json +14 -0
  142. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/symbols.json +14 -0
  143. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/the_difference_between_and_operators.json +15 -0
  144. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/unless_wtf.json +14 -0
  145. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/weakref.json +10 -0
  146. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/what_did_matz_say_about_ruby.json +15 -0
  147. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/what_do_array.json +14 -0
  148. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/what_do_string.json +14 -0
  149. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/what_does_gil_stands_for.json +15 -0
  150. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/what_does_negate_regexp_operator_do.json +15 -0
  151. data/lib/muzang-plugins/muzang-nerdpursuit/questions/ruby/what_is_a_mixin.json +14 -0
  152. data/lib/muzang-plugins/muzang-plusone.rb +49 -0
  153. data/lib/muzang-plugins/muzang-reddit.rb +42 -0
  154. data/lib/muzang-plugins/muzang-rubygems.rb +43 -0
  155. data/lib/muzang-plugins/version.rb +5 -0
  156. data/muzang-plugins.gemspec +23 -0
  157. data/spec/livereload_spec.rb +23 -0
  158. data/spec/meme_spec.rb +43 -0
  159. data/spec/motd_spec.rb +18 -0
  160. data/spec/muzang-eval_spec.rb +43 -0
  161. data/spec/nerdpursuit_spec.rb +76 -0
  162. data/spec/plusone_spec.rb +67 -0
  163. data/spec/reddit_spec.rb +45 -0
  164. data/spec/rubygems_spec.rb +37 -0
  165. data/spec/spec_helper.rb +11 -0
  166. data/spec/support/connection_mock.rb +15 -0
  167. data/spec/support/responses/meme.response +4 -0
  168. data/spec/support/responses/reddit.response +3 -0
  169. data/spec/support/responses/rubygems.response +3 -0
  170. metadata +259 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in muzang-plugins.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.rspec_opts = ['-fd -c']
8
+ spec.pattern = FileList['spec/**/*_spec.rb']
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ require 'muzang-plugins/version'
2
+ require 'muzang-plugins/helpers'
3
+
4
+ autoload :Eval, 'muzang-plugins/muzang-eval'
5
+ autoload :LiveReload, 'muzang-plugins/muzang-livereload'
6
+ autoload :Meme, 'muzang-plugins/muzang-meme'
7
+ autoload :Motd, 'muzang-plugins/muzang-motd'
8
+ autoload :NerdPursuit, 'muzang-plugins/muzang-nerdpursuit'
9
+ autoload :PlusOne, 'muzang-plugins/muzang-plusone'
10
+ autoload :Reddit, 'muzang-plugins/muzang-reddit'
11
+ autoload :RubyGems, 'muzang-plugins/muzang-rubygems'
@@ -0,0 +1,39 @@
1
+ module Muzang
2
+ module Plugins
3
+ module Helpers
4
+ DEFAULT_MATCH_OPTIONS = { position: 1 }
5
+
6
+ def on_channel?(message)
7
+ message.channel
8
+ end
9
+
10
+ def match?(message, options = {})
11
+ options = DEFAULT_MATCH_OPTIONS.merge(options)
12
+ message.message.match(options[:regexp]) ? message.message.match(options[:regexp])[options[:position]] : false
13
+ end
14
+
15
+ def on_join?(connection, message)
16
+ message.command == :join && message.nick == connection.nick
17
+ end
18
+
19
+ def create_database(file, container, variable)
20
+ unless File.exist?(@config = ENV["HOME"] + "/.muzang")
21
+ FileUtils.mkdir @config
22
+ end
23
+
24
+ unless File.exist? @config + "/#{file}"
25
+ db = YAML.dump container
26
+ File.open(@config + "/#{file}", "w"){|f| f.write(db)}
27
+ end
28
+
29
+ send(:"#{variable}=", YAML.load(File.open(@config + "/#{file}", "r").read))
30
+
31
+ unless self.respond_to?(:save)
32
+ self.class.send(:define_method, :save) do
33
+ File.open(@config + "/#{file}", "w"){|f| f.write YAML.dump(send(variable))}
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,51 @@
1
+ module Safe; end
2
+ class << Safe
3
+ def safe(code, sandbox=nil)
4
+ error = nil
5
+
6
+ begin
7
+ $-w = nil
8
+ sandbox ||= Object.new.taint
9
+ yield(sandbox) if block_given?
10
+
11
+ $SAFE = 5
12
+ value = eval(code, sandbox.send(:binding))
13
+ result = Marshal.load(Marshal.dump(value))
14
+ rescue Exception => error
15
+ error = Marshal.load(Marshal.dump(error))
16
+ end
17
+
18
+ return result, error
19
+ end
20
+ end
21
+
22
+ def safe(*args, &block)
23
+ unless args.first =~ /EM|EventMachine/
24
+ Safe::safe(*args, &block)
25
+ end
26
+ end
27
+
28
+ class Eval
29
+ include Muzang::Plugins::Helpers
30
+
31
+ def initialize(bot)
32
+ @bot = bot
33
+ end
34
+
35
+ def call(connection, message)
36
+ if on_channel?(message)
37
+ if match?(message, :regexp => /^\% (.*)/, :position => 1)
38
+ operation = proc do
39
+ safe(message.message.match(/^\% (.*)/)[1])
40
+ end
41
+ callback = proc do |tuple|
42
+ result, error = tuple
43
+ connection.msg(message.channel, "#{result}") if result
44
+ connection.msg(message.channel, "Error: #{error}") if error
45
+ end
46
+ EM.defer(operation, callback)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,19 @@
1
+ class LiveReload
2
+ include Muzang::Plugins::Helpers
3
+
4
+ def initialize(bot)
5
+ @bot = bot
6
+ end
7
+
8
+ def call(connection, message)
9
+ if on_channel?(message)
10
+ if match?(message, :regexp => /^!reload$/, :position => 0)
11
+ @bot.plugins.each do |plugin, instance|
12
+ Kernel.load("muzang-plugins/muzang-#{plugin.to_s.downcase}.rb")
13
+ instance = plugin.new(@bot)
14
+ connection.msg(message.channel, "Reloading: #{plugin}")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ require "em-http-request"
2
+ require "json"
3
+
4
+ class Meme
5
+ include Muzang::Plugins::Helpers
6
+
7
+ MEMES = {
8
+ "idont" => { :image_id => 2485, :generator => 74 },
9
+ "yuno" => { :image_id => 166088, :generator => 2 },
10
+ "orly" => { :image_id => 117049, :generator => 920 },
11
+ "suc" => { :image_id => 1031, :generator => 121 },
12
+ "all" => { :image_id => 1121885, :generator => 6013 }
13
+ }
14
+
15
+ def initialize(bot)
16
+ @bot = bot
17
+ end
18
+
19
+ def call(connection, message)
20
+ message.message.match(/^meme$/) do
21
+ connection.msg("#{@bot.channels.first}", "Type 'meme [name of meme] \"Text0\" \"Text1\"'")
22
+ connection.msg("#{@bot.channels.first}", "Available memes: #{MEMES.keys.join(" ")}")
23
+ end
24
+ message.message.match(/^meme (.*?) "(.*?)"( "(.*?)")?$/) do |m|
25
+ if meme_ids = MEMES[m[1]]
26
+ @generator = meme_ids[:generator]
27
+ @image_id = meme_ids[:image_id]
28
+ else
29
+ return nil
30
+ end
31
+
32
+ @text0 = m[2]
33
+ @text1 = m[4]
34
+
35
+ http = EventMachine::HttpRequest.new('http://version1.api.memegenerator.net/Instance_Create')
36
+ .get(:query => {:username => 'drug-bot',
37
+ :password => 'drug-bot',
38
+ :languageCode => 'en',
39
+ :generatorID => @generator,
40
+ :imageID => @image_id,
41
+ :text0 => @text0,
42
+ :text1 => @text1})
43
+
44
+ http.callback {
45
+ meme = JSON.parse(http.response)
46
+ url = "http://version1.api.memegenerator.net#{meme['result']['instanceImageUrl']}"
47
+ connection.msg("#{@bot.channels.first}", "Meme: #{url}")
48
+ }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'muzang/version'
2
+
3
+ class Motd
4
+ include Muzang::Plugins::Helpers
5
+
6
+ def initialize(bot)
7
+ @bot = bot
8
+ end
9
+
10
+ def call(connection, message)
11
+ if on_join?(connection, message)
12
+ connection.msg(message.channel, "DRUG-bot | Version: #{Muzang::VERSION} | Plugins: #{plugins}")
13
+ end
14
+ end
15
+
16
+ def plugins
17
+ list = ""
18
+ @bot.plugins.each{|plugin, instance| list << "*#{plugin}* "}
19
+ list
20
+ end
21
+ end
@@ -0,0 +1,95 @@
1
+ require "json"
2
+
3
+ class NerdPursuit
4
+ include Muzang::Plugins::Helpers
5
+
6
+ attr_accessor :questions, :quiz_time
7
+
8
+ def initialize(bot)
9
+ @bot = bot
10
+ @quiz_time = false
11
+ @answers = {}
12
+ create_database("nerd_pursuit.yml", Array.new, :questions)
13
+ end
14
+
15
+ def all_questions
16
+ names = Dir["#{File.dirname(__FILE__)}/muzang-nerdpursuit/questions/**/*.json"]
17
+ end
18
+
19
+ def quiz!(&block)
20
+ @quiz_time = true
21
+ current_question # load current question
22
+ end
23
+
24
+ def end_quiz!
25
+ @quiz_time = false
26
+ @current_question = nil
27
+ end
28
+
29
+ def current_question
30
+ if @current_question
31
+ @current_question
32
+ else
33
+ begin
34
+ sample_question = (all_questions - questions).sample
35
+ questions << sample_question
36
+ save
37
+ @current_question = ::JSON.parse(File.open(sample_question).read)["question"]
38
+ end while(!valid?(@current_question))
39
+ end
40
+
41
+ @current_question
42
+ end
43
+
44
+ def valid?(question)
45
+ if question
46
+ question["category"] and question["text"] and question["right_answer"]
47
+ else
48
+ false
49
+ end
50
+ end
51
+
52
+ def find_winner
53
+ @winner = @answers.reject do |_, answer|
54
+ answer[:answer] != current_question["right_answer"][1..1]
55
+ end.sort_by do |_,answer|
56
+ answer[:time]
57
+ end
58
+ end
59
+
60
+ def period(time)
61
+ time # need for speed up tests
62
+ end
63
+
64
+ def call(connection, message)
65
+ if on_channel?(message)
66
+ if match?(message, :regexp => /^!quiz$/, :position => 0)
67
+ quiz!
68
+ connection.msg(message.channel, "Quiz time!")
69
+ EM.add_timer(period(1)) { connection.msg(message.channel, "Category: #{current_question["category"]}") }
70
+ EM.add_timer(period(2)) { connection.msg(message.channel, "Question: #{current_question["text"]}") }
71
+ 4.times do |time|
72
+ EM.add_timer(period(2+time+1)) { connection.msg(message.channel, "Answer #{time+1}: #{current_question["a#{time+1}"]}") }
73
+ end
74
+ EM.add_timer(period(40)) do
75
+ connection.msg(message.channel, "Right answer: #{current_question["right_answer"][1..1]}")
76
+ @winner = find_winner
77
+ if @winner.first && @winner.first.first
78
+ connection.msg(message.channel, "The winner is... #{@winner.first.first}")
79
+ end
80
+ @answers = {}
81
+ @winner = nil
82
+ end_quiz!
83
+ end
84
+ end
85
+
86
+ if(answer = match?(message, :regexp => /\d/, :position => 0))
87
+ if @quiz_time
88
+ unless @answers[message.nick]
89
+ @answers[message.nick] = { :answer => answer, :time => Time.now }
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,14 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "algorithms",
4
+ "nerd_level": 3,
5
+ "text":"Which one is the fastest sorting algorithm?",
6
+ "a1": "Selection Sort",
7
+ "a2": "Quick Sort",
8
+ "a3": "Bubble Sort",
9
+ "a4": "All the same",
10
+ "right_answer":"a2",
11
+ "created_at": "2011-06-20",
12
+ "created_by": "eray"
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "algorithms",
4
+ "nerd_level": 2,
5
+ "text": "What's the average run time of a search in a Binary Search Tree?",
6
+ "a1": "O(n)",
7
+ "a2": "O(n log n)",
8
+ "a3": "O(log n)",
9
+ "a4": "O(1)",
10
+ "right_answer":"a3",
11
+ "created_at": "2011-06-20",
12
+ "created_by": "eray"
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "bash",
4
+ "nerd_level": 2,
5
+ "text":"How to call the last command after substituting some text?",
6
+ "a1": "^old_substring^new_substring^",
7
+ "a2": "/old_substring/new_substring/",
8
+ "a3": "sbl 'old_substring/new_substring'",
9
+ "right_answer": "a1",
10
+ "created_at": "2011-06-06",
11
+ "created_by": "mkorfmann"
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "bash",
4
+ "nerd_level": 3,
5
+ "text": "How to switch back to the previous directory?",
6
+ "a1": "cd ...",
7
+ "a2": "cd -P",
8
+ "a3": "cd -last",
9
+ "a4": "cd -",
10
+ "right_answer": "a4",
11
+ "created_at": "2011-06-25",
12
+ "created_by": "swilke"
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "bash",
4
+ "nerd_level": 2,
5
+ "text":"How to prefix the last command with for example 'sudo'?",
6
+ "a1": "sudo ^",
7
+ "a2": "sudo $LAST_COMMAND",
8
+ "a3": "sudo !!",
9
+ "right_answer": "a3",
10
+ "created_at": "2011-06-06",
11
+ "created_by": "mkorfmann"
12
+ }
13
+ }
@@ -0,0 +1,10 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "couchdb",
4
+ "nerd_level": 2,
5
+ "text":"How to create a couchdb collection called 'nerds' with curl",
6
+ "a1": "curl -X PUT http://localhost:5984/nerds",
7
+ "created_at": "2011-06-21",
8
+ "created_by": "kangguru"
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ { "question" : {
2
+ "id": "",
3
+ "category": "css",
4
+ "nerd_level": 4,
5
+ "text":"How would you style all links to PDF files via CSS?",
6
+ "a1": "[href*=.pdf]",
7
+ "a2": "[href?=.pdf]",
8
+ "a3": "[href$=.pdf]",
9
+ "a4": "[href^=.pdf]",
10
+ "right_answer":"a3",
11
+ "created_at": "2011-06-07",
12
+ "created_by": "Philipp"
13
+ }
14
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "question": {
3
+ "id": "",
4
+ "category": "css",
5
+ "nerd_level": 3,
6
+ "text": "Why it's better to use <img.. /> tag instead of background whenever it's possible?",
7
+ "a1": "Easier to manage images in dev mode.",
8
+ "a2": "Actually it's not. Better to use bg images.",
9
+ "a3": "Background images are not printable.",
10
+ "a4": "<img> tag's are easier to style as a inline elements.",
11
+ "right_answer":"a3",
12
+ "created_at": "2011-06-08",
13
+ "created_by": "Barto"
14
+ }
15
+ }