mirror of
https://github.com/Noratrieb/killjoy-turret.git
synced 2026-01-14 06:35:01 +01:00
can almost create message
This commit is contained in:
parent
120521e68b
commit
2416a28b09
6 changed files with 51 additions and 63 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
|
@ -6,15 +6,6 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.50"
|
||||
|
|
@ -465,8 +456,6 @@ dependencies = [
|
|||
name = "killjoy_turret"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serenity",
|
||||
|
|
@ -719,23 +708,6 @@ dependencies = [
|
|||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.3"
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ edition = "2018"
|
|||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
regex = "1.5.4"
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[dependencies.serenity]
|
||||
version = "0.10.7"
|
||||
|
|
|
|||
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
max_width = 120
|
||||
|
|
@ -5,15 +5,6 @@ use serenity::framework::standard::{
|
|||
};
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
use serenity::{
|
||||
async_trait,
|
||||
collector::MessageCollectorBuilder,
|
||||
framework::standard::{help_commands, CommandGroup, HelpOptions, StandardFramework},
|
||||
futures::stream::StreamExt,
|
||||
http::Http,
|
||||
model::prelude::*,
|
||||
prelude::*,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -28,13 +19,26 @@ impl TypeMapKey for AutoRoleDataKey {
|
|||
#[description = "Auto role related commands"]
|
||||
struct AutoRole;
|
||||
|
||||
const DEFAULT_MESSAGE: &'static str = "Select your role";
|
||||
|
||||
#[command]
|
||||
#[aliases("a")]
|
||||
#[description = "Add auto assign roles"]
|
||||
#[usage = "sdakhnfj"]
|
||||
async fn autorole(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
async fn autorole(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let http = &ctx.http;
|
||||
let mut data = ctx.data.write().await;
|
||||
let mut auto_roles = data.get_mut::<AutoRoleDataKey>();
|
||||
|
||||
let target_channel = args.single::<ChannelId>();
|
||||
args.quoted();
|
||||
let message = args.single::<String>().unwrap_or(DEFAULT_MESSAGE.to_string());
|
||||
|
||||
if let Err(_) = target_channel {
|
||||
msg.channel_id
|
||||
.say(http, "You need to mention the channel the message should be sent in")
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let target_channel = target_channel.unwrap();
|
||||
|
||||
msg.channel_id
|
||||
.send_message(http, |m| {
|
||||
|
|
@ -51,22 +55,40 @@ async fn autorole(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||
})
|
||||
.await?;
|
||||
|
||||
while let Some(answer) = &msg
|
||||
.author
|
||||
.await_reply(&ctx)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.await
|
||||
{
|
||||
let mut roles = vec![];
|
||||
|
||||
while let Some(answer) = &msg.author.await_reply(&ctx).timeout(Duration::from_secs(30)).await {
|
||||
if answer.content.contains("cancel") {
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(role) = answer.mention_roles.get(0) {
|
||||
if let Some(emote) = answer.content.split(' ').next() {
|
||||
lazy_static! {
|
||||
|
||||
}
|
||||
|
||||
println!("should add emote: {}", emote);
|
||||
println!("should add emote: {} for role {}", emote, role.0);
|
||||
answer.react(http, '☑').await?;
|
||||
|
||||
roles.push((emote.to_string(), role.0));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
msg.channel_id.say(http, "done").await?;
|
||||
|
||||
target_channel
|
||||
.send_message(http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title(message);
|
||||
e.field("neutral", "same", false)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
let mut data = ctx.data.write().await;
|
||||
let mut auto_roles = data.get_mut::<AutoRoleDataKey>().unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,9 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{
|
||||
help_commands,
|
||||
macros::{command, group, help},
|
||||
Args, CommandGroup, CommandResult, HelpOptions,
|
||||
};
|
||||
use serenity::framework::standard::{help_commands, macros::help, Args, CommandGroup, CommandResult, HelpOptions};
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::model::id::UserId;
|
||||
use serenity::utils::{content_safe, ContentSafeOptions};
|
||||
|
||||
#[help]
|
||||
#[individual_command_tip = "Killjoy Turret Command Info"]
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ mod autorole;
|
|||
mod commands;
|
||||
mod general;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
use crate::autorole::{AutoRoleData, AutoRoleDataKey, AUTOROLE_GROUP};
|
||||
use crate::commands::MY_HELP;
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::StandardFramework;
|
||||
use serenity::http::Http;
|
||||
use serenity::model::id::{ChannelId, UserId};
|
||||
use serenity::model::id::UserId;
|
||||
use serenity::{async_trait, model::gateway::Ready, prelude::*};
|
||||
use crate::autorole::{AUTOROLE_GROUP, AutoRoleDataKey, AutoRoleData};
|
||||
use crate::commands::MY_HELP;
|
||||
|
||||
struct Handler;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue