mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-02 15:56:34 +00:00
[AB-xxx] fixing not showing assignable role actions in metrics
This commit is contained in:
@@ -97,6 +97,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
|
||||
.anyMatch(memberRole -> memberRole.getIdLong() == payload.getRoleId());
|
||||
if(!memberHasRole) {
|
||||
if(place.getType().equals(AssignableRolePlaceType.BOOSTER) && member.getTimeBoosted() == null) {
|
||||
assignableRoleService.assignableRoleConditionFailure();
|
||||
throw new BoosterAssignableRolePlaceMemberNotBoostingException();
|
||||
}
|
||||
AssignableRole assignableRole = assignableRoleOptional.get();
|
||||
@@ -106,8 +107,9 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
|
||||
AssignableRoleConditionResult conditionResult =
|
||||
assignableRoleConditionServiceBean.evaluateConditions(assignableRole.getConditions(), aUserInAServer, roleById);
|
||||
if(!conditionResult.getFulfilled()) {
|
||||
log.info("One condition failed to be fullfilled - notifying user.");
|
||||
log.info("One condition failed to be fulfilled - notifying user.");
|
||||
self.notifyUserAboutConditionFail(model, event.getInteraction(), conditionResult.getModel());
|
||||
assignableRoleService.assignableRoleConditionFailure();
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
}
|
||||
}
|
||||
@@ -134,7 +136,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
|
||||
} else {
|
||||
removalFuture = CompletableFuture.completedFuture(null);
|
||||
}
|
||||
CompletableFuture<Void> roleAdditionFuture = roleService.addRoleToMemberAsync(member, roleById);
|
||||
CompletableFuture<Void> roleAdditionFuture = assignableRoleService.assignAssignableRoleToUser(roleById, member);
|
||||
CompletableFuture.allOf(removalFuture, roleAdditionFuture).whenComplete((unused, throwable) -> {
|
||||
if(throwable != null) {
|
||||
log.error("Failed to either add or remove roles for assignable role place {} in server {}.", payload.getPlaceId(), guild.getIdLong());
|
||||
@@ -149,7 +151,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
|
||||
}
|
||||
});
|
||||
} else {
|
||||
roleService.removeRoleFromUserAsync(member, roleById)
|
||||
assignableRoleService.removeAssignableRoleFromUser(roleById, member)
|
||||
.thenAccept(unused -> {
|
||||
self.notifyUser(model, false, roleById, event.getInteraction(), new ArrayList<>());
|
||||
log.info("Removed role {} from member {} in server {} for assignable role interaction {} on component {}.",
|
||||
|
||||
@@ -140,7 +140,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
|
||||
@Transactional
|
||||
public void persistAssignableRoleAddition(Long placeId, Role role, String description, FullEmote fakeEmote, String componentId) {
|
||||
AssignableRolePlace place = assignableRolePlaceManagementServiceBean.findByPlaceId(placeId);
|
||||
log.info("Adding role {} to assignable role place {} with component ID {}.", role.getId(), place, componentId);
|
||||
log.info("Adding role {} to assignable role place {} with component ID {}.", role.getId(), place.getId(), componentId);
|
||||
ComponentPayload payload = persistButtonCallback(place, componentId, role.getIdLong());
|
||||
assignableRoleManagementServiceBean.addRoleToPlace(fakeEmote, role, description, place, payload);
|
||||
}
|
||||
|
||||
@@ -72,14 +72,36 @@ public class AssignableRoleServiceBean implements AssignableRoleService {
|
||||
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "removed")))
|
||||
.build();
|
||||
|
||||
private static final CounterMetric ASSIGNABLE_ROLES_CONDITION_FAILED =
|
||||
CounterMetric
|
||||
.builder()
|
||||
.name(ASSIGNABLE_ROLES_METRIC)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "condition")))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member) {
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
|
||||
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
|
||||
log.info("Assigning role {} to member {} in server {}.", assignableRoleId, member.getId(), member.getGuild().getId());
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
|
||||
return roleService.addRoleToMemberAsync(member, role.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> assignAssignableRoleToUser(Role role, Member member) {
|
||||
return assignRoleToUser(role.getIdLong(), member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignableRoleConditionFailure() {
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_CONDITION_FAILED);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> assignRoleToUser(Long roleId, Member member) {
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
|
||||
return roleService.addRoleToMemberAsync(member, roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllRolesOfUserInPlace(AssignableRolePlace place, AUserInAServer userInAServer) {
|
||||
Optional<AssignedRoleUser> userOptional = assignedRoleUserManagementServiceBean.findByUserInServerOptional(userInAServer);
|
||||
@@ -103,8 +125,17 @@ public class AssignableRoleServiceBean implements AssignableRoleService {
|
||||
@Override
|
||||
public CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member) {
|
||||
log.info("Removing assignable role {} from user {} in server {}.", assignableRole.getId(), member.getId(), member.getGuild().getId());
|
||||
return removeRoleFromUser(assignableRole.getRole().getId(), member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeAssignableRoleFromUser(Role role, Member member) {
|
||||
return removeRoleFromUser(role.getIdLong(), member);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> removeRoleFromUser(Long roleId, Member member) {
|
||||
metricService.incrementCounter(ASSIGNABLE_ROLES_REMOVED);
|
||||
return roleService.removeRoleFromMemberAsync(member, assignableRole.getRole());
|
||||
return roleService.removeRoleFromMemberAsync(member, roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,5 +190,6 @@ public class AssignableRoleServiceBean implements AssignableRoleService {
|
||||
public void postConstruct() {
|
||||
metricService.registerCounter(ASSIGNABLE_ROLES_ASSIGNED, "Assignable roles assigned.");
|
||||
metricService.registerCounter(ASSIGNABLE_ROLES_REMOVED, "Assignable roles removed.");
|
||||
metricService.registerCounter(ASSIGNABLE_ROLES_CONDITION_FAILED, "Assignable roles failed to assign because of condition.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@ package dev.sheldan.abstracto.assignableroles.exception;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
|
||||
|
||||
public class BoosterAssignableRolePlaceMemberNotBoostingException extends AbstractoTemplatableException {
|
||||
|
||||
public BoosterAssignableRolePlaceMemberNotBoostingException() {
|
||||
super("Clicking member does not boost");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "assignable_role_booster_place_member_not_boosting_exception";
|
||||
|
||||
@@ -24,6 +24,8 @@ public interface AssignableRoleService {
|
||||
*/
|
||||
|
||||
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member);
|
||||
CompletableFuture<Void> assignAssignableRoleToUser(Role role, Member member);
|
||||
void assignableRoleConditionFailure();
|
||||
|
||||
/**
|
||||
* Clears all {@link AssignableRole assignableRoles} which are currently given to the {@link AUserInAServer user} of a certain
|
||||
@@ -41,6 +43,7 @@ public interface AssignableRoleService {
|
||||
* has been removed from the {@link Member member}
|
||||
*/
|
||||
CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member);
|
||||
CompletableFuture<Void> removeAssignableRoleFromUser(Role role, Member member);
|
||||
|
||||
/**
|
||||
* Removes the {@link AssignableRole role} from the given {@link Member member}
|
||||
|
||||
@@ -90,8 +90,16 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
|
||||
public static final String COMMAND_PROCESSED = "command.processed";
|
||||
public static final String STATUS_TAG = "status";
|
||||
public static final CounterMetric COMMANDS_PROCESSED_COUNTER = CounterMetric.builder().name(COMMAND_PROCESSED).tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "processed"))).build();
|
||||
public static final CounterMetric COMMANDS_WRONG_PARAMETER_COUNTER = CounterMetric.builder().name(COMMAND_PROCESSED).tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "parameter.wrong"))).build();
|
||||
public static final CounterMetric COMMANDS_PROCESSED_COUNTER = CounterMetric
|
||||
.builder()
|
||||
.name(COMMAND_PROCESSED)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "processed")))
|
||||
.build();
|
||||
public static final CounterMetric COMMANDS_WRONG_PARAMETER_COUNTER = CounterMetric
|
||||
.builder()
|
||||
.name(COMMAND_PROCESSED)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "parameter.wrong")))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
|
||||
@@ -53,7 +53,11 @@ public class MessageReceivedListenerBean extends ListenerAdapter {
|
||||
|
||||
public static final String MESSAGE_METRIC = "message";
|
||||
public static final String ACTION = "action";
|
||||
private static final CounterMetric MESSAGE_RECEIVED_COUNTER = CounterMetric.builder().name(MESSAGE_METRIC).tagList(Arrays.asList(MetricTag.getTag(ACTION, "received"))).build();
|
||||
private static final CounterMetric MESSAGE_RECEIVED_COUNTER = CounterMetric
|
||||
.builder()
|
||||
.name(MESSAGE_METRIC)
|
||||
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "received")))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
|
||||
Reference in New Issue
Block a user