~/paste/19089
~/paste/19089
~/paste/19089

  1. # *********** Paste the following section into auto_include.ms ***********
  2.  
  3. #Random Code Generation
  4. export('codegen.version', '2.0')
  5.  
  6.  
  7. proc(_codegen, @codelength, @codetype, @codetype2,
  8. #How to use:
  9. # call _codegen(NUMBER, character type 1, character type 2)
  10. # The number determines how long the code is, and the 2 types determine which types of characters you want.
  11. # Character types: lowercase ("lower"), uppercase ("upper"), number ("num"), or all.
  12.  
  13. #--- User Input Checks
  14.         @string = array()
  15.         if(@codelength == '' || is_numeric(@codelength) == false){
  16.                 assign(@codelength, 7)
  17.         }
  18.         if(@codetype == ''){
  19.                 @codetype = full
  20.         }
  21.  
  22. #--- List of Characters
  23.         assign(@lower, array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z))
  24.         assign(@upper, array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z))
  25.         assign(@number, array(1,2,3,4,5,6,7,8,9))
  26.         assign(@full, array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9))
  27.  
  28. #--- Character Set 1
  29.         switch(to_lower(@codetype)){
  30.         case lower:
  31.         case l:
  32.         case low:
  33.                 @chars = array_get(@lower)
  34.         case upper:
  35.         case u:
  36.         case up:
  37.                 @chars = array_get(@upper)
  38.         case number:
  39.         case n:
  40.         case '#':
  41.         case num:
  42.                 @chars = array_get(@number)
  43.         case full:
  44.         case all:
  45.                 @chars = array_get(@full)
  46.         default:
  47.                 die(color(3).' - '.color(4).'Fail:'.color(3).' Invalid code type given (1)')
  48.         }
  49.  
  50. #--- Character Set 2
  51.         if(@codetype2 !== '',
  52.                 switch(to_lower(@codetype2)){
  53.                 case lower:
  54.                 case l:
  55.                 case low:
  56.                         @chars2 = array_get(@lower)
  57.                 case upper:
  58.                 case u:
  59.                 case up:
  60.                         @chars2 = array_get(@upper)
  61.                 case number:
  62.                 case n:
  63.                 case '#':
  64.                 case num:
  65.                         @chars2 = array_get(@number)
  66.                 case full:
  67.                 case all:
  68.                         @chars2 = array_get(@full)
  69.                 default:
  70.                         die(color(3).' - '.color(4).'Fail:'.color(3).' Invalid code type given (2)')
  71.                 }
  72.                 foreach(@chars2, @i,
  73.                         array_push(@chars, @i)
  74.                 )
  75.         )
  76. #--- Generate code
  77.         for(@i = 0, @i < @codelength, @i++,
  78.                 @string[@i] = @chars[rand(array_size(@chars))]
  79.         )
  80.         @string = array_implode(@string, '')
  81.  
  82.         return(@string)
  83. )
  84.  
  85.  
  86. # *********** Paste the following section into aliases.msa ***********
  87.  
  88. everyone:/codegen [$length] [$type1] [$type2] [$] = >>>
  89. proc(_codegen_help,
  90.         msg(color(6).'CodeGen!')
  91.         msg(color(7).'/codegen'.color(3).' - '.color(f).'Prints a randomly generated code. Defaults to a code 7 characters in length using uppercase, lowercase, and numbers.')
  92.         msg(color(a).'Command usage: <required> [optional]')
  93.         msg(color(3).'/codegen [length] [Character type 1] [Character type 2]')
  94.         msg(color(3).' - '.color(f).' You can specify how many characters the code should be, and specify the types of characters.')
  95.         msg(color(3).' - '.color(f).' Character types: lowercase ("lower"), uppercase ("upper"), number ("num"), or all.')
  96.  
  97. )
  98.  
  99. switch($length){
  100.  
  101. case help:
  102. case -help:
  103. case ?:
  104. case '/?':
  105.         _codegen_help()
  106.  
  107. default:
  108.         assign(@code, _codegen($length, $type1, $type2))
  109.         msg(color(7).'['.color(6).'CodeGen'.color(7).'] '.color(7).'Random generated code at '.simple_date(E.', '.h.':'.m.':'.s.'.'.S.' '.a).':')
  110.         msg(@code)
  111. }
  112. <<<
Language: commandhelper
Posted by CypherNova139 at 17 Jan 2016, 11:38:36 UTC