Created
November 7, 2020 17:30
-
-
Save aNNiMON/c1cd2e7fe26e5dedc86708dc7fe65a14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void processUpdates(List<Update> updates) { | |
for (Update update : updates) { | |
if (update != null) { | |
Message message = update.getMessage(); | |
// don't process old messages | |
long current = System.currentTimeMillis() / 1000; | |
if (message.getDate() + 60 >= current) { | |
long chatId = message.getChatId(); | |
if (chatId == config.tournamentChat()) { | |
if ("/tournament".equals(message.getText())) { | |
for (Members member : members) { | |
if (member.isBlocked()) { | |
Log.warning("Member {} is blocked", member); | |
tournamentMembers.remove(member); | |
if (tournamentMembers.size() > MIN_MEMBERS_COUNT) { | |
tournamentEnabled = false; | |
// 9th nesting level!!!!! | |
} | |
} else { | |
Member opponent = tournamentMembers.pop(); | |
tournamentEnabled = true; | |
Message.create() | |
.withText("Tournament started. Your opponent is {}", opponent) | |
.toChat(member.getId()) | |
.send(); | |
Message.create() | |
.withText("Tournament started. Your opponent is {}", member) | |
.toChat(opponent.getId()) | |
.send(); | |
Message.create() | |
.withText("Tournament started. {} vs {}", member, opponent) | |
.toChat(chatId) | |
.send(); | |
} | |
} | |
} | |
} else { | |
String text = message.getText(); | |
if (text != null) { | |
// 20 more lines before this | |
String[] params = text.split(" "); | |
members.clear() | |
members.add(params[1]); | |
members.add(params[2]); | |
tournamentEnabled = true; | |
markup = new Markup(); | |
rows = List.of(members); | |
markup.setRows(rows); | |
markup.setAction("tournament"); | |
status = Message.create() | |
.withText("Let's go!") | |
.withMarkup(markup) | |
.toChat(chatId) | |
.send(); | |
validateStatus(status); | |
} else { | |
Log.error("Empty command"); | |
} | |
} | |
} | |
} | |
} | |
} | |
// I especially love this wall of closing curly braces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment