mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 20:36:10 +01:00
new commands, music fixes and more
This commit is contained in:
@@ -1,12 +1,48 @@
|
||||
use poise::CreateReply;
|
||||
use serenity::{
|
||||
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||
model::{Colour, Timestamp},
|
||||
};
|
||||
|
||||
use crate::{commands::embeds::embed, Context, Error};
|
||||
use crate::{Context, Error};
|
||||
use url::form_urlencoded;
|
||||
|
||||
/// Creates a qr code from text
|
||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||
pub async fn qr(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||
.await?;
|
||||
pub async fn qr(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Message to encode"]
|
||||
#[rest]
|
||||
message: String,
|
||||
) -> Result<(), Error> {
|
||||
let response = CreateReply::default().embed(generate_embed(ctx, message).await.unwrap());
|
||||
ctx.send(response).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn generate_embed(ctx: Context<'_>, message: String) -> Result<CreateEmbed, Error> {
|
||||
let timestamp = Timestamp::now();
|
||||
let data: String = form_urlencoded::byte_serialize(message.as_bytes()).collect();
|
||||
let url = format!(
|
||||
"http://api.qrserver.com/v1/create-qr-code/?data={}&size=1000x1000&ecc=Q&margin=8",
|
||||
data
|
||||
);
|
||||
|
||||
let embed = CreateEmbed::default()
|
||||
.author(
|
||||
CreateEmbedAuthor::new("Your message as a QR Code!")
|
||||
.icon_url(ctx.author().clone().face()),
|
||||
)
|
||||
.colour(Colour::from_rgb(255, 58, 97))
|
||||
.title("Your QR Code:")
|
||||
.url(url.clone())
|
||||
.image(url)
|
||||
.timestamp(timestamp)
|
||||
.footer(
|
||||
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||
.icon_url(ctx.cache().current_user().face()),
|
||||
);
|
||||
|
||||
Ok(embed)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,78 @@
|
||||
use crate::{
|
||||
commands::embeds::{embed, error_embed},
|
||||
Context, Error,
|
||||
};
|
||||
use poise::CreateReply;
|
||||
|
||||
use crate::{commands::embeds::embed, Context, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::form_urlencoded;
|
||||
|
||||
/// Reference Bible by verse
|
||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||
pub async fn verse(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||
.await?;
|
||||
pub async fn verse(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Latin?"]
|
||||
#[flag]
|
||||
latin: bool,
|
||||
#[description = "BOOK+CHAPTER:VERSE"]
|
||||
#[rest]
|
||||
verse: String,
|
||||
) -> Result<(), Error> {
|
||||
let data: String = form_urlencoded::byte_serialize(verse.as_bytes()).collect();
|
||||
let translation = if latin { "clementine" } else { "web" };
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.get(format!(
|
||||
"https://bible-api.com/{}?translation={}",
|
||||
data, translation
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
match response.status() {
|
||||
reqwest::StatusCode::OK => {
|
||||
match response.json::<APIResponse>().await {
|
||||
Ok(parsed) => {
|
||||
if parsed.text.len() > 4000 {
|
||||
ctx.send(
|
||||
CreateReply::default()
|
||||
.embed(error_embed(ctx, "Quoted text is too long!").await.unwrap()),
|
||||
)
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
ctx.send(
|
||||
CreateReply::default().embed(
|
||||
embed(
|
||||
ctx,
|
||||
&parsed.translation_name,
|
||||
&parsed.text,
|
||||
&parsed.reference,
|
||||
)
|
||||
.await
|
||||
.unwrap(),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Err(err) => println!("Something is messed up! {:?}", err),
|
||||
};
|
||||
}
|
||||
reqwest::StatusCode::UNAUTHORIZED => {
|
||||
println!("Unauthorized.. Uoops!!");
|
||||
}
|
||||
error => {
|
||||
println!("Something went wrong: {:?}", error);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct APIResponse {
|
||||
reference: String,
|
||||
text: String,
|
||||
translation_name: String,
|
||||
translation_note: String,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,12 @@ use crate::{commands::embeds::embed, Context, Error};
|
||||
|
||||
/// Shows weather for provided location
|
||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||
pub async fn weather(ctx: Context<'_>) -> Result<(), Error> {
|
||||
pub async fn weather(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Provide a city name"]
|
||||
#[rest]
|
||||
_location: String,
|
||||
) -> Result<(), Error> {
|
||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user