DeadEd.com
IRC Bots, Java Game Query and Control Libraries, and More ...
Sign Up!
Login
Welcome to DeadEd.com
Monday, September 25 2017 @ 01:07 AM CDT

 Forum Index > DeadEd.com > IRC Bots
 Sorting channel users by channel operator status
 |  Printable Version
By: Tayotoshi (offline) on Monday, August 23 2010 @ 08:22 AM CDT (Read 1716 times)  
Tayotoshi

 

The channel operator symbols (~&@%+) don't sort right alphabetically, but we want to see them in the right order,

so we need to sort them in another way. This is what I've come up with, and it works, so it thought I'd share it.

Got remarks? Know a better method?

Please let me know Mr. Green

 

 

PHP Formatted Code

private List<String[]> getChannelUsers( String channel ){
       
   //get users and store nicknames in array
   //this may vary according to the bot you use
   User users[] = getUsers( channel );
   String array[] = new String[users.length];
   for( int i = 0; i < users.length; i++ ){
      array[i] = users[i].getNickname();
   }

   //temporary arrays
   String q_temp[] = new String[ array.length ]; //~ q owner
   String a_temp[] = new String[ array.length ]; //& a admin
   String o_temp[] = new String[ array.length ]; //@ o operator
   String h_temp[] = new String[ array.length ]; //% h halfoperator
   String v_temp[] = new String[ array.length ]; //+ v voiced
   String temp[] = new String[ array.length ];   //    normal user

   //counters for number of each kind
   int q_count = 0;
   int a_count = 0;
   int o_count = 0;
   int h_count = 0;
   int v_count = 0;
   int count = 0;

   //sort users into temp arrays
   for( int i = 0; i < array.length; i++ ){
      if( array[i].startsWith( "~" ) ){
         q_temp[q_count] = array[i];
         q_count++;
      }
      else if( array[i].startsWith( "&" ) ){
         a_temp[a_count] = array[i];
         a_count++;
      }
      else if( array[i].startsWith( "@" ) ){
         o_temp[o_count] = array[i];
         o_count++;
      }
      else if( array[i].startsWith( "%" ) ){
         h_temp[h_count] = array[i];
         h_count++;
      }
      else if( array[i].startsWith( "+" ) ){
         v_temp[v_count] = array[i];
         v_count++;
      }
      else{
         temp[count] = array[i];
         count++;
      }
   }

   //copy temp arrays to new arrays with specific size
   String q_list[] = new String[q_count];
   String a_list[] = new String[a_count];
   String o_list[] = new String[o_count];
   String h_list[] = new String[h_count];
   String v_list[] = new String[v_count];
   String list[] = new String[count];
   System.arraycopy(q_temp, 0, q_list, 0, q_count);
   System.arraycopy(a_temp, 0, a_list, 0, a_count);
   System.arraycopy(o_temp, 0, o_list, 0, o_count);
   System.arraycopy(h_temp, 0, h_list, 0, h_count);
   System.arraycopy(v_temp, 0, v_list, 0, v_count);
   System.arraycopy(  temp, 0,   list, 0,   count);

   //add arrays to list
   List<String[]> channelUsers = new ArrayList<String[]>();
   channelUsers.add( q_list );
   channelUsers.add( a_list );
   channelUsers.add( o_list );
   channelUsers.add( h_list );
   channelUsers.add( v_list );
   channelUsers.add(   list );
       
   return channelUsers;
}

 

You can now print them, or add to a JList:

PHP Formatted Code

List<String[]> users = getChannelUsers( channel );

for( String[] list : users ){
   for( String nick : list ){
      System.out.println( nick );
   }
}
 

PHP Formatted Code

DefaultListModel model = new DefaultListModel();
JList userJList = new JList(model);


List<String[]> users = getChannelUsers( channel );
       
int count = 0;         
for( String[] list : users ){
   for( String nick : list ){
      model.add( count, nick );
      count++;
   }
}

 

 


Forum Junior
Junior

Status: offline

Registered: 08/11/10
Posts: 26

Profile      
   



 All times are CDT. The time is now 01:07 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

My Account





Sign up as a New User
Lost your password?

What's New

Stories

No new stories

Comments last 2 days

No new comments

Files last 14 days

No new files
No new comments

Links last 2 weeks

No new links