Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #33 from frc5183/32-owner-handling-and-maybe-admin…
Browse files Browse the repository at this point in the history
…-handling-are-broken

fix(oatmeal): Fixes Admin/Owner issues by removing double-checking an…
  • Loading branch information
Trip-kun authored Dec 4, 2023
2 parents 211558c + 9a13422 commit 97e2ffc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
import wtf.triplapeeck.oatmeal.Config;
import wtf.triplapeeck.oatmeal.DataCarriage;
import wtf.triplapeeck.oatmeal.Main;
import wtf.triplapeeck.oatmeal.entities.UserData;
Expand All @@ -25,6 +26,10 @@ public void handler(MessageReceivedEvent event, DataCarriage carriage, ThreadMan
List<User> userList = carriage.message.getMentions().getUsers();
User user = userList.get(0);
UserData usUsr = Main.dataManager.getUserData(user.getId());
if (Config.getConfig().owners.contains(Long.valueOf(usUsr.getID()))) {
carriage.channel.sendMessage(user.getName() + " is in the Owner Config, cannot change as owner config also allows for admin status").queue();
return;
}
usUsr.setAdmin(!usUsr.isAdmin());
carriage.channel.sendMessage(user.getName() + " now " + Utils.isNot(usUsr.isAdmin()) + " an Admin").queue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
import wtf.triplapeeck.oatmeal.Config;
import wtf.triplapeeck.oatmeal.DataCarriage;
import wtf.triplapeeck.oatmeal.Main;
import wtf.triplapeeck.oatmeal.entities.UserData;
Expand All @@ -20,9 +21,12 @@ public void handler(MessageReceivedEvent event, DataCarriage carriage, ThreadMan
List<User> userList = carriage.message.getMentions().getUsers();
User user = userList.get(0);
UserData usUsr = Main.dataManager.getUserData(user.getId());

if (Config.getConfig().owners.contains(Long.valueOf(usUsr.getID()))) {
carriage.channel.sendMessage(user.getName() + " is in the Owner Config, cannot change").queue();
return;
}
usUsr.setOwner(!usUsr.isOwner());
carriage.channel.sendMessage(user.getName() + " now " + Utils.isNot(usUsr.isAdmin()) + " an Owner").queue();
carriage.channel.sendMessage(user.getName() + " now " + Utils.isNot(usUsr.isOwner()) + " an Owner").queue();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ public synchronized Boolean isAdmin() {
}

@Override
public void setAdmin(Boolean admin) {

public void setAdmin(@NotNull Boolean admin) {
this.admin=admin;
}

public synchronized void setAdmin(@NotNull boolean admin) {
this.admin = (admin || isOwner());
}

@NotNull
public synchronized Boolean isOwner() {
Expand All @@ -74,7 +71,7 @@ public void setOwner(Boolean owner) {
}

public synchronized void setOwner(@NotNull boolean owner) {
this.owner = (owner || Config.getConfig().owners.contains(userId));
this.owner = owner;
}

public Boolean isCurrencyPreference() {
Expand Down

0 comments on commit 97e2ffc

Please sign in to comment.