mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 09:10:49 +00:00
Move to SQLite (#13)
This commit is contained in:
parent
750ddb7762
commit
1799b70bc1
50 changed files with 2122 additions and 394 deletions
|
@ -80,7 +80,7 @@ async fn ban(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|||
)
|
||||
.await?;
|
||||
msg.guild_id
|
||||
.ok_or(Error::msg("Can't get guild from message?"))? // we had a contract
|
||||
.ok_or_else(|| Error::msg("Can't get guild from message?"))? // we had a contract
|
||||
.ban_with_reason(&ctx.http, user, dmds, &reason)
|
||||
.await?;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ async fn ban(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|||
msg.reply(&ctx, format!("🔨 Banning user {}.", user.tag()))
|
||||
.await?;
|
||||
msg.guild_id
|
||||
.ok_or(Error::msg("Can't get guild from message?"))? // we had a contract
|
||||
.ok_or_else(|| Error::msg("Can't get guild from message?"))? // we had a contract
|
||||
.ban(&ctx.http, user, dmds)
|
||||
.await?;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ pub async fn soft_ban(ctx: &Context, msg: &Message, mut args: Args) -> CommandRe
|
|||
} else {
|
||||
Some(args.single::<args::Duration>()?)
|
||||
};
|
||||
let guild = msg.guild_id.ok_or(Error::msg("Command is guild only"))?;
|
||||
let guild = msg
|
||||
.guild_id
|
||||
.ok_or_else(|| Error::msg("Command is guild only"))?;
|
||||
|
||||
let mut db = SoftBans::open(&*data);
|
||||
let val = db
|
||||
|
@ -37,7 +39,7 @@ pub async fn soft_ban(ctx: &Context, msg: &Message, mut args: Args) -> CommandRe
|
|||
.map(|v| (v.role, v.periodical_bans.get(&user.id).cloned()));
|
||||
let (role, current_ban_deadline) = match val {
|
||||
None => {
|
||||
msg.reply(&ctx, format!("⚠ This server has not enabled the soft-ban feature. Check out `y!a soft-ban-init`.")).await?;
|
||||
msg.reply(&ctx, "⚠ This server has not enabled the soft-ban feature. Check out `y!a soft-ban-init`.").await?;
|
||||
return Ok(());
|
||||
}
|
||||
Some(v) => v,
|
||||
|
@ -58,7 +60,7 @@ pub async fn soft_ban(ctx: &Context, msg: &Message, mut args: Args) -> CommandRe
|
|||
Some(v) => {
|
||||
// Add the duration into the ban timeout.
|
||||
let until =
|
||||
current_ban_deadline.unwrap_or(Utc::now()) + chrono::Duration::from_std(v.0)?;
|
||||
current_ban_deadline.unwrap_or_else(Utc::now) + chrono::Duration::from_std(v.0)?;
|
||||
msg.reply(
|
||||
&ctx,
|
||||
format!("⛓ Soft-banning user {} until {}.", user.tag(), until),
|
||||
|
@ -86,10 +88,7 @@ pub async fn soft_ban_init(ctx: &Context, msg: &Message, mut args: Args) -> Comm
|
|||
let guild = msg.guild(&ctx).await.unwrap();
|
||||
// Check whether the role_id is the one we wanted
|
||||
if !guild.roles.contains_key(&role_id) {
|
||||
Err(Error::msg(format!(
|
||||
"{} is not a role in this server.",
|
||||
role_id
|
||||
)))?;
|
||||
return Err(Error::msg(format!("{} is not a role in this server.", role_id)).into());
|
||||
}
|
||||
// Check if we already set up
|
||||
let mut db = SoftBans::open(&*data);
|
||||
|
@ -100,7 +99,7 @@ pub async fn soft_ban_init(ctx: &Context, msg: &Message, mut args: Args) -> Comm
|
|||
.insert(guild.id, ServerSoftBans::new(role_id));
|
||||
msg.react(&ctx, '👌').await?;
|
||||
} else {
|
||||
Err(Error::msg("Server already set up soft-bans."))?
|
||||
return Err(Error::msg("Server already set up soft-bans.").into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ pub async fn choose(ctx: &Context, m: &Message, mut args: Args) -> CommandResult
|
|||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.map(|mem| future::ready(mem))
|
||||
.map(future::ready)
|
||||
.collect::<stream::FuturesUnordered<_>>()
|
||||
.filter_map(|member| async move {
|
||||
// Filter by role if provided
|
||||
|
@ -110,7 +110,7 @@ pub async fn choose(ctx: &Context, m: &Message, mut args: Args) -> CommandResult
|
|||
.push(" ")
|
||||
.push(
|
||||
role.map(|r| format!("{}s", r.mention()))
|
||||
.unwrap_or("potential prayers".to_owned()),
|
||||
.unwrap_or_else(|| "potential prayers".to_owned()),
|
||||
)
|
||||
.push(", ")
|
||||
.push(winner.mention())
|
||||
|
|
|
@ -388,7 +388,7 @@ mod reaction_watcher {
|
|||
.flat_map(|(&guild, rs)| {
|
||||
rs.reaction_messages
|
||||
.iter()
|
||||
.map(move |(m, r)| (guild, m.clone(), r.clone()))
|
||||
.map(move |(m, r)| (guild, *m, r.clone()))
|
||||
})
|
||||
.collect();
|
||||
Ok(Self {
|
||||
|
@ -554,11 +554,11 @@ mod reaction_watcher {
|
|||
let role = Roles::open(&*data)
|
||||
.borrow()?
|
||||
.get(&guild)
|
||||
.ok_or(Error::msg("guild no longer has role list"))?
|
||||
.ok_or_else(|| Error::msg("guild no longer has role list"))?
|
||||
.reaction_messages
|
||||
.get(&message)
|
||||
.map(|msg| &msg.roles[..])
|
||||
.ok_or(Error::msg("message is no longer a role list handler"))?
|
||||
.ok_or_else(|| Error::msg("message is no longer a role list handler"))?
|
||||
.iter()
|
||||
.find_map(|(role, role_reaction)| {
|
||||
if &reaction.as_inner_ref().emoji == role_reaction {
|
||||
|
|
|
@ -87,7 +87,7 @@ pub async fn vote(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
|||
let panel = channel.send_message(&ctx, |c| {
|
||||
c.content("@here").embed(|e| {
|
||||
e.author(|au| {
|
||||
au.icon_url(author.avatar_url().unwrap_or("".to_owned()))
|
||||
au.icon_url(author.avatar_url().unwrap_or_else(|| "".to_owned()))
|
||||
.name(&author.name)
|
||||
})
|
||||
.title(format!("You have {} to vote!", _duration))
|
||||
|
@ -97,7 +97,6 @@ pub async fn vote(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
|||
})
|
||||
}).await?;
|
||||
msg.delete(&ctx).await?;
|
||||
drop(msg);
|
||||
|
||||
// React on all the choices
|
||||
choices
|
||||
|
@ -160,7 +159,7 @@ pub async fn vote(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
|||
|
||||
result.sort_unstable_by(|(_, v), (_, w)| w.len().cmp(&v.len()));
|
||||
|
||||
if result.len() == 0 {
|
||||
if result.is_empty() {
|
||||
msg.reply(
|
||||
&ctx,
|
||||
MessageBuilder::new()
|
||||
|
@ -227,7 +226,7 @@ fn pick_n_reactions(n: usize) -> Result<Vec<String>, Error> {
|
|||
const MAX_CHOICES: usize = 15;
|
||||
|
||||
// All the defined reactions.
|
||||
const REACTIONS: [&'static str; 90] = [
|
||||
const REACTIONS: [&str; 90] = [
|
||||
"😀", "😁", "😂", "🤣", "😃", "😄", "😅", "😆", "😉", "😊", "😋", "😎", "😍", "😘", "🥰", "😗",
|
||||
"😙", "😚", "☺️", "🙂", "🤗", "🤩", "🤔", "🤨", "😐", "😑", "😶", "🙄", "😏", "😣", "😥", "😮",
|
||||
"🤐", "😯", "😪", "😫", "😴", "😌", "😛", "😜", "😝", "🤤", "😒", "😓", "😔", "😕", "🙃", "🤑",
|
||||
|
|
|
@ -95,7 +95,7 @@ async fn pick(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|||
.peekable();
|
||||
// If we have the first argument as question, use it.
|
||||
let question = match choices.peek() {
|
||||
Some(ref q) if q.starts_with("?") => Some(q.replacen("?", "", 1) + "?"),
|
||||
Some(ref q) if q.starts_with('?') => Some(q.replacen("?", "", 1) + "?"),
|
||||
_ => None,
|
||||
};
|
||||
// If we have a question, that's not a choice.
|
||||
|
|
|
@ -10,7 +10,7 @@ pub fn name_from_userid(u: UserId) -> (&'static str, &'static str) {
|
|||
)
|
||||
}
|
||||
|
||||
const FIRST_NAMES: [&'static str; 440] = [
|
||||
const FIRST_NAMES: [&str; 440] = [
|
||||
// A Female names
|
||||
"Ai",
|
||||
"Aiko",
|
||||
|
@ -473,7 +473,7 @@ const FIRST_NAMES: [&'static str; 440] = [
|
|||
"Yusuke",
|
||||
];
|
||||
|
||||
const LAST_NAMES: [&'static str; 1051] = [
|
||||
const LAST_NAMES: [&str; 1051] = [
|
||||
// A Surnames
|
||||
"Abe",
|
||||
"Abukara",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue