Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.16 KB | None | 0 0
  1. class IRCBot::Plugins::PluginConverter
  2.     def convert(plugin_code,plugin_name)
  3.         main_code = plugin_code.sub(/^IRCBot\:\:Plugin\.define(.+?)do/,'').chomp
  4.         main_code[-3..-1]='' # Stripping the trailing 'end'
  5.         init_code = main_code.match(/^(.+?)def\ /m)[1]
  6.         main_code.sub!(init_code,'')
  7.         if init_code.match(/help_string(\t+|\ +)(.+?)$/)
  8.             help_string = init_code.match(/help_string(\t+|\ +)(.+?)$/)[2].strip
  9.             init_code = init_code.sub(/\thelp_string(.+?)$/,'')
  10.         else
  11.             help_string = "false"
  12.         end
  13.        
  14.         # Dependencies.
  15.         if init_code.match(/depends(\t+|\ +)(.+?)$/) then
  16.             depends = init_code.match(/depends(\t+|\ +)(.+?)$/)[2]
  17.             init_code = init_code.sub(/\tdepends(.+?)$/,'')
  18.         else
  19.             depends = false
  20.         end
  21.         class_name = "IRCBot::Plugins::#{plugin_name.capitalize}Plugin"
  22.        
  23.         newplugin = <<EOF
  24. class #{class_name} < IRCBot::Plugins::Base
  25.     def initialize()
  26.         #{init_code}
  27.     end
  28.     def help()
  29.         #{unless help_string == "false" or help_string == "nil" then help_string; else ""; end}
  30.     end
  31.    
  32.     #{"def depends; #{depends}; end" if depends}
  33.    
  34.     #{main_code}
  35. end
  36. IRCBot::Plugins.register #{class_name}, "#{plugin_name}"
  37. EOF
  38.     return newplugin
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement