summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java')
-rw-r--r--src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java47
1 files changed, 17 insertions, 30 deletions
diff --git a/src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java b/src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java
index 00780fc..dcab6bb 100644
--- a/src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java
+++ b/src/main/java/net/tylermurphy/ken/command/moderation/TempBan.java
@@ -14,6 +14,7 @@ import net.tylermurphy.ken.command.annotation.Command;
import net.tylermurphy.ken.command.annotation.Option;
import net.tylermurphy.ken.command.annotation.Requirement;
import net.tylermurphy.ken.database.ModerationTable;
+import net.tylermurphy.ken.database.UserTable;
import net.tylermurphy.ken.util.Checks;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -36,21 +37,10 @@ public class TempBan {
String timeString = (String) args.get(1);
String reason = (String) args.get(2);
boolean purge = (boolean) args.get(3);
- if(target == sender){
- return Response.error("You are not allowed to do this to yourself");
- }
- Role low = Checks.getHighestRole(target);
- Role high = Checks.getHighestRole(sender);
- if(!Checks.getRolePermission(high, low)){
- return Response.error("You need a higher role than the target");
- }
- Role self = Checks.getHighestRole(guild.getSelfMember());
- if(!Checks.getRolePermission(self, low)){
- return Response.error("I need a higher role than the target");
- }
- if(guild.getOwner() == target){
- return Response.error("You cannot to this to the server owner");
- }
+
+ try { Checks.hasPermission(sender, target); }
+ catch (RuntimeException e) { return Response.error(e.getMessage()); }
+
try {
guild.retrieveBan(target).complete();
return Response.error("User is already banned from this server");
@@ -62,10 +52,6 @@ public class TempBan {
SimpleDateFormat format = new SimpleDateFormat("MMM d, y h:ma zz");
String date = format.format(time);
- ModerationTable table = Ken.getInstance().getDatabase().getModerationTable();
- String data = table.getData(guild.getIdLong(), target.getUser().getIdLong());
- JSONObject json = table.updateData(data);
-
try {
guild.removeTimeout(target).queue();
} catch (Exception ignored){}
@@ -76,19 +62,20 @@ public class TempBan {
return Response.error("Failed to temp ban user");
}
- JSONObject status = json.getJSONObject("status");
- status.put("type", "temp-ban");
- status.put("reason", reason);
- status.put("until", time);
- json.put("status", status);
-
+ ModerationTable table = Ken.getInstance().getDatabase().getModerationTable();
+ UserTable userTable = Ken.getInstance().getDatabase().getUserTable();
+ JSONObject json = table.getData(guild.getIdLong(), target.getUser().getIdLong());
JSONArray history = json.getJSONArray("history");
- history.put(new JSONObject().put("type", "temp-ban").put("reason", reason).put("date",new Date().getTime()).put("by", sender.getIdLong()));
- json.put("history", history);
-
- table.setData(guild.getIdLong(), target.getUser().getIdLong(), json.toString());
+ history.put(new JSONObject()
+ .put("type", "tempban")
+ .put("reason", reason)
+ .put("date",new Date().getTime())
+ .put("by", sender.getIdLong())
+ .put("duration", time)
+ );
- Ken.getInstance().getDatabase().getUserTable().setData(target.getIdLong(), target.getUser().getName(), Integer.parseInt(target.getUser().getDiscriminator()));
+ table.setData(guild.getIdLong(), target.getUser().getIdLong(), history, "tempban", time);
+ userTable.setData(target.getIdLong(), target.getUser().getName(), Integer.parseInt(target.getUser().getDiscriminator()));
PrivateChannel channel = target.getUser().openPrivateChannel().complete();
if(channel != null){