Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IRCBot::Plugins::PluginConverter
- def convert(plugin_code,plugin_name)
- main_code = plugin_code.sub(/^IRCBot\:\:Plugin\.define(.+?)do/,'').chomp
- main_code[-3..-1]='' # Stripping the trailing 'end'
- init_code = main_code.match(/^(.+?)def\ /m)[1]
- main_code.sub!(init_code,'')
- if init_code.match(/help_string(\t+|\ +)(.+?)$/)
- help_string = init_code.match(/help_string(\t+|\ +)(.+?)$/)[2].strip
- init_code = init_code.sub(/\thelp_string(.+?)$/,'')
- else
- help_string = "false"
- end
- # Dependencies.
- if init_code.match(/depends(\t+|\ +)(.+?)$/) then
- depends = init_code.match(/depends(\t+|\ +)(.+?)$/)[2]
- init_code = init_code.sub(/\tdepends(.+?)$/,'')
- else
- depends = false
- end
- class_name = "IRCBot::Plugins::#{plugin_name.capitalize}Plugin"
- newplugin = <<EOF
- class #{class_name} < IRCBot::Plugins::Base
- def initialize()
- #{init_code}
- end
- def help()
- #{unless help_string == "false" or help_string == "nil" then help_string; else ""; end}
- end
- #{"def depends; #{depends}; end" if depends}
- #{main_code}
- end
- IRCBot::Plugins.register #{class_name}, "#{plugin_name}"
- EOF
- return newplugin
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement