Skip to content

Commit

Permalink
Merge pull request #17 from hahayupgit/main
Browse files Browse the repository at this point in the history
Adds new "Does My Game Work" command and functionality in ~gs command to return URL of inputted argument
  • Loading branch information
IsaacMarovitz authored Apr 23, 2024
2 parents ad9a1dd + b50d706 commit cbeaf63
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ shuttle-serenity = "0.43.0"
shuttle-runtime = "0.43.0"

[dependencies.serenity]
version = "0.12.1"
version = "0.12.1"
features = ["collector"]
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# uisuki
Whisky's Discord Log Bot

## Instructions for running locally
You'll need to have a Discord application created, and a bot under that application added to a server. You can create that [here](https://discord.com/developers/applications). Ensure the bot has the proper "Privileged Gateway Intents" enabled.

After you have completed the above steps, do the following:
```
// Clone into the uisuki repository
git clone https://github.com/Whisky-App/uisuki.git
// cd to the uisuki directory
cd uisuki
/*
Inside the uisuki directory, create a Secrets.toml file, and add the following line,
replacing <token> with the private token of the bot:
DISCORD_TOKEN="<token>"
*/
// Start the bot
cargo shuttle run
```
49 changes: 49 additions & 0 deletions src/commands/does_my_game_work.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
created by hahayupgit 2024/4/16
desc: command for if someone asks "does x game work?"
*/
use serenity::all::EditMessage;
use serenity::futures::StreamExt;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*;
use serenity::prelude::*;
use std::time::Duration;

#[command]
#[aliases("dmgw")]
async fn does_my_game_work(ctx: &Context, msg: &Message) -> CommandResult {

let reply = String::from("Does your game work? Check https://docs.getwhisky.app/game-support/ first, and search to see if anyone else has this same issue in this Discord or the GitHub repository.
Can't find your game from those sources? Check here:
https://www.protondb.com/
https://appdb.winehq.org/
https://www.codeweavers.com/compatibility
https://www.applegamingwiki.com/wiki/Home
https://www.pcgamingwiki.com/wiki/Home
If you've checked all of these places and still can't find an answer, feel free to create a support post in #support !
As a reminder: Most games with EasyAntiCheat and most other anti-cheats will **NOT** work without workarounds.");

let mut reply_msg = msg.reply(&ctx, reply).await?;

// below code pulled directly from serenity-rs documentation
// can be found here: https://docs.rs/serenity/latest/serenity/builder/struct.EditMessage.html#method.suppress_embeds

// When the embed appears, a MessageUpdate event is sent and we suppress
// the embed. No MessageUpdate event is sent if the message contains no
// embeddable link or if the link has been posted before and is still
// cached in Discord's servers (in which case the embed appears
// immediately), no MessageUpdate event is sent. To not wait forever in
// those cases, a timeout of 2000ms was added.
let msg_id = reply_msg.id;
let mut message_updates = serenity::collector::collect(&ctx.shard, move |ev| match ev {
Event::MessageUpdate(x) if x.id == msg_id => Some(()),
_ => None,
});
let _ = tokio::time::timeout(Duration::from_millis(2000), message_updates.next()).await;
reply_msg.edit(&ctx, EditMessage::new().suppress_embeds(true)).await?;
Ok(())
}
47 changes: 46 additions & 1 deletion src/commands/game_support.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
modified by hahayupgit 2024/4/9
desc: added ability to return webpage of inputted argument
*/

use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*;
Expand All @@ -6,6 +11,46 @@ use serenity::prelude::*;
#[command]
#[aliases("gs")]
async fn game_support(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(&ctx, "https://docs.getwhisky.app/game-support").await?;

// String containing default response
let mut site = String::from("https://docs.getwhisky.app/game-support/");

// command stripped of leading and trailing whitespace
let mut message = msg.content.trim().to_string();

// if command is only "~gs" or "~game_support", reply with default response
if message == "~gs" || message == "~game_support" {
msg.reply(&ctx, site).await?;
}

// if command has arguments
else {

// determine which command was said & remove command given
if message.contains("~gs") {
message = message.replace("~gs ", "");
}
else {
message = message.replace("~game_support ", "");
}

// concatenate the argument to the original default response & reply
site.push_str(&message);
msg.reply(&ctx, site).await?;

/*
NOTE: this method does not have any checks for
URLs that are incorrect. this should not pose
any security threats, however may make it harder
for people who don't know the exact URL of longer games
(i.e. Star Wars Jedi: Fallen Order being sw-fallen-order
or Geometry Wars 3: Dimensions Evolved being gw3-dimensions-evolved).
if i was a better developer, i'd figure out how to handle
this. but i'm not, so i may return to this in a future change.
- hahayupgit 2024/4/9
*/
}
Ok(())
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod ping;
pub mod say;
pub mod does_my_game_work;
pub mod game_support;
pub mod github;
pub mod website;
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ use crate::commands::discord::*;
use crate::commands::game_support::*;
use crate::commands::github::*;
use crate::commands::website::*;
use crate::commands::does_my_game_work::*;

pub mod header;
mod commands;

#[group]
#[commands(ping, say, discord, game_support, github, website)]
#[commands(ping, say, discord, game_support, github, website, does_my_game_work)]
struct General;

struct Handler;
Expand Down

0 comments on commit cbeaf63

Please sign in to comment.