daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Mar 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package commands;
  2.  
  3. import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
  4. import net.dv8tion.jda.api.hooks.ListenerAdapter;
  5.  
  6. public class InviteCommand extends ListenerAdapter {
  7.  
  8.     private String text[];
  9.  
  10.     @Override
  11.     public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
  12.  
  13.         if (!e.getMember().getUser().isBot()) {
  14.  
  15.             text = e.getMessage().getContentRaw().split(" ");
  16.             if (text.length >= 2) {
  17.  
  18.                 if (text[0].equalsIgnoreCase("$invite") && text[1].equalsIgnoreCase("create") && isInteger(text[2])) {
  19.                    
  20.                     double numberTest=Double.parseDouble(text[2]);
  21.                     String time=TimeCalculator(numberTest);
  22.                     e.getChannel().sendMessage("Hey " + e.getAuthor().getName()
  23.                     + " invite your friends to this server <:PogYou:557333280039501844>"
  24.                     + "\nLink: "+ e.getChannel().createInvite().setMaxAge(Integer.parseInt(text[2])).complete().getUrl()).queue();
  25.                     e.getChannel().sendMessage("This link will expire after: "+time).queue();
  26.                    
  27.  
  28.                 } else if (text[0].contains("inv") || text[1].contains("inv")) {
  29.  
  30.                     e.getChannel().sendMessage("Use the following syntax : $invite create [minutes]").queue();
  31.  
  32.                 }
  33.             }
  34.         }
  35.  
  36.     }
  37.  
  38.     private String TimeCalculator(double numberTest) {
  39.        
  40.         String time = "";
  41.         int noDigit = 0;
  42.  
  43.         if (numberTest >= 60) {
  44.  
  45.             noDigit = (int) (numberTest / 60);
  46.             numberTest = numberTest % 60;
  47.  
  48.             if (numberTest != 0) {
  49.  
  50.                 time = noDigit+"h"+ (int)numberTest+"min";
  51.  
  52.             }else {
  53.                
  54.                 time=noDigit+"h";
  55.                
  56.             }
  57.  
  58.         }else {
  59.            
  60.             time=(int)numberTest+"min";
  61.            
  62.         }
  63.  
  64.         return time;
  65.     }
  66.  
  67.     private boolean isInteger(String numberTest) {
  68.  
  69.         boolean error = false;
  70.  
  71.         try {
  72.             Integer.parseInt(numberTest);
  73.             error = true;
  74.         } catch (Exception ex) {
  75.             error = false;
  76.         }
  77.  
  78.         return error;
  79.     }
  80.  
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top