Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit e558fb9

Browse files
CodeDoctorDECodeDoctorDE
andauthored
1.0.3 (#20)
* changing format * change readme * remove unused capture of sentry * change format parameter * bump version * fixing karma leaderboard * registerr karma leaderboard * minor changes Co-authored-by: CodeDoctorDE <[email protected]>
1 parent 38cc335 commit e558fb9

File tree

74 files changed

+214
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+214
-166
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ Java bot with many features. Developed by @CodeDoctorDE (Discord: CodeDoctor#871
2323
### What is it?
2424
Guess what word the writer has chosen. This is a turn based game. Every player can join in.
2525

26+
# Contributing
27+
28+
To contribute, fork this repository and create a pull request. If you want you can also join my discord. If you contribute more, you can get the contributor role.
29+
30+
## Branches
31+
32+
Name | Description
33+
--- | ---
34+
feature/* | Every new feature will developed here
35+
hotfix/* | Fixing bugs will be developed here
36+
master | Every feature and hotfix will be merged here
37+
stable | Stable changes will be merged here
38+
2639
# Current servers
2740
You can visit my bot on this servers:
2841
* [KniffelGames](https://discord.gg/J7EUgvN)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.codedoctorde</groupId>
88
<artifactId>linwood</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.0.3</version>
1010
<properties>
1111
<java.version>11</java.version>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/com/github/codedoctorde/linwood/apps/single/game/mode/tictactoe/TicTacToe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public void start(SingleApplication app) {
5757
var bundle = getBundle(session);
5858
Category finalCategory = category;
5959
ChannelAction<TextChannel> action;
60-
action = finalCategory == null ?game.getGuild().createTextChannel(MessageFormat.format(bundle.getString("TextChannel"),game.getId())):
61-
finalCategory.createTextChannel(MessageFormat.format(bundle.getString("TextChannel"),game.getId()));
60+
action = finalCategory == null ?game.getGuild().createTextChannel(String.format(bundle.getString("TextChannel"),game.getId())):
61+
finalCategory.createTextChannel(String.format(bundle.getString("TextChannel"),game.getId()));
6262
session.close();
6363
action.queue((textChannel -> {
6464
this.textChannelId = textChannel.getIdLong();

src/main/java/com/github/codedoctorde/linwood/apps/single/game/mode/whatisit/WhatIsIt.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,12 @@ public void start(SingleApplication app) {
4646
var guild = GuildEntity.get(session, game.getGuildId());
4747
Category category = null;
4848
if(guild.getGameEntity().getGameCategoryId() != null)
49-
category = guild.getGameEntity().getGameCategory();
49+
category = guild.getGameEntity().getGameCategory();
5050
var bundle = getBundle(session);
5151
Category finalCategory = category;
52-
ChannelAction<TextChannel> action;
53-
if(finalCategory == null)
54-
action = game.getGuild().createTextChannel(MessageFormat.format(bundle.getString("TextChannel"),game.getId()));
55-
else
56-
action = finalCategory.createTextChannel(MessageFormat.format(bundle.getString("TextChannel"),game.getId()));
5752
session.close();
58-
action.queue((textChannel -> {
53+
((finalCategory == null)?game.getGuild().createTextChannel(String.format(bundle.getString("TextChannel"),game.getId())):
54+
finalCategory.createTextChannel(String.format(bundle.getString("TextChannel"),game.getId()))).queue((textChannel -> {
5955
this.textChannelId = textChannel.getIdLong();
6056
if(finalCategory != null)
6157
textChannel.getManager().setParent(finalCategory).queue();
@@ -84,10 +80,10 @@ public void chooseNextPlayer(){
8480
var session = Linwood.getInstance().getDatabase().getSessionFactory().openSession();
8581
var bundle = getBundle(session);
8682
sendLeaderboard(session);
87-
getTextChannel().sendMessage(MessageFormat.format(bundle.getString("Next"), currentRound + 1)).queue(message -> {
83+
getTextChannel().sendMessageFormat(bundle.getString("Next"), currentRound + 1).queue(message -> {
8884
wantWriterMessageId = message.getIdLong();
8985
message.addReaction("\uD83D\uDD90️").queue(aVoid ->
90-
message.addReaction("⛔").queue());
86+
message.addReaction("⛔").queue());
9187
stopTimer();
9288
timer.schedule(new TimerTask() {
9389
@Override
@@ -117,7 +113,7 @@ public void nextRound(Session session, long writerId){
117113
var bundle = getBundle(session);
118114
game.getGuild().retrieveMemberById(writerId).queue(member -> {
119115
var session1 = Linwood.getInstance().getDatabase().getSessionFactory().openSession();
120-
getTextChannel().sendMessage(MessageFormat.format(bundle.getString("Round"), member.getAsMention())).queue();
116+
getTextChannel().sendMessageFormat(bundle.getString("Round"), member.getAsMention()).queue();
121117
sendLeaderboard(session1);
122118
session1.close();
123119
round.inputWriter();
@@ -164,7 +160,7 @@ public void finishRound(){
164160
wantWriter.clear();
165161
if(currentRound >= maxRounds) finishGame();
166162
else
167-
chooseNextPlayer();
163+
chooseNextPlayer();
168164
session.close();
169165
});
170166
}
@@ -182,16 +178,16 @@ private void sendLeaderboard(ResourceBundle bundle, TextChannel textChannel){
182178
var leaderboard = getLeaderboard();
183179
if(textChannel == null)
184180
return;
185-
textChannel.getGuild().retrieveMembersByIds(leaderboard.stream().map(Map.Entry::getKey).collect(Collectors.toList())).onSuccess(members -> {
186-
StringBuilder stringBuilder = new StringBuilder();
187-
for (int i = 0; i < members.size(); i++) {
188-
var member = members.get(i);
189-
if (member != null)
190-
stringBuilder.append(MessageFormat.format(bundle.getString("Leaderboard"), i + 1,
191-
member.getAsMention(), leaderboard.get(i).getValue()));
192-
}
193-
textChannel.sendMessage(new EmbedBuilder().setTitle(bundle.getString("LeaderboardHeader")).setDescription(stringBuilder.toString()).setFooter(bundle.getString("LeaderboardFooter")).build()).queue();
194-
});
181+
textChannel.getGuild().retrieveMembersByIds(leaderboard.stream().map(Map.Entry::getKey).collect(Collectors.toList())).onSuccess(members -> {
182+
StringBuilder stringBuilder = new StringBuilder();
183+
for (int i = 0; i < members.size(); i++) {
184+
var member = members.get(i);
185+
if (member != null)
186+
stringBuilder.append(String.format(bundle.getString("Leaderboard"), i + 1,
187+
member.getAsMention(), leaderboard.get(i).getValue()));
188+
}
189+
textChannel.sendMessage(new EmbedBuilder().setTitle(bundle.getString("LeaderboardHeader")).setDescription(stringBuilder.toString()).setFooter(bundle.getString("LeaderboardFooter")).build()).queue();
190+
});
195191
}
196192

197193
private ArrayList<Map.Entry<Long, Integer>> getLeaderboard() {
@@ -251,12 +247,12 @@ public boolean wantWriter(Session session, Member member) {
251247
if(getRound() != null)
252248
return false;
253249
wantWriter.add(member.getIdLong());
254-
getTextChannel().sendMessage(MessageFormat.format(getBundle(session).getString("Join"), member.getUser().getAsMention())).queue();
250+
getTextChannel().sendMessageFormat(getBundle(session).getString("Join"), member.getUser().getAsMention()).queue();
255251
return true;
256252
}
257253

258254
public void removeWriter(Session session, Member member) {
259255
wantWriter.remove(member.getIdLong());
260-
getTextChannel().sendMessage(MessageFormat.format(getBundle(session).getString("Leave"), member.getUser().getAsMention())).queue();
256+
getTextChannel().sendMessageFormat(getBundle(session).getString("Leave"), member.getUser().getAsMention()).queue();
261257
}
262258
}

src/main/java/com/github/codedoctorde/linwood/apps/single/game/mode/whatisit/WhatIsItEvents.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
77
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
88
import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent;
9+
import net.dv8tion.jda.api.exceptions.PermissionException;
910
import net.dv8tion.jda.api.hooks.SubscribeEvent;
1011

1112
import java.text.MessageFormat;
@@ -21,17 +22,17 @@ public WhatIsItEvents(WhatIsIt whatIsIt){
2122
}
2223
@SubscribeEvent
2324
public void onGuess(MessageReceivedEvent event){
24-
try {
25+
try{
2526
if (event.getChannel().getIdLong() != whatIsIt.getTextChannelId() || event.getMember() == null)
26-
;
27+
return;
2728
var session = Linwood.getInstance().getDatabase().getSessionFactory().openSession();
2829
var message = event.getMessage();
2930
if (whatIsIt.getTextChannelId() == message.getTextChannel().getIdLong()){
3031
var round = whatIsIt.getRound();
3132
if (round != null && round.getWord() != null && message.getContentStripped().toLowerCase().contains(round.getWord().toLowerCase())) {
3233
message.delete().queue();
3334
if (!round.isGuesser(event.getMember()) && message.getAuthor().getIdLong() != round.getWriterId())
34-
event.getChannel().sendMessage(MessageFormat.format(whatIsIt.getBundle(session).getString("Guess"), event.getAuthor().getName(), round.guessCorrectly(event.getMember()))).queue(message1 -> {
35+
event.getChannel().sendMessageFormat(whatIsIt.getBundle(session).getString("Guess"), event.getAuthor().getName(), round.guessCorrectly(event.getMember())).queue(message1 -> {
3536
var session1 = Linwood.getInstance().getDatabase().getSessionFactory().openSession();
3637
round.checkEverybody(session1);
3738
session1.close();
@@ -40,6 +41,9 @@ public void onGuess(MessageReceivedEvent event){
4041
}
4142
session.close();
4243
}
44+
catch(PermissionException e){
45+
e.printStackTrace();
46+
}
4347
catch(Exception e){
4448
e.printStackTrace();
4549
Sentry.capture(e);
@@ -51,6 +55,9 @@ public void onWord(MessageReceivedEvent event) {
5155
if (event.getChannelType() == ChannelType.PRIVATE && whatIsIt.getRound() != null && whatIsIt.getRound().getWriterId() == event.getAuthor().getIdLong() && whatIsIt.getRound().getWord() == null)
5256
whatIsIt.getRound().startRound(event.getMessage().getContentStripped());
5357
}
58+
catch(PermissionException e){
59+
e.printStackTrace();
60+
}
5461
catch(Exception e){
5562
e.printStackTrace();
5663
Sentry.capture(e);
@@ -83,6 +90,9 @@ public void onJoin(MessageReactionAddEvent event){
8390
session.close();
8491
});
8592
}
93+
catch(PermissionException e){
94+
e.printStackTrace();
95+
}
8696
catch(Exception e){
8797
e.printStackTrace();
8898
Sentry.capture(e);
@@ -99,6 +109,9 @@ public void onLeave(MessageReactionRemoveEvent event){
99109
session.close();
100110
});
101111
}
112+
catch(PermissionException e){
113+
e.printStackTrace();
114+
}
102115
catch(Exception e){
103116
e.printStackTrace();
104117
Sentry.capture(e);

src/main/java/com/github/codedoctorde/linwood/apps/single/game/mode/whatisit/WhatIsItRound.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void run() {
7272
String message = null;
7373
switch (time) {
7474
case 120:
75-
message = MessageFormat.format(bundle.getString("CountdownMinutes"), time / 60);
75+
message = String.format(bundle.getString("CountdownMinutes"), time / 60);
7676
break;
7777
case 60:
7878
message = bundle.getString("CountdownMinute");
@@ -84,7 +84,7 @@ public void run() {
8484
case 4:
8585
case 3:
8686
case 2:
87-
message = MessageFormat.format(bundle.getString("CountdownSeconds"), time);
87+
message = String.format(bundle.getString("CountdownSeconds"), time);
8888
break;
8989
case 1:
9090
message = bundle.getString("CountdownSecond");
@@ -101,7 +101,7 @@ public void stopRound(){
101101
var session = Linwood.getInstance().getDatabase().getSessionFactory().openSession();
102102
var bundle = whatIsIt.getBundle(session);
103103
if(word != null)
104-
whatIsIt.getTextChannel().sendMessage(MessageFormat.format(bundle.getString("Word"), word)).queue();
104+
whatIsIt.getTextChannel().sendMessageFormat(bundle.getString("Word"), word).queue();
105105
stopTimer();
106106
session.close();
107107
}

src/main/java/com/github/codedoctorde/linwood/commands/ClearCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S
3333
message.getChannel().sendMessage(bundle.getString("Between")).queue();
3434
message.getChannel().getHistory().retrievePast(count).queue(messages -> {
3535
messages.forEach(deleteMessage -> deleteMessage.delete().queue());
36-
message.getChannel().sendMessage(MessageFormat.format(bundle.getString("Success"), messages.size())).queue();
36+
message.getChannel().sendMessageFormat(bundle.getString("Success"), messages.size()).queue();
3737
});
3838
return true;
3939
}

src/main/java/com/github/codedoctorde/linwood/commands/CommandManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S
2727
if (!command.onCommand(session, message, entity,
2828
(args.length > 0) ? args[0] : "",
2929
(args.length > 0) ? Arrays.copyOfRange(args, 1, args.length) : new String[0]))
30-
message.getChannel().sendMessage(MessageFormat.format(ResourceBundle.getBundle("locale.Command").getString("Syntax"), Objects.requireNonNull(command.getBundle(entity)).getString("Syntax"))).queue();
30+
message.getChannel().sendMessageFormat(ResourceBundle.getBundle("locale.Command").getString("Syntax"), Objects.requireNonNull(command.getBundle(entity)).getString("Syntax")).queue();
3131
}
3232
else
3333
message.getChannel().sendMessage(baseBundle.getString("NoPermission")).queue();

src/main/java/com/github/codedoctorde/linwood/commands/InfoCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public String infoFormat(Message message, GuildEntity entity, String text){
3636
long hour = (uptime / (1000 * 60 * 60)) % 24;
3737
long days = (uptime / (1000 * 60 * 24));
3838
var prefixes = String.join(", ", entity.getPrefixes());
39-
return MessageFormat.format(text, Linwood.getInstance().getVersion(), message.getAuthor().getAsMention(), prefixes.isBlank()? " ": prefixes,
39+
return String.format(text, Linwood.getInstance().getVersion(), message.getAuthor().getAsMention(), prefixes.isBlank()? " ": prefixes,
4040
days, hour, minute, second, millis, Linwood.getInstance().getConfig().getSupportURL());
4141
}
4242

src/main/java/com/github/codedoctorde/linwood/commands/PlanCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public boolean onCommand(Session session, Message message, GuildEntity entity, S
2424
var bundle = getBundle(entity);
2525
message.getChannel().sendMessage(new EmbedBuilder()
2626
.addField(bundle.getString("Plan"), bundle.getString("Plan" + entity.getPlan().name()), false)
27-
.addField(bundle.getString("PrefixLimitTitle"), MessageFormat.format(bundle.getString("PrefixLimitBody"), entity.getPlan().getPrefixLimit()), false)
27+
.addField(bundle.getString("PrefixLimitTitle"), String.format(bundle.getString("PrefixLimitBody"), entity.getPlan().getPrefixLimit()), false)
2828
.build()).queue();
2929
return true;
3030
}

0 commit comments

Comments
 (0)