Skip to content

Commit 13a6776

Browse files
authored
Merge pull request #9 from yoinc-development/csbot-features
version 3.3 bugfixes
2 parents 689f4f3 + 7daae75 commit 13a6776

9 files changed

Lines changed: 110 additions & 72 deletions

File tree

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,52 @@
22

33
[![GitHub release](https://img.shields.io/github/v/release/janesth/CounterStrikeBot)](https://github.com/janesth/CounterStrikeBot)
44

5-
The purpose of this bot is to inform users of a Discord server in a specific channel about played matches.
6-
Continuing from its original purpose, it also allows a specific user group to execute "rcon changelevel <map_name>" to change the level on a retake server.
5+
This bot enables Discord users to join a custom retake server, inform members of a specific guild about Counter Strike stats or lets you share your favourite gaming moment. Each running instance of this bot is independent of each other and be configured to suit your guild's needs.
6+
7+
## Features
8+
9+
### Slash Commands
10+
11+
- `/map <map>` - allows users to change the current map on the retake server. For users to be allowed to use this command, they must be assigned to a designated role - defined in the properties below. `map` contains the prefered map - also to be defined in a property.
12+
- `/stas <steamID>` - display this user's Counter Strike stats based on their Steam account. `steamID` is the user's [steam ID](https://www.steamidfinder.com/).
13+
- `/comapre <steamID1> <steamID2>` - compares two users' Counter Strike stats.
14+
- `/teams <amount>` - divides the current members of a voice channel into teams. `amount` defines the amount of teams to be created. The requester has to be in a voice chat for this feature to work.
15+
- `/wow <url>` - allows to set a personal gaming moment (wow moment). `url` has to be either a YouTube or a Discord url.
16+
- `/status` - returns the current status of the retake server.
17+
18+
### User Context Commands
19+
20+
To execute these commands, right-click on a user, choose "Apps" and then one of the followings commands:
21+
22+
- `wow` - returns this user's wow moment for everyone to see.
23+
- `retake stats` - return this user's stats on the set retake server.
24+
25+
### Scheduled Tasks
26+
27+
There are two Counter Strike relavant scheduled tasks running:
28+
29+
- A collection task to receive discord user information to enable all users to use relevant commands.
30+
- A join task to send an invite to the retake server after a user has joined the server.
731

832
## Configuration
933

10-
All of these properties are defined in "config.properties". Mandatory properties are **bold**.
34+
All of these properties are defined in "config.properties". If you choose to run your own instance of the bot, please consider all these properties to be mandatory. Due to privacy reasons we won't be commiting our own properties into this repository.
1135

1236
These properties are relevant to connect to Discord and to limit this bot's functionalities by various factors:
13-
- **`discord.apiToken` - https://discord.com/developers/applications to receive your individual bot token**
37+
- `discord.apiToken` - visit the official [Discord Developers Portal](https://discord.com/developers/applications) to receive your individual bot token
1438
- `discord.allowedRoleId` - the ID of a user group to use commands
1539
- `discord.thisIsMyHome` - the ID of the server's home base
1640

1741
These properties are currently relevant for the CS2 stats feature.
18-
- **`steam.api` - Steam Web API key**
42+
- `steam.api` - Steam Web API key
1943

2044
The following properties were relevant to connect to the retake server and what maps are allowed to be played:
2145
- `server.ip` - the IP address of the csgo server
2246
- `server.port` - the port of the csgo server
2347
- `server.password` - the RCON password of the csgo server (to define in `server.cfg`)
2448
- `csgo.maps` - a comma seperated list of allowed maps to switch to (like `de_dust,de_tuscan,...`)
2549
- `server.delay` - a delay (in seconds) to stop users from spamming a map change.
50+
- `server.connectLink` - a link to an external website to redirect to the game server (see [this reddit thread](https://www.reddit.com/r/discordapp/comments/13kk1bz/discord_has_stopped_to_support_steam_links_why/) as to why a direct link to Steam isn't possible)
2651

2752
The next properties were relevant for a scratched commendation system:
2853
- `server.ftp.ip` - the IP address to access the server using FTP
@@ -31,7 +56,7 @@ The next properties were relevant for a scratched commendation system:
3156
- `server.ftp.password` - the FTP password
3257

3358
The last property is relevant regarding the bot's wow feature:
34-
- **`db.url` - the URL of a database for the bot to store all submitted wow clips**
59+
- `db.url` - the URL of a database for the bot to store all submitted wow clips
3560

3661
## Run the bot
3762

@@ -40,10 +65,7 @@ TO BE DEFINED
4065
## F.A.Q.
4166

4267
### Can I run the bot myself? Do I have to invite the public instance of the bot to my server??
43-
You can invite the bot to your server or run it yourself by changing the properties in config.properties and following the tutorial above the F.A.Q. section.
44-
45-
### Why doesn't ``/map`` work?
46-
SourceMod is not compatible with Counter Strike 2.
68+
It would be recommended to run the bot yourself, even though you are able to invite any running instance of it to your server. The downside of inviting an already running instance to your server would be the lack of customization you could do (your own retake server ip, roles, etc.).
4769

4870
### Can I fork this and make it better?
4971
Yes.

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<modelVersion>4.0.0</modelVersion>
77

88
<groupId>ch.yoinc</groupId>
9-
<artifactId>retakeBot</artifactId>
10-
<version>1.0</version>
9+
<artifactId>CounterStrikeBot</artifactId>
10+
<version>3.3</version>
1111

12-
<name>RetakeBot</name>
13-
<url>https://www.github.com/janesth/retakeBot</url>
12+
<name>CounterStrikeBot</name>
13+
<url>https://github.com/yoinc-development/CounterStrikeBot</url>
1414

1515
<properties>
1616
<maven.compiler.source>20</maven.compiler.source>

src/main/java/listeners/CounterStrikeBotListener.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,37 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
3535

3636
String locale = discordService.getUserLocale(event);
3737

38-
if(event.getGuild().getMembers().contains(event.getMember())) {
39-
if ("stats".equals(event.getName())) {
40-
event.deferReply().queue();
41-
event.getHook().sendMessageEmbeds(csStatsService.handleStatsEvent(event, locale).build()).queue();
42-
}
43-
44-
if ("compare".equals(event.getName())) {
45-
event.deferReply().queue();
46-
event.getHook().sendMessageEmbeds(csStatsService.handleCompareEvent(event, locale).build()).queue();
47-
}
48-
49-
if ("map".equals(event.getName())) {
50-
event.deferReply().queue();
51-
event.getHook().sendMessage(retakeService.handleMapEvent(event, locale)).queue();
52-
}
53-
54-
if ("wow".equals(event.getName())) {
55-
event.deferReply().queue();
56-
event.getHook().sendMessage(csFunService.handleAddWowEvent(event, locale)).queue();
57-
}
58-
59-
if ("teams".equals(event.getName())) {
60-
event.deferReply().queue();
61-
event.getHook().sendMessageEmbeds(csFunService.handleSetTeamsEvent(event, locale).build()).queue();
62-
}
63-
64-
if ("status".equals(event.getName())) {
65-
event.deferReply().queue();
66-
event.getHook().sendMessageEmbeds(retakeService.handleStatusEvent(event, locale).build()).queue();
38+
if(!event.getChannel().getType().equals(ChannelType.PRIVATE)) {
39+
if (event.getGuild() != null && event.getGuild().getMembers().contains(event.getMember())) {
40+
if ("stats".equals(event.getName())) {
41+
event.deferReply().queue();
42+
event.getHook().sendMessageEmbeds(csStatsService.handleStatsEvent(event, locale).build()).queue();
43+
}
44+
45+
if ("compare".equals(event.getName())) {
46+
event.deferReply().queue();
47+
event.getHook().sendMessageEmbeds(csStatsService.handleCompareEvent(event, locale).build()).queue();
48+
}
49+
50+
if ("map".equals(event.getName())) {
51+
event.deferReply().queue();
52+
event.getHook().sendMessage(retakeService.handleMapEvent(event, locale)).queue();
53+
}
54+
55+
if ("wow".equals(event.getName())) {
56+
event.deferReply().queue();
57+
event.getHook().sendMessage(csFunService.handleAddWowEvent(event, locale)).queue();
58+
}
59+
60+
if ("teams".equals(event.getName())) {
61+
event.deferReply().queue();
62+
event.getHook().sendMessageEmbeds(csFunService.handleSetTeamsEvent(event, locale).build()).queue();
63+
}
64+
65+
if ("status".equals(event.getName())) {
66+
event.deferReply().queue();
67+
event.getHook().sendMessageEmbeds(retakeService.handleStatusEvent(event, locale).build()).queue();
68+
}
6769
}
6870
}
6971
}
@@ -111,7 +113,7 @@ public void onMessageReceived(MessageReceivedEvent messageReceivedEvent) {
111113

112114
@Override
113115
public void onButtonInteraction(ButtonInteractionEvent buttonInteractionEvent) {
114-
String locale = "en";
116+
String locale = discordService.getUserLocale(buttonInteractionEvent);
115117
buttonInteractionEvent.getMessageChannel().sendMessage(gregflixService.handleButtonEvent(buttonInteractionEvent, locale)).queue();
116118
}
117119

src/main/java/services/DataService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public List<User> getAllGregflixUsers() throws SQLException {
5353
}
5454

5555
public List<GregflixEntry> getGregflixEntriesForThisWeek(Date startOfWeek, Date endOfWeek) throws SQLException{
56-
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM gregflix WHERE uploadedDate >= ? AND uploadedDate <= ?");
56+
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM gregflix WHERE uploadedDate >= ? AND uploadedDate <= ? ORDER BY title ASC");
5757
preparedStatement.setDate(1, startOfWeek);
5858
preparedStatement.setDate(2, endOfWeek);
5959
ResultSet resultSet = preparedStatement.executeQuery();

src/main/java/services/DiscordService.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import net.dv8tion.jda.api.JDA;
88
import net.dv8tion.jda.api.entities.Guild;
99
import net.dv8tion.jda.api.entities.Member;
10+
import net.dv8tion.jda.api.events.Event;
1011
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
12+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
1113
import net.dv8tion.jda.api.interactions.components.ItemComponent;
1214
import net.dv8tion.jda.api.interactions.components.buttons.Button;
1315
import retakeServer.RetakeWatchdog;
@@ -58,10 +60,16 @@ public void run() {
5860
timer.schedule(weekInReviewTask, weeklyReportdelay, (7 * 24 * 60 * 60 * 1000L));
5961
}
6062

61-
public String getUserLocale(GenericCommandInteractionEvent event) {
63+
public String getUserLocale(Event event) {
6264
String locale = "en";
63-
if (event.getInteraction().getUserLocale().getLocale().equals("de")) {
64-
locale = "de";
65+
if(event instanceof GenericCommandInteractionEvent) {
66+
if (((GenericCommandInteractionEvent)event).getInteraction().getUserLocale().getLocale().equals("de")) {
67+
locale = "de";
68+
}
69+
} else if(event instanceof ButtonInteractionEvent) {
70+
if(((ButtonInteractionEvent) event).getInteraction().getUserLocale().getLocale().equals("de")) {
71+
locale = "de";
72+
}
6573
}
6674
return locale;
6775
}

src/main/java/services/MessageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void sendGregflixEmbedMessage(PrivateChannel privateChannel, EmbedBuilder
6262

6363
public void contactGreg(String message, String discordId, JDA jda) {
6464
jda.getUserById(discordId).openPrivateChannel().queue((privateChannel -> {
65-
privateChannel.sendMessage("``" + message + "``").queue();
65+
privateChannel.sendMessage(message).queue();
6666
}));
6767
}
6868

src/main/resources/localization.properties

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ gregflix.cancel=Okay. Happy searching!
7474
gregflix.requestedDone=Great news! %s has been added to Gregflix. Have fun!
7575

7676
weeklyReport.introduction=## This Week On Gregflix\nThis week the following entries have been added to Gregflix:\n\n
77-
weeklyReport.movieList=__Movies:__\n
78-
weeklyReport.seriesList=__Series:__\n
79-
weeklyReport.signature=You can request movies and shows by simply responding to me and confirming your selection. You will be notified when your entry was added.\nEnjoy your weekend! :wave:
77+
weeklyReport.movieList=### Movies\n
78+
weeklyReport.seriesList=### Series\n
79+
weeklyReport.howto=You can request movies and shows by simply responding to me and confirming your selection. You will be notified when your entry was added.
80+
weeklyReport.maintenance=### Maintenance\nDue to updates Gregflix won't be available on %s at %t - the downtime is expected to last %u minutes.
81+
weeklyReport.signature=Enjoy your weekend! :wave:

src/main/resources/localization_de.properties

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ error.wrongQueryParameters=Die Spieler wurden nicht korrekt mitgegeben.
44
error.cantwowabot=Bots haben keine Highlights. :(
55
error.hasnowow=Dieser Benutzer hat kein Highlight. F�ge eines hinzu mit ``/wow url``.
66
error.invalidwow=Die URL ist nicht g�ltig. Nur Discord oder YouTube Links sind erlaubt.
7-
error.noteamcreation=No teams could be created.
8-
error.notincorrectvc=You are not in a voice channel.
7+
error.noteamcreation=Es konnten keine Teams erstellt werden.
8+
error.notincorrectvc=Du befindest dich nicht in einem Voice Channel.
99
error.mapsdisabled=``/maps`` has been disabled due to SourceMod not working in CS2.\n\nMore info: https://wiki.alliedmods.net/Introduction_to_SourceMod_Plugins#Will_SourceMod_support_Source_2.3F_Will_plugins_for_existing_games_continue_to_work_if_they_are_ported.3F
1010
error.invalidmap=Diese Map ist nicht g�ltig.
1111
error.mapnotallowed=Du darfst leider keine Maps wechseln.
1212
error.majorerror=Etwas lief schief. Wir arbeiten dran.
13-
info.nomoviefound=No movie/TV show was found.
14-
info.movieexists=This movie is already on Gregflix or has already been requested.
15-
info.showexists=This TV show is already on Gregflix.
16-
info.showrequested=This TV show has already been requested.
17-
info.showexists.description=Are you requesting this show again for a new season?
13+
info.nomoviefound=Es wurde kein Film oder Serie gefunden.
14+
info.movieexists=Dieser Film befindet sich bereits auf Gregflix oder wurde bereits angefordert.
15+
info.showexists=Diese Serie befindet sich bereits auf Gregflix.
16+
info.showrequested=Diese Serie wurde bereits angefordert.
17+
info.showexists.description=Forderst du diese Serie an, da eine neue Staffel verf�gbar ist?
1818
info.messagesent=Es gibt eine neue Nachricht in csgo-stuff.
1919

2020
serverstatus.title=__Retake-Server Status__
@@ -61,16 +61,18 @@ command.compare.valueone.description=Gib die SteamID des ersten Spielers ein
6161
command.compare.valuetwo.description=Gib die SteamID des zweiten Spielers ein
6262
command.wow.description=F�ge ein Highlight hinzu
6363
command.wow.value.description=Gib eine URL an (YouTube oder Discord)
64-
command.teams.description=Divide your voice chat into teams
65-
command.teams.value.description=How many teams should be created
64+
command.teams.description=Teile dein Voice Chat in Teams auf
65+
command.teams.value.description=Wie viele Teams sollen erstellt werden
6666
command.status.description=Gibt den aktuellen Status des Retake-Servers zur�ck
6767

68-
gregflix.description=Are you looking for this?
69-
gregflix.confirm=Thanks! Your request has been submitted.
70-
gregflix.cancel=Okay. Happy searching!
71-
gregflix.requestedDone=Great news! %s has been added to Gregflix. Have fun!
68+
gregflix.description=Ist das, was du suchst?
69+
gregflix.confirm=Danke! Deine Anforderung wurde �bermittelt.
70+
gregflix.cancel=Okay. Viel Spass beim weiteren Suchen!
71+
gregflix.requestedDone=Tolle Neuigkeiten! %s wurde auf Gregflix hinzugef�gt! Viel Spass!
7272

73-
weeklyReport.introduction=## This Week On Gregflix\nThis week the following entries have been added to Gregflix:\n\n
74-
weeklyReport.movieList=__Movies:__\n
75-
weeklyReport.seriesList=__Series:__\n
76-
weeklyReport.signature=You can request movies and shows by simply responding to me and confirming your selection. You will be notified when your entry was added.\nEnjoy your weekend! :wave:
73+
weeklyReport.introduction=## This Week On Gregflix\nIn dieser Woche wurden die folgenden Eintr�ge auf Gregflix hinzugef�gt:\n\n
74+
weeklyReport.movieList=### Filme\n
75+
weeklyReport.seriesList=### Serien\n
76+
weeklyReport.howto=Du kannst Filme und Series anfordern, indem du einfach den Namen hier in diesen Chat schreibst und deine Auswahl best�tigst. Du wirst informiert, sobald diese hinzugef�gt wurde.
77+
weeklyReport.maintenance=### Wartung\nF�r Updates wird Gregflix am %s um %t nicht verf�gbar sein - die erwartete Downtime betr�gt %u Minuten.
78+
weeklyReport.signature=Sch�nes Wochenende! :wave:

src/main/resources/localization_en.properties

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ gregflix.cancel=Okay. Happy searching!
7171
gregflix.requestedDone=Great news! %s has been added to Gregflix. Have fun!
7272

7373
weeklyReport.introduction=## This Week On Gregflix\nThis week the following entries have been added to Gregflix:\n\n
74-
weeklyReport.movieList=__Movies:__\n
75-
weeklyReport.seriesList=__Series:__\n
76-
weeklyReport.signature=You can request movies and shows by simply responding to me and confirming your selection. You will be notified when your entry was added.\nEnjoy your weekend! :wave:
74+
weeklyReport.movieList=### Movies\n
75+
weeklyReport.seriesList=### Series\n
76+
weeklyReport.howto=You can request movies and shows by simply responding to me and confirming your selection. You will be notified when your entry was added.
77+
weeklyReport.maintenance=### Maintenance\nDue to updates Gregflix won't be available on %s at %t - the downtime is expected to last %u minutes.
78+
weeklyReport.signature=Enjoy your weekend! :wave:

0 commit comments

Comments
 (0)