named colours, better output for register and name command
This commit is contained in:
@@ -2,27 +2,50 @@
|
|||||||
use crate::common::{Context, Error};
|
use crate::common::{Context, Error};
|
||||||
|
|
||||||
use hex_color::HexColor;
|
use hex_color::HexColor;
|
||||||
use poise::serenity_prelude::{Color, EditRole};
|
use poise::serenity_prelude::{colours, Color, EditRole};
|
||||||
|
|
||||||
/// Change the color of your personal role
|
/// Change the color of your personal role
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn color(ctx: Context<'_>, color: String) -> Result<(), Error> {
|
pub async fn color(ctx: Context<'_>, color: String) -> Result<(), Error> {
|
||||||
|
let color = match color.to_lowercase().as_str() {
|
||||||
|
"reset" | "default" => colours::roles::DEFAULT,
|
||||||
|
"teal" => colours::roles::TEAL,
|
||||||
|
"dark teal" => colours::roles::DARK_TEAL,
|
||||||
|
"green" => colours::roles::GREEN,
|
||||||
|
"dark green" => colours::roles::DARK_GREEN,
|
||||||
|
"blue" => colours::roles::BLUE,
|
||||||
|
"dark blue" => colours::roles::DARK_BLUE,
|
||||||
|
"purple" => colours::roles::PURPLE,
|
||||||
|
"dark purple" => colours::roles::DARK_PURPLE,
|
||||||
|
"magenta" => colours::roles::MAGENTA,
|
||||||
|
"dark magenta" => colours::roles::DARK_MAGENTA,
|
||||||
|
"gold" => colours::roles::GOLD,
|
||||||
|
"dark gold" => colours::roles::DARK_GOLD,
|
||||||
|
"orange" => colours::roles::DARK_ORANGE,
|
||||||
|
"dark orange" => colours::roles::DARK_ORANGE,
|
||||||
|
"red" => colours::roles::RED,
|
||||||
|
"dark red" => colours::roles::DARK_RED,
|
||||||
|
"lighter grey" | "lighter gray" => colours::roles::LIGHTER_GREY,
|
||||||
|
"light grey" | "light gray" => colours::roles::LIGHT_GREY,
|
||||||
|
"dark grey" | "dark gray" => colours::roles::DARK_GREY,
|
||||||
|
"darker grey" | "darker gray" => colours::roles::DARKER_GREY,
|
||||||
|
hex => match HexColor::parse_rgb(hex) {
|
||||||
|
Ok(color) => Color::from_rgb(color.r, color.g, color.b),
|
||||||
|
Err(_) => {
|
||||||
|
ctx.reply(format!("Unable to parse `{}` as a color.", color)).await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let data = ctx.data();
|
let data = ctx.data();
|
||||||
let mut db = data.database.lock().await;
|
let mut db = data.database.lock().await;
|
||||||
let db = db.as_mut();
|
let db = db.as_mut();
|
||||||
|
|
||||||
let color = match HexColor::parse_rgb(&color) {
|
|
||||||
Ok(color) => color,
|
|
||||||
Err(e) => {
|
|
||||||
ctx.reply(format!("Couldn't parse color: {e}")).await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(guild) = ctx.guild_id() {
|
if let Some(guild) = ctx.guild_id() {
|
||||||
match super::get_user_role(ctx.author().id, guild, db).await? {
|
match super::get_user_role(ctx.author().id, guild, db).await? {
|
||||||
Some(role) => {
|
Some(role) => {
|
||||||
guild.edit_role(ctx, role, EditRole::new().colour(Color::from_rgb(color.r, color.g, color.b))).await?;
|
guild.edit_role(ctx, role, EditRole::new().colour(color)).await?;
|
||||||
let role = guild.role(ctx, role).await?;
|
let role = guild.role(ctx, role).await?;
|
||||||
|
|
||||||
ctx.reply(format!("{}'s color has been updated!", role)).await?;
|
ctx.reply(format!("{}'s color has been updated!", role)).await?;
|
||||||
@@ -32,8 +55,8 @@ pub async fn color(ctx: Context<'_>, color: String) -> Result<(), Error> {
|
|||||||
None => {
|
None => {
|
||||||
let role = guild.create_role(ctx,
|
let role = guild.create_role(ctx,
|
||||||
EditRole::new()
|
EditRole::new()
|
||||||
.name(format!("{}", color.display_rgb()))
|
.name(format!("#{:06x}", color.0))
|
||||||
.colour(Color::from_rgb(color.r, color.g, color.b))).await?;
|
.colour(color)).await?;
|
||||||
|
|
||||||
sqlx::query("INSERT INTO selfroles (userid, roleid, guildid) VALUES ($1, $2, $3)")
|
sqlx::query("INSERT INTO selfroles (userid, roleid, guildid) VALUES ($1, $2, $3)")
|
||||||
.bind(ctx.author().id.get() as i64)
|
.bind(ctx.author().id.get() as i64)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pub async fn name(ctx: Context<'_>, name: String) -> Result<(), Error> {
|
|||||||
guild.edit_role(ctx, role, EditRole::new().name(name)).await?;
|
guild.edit_role(ctx, role, EditRole::new().name(name)).await?;
|
||||||
let role = guild.role(ctx, role).await?;
|
let role = guild.role(ctx, role).await?;
|
||||||
|
|
||||||
ctx.reply(format!("Your custom role's name has been updated to {}.", role)).await?;
|
ctx.reply(format!("{} has been updated.", role)).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Ro
|
|||||||
if let Some(guild) = ctx.guild_id() {
|
if let Some(guild) = ctx.guild_id() {
|
||||||
match super::get_user_role(user.id, guild, db).await? {
|
match super::get_user_role(user.id, guild, db).await? {
|
||||||
Some(role) => {
|
Some(role) => {
|
||||||
|
let role = guild.role(ctx, role).await?;
|
||||||
common::no_ping_reply(&ctx, format!("{} already has the role {} registered.", user, role)).await?;
|
common::no_ping_reply(&ctx, format!("{} already has the role {} registered.", user, role)).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user