Advertisement
Stiepen

[KVS] querywhitelist plugin

Mar 23rd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. // Register classes
  2. QueryAccept::classes::register
  3.  
  4. // Initialize events
  5. QueryAccept::events::init
  6.  
  7. // Load configuration
  8. QueryAccept::config::load
  9.  
  10. // Set options
  11. option boolShowMinimizedDebugWindow 1
  12.  
  13.     // Register the classes
  14. alias(QueryAccept::classes::register)
  15. {
  16.     // Create an array with all the classes of our addon.
  17.     // In this way it's easy to add or remove classes to registering routine
  18.     %classes[] = $array()
  19.         //QueryAccept::classes::database, \
  20.         //QueryAccept::classes::gui::options)
  21.    
  22.     // Scan the array and register the classes
  23.     for(%i=0; %i < $length(%classes[]); %i++)
  24.     {
  25.         if($classdefined("%classes[%i]"))
  26.         {
  27.             objects.killclass %classes[%i]
  28.         }
  29.         eval %classes[%i]
  30.     }
  31. }
  32.  
  33. // Initialize events
  34. alias(QueryAccept::events::init)
  35. {
  36.     event(OnKVIrcStartup,"QueryAccept")
  37.     {
  38.         // Load the catalogue (translation) file "queryaccept" from the path provided
  39.         trload queryaccept $file.localdir("locale/QueryAccept")
  40.         QueryAccept::config::load
  41.     }
  42.     event(OnChannelMessage,"QueryAccept_onmsg")
  43.     {
  44.  
  45.     }
  46. }
  47.  
  48. // Load configuration
  49. alias(QueryAccept::config::load)
  50. {
  51.     // If the class ConfHandler is not defined, register all classes we have
  52.     if(!$classdefined(QueryAccept::classes::ConfHandler))
  53.     {
  54.         QueryAccept::classes::register
  55.     }
  56.    
  57.     // Sets some variables
  58.     // %QueryAcceptConfig = $new(QueryAccept::classes::ConfHandler)
  59.     %QueryAcceptConfigPath = $file.localdir(config/scripts/QueryAccept)
  60.    
  61.     // Open the configuration file and sets the section "general"
  62.     %c = $config.open(%QueryAcceptConfigPath/QueryAccept.kvc,"r")
  63.     config.setsection %c whitelist
  64.     %Whitelist = $array()
  65.     %a = $config.keylist(%c)
  66.     foreach(%key, %a) {
  67.         %Whitelist[$length(%a)] = $config.read(%c, %key)
  68.     }
  69.     // Store the value of the key "Key" in the global variable %Key
  70.    
  71.    
  72.     config.close %c
  73. }
  74.  
  75. alias(QueryAccept::config::save) {
  76.     %c = $config.open(%QueryAcceptConfigPath/QueryAccept.kvc)
  77.     config.setsection %c whitelist
  78.     for(%i=0;%i<$length(%Whitelist);%i++)
  79.         config.write %c %i %Whitelist[%i]
  80. }
  81.  
  82. alias(QueryAccept::isWhitelisted) {
  83.     for(%i = 0; %i < $length(%Whitelist); %i++) {
  84.         if ($0 == %Whitelist[%i]) return true
  85.     }
  86.     return
  87. }
  88.  
  89. alias(querywhitelist) {
  90.     if ($0 == "add") {
  91.         %Whitelist[$length[%Whitelist]] = $1
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement