Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,52 @@

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

The purpose of this bot is to inform users of a Discord server in a specific channel about played matches.
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.
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.

## Features

### Slash Commands

- `/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.
- `/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/).
- `/comapre <steamID1> <steamID2>` - compares two users' Counter Strike stats.
- `/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.
- `/wow <url>` - allows to set a personal gaming moment (wow moment). `url` has to be either a YouTube or a Discord url.
- `/status` - returns the current status of the retake server.

### User Context Commands

To execute these commands, right-click on a user, choose "Apps" and then one of the followings commands:

- `wow` - returns this user's wow moment for everyone to see.
- `retake stats` - return this user's stats on the set retake server.

### Scheduled Tasks

There are two Counter Strike relavant scheduled tasks running:

- A collection task to receive discord user information to enable all users to use relevant commands.
- A join task to send an invite to the retake server after a user has joined the server.

## Configuration

All of these properties are defined in "config.properties". Mandatory properties are **bold**.
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.

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

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

The following properties were relevant to connect to the retake server and what maps are allowed to be played:
- `server.ip` - the IP address of the csgo server
- `server.port` - the port of the csgo server
- `server.password` - the RCON password of the csgo server (to define in `server.cfg`)
- `csgo.maps` - a comma seperated list of allowed maps to switch to (like `de_dust,de_tuscan,...`)
- `server.delay` - a delay (in seconds) to stop users from spamming a map change.
- `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)

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

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

## Run the bot

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

### Can I run the bot myself? Do I have to invite the public instance of the bot to my server??
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.

### Why doesn't ``/map`` work?
SourceMod is not compatible with Counter Strike 2.
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.).

### Can I fork this and make it better?
Yes.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<modelVersion>4.0.0</modelVersion>

<groupId>ch.yoinc</groupId>
<artifactId>retakeBot</artifactId>
<version>1.0</version>
<artifactId>CounterStrikeBot</artifactId>
<version>3.3</version>

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

<properties>
<maven.compiler.source>20</maven.compiler.source>
Expand Down
62 changes: 32 additions & 30 deletions src/main/java/listeners/CounterStrikeBotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,37 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {

String locale = discordService.getUserLocale(event);

if(event.getGuild().getMembers().contains(event.getMember())) {
if ("stats".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(csStatsService.handleStatsEvent(event, locale).build()).queue();
}

if ("compare".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(csStatsService.handleCompareEvent(event, locale).build()).queue();
}

if ("map".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessage(retakeService.handleMapEvent(event, locale)).queue();
}

if ("wow".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessage(csFunService.handleAddWowEvent(event, locale)).queue();
}

if ("teams".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(csFunService.handleSetTeamsEvent(event, locale).build()).queue();
}

if ("status".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(retakeService.handleStatusEvent(event, locale).build()).queue();
if(!event.getChannel().getType().equals(ChannelType.PRIVATE)) {
if (event.getGuild() != null && event.getGuild().getMembers().contains(event.getMember())) {
if ("stats".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(csStatsService.handleStatsEvent(event, locale).build()).queue();
}

if ("compare".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(csStatsService.handleCompareEvent(event, locale).build()).queue();
}

if ("map".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessage(retakeService.handleMapEvent(event, locale)).queue();
}

if ("wow".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessage(csFunService.handleAddWowEvent(event, locale)).queue();
}

if ("teams".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(csFunService.handleSetTeamsEvent(event, locale).build()).queue();
}

if ("status".equals(event.getName())) {
event.deferReply().queue();
event.getHook().sendMessageEmbeds(retakeService.handleStatusEvent(event, locale).build()).queue();
}
}
}
}
Expand Down Expand Up @@ -111,7 +113,7 @@ public void onMessageReceived(MessageReceivedEvent messageReceivedEvent) {

@Override
public void onButtonInteraction(ButtonInteractionEvent buttonInteractionEvent) {
String locale = "en";
String locale = discordService.getUserLocale(buttonInteractionEvent);
buttonInteractionEvent.getMessageChannel().sendMessage(gregflixService.handleButtonEvent(buttonInteractionEvent, locale)).queue();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/services/DataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<User> getAllGregflixUsers() throws SQLException {
}

public List<GregflixEntry> getGregflixEntriesForThisWeek(Date startOfWeek, Date endOfWeek) throws SQLException{
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM gregflix WHERE uploadedDate >= ? AND uploadedDate <= ?");
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM gregflix WHERE uploadedDate >= ? AND uploadedDate <= ? ORDER BY title ASC");
preparedStatement.setDate(1, startOfWeek);
preparedStatement.setDate(2, endOfWeek);
ResultSet resultSet = preparedStatement.executeQuery();
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/services/DiscordService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import retakeServer.RetakeWatchdog;
Expand Down Expand Up @@ -58,10 +60,16 @@ public void run() {
timer.schedule(weekInReviewTask, weeklyReportdelay, (7 * 24 * 60 * 60 * 1000L));
}

public String getUserLocale(GenericCommandInteractionEvent event) {
public String getUserLocale(Event event) {
String locale = "en";
if (event.getInteraction().getUserLocale().getLocale().equals("de")) {
locale = "de";
if(event instanceof GenericCommandInteractionEvent) {
if (((GenericCommandInteractionEvent)event).getInteraction().getUserLocale().getLocale().equals("de")) {
locale = "de";
}
} else if(event instanceof ButtonInteractionEvent) {
if(((ButtonInteractionEvent) event).getInteraction().getUserLocale().getLocale().equals("de")) {
locale = "de";
}
}
return locale;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/services/MessageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void sendGregflixEmbedMessage(PrivateChannel privateChannel, EmbedBuilder

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

Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/localization.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ gregflix.cancel=Okay. Happy searching!
gregflix.requestedDone=Great news! %s has been added to Gregflix. Have fun!

weeklyReport.introduction=## This Week On Gregflix\nThis week the following entries have been added to Gregflix:\n\n
weeklyReport.movieList=__Movies:__\n
weeklyReport.seriesList=__Series:__\n
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:
weeklyReport.movieList=### Movies\n
weeklyReport.seriesList=### Series\n
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.
weeklyReport.maintenance=### Maintenance\nDue to updates Gregflix won't be available on %s at %t - the downtime is expected to last %u minutes.
weeklyReport.signature=Enjoy your weekend! :wave:
36 changes: 19 additions & 17 deletions src/main/resources/localization_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ error.wrongQueryParameters=Die Spieler wurden nicht korrekt mitgegeben.
error.cantwowabot=Bots haben keine Highlights. :(
error.hasnowow=Dieser Benutzer hat kein Highlight. F�ge eines hinzu mit ``/wow url``.
error.invalidwow=Die URL ist nicht g�ltig. Nur Discord oder YouTube Links sind erlaubt.
error.noteamcreation=No teams could be created.
error.notincorrectvc=You are not in a voice channel.
error.noteamcreation=Es konnten keine Teams erstellt werden.
error.notincorrectvc=Du befindest dich nicht in einem Voice Channel.
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
error.invalidmap=Diese Map ist nicht g�ltig.
error.mapnotallowed=Du darfst leider keine Maps wechseln.
error.majorerror=Etwas lief schief. Wir arbeiten dran.
info.nomoviefound=No movie/TV show was found.
info.movieexists=This movie is already on Gregflix or has already been requested.
info.showexists=This TV show is already on Gregflix.
info.showrequested=This TV show has already been requested.
info.showexists.description=Are you requesting this show again for a new season?
info.nomoviefound=Es wurde kein Film oder Serie gefunden.
info.movieexists=Dieser Film befindet sich bereits auf Gregflix oder wurde bereits angefordert.
info.showexists=Diese Serie befindet sich bereits auf Gregflix.
info.showrequested=Diese Serie wurde bereits angefordert.
info.showexists.description=Forderst du diese Serie an, da eine neue Staffel verf�gbar ist?
info.messagesent=Es gibt eine neue Nachricht in csgo-stuff.

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

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

weeklyReport.introduction=## This Week On Gregflix\nThis week the following entries have been added to Gregflix:\n\n
weeklyReport.movieList=__Movies:__\n
weeklyReport.seriesList=__Series:__\n
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:
weeklyReport.introduction=## This Week On Gregflix\nIn dieser Woche wurden die folgenden Eintr�ge auf Gregflix hinzugef�gt:\n\n
weeklyReport.movieList=### Filme\n
weeklyReport.seriesList=### Serien\n
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.
weeklyReport.maintenance=### Wartung\nF�r Updates wird Gregflix am %s um %t nicht verf�gbar sein - die erwartete Downtime betr�gt %u Minuten.
weeklyReport.signature=Sch�nes Wochenende! :wave:
8 changes: 5 additions & 3 deletions src/main/resources/localization_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ gregflix.cancel=Okay. Happy searching!
gregflix.requestedDone=Great news! %s has been added to Gregflix. Have fun!

weeklyReport.introduction=## This Week On Gregflix\nThis week the following entries have been added to Gregflix:\n\n
weeklyReport.movieList=__Movies:__\n
weeklyReport.seriesList=__Series:__\n
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:
weeklyReport.movieList=### Movies\n
weeklyReport.seriesList=### Series\n
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.
weeklyReport.maintenance=### Maintenance\nDue to updates Gregflix won't be available on %s at %t - the downtime is expected to last %u minutes.
weeklyReport.signature=Enjoy your weekend! :wave: