Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Remove SendSyncError and uesless constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kangalio committed Feb 1, 2021
1 parent b0215a8 commit 3310573
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/ban.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{
api, commands::Args, db::DB, schema::bans, text::ban_message, Error, SendSyncError, HOUR,
};
use crate::{api, commands::Args, db::DB, schema::bans, text::ban_message, Error};
use diesel::prelude::*;
use serenity::{model::prelude::*, prelude::*, utils::parse_username};
use std::time::{Duration, SystemTime};
Expand All @@ -14,7 +12,7 @@ pub fn save_ban(user_id: String, guild_id: String, hours: u64) -> Result<(), Err
bans::guild_id.eq(guild_id),
bans::start_time.eq(SystemTime::now()),
bans::end_time.eq(SystemTime::now()
.checked_add(Duration::new(hours * HOUR, 0))
.checked_add(Duration::from_secs(hours * 3600))
.ok_or("out of range Duration for ban end_time")?),
))
.execute(&conn)?;
Expand All @@ -37,7 +35,7 @@ pub fn save_unban(user_id: String, guild_id: String) -> Result<(), Error> {
Ok(())
}

pub fn unban_users(cx: &Context) -> Result<(), SendSyncError> {
pub fn unban_users(cx: &Context) -> Result<(), Error> {
let conn = DB.get()?;
let to_unban = bans::table
.filter(
Expand Down
6 changes: 3 additions & 3 deletions src/command_history.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{
commands::{Commands, PREFIXES},
Error, SendSyncError, HOUR,
Error,
};
use indexmap::IndexMap;
use serenity::{model::prelude::*, prelude::*, utils::CustomMessage};
use std::time::Duration;

const MESSAGE_AGE_MAX: Duration = Duration::from_secs(HOUR);
const MESSAGE_AGE_MAX: Duration = Duration::from_secs(3600);

pub struct CommandHistory;

Expand Down Expand Up @@ -40,7 +40,7 @@ pub fn replay_message(cx: Context, ev: MessageUpdateEvent, cmds: &Commands) -> R
Ok(())
}

pub fn clear_command_history(cx: &Context) -> Result<(), SendSyncError> {
pub fn clear_command_history(cx: &Context) -> Result<(), Error> {
let mut data = cx.data.write();
let history = data.get_mut::<CommandHistory>().unwrap();

Expand Down
6 changes: 3 additions & 3 deletions src/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ban::unban_users, command_history::clear_command_history, SendSyncError, HOUR};
use crate::{ban::unban_users, command_history::clear_command_history, Error};
use serenity::client::Context;
use std::{
sync::atomic::{AtomicBool, Ordering},
Expand All @@ -11,12 +11,12 @@ static JOBS_THREAD_INITIALIZED: AtomicBool = AtomicBool::new(false);
pub fn start_jobs(cx: Context) {
if !JOBS_THREAD_INITIALIZED.load(Ordering::SeqCst) {
JOBS_THREAD_INITIALIZED.store(true, Ordering::SeqCst);
std::thread::spawn(move || -> Result<(), SendSyncError> {
std::thread::spawn(move || -> Result<(), Error> {
loop {
unban_users(&cx)?;
clear_command_history(&cx)?;

sleep(Duration::new(HOUR, 0));
sleep(Duration::from_secs(3600));
}
});
}
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use indexmap::IndexMap;
use serde::Deserialize;
use serenity::{model::prelude::*, prelude::*};

pub type Error = Box<dyn std::error::Error>;
pub type SendSyncError = Box<dyn std::error::Error + Send + Sync>;

pub const HOUR: u64 = 3600;
pub type Error = Box<dyn std::error::Error + Send + Sync>;

#[derive(Deserialize)]
struct Config {
Expand Down Expand Up @@ -65,7 +62,7 @@ fn init_data(config: &Config) -> Result<(), Error> {
let _ = conn
.build_transaction()
.read_write()
.run::<_, Box<dyn std::error::Error>, _>(|| {
.run::<_, Error, _>(|| {
upsert_role("mod", &config.mod_id)?;
upsert_role("talk", &config.talk_id)?;

Expand Down
6 changes: 3 additions & 3 deletions src/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum Channel {
}

impl FromStr for Channel {
type Err = Box<dyn std::error::Error>;
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
match s {
Expand All @@ -65,7 +65,7 @@ enum Edition {
}

impl FromStr for Edition {
type Err = Box<dyn std::error::Error>;
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
match s {
Expand All @@ -92,7 +92,7 @@ enum Mode {
}

impl FromStr for Mode {
type Err = Box<dyn std::error::Error>;
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
match s {
Expand Down
4 changes: 2 additions & 2 deletions src/welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn post_message(args: &Args) -> Result<(), Error> {
let _ = conn
.build_transaction()
.read_write()
.run::<_, Box<dyn std::error::Error>, _>(|| {
.run::<_, Error, _>(|| {
let message_id = message.id.0.to_string();
let channel_id = channel_id.0.to_string();

Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn assign_talk_role(cx: &Context, reaction: &Reaction) -> Result<(), Error>
let (msg, talk_role, me) = conn
.build_transaction()
.read_only()
.run::<_, Box<dyn std::error::Error>, _>(|| {
.run::<_, Error, _>(|| {
let msg: Option<_> = messages::table
.filter(messages::name.eq("welcome"))
.first::<(i32, String, String, String)>(&conn)
Expand Down

0 comments on commit 3310573

Please sign in to comment.