feat: make midi playing fully async, make queue better w/ more info,
player information, and bug fix for commands which aren't found
This commit is contained in:
parent
257bc55b75
commit
b4f989bf92
7 changed files with 234 additions and 81 deletions
72
src/main.rs
72
src/main.rs
|
|
@ -34,7 +34,7 @@ use std::sync::Arc;
|
|||
#[global_allocator]
|
||||
static ALLOCATOR: Cap<std::alloc::System> = Cap::new(std::alloc::System, usize::MAX);
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
#[derive(sqlx::FromRow, Clone, Debug)]
|
||||
pub struct User {
|
||||
_id: String,
|
||||
balance: i32,
|
||||
|
|
@ -156,11 +156,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||
registry,
|
||||
client,
|
||||
[
|
||||
PlayCommand::new(midi_state.clone(), conf.clone()),
|
||||
StopCommand::new(midi_state.clone()),
|
||||
PlaylistCommand::new(midi_state.clone(), conf.clone()),
|
||||
QueueCommand::new(midi_state.clone()),
|
||||
SkipCommand::new(midi_state),
|
||||
SkipCommand::new(midi_state.clone()),
|
||||
LaunchCommand,
|
||||
FollowCommand::new(),
|
||||
TestCommand::new(),
|
||||
|
|
@ -173,6 +172,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||
TranslateCommand,
|
||||
AboutCommand,
|
||||
RankCommand::new(arc_pool.clone(), ranks.clone()),
|
||||
PlayCommand::new(midi_state.clone(), conf.clone(), ranks.clone()),
|
||||
]
|
||||
);
|
||||
|
||||
|
|
@ -182,6 +182,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||
|
||||
let ranks = get_ranks(registry.clone()).await;
|
||||
|
||||
registry
|
||||
.register(
|
||||
PlayCommand::new(midi_state, conf.clone(), ranks.clone()),
|
||||
client.clone(),
|
||||
)
|
||||
.await;
|
||||
registry
|
||||
.register(
|
||||
RankCommand::new(arc_pool.clone(), ranks.clone()),
|
||||
|
|
@ -218,39 +224,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||
if let Some(no_prefix) = message.strip_prefix(conf.commands.prefix.as_str()) {
|
||||
let mut parts = no_prefix.split_whitespace();
|
||||
if let Some(cmd_name) = parts.next() {
|
||||
let user =
|
||||
sqlx::query_as::<_, User>("SELECT * FROM users WHERE _id = $1")
|
||||
.bind(&player._id)
|
||||
.fetch_optional(events_pool.as_ref())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let args = Arguments::new(parts.map(|s| s.to_string()).collect());
|
||||
|
||||
if !has_permission(
|
||||
&user,
|
||||
ranks.clone(),
|
||||
format!("commands.{}", cmd_name),
|
||||
) {
|
||||
client_events
|
||||
.message(format!("You do not have permission \"commands.{}\" to run this command.", cmd_name))
|
||||
.await;
|
||||
} else {
|
||||
let args = Arguments::new(parts.map(|s| s.to_string()).collect());
|
||||
|
||||
let mut cmd_opt: Option<CommandArc> = None;
|
||||
for cmd in registry.values() {
|
||||
let cmd_lock = cmd.lock().await;
|
||||
if cmd_lock.name() == cmd_name
|
||||
|| cmd_lock.aliases().contains(&cmd_name)
|
||||
{
|
||||
cmd_opt = Some(cmd.clone());
|
||||
break;
|
||||
}
|
||||
let mut cmd_opt: Option<CommandArc> = None;
|
||||
for cmd in registry.values() {
|
||||
let cmd_lock = cmd.lock().await;
|
||||
if cmd_lock.name() == cmd_name
|
||||
|| cmd_lock.aliases().contains(&cmd_name)
|
||||
{
|
||||
cmd_opt = Some(cmd.clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cmd) = cmd_opt {
|
||||
let mut cmd_lock = cmd.lock().await;
|
||||
let specs = cmd_lock.argument_spec();
|
||||
if let Some(cmd) = cmd_opt {
|
||||
let mut cmd_lock = cmd.lock().await;
|
||||
let specs = cmd_lock.argument_spec();
|
||||
let user =
|
||||
sqlx::query_as::<_, User>("SELECT * FROM users WHERE _id = $1")
|
||||
.bind(&player._id)
|
||||
.fetch_optional(events_pool.as_ref())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
if !has_permission(
|
||||
&user,
|
||||
ranks.clone(),
|
||||
format!("commands.{}", cmd_name),
|
||||
) {
|
||||
client_events
|
||||
.message(format!("You do not have permission \"commands.{}\" to run this command.", cmd_name))
|
||||
.await;
|
||||
} else {
|
||||
match crate::commands::argument::parse_arguments(
|
||||
specs, &args.args,
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue