From a86abed974aa2d0fb75a6b50d97a81a6d30ac5e8 Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Sat, 21 Sep 2024 02:03:55 +0200 Subject: [PATCH 1/7] who needs readability --- src/main/java/services/MessageService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/services/MessageService.java b/src/main/java/services/MessageService.java index f8e50f2..ce5eb01 100644 --- a/src/main/java/services/MessageService.java +++ b/src/main/java/services/MessageService.java @@ -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(); })); } From ddd2983acb2214775fda0c39cc5cd6b5a7810c6b Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Sat, 21 Sep 2024 02:36:42 +0200 Subject: [PATCH 2/7] updated pom.xml to reflect current version --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index fa58d05..44f0142 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ 4.0.0 ch.yoinc - retakeBot - 1.0 + CounterStrikeBot + 3.2 - RetakeBot - https://www.github.com/janesth/retakeBot + CounterStrikeBot + https://github.com/yoinc-development/CounterStrikeBot 20 From ddfde2b2dce033f246cfa6244b3cd3d175855988 Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Sat, 21 Sep 2024 03:12:25 +0200 Subject: [PATCH 3/7] disable slash commands in private channels --- .../listeners/CounterStrikeBotListener.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/java/listeners/CounterStrikeBotListener.java b/src/main/java/listeners/CounterStrikeBotListener.java index 474a07b..9597d79 100644 --- a/src/main/java/listeners/CounterStrikeBotListener.java +++ b/src/main/java/listeners/CounterStrikeBotListener.java @@ -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(); + } } } } From 23bf2a381aca6b0c0f9548c07ef14048443a2567 Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Sat, 21 Sep 2024 03:23:48 +0200 Subject: [PATCH 4/7] changed set language "en" to user-specific locale --- .../java/listeners/CounterStrikeBotListener.java | 2 +- src/main/java/services/DiscordService.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/listeners/CounterStrikeBotListener.java b/src/main/java/listeners/CounterStrikeBotListener.java index 9597d79..6c36a8d 100644 --- a/src/main/java/listeners/CounterStrikeBotListener.java +++ b/src/main/java/listeners/CounterStrikeBotListener.java @@ -113,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(); } diff --git a/src/main/java/services/DiscordService.java b/src/main/java/services/DiscordService.java index 11807c1..2b44621 100644 --- a/src/main/java/services/DiscordService.java +++ b/src/main/java/services/DiscordService.java @@ -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; @@ -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; } From 7a7cc6b5977b6544bf45d2b47ad475418ba2eff9 Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Sat, 21 Sep 2024 14:35:50 +0200 Subject: [PATCH 5/7] localization translations and README.md update --- README.md | 42 ++++++++++++++----- src/main/resources/localization.properties | 8 ++-- src/main/resources/localization_de.properties | 36 ++++++++-------- src/main/resources/localization_en.properties | 8 ++-- 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index a124d61..339b636 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,44 @@ [![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 " 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 ` - 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 ` - display this user's Counter Strike stats based on their Steam account. `steamID` is the user's [steam ID](https://www.steamidfinder.com/). +- `/comapre ` - compares two users' Counter Strike stats. +- `/teams ` - 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 ` - 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 @@ -23,6 +47,7 @@ The following properties were relevant to connect to the retake server and what - `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 @@ -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 @@ -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. \ No newline at end of file diff --git a/src/main/resources/localization.properties b/src/main/resources/localization.properties index 46632fd..6346155 100644 --- a/src/main/resources/localization.properties +++ b/src/main/resources/localization.properties @@ -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: \ No newline at end of file +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: \ No newline at end of file diff --git a/src/main/resources/localization_de.properties b/src/main/resources/localization_de.properties index 2e0fe76..bae62bc 100644 --- a/src/main/resources/localization_de.properties +++ b/src/main/resources/localization_de.properties @@ -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__ @@ -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: \ No newline at end of file +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: diff --git a/src/main/resources/localization_en.properties b/src/main/resources/localization_en.properties index 0c7211d..dfc663b 100644 --- a/src/main/resources/localization_en.properties +++ b/src/main/resources/localization_en.properties @@ -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: \ No newline at end of file +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: \ No newline at end of file From 7e1acb9e6ecc0744c36aac850e898698ced0deff Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Tue, 24 Sep 2024 11:53:52 +0200 Subject: [PATCH 6/7] sort entries for report by title ASC --- src/main/java/services/DataService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/services/DataService.java b/src/main/java/services/DataService.java index de9b390..e658c20 100644 --- a/src/main/java/services/DataService.java +++ b/src/main/java/services/DataService.java @@ -53,7 +53,7 @@ public List getAllGregflixUsers() throws SQLException { } public List 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(); From 7daae75b47f94c23c7c2441f75447ad43550821c Mon Sep 17 00:00:00 2001 From: Janes Thomas Date: Tue, 24 Sep 2024 11:58:11 +0200 Subject: [PATCH 7/7] updated to v3.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 44f0142..289c4e9 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ ch.yoinc CounterStrikeBot - 3.2 + 3.3 CounterStrikeBot https://github.com/yoinc-development/CounterStrikeBot