Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AEnterprise committed May 8, 2020
1 parent 5315a56 commit 0d81247
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
5 changes: 0 additions & 5 deletions src/commands/moderation/userinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ use crate::utils::Emoji;
use crate::utils::{CommandError, Error};
use crate::{utils, CommandResult};
use chrono::{DateTime, Utc};
use log::debug;
use serde::export::TryFrom;
use std::borrow::Borrow;
use std::sync::Arc;
use std::time::Duration;
use twilight::builders::embed::EmbedBuilder;
use twilight::model::channel::Message;
use twilight::model::guild::Permissions;
use twilight::model::id::ChannelId;
use twilight::model::user::UserFlags;

pub async fn userinfo(ctx: Arc<Context>, msg: Message, mut parser: Parser) -> CommandResult {
Expand Down
12 changes: 8 additions & 4 deletions src/core/context/logpump.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use crate::core::Context;
use crate::utils::Error;
use crate::utils::LogType;
use chrono::Utc;

impl Context {
pub fn log(&self, guild_id: u64, log: LogType) {
pub fn log(&self, guild_id: u64, log: LogType) -> Result<(), Error> {
match self.log_pumps.get(&guild_id) {
Some(pump) => {
pump.value().send((Utc::now(), log));
pump.value()
.send((Utc::now(), log))
.map_err(|_| Error::LogError(guild_id))?;
Ok(())
}
None => {}
};
None => Ok(()),
}
}
}
2 changes: 0 additions & 2 deletions src/core/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use twilight::model::gateway::payload::MemberChunk;
use twilight::model::id::GuildId;
use twilight::model::user::CurrentUser;

const GIT_VERSION: &str = git_version!();

pub struct Context {
pub cache: InMemoryCache,
pub cluster: Cluster,
Expand Down
4 changes: 2 additions & 2 deletions src/core/handlers/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub async fn handle_event(shard_id: u64, event: &Event, ctx: Arc<Context>) -> Re
Some(nonce) => {
debug!("waiter found: {}", ctx.chunk_requests.contains_key(nonce));
match ctx.chunk_requests.remove(nonce) {
Some(mut waiter) => {
waiter.1.send(chunk.clone());
Some(waiter) => {
waiter.1.send(chunk.clone()).expect("Something went wrong when trying to forward a member chunk to it's receiver");
}
None => {}
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum Error {
UnknownEmoji(String),
Serde(serde_json::error::Error),
ParseError(ParseError),
LogError(u64),
}

#[derive(Debug)]
Expand Down Expand Up @@ -120,6 +121,11 @@ impl fmt::Display for Error {
Error::UnknownEmoji(e) => write!(f, "Unknown emoji: {}", e),
Error::Serde(e) => write!(f, "Serde error: {}", e),
Error::ParseError(e) => write!(f, "{}", e),
Error::LogError(guild_id) => write!(
f,
"Something went horribly wrong when trying to push to the logpump for guild {}",
guild_id
),
}
}
}
Expand Down

0 comments on commit 0d81247

Please sign in to comment.