Vaerys_Dawn

GuildConfig.java

Mar 12th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.35 KB | None | 0 0
  1. package POGOs;
  2.  
  3. import Interfaces.Command;
  4. import Main.Globals;
  5. import Objects.BlackListObject;
  6. import Objects.ChannelTypeObject;
  7. import Objects.OffenderObject;
  8. import Objects.RoleTypeObject;
  9. import sx.blah.discord.handle.obj.IChannel;
  10. import sx.blah.discord.handle.obj.IGuild;
  11. import sx.blah.discord.handle.obj.IRole;
  12. import sx.blah.discord.handle.obj.IUser;
  13.  
  14. import java.util.ArrayList;
  15.  
  16. /**
  17.  * Created by Vaerys on 03/08/2016.
  18.  */
  19. public class GuildConfig {
  20.     String prefixCommand = Globals.defaultPrefixCommand;
  21.     String prefixCC = Globals.defaultPrefixCC;
  22.     boolean properlyInit = false;
  23.     String guildName = "";
  24.     //toggles
  25.     //--AutoMessages
  26.     public boolean loginMessage = true;
  27.     public boolean dailyMessage = true;
  28.     //--Logging
  29.     public boolean generalLogging = false;
  30.     public boolean adminLogging = false;
  31.     public boolean deleteLogging = false;
  32.     public boolean joinLeaveLogging = false;
  33.     public boolean userRoleLogging = false;
  34.     public boolean editLogging = false;
  35.     public boolean extendEditLog = false;
  36.     public boolean channelLogging = false;
  37.     public boolean useTimeStamps = false;
  38.     //--Admin
  39.     public boolean denyInvites = false;
  40.     public boolean maxMentions = true;
  41.     public boolean shitPostFiltering = false;
  42.     public boolean muteRepeatOffenders = true;
  43.     public boolean rateLimiting = false;
  44.     //--Competition
  45.     public boolean compEntries = false;
  46.     public boolean compVoting = false;
  47.     //modules
  48.     public boolean moduleServers = true;
  49.     public boolean moduleChars = true;
  50.     public boolean moduleComp = false;
  51.     public boolean moduleRoles = true;
  52.     public boolean moduleCC = true;
  53.     public boolean moduleMe = true;
  54.     public boolean moduleModMute = true;
  55.     public int maxMentionLimit = 8;
  56.     public int messageLimit = 10;
  57.  
  58.     public int xpRate = 20;
  59.     public float xpModifier = 1;
  60.  
  61.     // TODO: 04/10/2016 let the mention limit be customisable.
  62.     ArrayList<ChannelTypeObject> channels = new ArrayList<>();
  63.     ArrayList<RoleTypeObject> cosmeticRoles = new ArrayList<>();
  64.     ArrayList<RoleTypeObject> modifierRoles = new ArrayList<>();
  65.     ArrayList<RoleTypeObject> trustedRoles = new ArrayList<>();
  66.     ArrayList<BlackListObject> blackList = new ArrayList<>();
  67.     ArrayList<OffenderObject> repeatOffenders = new ArrayList<>();
  68.     RoleTypeObject roleToMention = new RoleTypeObject("No Role Set", null);
  69.     RoleTypeObject mutedRole = new RoleTypeObject("No Role Set", null);
  70.  
  71.  
  72.     public String getPrefixCommand() {
  73.         return prefixCommand;
  74.     }
  75.  
  76.     public void setPrefixCommand(String prefixCommand) {
  77.         this.prefixCommand = prefixCommand;
  78.     }
  79.  
  80.     public String getPrefixCC() {
  81.         return prefixCC;
  82.     }
  83.  
  84.     public void setPrefixCC(String prefixCC) {
  85.         this.prefixCC = prefixCC;
  86.     }
  87.  
  88.     public boolean isProperlyInit() {
  89.         return properlyInit;
  90.     }
  91.  
  92.     public void setProperlyInit(boolean properlyInit) {
  93.         this.properlyInit = properlyInit;
  94.     }
  95.  
  96.     public void initConfig() {
  97.         for (BlackListObject b: blackList){
  98.             if (b.getReason().contains("**invites**")){
  99.                 blackList.clear();
  100.                 blackList.add(new BlackListObject("discord.gg", "#user# Please do not post Instant Invites To this Server.\n#mentionaAdmin#"));
  101.                 blackList.add(new BlackListObject("discordapp.com/Invite/", "#user# Please do not post Instant Invites To this Server.\n#mentionaAdmin#"));
  102.             }
  103.         }
  104.         if (!properlyInit){
  105.             blackList.add(new BlackListObject("discord.gg", "#user# Please do not post Instant Invites To this Server.\n#mentionaAdmin#"));
  106.             blackList.add(new BlackListObject("discordapp.com/Invite/", "#user# Please do not post Instant Invites To this Server.\n#mentionaAdmin#"));
  107.         }
  108.     }
  109.  
  110.     public void setGuildName(String guildName) {
  111.         this.guildName = guildName;
  112.     }
  113.  
  114.     public ArrayList<ChannelTypeObject> getChannels() {
  115.         return channels;
  116.     }
  117.  
  118.     public void setUpChannel(String channelType, String channelID) {
  119.         if (channelType.equals(Command.CHANNEL_SERVERS) && !moduleServers) {
  120.             return;
  121.         }
  122.         if (channels.size() == 0) {
  123.             channels.add(new ChannelTypeObject(channelType, channelID));
  124.             return;
  125.         }
  126.         for (int i = 0; i < channels.size(); i++) {
  127.             if (channels.get(i).getType().equals(channelType)) {
  128.                 channels.set(i, new ChannelTypeObject(channelType, channelID));
  129.                 return;
  130.             }
  131.         }
  132.         channels.add(new ChannelTypeObject(channelType, channelID));
  133.     }
  134.  
  135.     public String getChannelTypeID(String channelType) {
  136.         for (ChannelTypeObject c : channels) {
  137.             if (c.getType().equals(channelType)) {
  138.                 if (channelType.equalsIgnoreCase(Command.CHANNEL_SERVERS) && !moduleServers) {
  139.                     return null;
  140.                 }
  141.                 return c.getID();
  142.             }
  143.         }
  144.         return null;
  145.     }
  146.  
  147.     public void updateVariables(IGuild guild) {
  148.         //update Guild Name
  149.         setGuildName(guild.getName());
  150.  
  151.         //Update Races
  152.         ArrayList<RoleTypeObject> newRaces = new ArrayList<>();
  153.         for (RoleTypeObject r : cosmeticRoles) {
  154.             if (guild.getRoleByID(r.getRoleID()) != null) {
  155.                 r.updateRoleName(guild.getRoleByID(r.getRoleID()).getName());
  156.                 newRaces.add(r);
  157.             }
  158.         }
  159.         cosmeticRoles = newRaces;
  160.  
  161.         //Update Trusted Roles
  162.         ArrayList<RoleTypeObject> newTrustedRoles = new ArrayList<>();
  163.         for (RoleTypeObject r : trustedRoles) {
  164.             if (guild.getRoleByID(r.getRoleID()) != null) {
  165.                 r.updateRoleName(guild.getRoleByID(r.getRoleID()).getName());
  166.                 newTrustedRoles.add(r);
  167.             }
  168.         }
  169.         trustedRoles = newTrustedRoles;
  170.  
  171.         //Update Role to Mention
  172.         if (roleToMention.getRoleID() != null) {
  173.             if (guild.getRoleByID(roleToMention.getRoleID()) == null) {
  174.                 roleToMention = new RoleTypeObject("Role Missing", null);
  175.             } else {
  176.                 roleToMention.updateRoleName(guild.getRoleByID(roleToMention.getRoleID()).getName());
  177.             }
  178.         }
  179.  
  180.         //update Muted Role
  181.         if (mutedRole.getRoleID() != null) {
  182.             if (guild.getRoleByID(mutedRole.getRoleID()) == null) {
  183.                 mutedRole = new RoleTypeObject("Role Missing", null);
  184.             } else {
  185.                 mutedRole.updateRoleName(guild.getRoleByID(mutedRole.getRoleID()).getName());
  186.             }
  187.         }
  188.  
  189.         //update repeat offenders.
  190.         ArrayList<OffenderObject> newMentionSpammers = new ArrayList<>();
  191.         for (int i = 0; i < repeatOffenders.size(); i++) {
  192.             IUser offender = Globals.getClient().getUserByID(repeatOffenders.get(i).getID());
  193.             if (offender != null) {
  194.                 repeatOffenders.get(i).setDisplayName(offender.getName() + "#" + offender.getDiscriminator());
  195.             }
  196.         }
  197.  
  198.         //update channels
  199.         for (ChannelTypeObject c : channels) {
  200.             IChannel channel = guild.getChannelByID(c.getID());
  201.             if (channel == null) {
  202.                 channels.remove(c);
  203.             }
  204.         }
  205.         repeatOffenders = newMentionSpammers;
  206.     }
  207.  
  208.     public ArrayList<BlackListObject> getBlackList() {
  209.         return blackList;
  210.     }
  211.  
  212.     public String setRoleToMention(String roleName, String roleID) {
  213.         roleToMention = new RoleTypeObject(roleName, roleID);
  214.         return "> the Role `" + roleName + "` will now be mentioned when the tag #admin# is called within the blacklisting process.";
  215.     }
  216.  
  217.     public RoleTypeObject getRoleToMention() {
  218.         return roleToMention;
  219.     }
  220.  
  221.     public String addRole(String roleID, String roleName, boolean isCosmetic) {
  222.         ArrayList<RoleTypeObject> roleList;
  223.         boolean isfound = false;
  224.         int i = 0;
  225.         if (isCosmetic) {
  226.             roleList = cosmeticRoles;
  227.         } else {
  228.             roleList = modifierRoles;
  229.         }
  230.         while (i < roleList.size()) {
  231.             if (roleList.get(i).getRoleID().equals(roleID)) {
  232.                 isfound = true;
  233.             }
  234.             i++;
  235.         }
  236.         if (!isfound) {
  237.             roleList.add(new RoleTypeObject(roleName, roleID));
  238.             if (isCosmetic) {
  239.                 cosmeticRoles = roleList;
  240.             } else {
  241.                 modifierRoles = roleList;
  242.             }
  243.             return "> Role `" + roleName + "` Added to Role List.";
  244.         }
  245.         return "> Role already added to list.";
  246.     }
  247.  
  248.     public String removeRole(String roleID, String roleName, boolean isCosmetic) {
  249.         ArrayList<RoleTypeObject> roleList;
  250.         if (isCosmetic) {
  251.             roleList = cosmeticRoles;
  252.         } else {
  253.             roleList = modifierRoles;
  254.         }
  255.         for (int i = 0; i < roleList.size(); i++) {
  256.             if (roleList.get(i).getRoleID().equals(roleID)) {
  257.                 roleList.remove(i);
  258.                 if (isCosmetic) {
  259.                     cosmeticRoles = roleList;
  260.                 } else {
  261.                     modifierRoles = roleList;
  262.                 }
  263.                 return "> Role `" + roleName + "` Removed from Role List.";
  264.             }
  265.         }
  266.         return "> Role not in list of roles.";
  267.     }
  268.  
  269.     public ArrayList<RoleTypeObject> getModifierRoles() {
  270.         return modifierRoles;
  271.     }
  272.  
  273.     public ArrayList<RoleTypeObject> getCosmeticRoles() {
  274.         return cosmeticRoles;
  275.     }
  276.  
  277.     public boolean testIsTrusted(IUser author, IGuild guild) {
  278.         if (trustedRoles.size() == 0) {
  279.             return true;
  280.         } else {
  281.             for (RoleTypeObject task : trustedRoles) {
  282.                 for (IRole role : author.getRolesForGuild(guild)) {
  283.                     if (role.getID().equals(task.getRoleID())) {
  284.                         return true;
  285.                     }
  286.                 }
  287.             }
  288.             return false;
  289.         }
  290.     }
  291.  
  292.     public void addTrusted(String roleID) {
  293.         for (RoleTypeObject r : trustedRoles) {
  294.             if (r.getRoleID().equals(roleID)) {
  295.                 return;
  296.             }
  297.         }
  298.         trustedRoles.add(new RoleTypeObject(Globals.getClient().getRoleByID(roleID).getName(), roleID));
  299.     }
  300.  
  301.     public void delTrusted(String roleID) {
  302.         int i = 0;
  303.         for (RoleTypeObject r : trustedRoles) {
  304.             if (r.getRoleID().equals(roleID)) {
  305.                 trustedRoles.remove(i);
  306.                 return;
  307.             }
  308.             i++;
  309.         }
  310.     }
  311.  
  312.     public void setMaxMentionLimit(int maxMentionLimit) {
  313.         this.maxMentionLimit = maxMentionLimit;
  314.     }
  315.  
  316.     public void addOffender(OffenderObject offenderObject) {
  317.         repeatOffenders.add(offenderObject);
  318.     }
  319.  
  320.     public ArrayList<OffenderObject> getRepeatOffenders() {
  321.         return repeatOffenders;
  322.     }
  323.  
  324.     public void addOffence(String userID) {
  325.         for (int i = 0; i < repeatOffenders.size(); i++) {
  326.             if (repeatOffenders.get(i).getID().equals(userID)) {
  327.                 repeatOffenders.get(i).addOffence();
  328.             }
  329.         }
  330.     }
  331.  
  332.     public void setMutedRole(RoleTypeObject mutedRole) {
  333.         this.mutedRole = mutedRole;
  334.     }
  335.  
  336.     public RoleTypeObject getMutedRole() {
  337.         return mutedRole;
  338.     }
  339.  
  340.     public ArrayList<RoleTypeObject> getTrustedRoles() {
  341.         return trustedRoles;
  342.     }
  343.  
  344.     public boolean isRoleCosmetic(String id) {
  345.         for (RoleTypeObject r : cosmeticRoles) {
  346.             if (r.getRoleID().equals(id)) {
  347.                 return true;
  348.             }
  349.         }
  350.         return false;
  351.     }
  352.  
  353.     public boolean isRoleModifier(String id) {
  354.         for (RoleTypeObject r : modifierRoles) {
  355.             if (r.getRoleID().equals(id)) {
  356.                 return true;
  357.             }
  358.         }
  359.         return false;
  360.     }
  361.  
  362.     public boolean isRoleTrusted(String id) {
  363.         for (RoleTypeObject r : trustedRoles) {
  364.             if (r.getRoleID().equals(id)) {
  365.                 return true;
  366.             }
  367.         }
  368.         return false;
  369.     }
  370.  
  371.     public int getMaxMentionLimit() {
  372.         return maxMentionLimit;
  373.     }
  374.  
  375.     public void setRateLimit(int rateLimit) {
  376.         messageLimit = rateLimit;
  377.     }
  378. }
Add Comment
Please, Sign In to add comment