Skip to content

Commit

Permalink
Fixed rare exception where message size would exceed discords message…
Browse files Browse the repository at this point in the history
… max content length
  • Loading branch information
Alf-Melmac committed Feb 18, 2022
1 parent 13266b8 commit 0fb501a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ public List<String> getSlotList(long guildId) {
List<String> messages = new ArrayList<>();
for (SquadReferencelessDto squad : getSquadList()) {
final StringBuilder squadText = squad.toSlotList(guildId);

//Message can't fit new lines for new squad must start new message
if (slotListText.length() + 2 > Message.MAX_CONTENT_LENGTH) {
messages.add(slotListText.toString());
slotListText = new StringBuilder();
}

//Existing message size + 2 new line + new line may not exceed maximum discord message size
if ((slotListText.length() + 2 + squadText.length() > Message.MAX_CONTENT_LENGTH) && slotListText.length() + 2 <= Message.MAX_CONTENT_LENGTH) {
if (slotListText.length() + 2 + squadText.length() > Message.MAX_CONTENT_LENGTH) {
slotListText.append("\n"); //New squad

final List<String> splitSquadText = new ArrayList<>(Arrays.asList(squadText.toString().split("\\n"))); //Split squad text on every slot
Expand Down

0 comments on commit 0fb501a

Please sign in to comment.