Merge branch 'dev'

main
DaXcess 2022-11-08 14:16:27 +01:00
commit 8e19a9c4d4
10 changed files with 117 additions and 32 deletions

39
CONTRIBUTING.md 100644
View File

@ -0,0 +1,39 @@
# Contributing
## How to contribute
### By reporting bugs
If you find a bug, please report it to the [issue tracker](https://github.com/SpoticordMusic/spoticord) on GitHub. When reporting bugs, it is recommended that you make use of the provided template.
When filing your bug, please be as precise as possible. Bugs that can be reproduced by anyone are much easier to fix. If you can, please include a minimal test case that demonstrates the bug. This makes it much easier to track down the bug.
### By suggesting new features
If you have an idea for a new feature, please suggest it by creating a new issue on the [issue tracker][issues] on GitHub. When suggesting new features, it is recommended that you make use of the provided template. If you think that your feature is related to an existing issue, please mention it in your description.
If you want to suggest new features more casually, rather than officially here on GitHub, you can join our [Discord server](https://discord.gg/wRCyhVqBZ5) and discuss your ideas with us there.
### By writing code
If you want to contribute code, you can do so through GitHub by forking the repository and sending a pull request.
It is generally recommended that you create an issue on the [issue tracker](https://github.com/SpoticordMusic/spoticord) on GitHub before you start working on a feature. This allows us to discuss the feature and make sure that it is something that we want to add to the project. If you are not sure whether a feature is something that we want to add, you can always ask us on our [Discord server](https://discord.gg/wRCyhVqBZ5).
The flow will look something like this:
1. Fork the repository on GitHub
2. Create a named feature branch (like `add_component_x`)
3. Write your change
4. Test your change
5. Submit a Pull Request to the dev branch
A member of the team will review your pull request and either merge it, request changes to it, or close it with an explanation.
### Code style
When writing code we ask you to code in a way that is consistent with the rest of the codebase. This means that you should use the same indentation style, naming conventions, etc. as the rest of the codebase.
We make use of `rustfmt` to format our code. You can install it by running `rustup component add rustfmt` and then running `cargo fmt --all` to format your code. It is generally recommended to run this command before you commit your code. If you use VSCode, you can install the [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer) extension and enable the `Format on Save` option.
Also, **please do not write code that may panic**. If you are not sure how to handle a case, please use `Result` or `Option` to handle it.

View File

@ -26,6 +26,9 @@ Environment variables set this way take precedence over those in the `.env` file
# Compiling
For information about how to compile Spoticord from source, check out [COMPILING.md](COMPILING.md).
# Contributing
For information about how to contribute to Spoticord, check out [CONTRIBUTING.md](CONTRIBUTING.md).
# Contact
![Discord Shield](https://discordapp.com/api/guilds/779292533053456404/widget.png?style=shield)

View File

@ -19,8 +19,14 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
EmbedBuilder::new()
.title("Spoticord Help")
.icon_url("https://spoticord.com/img/logo-standard.webp")
.description(format!("Click **[here](https://spoticord.com/commands)** for a list of commands.\n{}",
"If you need help setting Spoticord up you can check out the **[Documentation](https://spoticord.com/documentation)** page on the Spoticord website.\n\n"))
.description(format!("**Welcome to Spoticord**
It seems you have requested some help. Not to worry, we can help you out.\n
**Not sure how the bot works?**
**[Click here](https://spoticord.com/#how-to)** for a quick overview about how to set up Spoticord and how to use it.\n
**Which commands are there?**
You can find all **[the commands](https://spoticord.com/#commands)** on the website. You may also just type `/` in Discord and see which commands are available there.\n
**Need more help?**
If you still need some help, whether you are having issues with the bot or you just want to give us some feedback, you can join our **[Discord server](https://discord.gg/wRCyhVqBZ5)**."))
.status(Status::Info)
.build(),
false,

View File

@ -44,7 +44,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
EmbedBuilder::new()
.title("Link your Spotify account")
.title_url(&link)
.icon_url("https://spoticord.com/img/spotify-logo.png")
.icon_url("https://spoticord.com/spotify-logo.png")
.description(format!(
"Go to [this link]({}) to connect your Spotify account.",
link
@ -111,7 +111,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
EmbedBuilder::new()
.title("Link your Spotify account")
.title_url(&link)
.icon_url("https://spoticord.com/img/spotify-logo.png")
.icon_url("https://spoticord.com/spotify-logo.png")
.description(format!(
"Go to [this link]({}) to connect your Spotify account.",
link

View File

@ -30,7 +30,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description("You need to connect to a voice channel")
.status(Status::Error)
.build(),
@ -61,7 +60,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description(msg)
.status(Status::Error)
.build(),
@ -80,7 +78,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description(
format!(
"You are already playing music in another server ({}).\nStop playing in that server first before joining this one.",
@ -115,7 +112,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description("You need to link your Spotify account. Use </link:1036714850367320136> or go to [the accounts website](https://account.spoticord.com/) to get started.")
.status(Status::Error)
.build(),
@ -131,7 +127,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description("An error occured while joining the channel. Please try again later.")
.status(Status::Error)
.build(),
@ -159,7 +154,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description("You need to link your Spotify account. Use </link:1036714850367320136> or go to [the accounts website](https://account.spoticord.com/) to get started.")
.status(Status::Error)
.build(),
@ -175,7 +169,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot join voice channel")
.icon_url("https://spoticord.com/static/image/prohibited.png")
.description("An error occured while joining the channel. Please try again later.")
.status(Status::Error)
.build(),
@ -191,7 +184,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Connected to voice channel")
.icon_url("https://spoticord.com/static/image/speaker.png")
.icon_url("https://spoticord.com/speaker.png")
.description(format!("Come listen along in <#{}>", channel_id))
.footer("Spotify will automatically start playing on Spoticord")
.status(Status::Info)

View File

@ -25,7 +25,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
&command,
EmbedBuilder::new()
.title("Cannot disconnect bot")
.icon_url("https://tabler-icons.io/static/tabler-icons/icons/ban.svg")
.description("I'm currently not connected to any voice channel")
.status(Status::Error)
.build(),

View File

@ -149,22 +149,24 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
response
.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|message| {
message
.embed(|embed| embed
.author(|author| author
message.embed(|embed| {
embed
.author(|author| {
author
.name("Currently Playing")
.icon_url("https://www.freepnglogos.com/uploads/spotify-logo-png/file-spotify-logo-png-4.png")
)
.icon_url("https://spoticord.com/spotify-logo.png")
})
.title(title)
.url(format!("https://open.spotify.com/{}/{}", audio_type, spotify_id.to_base62().unwrap()))
.url(format!(
"https://open.spotify.com/{}/{}",
audio_type,
spotify_id.to_base62().unwrap()
))
.description(description)
.footer(|footer| footer
.text(&owner.name)
.icon_url(owner.face())
)
.footer(|footer| footer.text(&owner.name).icon_url(owner.face()))
.thumbnail(&thumbnail)
.color(Status::Info as u64)
)
})
})
})
.await

View File

@ -7,6 +7,8 @@ pub enum IpcPacket {
Connect(String, String),
Disconnect,
ConnectError(String),
StartPlayback,
StopPlayback,

View File

@ -59,7 +59,13 @@ impl SpoticordPlayer {
// Connect the session
let (session, _) = match Session::connect(session_config, credentials, None, false).await {
Ok((session, credentials)) => (session, credentials),
Err(why) => panic!("Failed to connect: {}", why),
Err(why) => {
self
.client
.send(IpcPacket::ConnectError(why.to_string()))
.unwrap();
return;
}
};
// Store session for later use

View File

@ -199,6 +199,35 @@ impl SpoticordSession {
trace!("Received IPC message: {:?}", msg);
match msg {
// Session connect error
IpcPacket::ConnectError(why) => {
error!("Failed to connect to Spotify: {:?}", why);
// Notify the user in the text channel
if let Err(why) = ipc_instance
.text_channel_id
.send_message(&ipc_instance.http, |message| {
message.embed(|embed| {
embed.title("Failed to connect to Spotify");
embed.description(why);
embed.color(Status::Error as u64);
embed
});
message
})
.await
{
error!("Failed to send error message: {:?}", why);
}
// Clean up session
ipc_instance.player_stopped().await;
break;
}
// Sink requests playback to start/resume
IpcPacket::StartPlayback => {
check_result(ipc_track.play());
@ -217,6 +246,8 @@ impl SpoticordSession {
let mut instance = ipc_instance.clone();
let context = ipc_context.clone();
// TODO: Check if this is actually needed
// The new backend may have fixed the need for this
tokio::spawn(async move {
if let Err(why) = instance.update_track(&context, &owner_id, track_id).await {
error!("Failed to update track: {:?}", why);
@ -274,7 +305,8 @@ impl SpoticordSession {
}
IpcPacket::Stopped => {
ipc_instance.player_stopped().await;
check_result(ipc_track.pause());
ipc_instance.start_disconnect_timer().await;
}
// Ignore other packets
@ -441,6 +473,9 @@ impl SpoticordSession {
// Clear playback info
let mut playback_info = self.playback_info.write().await;
*playback_info = None;
// Disconnect automatically after some time
self.start_disconnect_timer().await;
}
/// Internal version of disconnect, which does not abort the disconnect timer