Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. package me.tfkjake.projectaltis;
  2.  
  3. import me.tfkjake.projectaltis.commands.*;
  4. import me.tfkjake.projectaltis.event.Message;
  5. import me.tfkjake.projectaltis.handlers.CommandHandler;
  6. import net.dv8tion.jda.core.AccountType;
  7. import net.dv8tion.jda.core.JDA;
  8. import net.dv8tion.jda.core.JDABuilder;
  9. import net.dv8tion.jda.core.entities.*;
  10.  
  11. import java.io.*;
  12. import java.net.InetAddress;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import java.util.Properties;
  16.  
  17. /**
  18. * Created by jakebooy on 10/03/17.
  19. */
  20. public class Cog extends CommandHandler {
  21.  
  22. public static JDA api = null;
  23. private String token;
  24.  
  25. public static void main(String args[]){
  26. try{
  27. // local
  28. System.out.println(InetAddress.getLocalHost().getHostAddress().toString());
  29. if(InetAddress.getLocalHost().getHostAddress().toString().equalsIgnoreCase("127.0.1.1")){
  30. new Cog();
  31. }else{
  32. System.out.println("Whoa there! You're trying to host me yourself? How dare you.");
  33. }
  34. /* live
  35. if(InetAddress.getLocalHost().getHostAddress().toString().equalsIgnoreCase("VPS_IP")){
  36.  
  37. }else{
  38. System.out.println("Whoa there! You're trying to host me yourself? How dare you.");
  39. }
  40. */
  41. }catch(Exception e){}
  42.  
  43.  
  44. }
  45.  
  46. public static Properties getStaticConfig(){
  47. Properties prop = new Properties();
  48. InputStream input = null;
  49. try{
  50. input = new FileInputStream("config.properties");
  51. prop.load(input);
  52. }catch(IOException e){
  53. e.printStackTrace();
  54. }finally{
  55. if (input != null) {
  56. try {
  57. input.close();
  58. } catch (IOException e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. }
  63. return prop;
  64. }
  65.  
  66. public Properties getConfig(){
  67. Properties prop = new Properties();
  68. InputStream input = null;
  69. try{
  70. input = new FileInputStream("config.properties");
  71. prop.load(input);
  72. }catch(IOException e){
  73. e.printStackTrace();
  74. }finally{
  75. if (input != null) {
  76. try {
  77. input.close();
  78. } catch (IOException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. }
  83. return prop;
  84. }
  85.  
  86. public void writeConfig(String key, String value){
  87. Properties prop = getConfig();
  88. OutputStream output = null;
  89. try {
  90. output = new FileOutputStream("config.properties");
  91. prop.setProperty(key, value);
  92. prop.store(output, null);
  93. } catch (IOException io) {
  94. io.printStackTrace();
  95. } finally {
  96. if (output != null) {
  97. try {
  98. output.close();
  99. } catch (IOException e) {
  100. e.printStackTrace();
  101. }
  102. }
  103.  
  104. }
  105.  
  106. }
  107.  
  108. public Cog(){
  109. try {
  110. BufferedReader br = new BufferedReader(new FileReader("token.txt"));
  111. String line;
  112. while ((line = br.readLine()) != null) {
  113. token = line;
  114. }
  115. br.close();
  116. }catch(Exception e){}
  117. cog(token);
  118. }
  119.  
  120.  
  121. public void cog(String token){
  122. try{
  123. api = new JDABuilder(AccountType.BOT).setToken(token).addListener(new Message(this)).buildBlocking();
  124. register(new Help(this));
  125. register(new Disable(this));
  126. register(new Enable(this));
  127. // register(new RequestDubito(this));
  128. register(new Ban(this));
  129. register(new Kick(this));
  130. //register(new Set(this));
  131. register(new AddCom(this));
  132. register(new DelCom(this));
  133. register(new EditCom(this));
  134. register(new Status(this));
  135. setStatus();
  136. }catch(Exception e){
  137. e.printStackTrace();
  138. cog(token);
  139. }
  140. }
  141.  
  142. public boolean userHasRole(Member user, String role){
  143. for(Role r : user.getRoles()){
  144. if(r.getName().equalsIgnoreCase(role))
  145. return true;
  146. }
  147. return false;
  148. }
  149.  
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement