Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tool for regenerating the module list from source.

  • Loading branch information...
commit c1b5c4ebe504ae9b763621e7485b230cee2676b1 1 parent 6426101
@SaberUK SaberUK authored
Showing with 59 additions and 0 deletions.
  1. +59 −0 _tools/regenerate-module-list
View
59 _tools/regenerate-module-list
@@ -0,0 +1,59 @@
+#!/usr/bin/env ruby
+unless ENV.include?('INSPIRCD_SOURCE')
+ puts "Error: You need to define an INSPIRCD_SOURCE environment variable containing the location of the InspIRCd source code"
+ exit 1
+end
+available_modules = Dir.glob("#{ENV['INSPIRCD_SOURCE']}/src/modules/m_**") + Dir.glob("#{ENV['INSPIRCD_SOURCE']}/src/modules/extra/m_**")
+module_infos = {}
+available_modules.each do |mod|
+ next unless File.extname(mod) =~ /^(?:\.cpp)?$/
+ module_name = File.basename(mod).gsub('.cpp', '')
+ module_infos[module_name] = {}
+ module_infos[module_name][:umodes] = []
+ module_infos[module_name][:cmodes] = []
+ module_infos[module_name][:extbans] = []
+ module_infos[module_name][:commands] = []
+ module_infos[module_name][:description] = '*Description missing*'
+ module_files = File.directory?(mod) ? Dir.glob("#{mod}/*.cpp") : [mod]
+ module_files.each do |module_file|
+ module_source = File.read(module_file)
+ module_source.scan(/(?:Simple|Param)(Channel|User)ModeHandler\(\w+,\s*\"\S+\",\s*\'([A-Za-z])\'\)/).each do |type, letter|
+ type == 'Channel' ? module_infos[module_name][:cmodes] << letter : module_infos[module_name][:umodes] << letter
+ end
+ module_source.scan(/ModeHandler\(\w+,\s*\"\S+\",\s*\'([A-Za-z])\',\s*PARAM_(?:NONE|SETONLY|ALWAYS),\s*MODETYPE_(CHANNEL|USER)\)/).each do |letter, type|
+ type == 'CHANNEL' ? module_infos[module_name][:cmodes] << letter : module_infos[module_name][:umodes] << letter
+ end
+ unless (extbans = module_source.scan(/ServerInstance->AddExtBanChar\('([A-Za-z])'\)/)).empty?
+ module_infos[module_name][:extbans].concat(extbans)
+ end
+ unless (commands = module_source.scan(/Command\(\w+,\s*"(\S+)",\s*\d+(?:\)|,\s*\d+\))/)).empty?
+ module_infos[module_name][:commands].concat(commands)
+ end
+ if /\/\* \$ModDesc: (.+) \*\// =~ module_source
+ module_infos[module_name][:description] = $~[1]
+ end
+ end
+end
+File.open('Modules.md', 'w') do |file|
+ file.write <<-EOMH
+---
+title: Modules
+layout: default
+---
+
+<!-- This file was automatically generated by #{$PROGRAM_NAME} on #{Time.now} -->
+
+Name | User Modes | Channel Modes | Extended Bans | Commands | Description
+---- | ---------- | ------------- | ------------- | -------- | -----------
+ EOMH
+ module_infos.sort.each do |module_name, module_info|
+ file.printf("[%s](/wiki/Modules/%s.html) | %s | %s | %s | %s | %s\n",
+ module_name,
+ module_name.gsub('m_', ''),
+ module_info[:umodes].empty? ? '-' : module_info[:umodes].sort.join(' '),
+ module_info[:cmodes].empty? ? '-' : module_info[:cmodes].sort.join(' '),
+ module_info[:extbans].empty? ? '-' : module_info[:extbans].sort.join(' '),
+ module_info[:commands].empty? ? '-' : module_info[:commands].sort.join(' '),
+ module_info[:description])
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.