aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2019-11-17 23:51:56 -0500
committerNathan Perry <np@nathanperry.dev>2019-11-17 23:51:56 -0500
commit8a5a841e619793ce81b177179694712284be23e4 (patch)
tree6e8b46b1a008a94236e5aaaf48fad95dee70451a
parentc068e82d2b6341cf7896bfc2e1fd4683f28d67b4 (diff)
borrowck fixes
-rw-r--r--Cargo.lock4
-rw-r--r--src/audio/play_queue.rs6
-rw-r--r--src/commands/meme/create.rs21
-rw-r--r--src/commands/meme/delete.rs6
-rw-r--r--src/commands/meme/history.rs39
-rw-r--r--src/commands/meme/invoke.rs14
-rw-r--r--src/commands/meme/mod.rs29
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/commands/playback.rs23
-rw-r--r--src/commands/roll.rs4
-rw-r--r--src/commands/sound_levels.rs8
-rw-r--r--src/game.rs19
-rw-r--r--src/main.rs4
13 files changed, 92 insertions, 87 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7a8c179..0ed105b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -294,7 +294,7 @@ dependencies = [
[[package]]
name = "command_attr"
version = "0.1.5"
-source = "git+https://github.com/mammothbane/serenity#58922b208f7b6241ee09dac5e5cef4bc1547d8a7"
+source = "git+https://github.com/mammothbane/serenity#9eb187138e30f44a86f32865081d5f9c15b93575"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1882,7 +1882,7 @@ dependencies = [
[[package]]
name = "serenity"
version = "0.7.2"
-source = "git+https://github.com/mammothbane/serenity#58922b208f7b6241ee09dac5e5cef4bc1547d8a7"
+source = "git+https://github.com/mammothbane/serenity#9eb187138e30f44a86f32865081d5f9c15b93575"
dependencies = [
"anyhow 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
"audiopus 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/src/audio/play_queue.rs b/src/audio/play_queue.rs
index 273f07b..6026587 100644
--- a/src/audio/play_queue.rs
+++ b/src/audio/play_queue.rs
@@ -79,7 +79,7 @@ impl PlayQueue {
let cache_http = c.cache_and_http.clone();
thread::spawn(move || {
loop {
- if let Err(e) = Self::update(cache_http, &queue, &voice_manager) {
+ if let Err(e) = Self::update(&cache_http, &queue, &voice_manager) {
error!("updating playqueue: {}", e);
}
@@ -89,7 +89,7 @@ impl PlayQueue {
}
- fn update(cache_http: Arc<CacheAndHttp>, queue_lck: &Arc<RwLock<Self>>, voice_manager: &Arc<Mutex<ClientVoiceManager>>) -> Result<()> {
+ fn update(cache_http: &CacheAndHttp, queue_lck: &Arc<RwLock<Self>>, voice_manager: &Arc<Mutex<ClientVoiceManager>>) -> Result<()> {
let (queue_is_empty, queue_has_playing) = {
let queue = queue_lck.read().unwrap();
@@ -246,7 +246,7 @@ impl PlayQueue {
},
None => {
error!("couldn't join channel");
- item.sender_channel.say(cache_http.http, "something happened somewhere somehow.")?;
+ item.sender_channel.say(&cache_http.http, "something happened somewhere somehow.")?;
}
}
diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs
index 0da2031..047c556 100644
--- a/src/commands/meme/create.rs
+++ b/src/commands/meme/create.rs
@@ -14,7 +14,7 @@ use log::{
};
use serenity::{
framework::standard::{
- Args, CommandResult,
+ Args,
Delimiter,
macros::command,
},
@@ -27,6 +27,7 @@ use anyhow::anyhow;
use lazy_static::lazy_static;
use crate::{
+ Result,
audio::{
parse_times,
ytdl_url,
@@ -41,12 +42,12 @@ use crate::{
};
lazy_static! {
- static ref delims: Vec<Delimiter> = vec![' '.into(), '\n'.into(), '\t'.into()];
+ static ref DELIMS: Vec<Delimiter> = vec![' '.into(), '\n'.into(), '\t'.into()];
}
#[command]
-pub fn addmeme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
- let mut args = Args::new(args.rest(), delims.as_ref());
+pub fn addmeme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
+ let mut args = Args::new(args.rest(), DELIMS.as_ref());
let title = args.single_quoted::<String>()?;
let text = args.rest().to_owned();
@@ -78,11 +79,11 @@ pub fn addmeme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
use diesel::result::DatabaseErrorKind;
match save_result {
- Ok(_) => msg.react(ctx, "👌"),
+ Ok(_) => msg.react(&ctx, "👌"),
Err(e) => {
if let Some(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) = e.downcast_ref::<DieselError>() {
error!("tried to create meme that already exists");
- msg.react(ctx, "❌")?;
+ msg.react(&ctx, "❌")?;
return ctx.send(msg.channel_id, "that meme already exists", msg.tts);
}
@@ -92,8 +93,8 @@ pub fn addmeme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
}
#[command]
-pub fn addaudiomeme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
- let mut args = Args::new(args.rest(), delims.as_ref());
+pub fn addaudiomeme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
+ let mut args = Args::new(args.rest(), DELIMS.as_ref());
let title = args.single_quoted::<String>()?;
let audio_str = args.single_quoted::<String>()?;
@@ -177,11 +178,11 @@ pub fn addaudiomeme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResu
use diesel::result::DatabaseErrorKind;
match save_result {
- Ok(_) => msg.react(ctx, "👌"),
+ Ok(_) => msg.react(&ctx, "👌"),
Err(e) => {
if let Some(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) = e.downcast_ref::<DieselError>() {
error!("tried to create meme that already exists");
- msg.react(ctx, "❌")?;
+ msg.react(&ctx, "❌")?;
return ctx.send(msg.channel_id, "that meme already exists", msg.tts);
}
diff --git a/src/commands/meme/delete.rs b/src/commands/meme/delete.rs
index cc507d1..e5e4333 100644
--- a/src/commands/meme/delete.rs
+++ b/src/commands/meme/delete.rs
@@ -6,7 +6,6 @@ use log::info;
use serenity::{
framework::standard::{
Args,
- CommandResult,
macros::command,
},
model::channel::Message,
@@ -14,6 +13,7 @@ use serenity::{
};
use crate::{
+ Result,
db::{
connection,
delete_meme,
@@ -23,7 +23,7 @@ use crate::{
#[command]
#[aliases("delmem")]
-pub fn delmeme(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
+pub fn delmeme(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
let title = args.single_quoted::<String>()?;
let conn = connection()?;
@@ -32,7 +32,7 @@ pub fn delmeme(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResul
Ok(_) => msg.react(ctx, "💀"),
Err(e) => {
if let Some(NotFound) = e.downcast_ref::<DieselError>() {
- msg.react(ctx, "❓")?;
+ msg.react(&ctx, "❓")?;
info!("attempted to delete nonexistent meme: '{}'", title);
ctx.send(msg.channel_id, "nice try", msg.tts)?;
return Ok(());
diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs
index 5921e1a..7579524 100644
--- a/src/commands/meme/history.rs
+++ b/src/commands/meme/history.rs
@@ -10,7 +10,6 @@ use log::{
use serenity::{
framework::standard::{
Args,
- CommandResult,
macros::command,
},
model::channel::Message,
@@ -51,7 +50,7 @@ static CLEAN_DATE_FORMAT: &'static str = "%b %-e %Y";
#[command]
#[aliases("what")]
-pub fn wat(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn wat(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let conn = connection()?;
let record = match InvocationRecord::last(&conn) {
@@ -72,7 +71,7 @@ pub fn wat(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
match meme {
Ok(ref meme) => {
let metadata = Metadata::find(&conn, meme.metadata_id)?;
- let author = crate::TARGET_GUILD_ID.member(ctx, metadata.created_by as u64)?;
+ let author = crate::TARGET_GUILD_ID.member(&ctx, metadata.created_by as u64)?;
ctx.send(msg.channel_id,
&format!("that was \"{}\" by {} ({})",
@@ -93,7 +92,7 @@ pub fn wat(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
}
#[command]
-pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
+pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
use itertools::Itertools;
lazy_static! {
@@ -134,8 +133,8 @@ pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResul
Metadata::find(&conn, meme.metadata_id).map(|metadata| (metadata, meme))
})
.map(|(metadata, meme)| {
- let author_name = crate::TARGET_GUILD_ID.member(ctx, metadata.created_by as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
- let invoker_name = crate::TARGET_GUILD_ID.member(ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
+ let author_name = crate::TARGET_GUILD_ID.member(&ctx, metadata.created_by as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
+ let invoker_name = crate::TARGET_GUILD_ID.member(&ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
format!("{}. [{}{}] \"{}\" by {} ({}). invoked by {}.", i + 1, rand, ago, meme.title, author_name, metadata.created.date().format(CLEAN_DATE_FORMAT), invoker_name)
})
.unwrap_or_else(|e| {
@@ -145,7 +144,7 @@ pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResul
}
}
- let invoker_name = crate::TARGET_GUILD_ID.member(ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
+ let invoker_name = crate::TARGET_GUILD_ID.member(&ctx, rec.user_id as u64).map(|m| m.display_name().into_owned()).unwrap_or("???".to_owned());
format!("{}. [{}{}] not found. invoked by {}.", i + 1, rand, ago, invoker_name)
})
})
@@ -156,7 +155,7 @@ pub fn history(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResul
#[command]
#[aliases("stat")]
-pub fn stats(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn stats(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
use db;
use serenity::model::{
id::UserId,
@@ -169,11 +168,11 @@ pub fn stats(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
debug!("reporting stats");
- let rand_user: User = UserId(stats.most_random_meme_user).to_user(ctx)?;
- let direct_user: User = UserId(stats.most_directly_named_meme_user).to_user(ctx)?;
+ let rand_user: User = UserId(stats.most_random_meme_user).to_user(&ctx)?;
+ let direct_user: User = UserId(stats.most_directly_named_meme_user).to_user(&ctx)?;
- let rand_user = rand_user.nick_in(ctx, *TARGET_GUILD_ID).unwrap_or(rand_user.name);
- let direct_user = direct_user.nick_in(ctx, *TARGET_GUILD_ID).unwrap_or(direct_user.name);
+ let rand_user = rand_user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(rand_user.name);
+ let direct_user = direct_user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(direct_user.name);
let s = format!(
r#"
@@ -219,7 +218,7 @@ and *{}* was the most-memed overall ({})"#,
}
#[command]
-pub fn memers(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult {
+pub fn memers(ctx: &mut Context, msg: &Message, _args: Args) -> Result<()> {
use db;
use itertools::Itertools;
use serenity::model::{
@@ -230,8 +229,8 @@ pub fn memers(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult {
let s = db::memers()?
.into_iter()
.map(|info| {
- let user = UserId(info.user_id).to_user(ctx)?;
- let username = user.nick_in(ctx, *TARGET_GUILD_ID).unwrap_or(user.name);
+ let user = UserId(info.user_id).to_user(&ctx)?;
+ let username = user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(user.name);
let res = format!(
"**{}**: {} total, {} random, {} specific. favorite meme: *{}* ({})",
@@ -253,7 +252,7 @@ pub fn memers(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult {
}
#[command]
-pub fn query(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
+pub fn query(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
use std::borrow::Borrow;
use itertools::Itertools;
@@ -271,12 +270,12 @@ pub fn query(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult
static ref AGE_REGEX: Regex = Regex::new(r"(?i)(?:age|order)=(.*)").unwrap();
}
- let guild = msg.channel_id.to_channel(ctx)?
+ let guild = msg.channel_id.to_channel(&ctx)?
.guild()
.ok_or(anyhow!("couldn't find guild"))?;
let guild = guild.read()
- .guild(ctx)
+ .guild(&ctx)
.ok_or(anyhow!("couldn't find guild"))?;
let guild = guild
@@ -310,8 +309,8 @@ pub fn query(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult
let result = db::query_meme(args.rest(), creator, order)?
.into_iter()
.map(|(meme, metadata)| {
- let user = UserId(metadata.created_by as u64).to_user(ctx)?;
- let username = user.nick_in(ctx, *TARGET_GUILD_ID).unwrap_or(user.name);
+ let user = UserId(metadata.created_by as u64).to_user(&ctx)?;
+ let username = user.nick_in(&ctx, *TARGET_GUILD_ID).unwrap_or(user.name);
Ok(format!("*{}* by **{}** ({}). text length: **{}**, image: **{}**, audio: **{}**",
meme.title,
diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs
index fb32ae2..d0b7a19 100644
--- a/src/commands/meme/invoke.rs
+++ b/src/commands/meme/invoke.rs
@@ -7,7 +7,6 @@ use log::info;
use serenity::{
framework::standard::{
Args,
- CommandResult,
macros::command,
},
model::channel::Message,
@@ -16,6 +15,7 @@ use serenity::{
use crate::{
commands::meme::send_meme,
+ Result,
db::{
self,
connection,
@@ -27,19 +27,19 @@ use crate::{
#[command]
#[aliases("mem")]
-pub fn meme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+pub fn meme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
_meme(ctx, msg, args, AudioPlayback::Optional)
}
#[command]
#[aliases("audiomeme", "audiomem")]
-pub fn audio_meme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+pub fn audio_meme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
_meme(ctx, msg, args, AudioPlayback::Required)
}
#[command]
#[aliases("silentmeme", "silentmem")]
-pub fn silent_meme(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+pub fn silent_meme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
_meme(ctx, msg, args, AudioPlayback::Prohibited)
}
@@ -50,7 +50,7 @@ enum AudioPlayback {
Prohibited,
}
-fn _meme(ctx: &mut Context, msg: &Message, args: Args, audio_playback: AudioPlayback) -> CommandResult {
+fn _meme(ctx: &mut Context, msg: &Message, args: Args, audio_playback: AudioPlayback) -> Result<()> {
if args.len() == 0 || audio_playback != AudioPlayback::Optional {
return rand_meme(ctx, msg, audio_playback);
}
@@ -78,7 +78,7 @@ fn _meme(ctx: &mut Context, msg: &Message, args: Args, audio_playback: AudioPlay
send_meme(ctx, &mem, &conn, msg)
}
-fn rand_meme(ctx: &Context, message: &Message, audio_playback: AudioPlayback) -> CommandResult {
+fn rand_meme(ctx: &Context, message: &Message, audio_playback: AudioPlayback) -> Result<()> {
let conn = connection()?;
let should_audio = ctx.users_listening()?;
@@ -112,7 +112,7 @@ fn rand_meme(ctx: &Context, message: &Message, audio_playback: AudioPlayback) ->
#[command]
#[aliases("rarememe", "raremem")]
-pub fn rare_meme(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult {
+pub fn rare_meme(ctx: &mut Context, msg: &Message, _args: Args) -> Result<()> {
let should_audio = ctx.users_listening()?;
let conn = connection()?;
diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs
index 1761ab1..93de288 100644
--- a/src/commands/meme/mod.rs
+++ b/src/commands/meme/mod.rs
@@ -2,7 +2,6 @@ use diesel::PgConnection;
use log::debug;
use rand::{Rng, thread_rng};
use serenity::{
- builder::CreateMessage,
framework::standard::macros::group,
http::AttachmentType,
model::channel::Message,
@@ -60,24 +59,30 @@ fn send_meme(ctx: &Context, t: &Meme, conn: &PgConnection, msg: &Message) -> Res
let image = t.image(conn);
let audio = t.audio(conn);
- let create_msg = |m: &mut CreateMessage| {
- let ret = m.tts(should_tts);
-
- match t.content {
- Some(ref text) if text.len() > 0 => ret.content(text),
- _ => ret,
- }
- };
-
match image {
Some(image) => {
let image = image?;
- msg.channel_id.send_files(ctx, vec!(AttachmentType::Bytes((&image.data, &image.filename))), create_msg)?;
+ msg.channel_id.send_files(ctx, vec!(AttachmentType::Bytes((&image.data, &image.filename))), |m| {
+ let ret = m.tts(should_tts);
+
+ match t.content {
+ Some(ref text) if text.len() > 0 => ret.content(text),
+ _ => ret,
+ }
+ })?;
},
None => match t.content {
- Some(_) => { msg.channel_id.send_message(ctx, create_msg)?; },
+ Some(_) => { msg.channel_id.send_message(ctx, |m| {
+ let ret = m.tts(should_tts);
+
+ match t.content {
+ Some(ref text) if text.len() > 0 => ret.content(text),
+ _ => ret,
+ }
+ })?; },
None => {},
+
},
};
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 82b359a..da75275 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -13,7 +13,7 @@ use crate::{
pub use self::{
playback::*,
sound_levels::*,
- roll::roll,
+ roll::{roll, ROLL_COMMAND},
};
#[cfg(feature = "diesel")]
pub use self::meme::*;
diff --git a/src/commands/playback.rs b/src/commands/playback.rs
index 63e061f..c11eac8 100644
--- a/src/commands/playback.rs
+++ b/src/commands/playback.rs
@@ -8,7 +8,6 @@ use log::{
use serenity::{
framework::standard::{
Args,
- CommandResult,
macros::{command, group},
},
model::channel::Message,
@@ -22,8 +21,10 @@ use crate::{
PlayQueue,
VoiceManager,
},
+ Result,
TARGET_GUILD_ID,
util::CtxExt,
+ commands::sound_levels::*,
};
group!({
@@ -44,7 +45,7 @@ group!({
],
});
-pub fn _play(ctx: &Context, msg: &Message, url: &str) -> CommandResult {
+pub fn _play(ctx: &Context, msg: &Message, url: &str) -> Result<()> {
use url::{Url, Host};
debug!("playing '{}'", url);
@@ -96,7 +97,7 @@ pub fn _play(ctx: &Context, msg: &Message, url: &str) -> CommandResult {
}
#[command]
-pub fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
+pub fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
if args.len() == 0 {
return _resume(ctx, msg);
}
@@ -113,7 +114,7 @@ pub fn play(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
}
#[command]
-pub fn pause(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn pause(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let queue_lock = ctx.data.write().get::<PlayQueue>().cloned().unwrap();
let done = || ctx.send(msg.channel_id, "r u srs", msg.tts);
@@ -146,11 +147,11 @@ pub fn pause(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
#[command]
#[aliases("continue")]
-pub fn resume(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn resume(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
_resume(ctx, msg)
}
-fn _resume(ctx: &mut Context, msg: &Message) -> CommandResult {
+fn _resume(ctx: &mut Context, msg: &Message) -> Result<()> {
let queue_lock = ctx.data.write().get::<PlayQueue>().cloned().unwrap();
let done = || ctx.send(msg.channel_id, "r u srs", msg.tts);
@@ -187,7 +188,7 @@ fn _resume(ctx: &mut Context, msg: &Message) -> CommandResult {
#[command]
#[aliases("next")]
-pub fn skip(ctx: &mut Context, _msg: &Message, _args: Args) -> CommandResult {
+pub fn skip(ctx: &mut Context, _msg: &Message, _args: Args) -> Result<()> {
let data = ctx.data.write();
let mgr_lock = data.get::<VoiceManager>().cloned().unwrap();
@@ -209,7 +210,7 @@ pub fn skip(ctx: &mut Context, _msg: &Message, _args: Args) -> CommandResult {
#[command]
#[aliases("sudoku", "fuckoff", "stop")]
-pub fn die(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn die(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let data = ctx.data.write();
let mgr_lock = data.get::<VoiceManager>().cloned().unwrap();
@@ -239,11 +240,11 @@ pub fn die(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
#[command]
#[aliases("queue")]
-pub fn list(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn list(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let queue_lock = ctx.data.write().get::<PlayQueue>().cloned().unwrap();
let play_queue = queue_lock.read().unwrap();
- let channel_tmp = msg.channel(ctx).unwrap().guild().unwrap();
+ let channel_tmp = msg.channel(&ctx).unwrap().guild().unwrap();
let channel = channel_tmp.read();
info!("listing queue");
@@ -274,7 +275,7 @@ pub fn list(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
Right(_) => "meme".to_owned(),
};
- let _ = channel.say(ctx, &format!("{} ({})", playing_info, info.initiator));
+ let _ = channel.say(&ctx, &format!("{} ({})", playing_info, info.initiator));
});
Ok(())
diff --git a/src/commands/roll.rs b/src/commands/roll.rs
index 1588d10..5f5ff6d 100644
--- a/src/commands/roll.rs
+++ b/src/commands/roll.rs
@@ -8,7 +8,6 @@ use rand::prelude::*;
use serenity::{
framework::standard::{
Args,
- CommandResult,
macros::command,
},
model::channel::Message,
@@ -20,6 +19,7 @@ use thiserror::Error;
use lazy_static::lazy_static;
use crate::{
+ Result,
util::CtxExt,
};
@@ -208,7 +208,7 @@ mod test {
#[command]
#[aliases("calc", "calculate")]
-pub fn roll(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+pub fn roll(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
match Calc::eval(args.rest()) {
Ok(result) => {
debug!("got calc result '{}'", result);
diff --git a/src/commands/sound_levels.rs b/src/commands/sound_levels.rs
index 46695d2..648e54b 100644
--- a/src/commands/sound_levels.rs
+++ b/src/commands/sound_levels.rs
@@ -7,7 +7,6 @@ use log::{
use serenity::{
framework::standard::{
Args,
- CommandResult,
macros::command,
},
model::channel::Message,
@@ -15,6 +14,7 @@ use serenity::{
};
use crate::{
+ Result,
audio::{PlayQueue, VoiceManager},
TARGET_GUILD_ID,
util::CtxExt,
@@ -23,7 +23,7 @@ use crate::{
pub const DEFAULT_VOLUME: f32 = 0.10;
#[command]
-pub fn mute(ctx: &mut Context, _: &Message, _: Args) -> CommandResult {
+pub fn mute(ctx: &mut Context, _: &Message, _: Args) -> Result<()> {
let mgr_lock = ctx.data.write().get::<VoiceManager>().cloned().unwrap();
let mut manager = mgr_lock.lock();
@@ -41,7 +41,7 @@ pub fn mute(ctx: &mut Context, _: &Message, _: Args) -> CommandResult {
}
#[command]
-pub fn unmute(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
+pub fn unmute(ctx: &mut Context, msg: &Message, _: Args) -> Result<()> {
let mgr_lock = ctx.data.write().get::<VoiceManager>().cloned().unwrap();
let mut manager = mgr_lock.lock();
@@ -60,7 +60,7 @@ pub fn unmute(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
}
#[command]
-pub fn volume(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
+pub fn volume(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
if args.len() == 0 {
let vol = {
let queue_lock = ctx.data.write().get::<PlayQueue>().cloned().unwrap();
diff --git a/src/game.rs b/src/game.rs
index 3d3db24..31e19b7 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -25,7 +25,6 @@ use serenity::{
framework::standard::{
ArgError,
Args,
- CommandResult,
macros::{command, group},
},
model::{
@@ -152,13 +151,13 @@ impl FromStr for GameStatus {
#[command]
#[aliases("installedgaem")]
-pub fn installedgame(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+pub fn installedgame(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
_game(ctx, msg, args, GameStatus::Installed)
}
#[command]
#[aliases("ownedgaem")]
-pub fn ownedgame(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+pub fn ownedgame(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
_game(ctx, msg, args, GameStatus::NotInstalled)
}
@@ -215,17 +214,17 @@ pub fn get_user_id<S: AsRef<str>>(g: &Guild, s: S) -> StdResult<UserId, UserLook
#[command]
#[aliases("gaem")]
-fn game(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
+fn game(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
_game(ctx, msg, args, GameStatus::Installed)
}
-fn _game(ctx: &mut Context, msg: &Message, mut args: Args, min_status: GameStatus) -> CommandResult {
- let guild = msg.channel_id.to_channel(ctx)?
+fn _game(ctx: &mut Context, msg: &Message, mut args: Args, min_status: GameStatus) -> Result<()> {
+ let guild = msg.channel_id.to_channel(&ctx)?
.guild()
.ok_or(anyhow!("couldn't find guild"))?;
let guild = guild.read()
- .guild(ctx)
+ .guild(&ctx)
.ok_or(anyhow!("couldn't find guild"))?;
let guild = guild
@@ -407,7 +406,7 @@ fn load_spreadsheet() -> Result<Vec<Vec<String>>> {
#[command]
#[aliases("updategame")]
-pub fn updategaem(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
+pub fn updategaem(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
use regex::Regex;
let arg_user = args.single_quoted::<String>();
@@ -417,12 +416,12 @@ pub fn updategaem(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandRe
} else {
use std::borrow::Borrow;
- let guild = msg.channel_id.to_channel(ctx)?
+ let guild = msg.channel_id.to_channel(&ctx)?
.guild()
.ok_or(anyhow!("couldn't find guild"))?;
let guild = guild.read()
- .guild(ctx)
+ .guild(&ctx)
.ok_or(anyhow!("couldn't find guild"))?;
let guild = guild
diff --git a/src/main.rs b/src/main.rs
index 720e830..98c9765 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -99,7 +99,7 @@ impl EventHandler for Handler {
.remove(&deleted_message_id)
.iter()
.for_each(|id| {
- if let Err(e) = channel_id.delete_message(ctx, id) {
+ if let Err(e) = channel_id.delete_message(&ctx, id) {
error!("deleting message: {}", e);
}
});
@@ -202,7 +202,7 @@ fn run() -> Result<()> {
},
Err(e) => {
- if let Err(e) = msg.react(ctx, "❌") {
+ if let Err(e) = msg.react(&ctx, "❌") {
error!("reacting to failed message: {}", e);
}