mirror of
https://github.com/Noratrieb/killjoy-turret.git
synced 2026-01-14 14:45:01 +01:00
autorole start
This commit is contained in:
parent
03087702af
commit
120521e68b
6 changed files with 127 additions and 26 deletions
|
|
@ -1,10 +1,96 @@
|
|||
use serenity::framework::standard::Args;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::framework::standard::{
|
||||
macros::{command, group},
|
||||
Args, CommandResult,
|
||||
};
|
||||
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;
|
||||
|
||||
pub struct AutoRoleDataKey;
|
||||
|
||||
impl TypeMapKey for AutoRoleDataKey {
|
||||
type Value = AutoRoleData;
|
||||
}
|
||||
|
||||
#[group]
|
||||
#[commands(autorole)]
|
||||
#[description = "Auto role related commands"]
|
||||
struct AutoRole;
|
||||
|
||||
#[command]
|
||||
#[desciption = "Add auto assign roles"]
|
||||
async fn auto_role(ctx: &Context, msg: &Message, args: &Args) {}
|
||||
#[description = "Add auto assign roles"]
|
||||
#[usage = "sdakhnfj"]
|
||||
async fn autorole(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let http = &ctx.http;
|
||||
let mut data = ctx.data.write().await;
|
||||
let mut auto_roles = data.get_mut::<AutoRoleDataKey>();
|
||||
|
||||
msg.channel_id
|
||||
.send_message(http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title("Started auto role assignment.");
|
||||
e.field(
|
||||
"Enter an emote and the assigned role seperated by a space.",
|
||||
"Write one message per role reaction.\n\n\
|
||||
A non-matching message finishes the process. Cancel with 'cancel', or after 30 seconds timeout\n\n\
|
||||
The emotes have to be from a server I'm in!",
|
||||
false,
|
||||
)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
while let Some(answer) = &msg
|
||||
.author
|
||||
.await_reply(&ctx)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.await
|
||||
{
|
||||
if let Some(emote) = answer.content.split(' ').next() {
|
||||
lazy_static! {
|
||||
|
||||
}
|
||||
|
||||
println!("should add emote: {}", emote);
|
||||
answer.react(http, '☑').await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AutoRoleData {
|
||||
messages: Vec<HashMap<DEmote, DRole>>,
|
||||
}
|
||||
|
||||
impl Default for AutoRoleData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
messages: Vec::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash)]
|
||||
struct DEmote {
|
||||
name: String,
|
||||
id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq)]
|
||||
struct DRole {
|
||||
name: String,
|
||||
id: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use rand::Rng;
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{
|
||||
help_commands,
|
||||
|
|
|
|||
23
src/main.rs
23
src/main.rs
|
|
@ -2,7 +2,6 @@ mod autorole;
|
|||
mod commands;
|
||||
mod general;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
|
||||
|
|
@ -11,17 +10,8 @@ use serenity::framework::StandardFramework;
|
|||
use serenity::http::Http;
|
||||
use serenity::model::id::{ChannelId, UserId};
|
||||
use serenity::{async_trait, model::gateway::Ready, prelude::*};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct AutoRoleData {
|
||||
|
||||
}
|
||||
|
||||
pub struct AutoRoleDataKey;
|
||||
|
||||
impl TypeMapKey for AutoRoleDataKey {
|
||||
type Value = AutoRoleData;
|
||||
}
|
||||
use crate::autorole::{AUTOROLE_GROUP, AutoRoleDataKey, AutoRoleData};
|
||||
use crate::commands::MY_HELP;
|
||||
|
||||
struct Handler;
|
||||
|
||||
|
|
@ -34,7 +24,7 @@ impl EventHandler for Handler {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let token = fs::read_to_string("bot_token").expect("Expected bot token in file 'bot_token'");
|
||||
let token = fs::read_to_string("token").expect("Expected bot token in file 'bot_token'");
|
||||
|
||||
let http = Http::new_with_token(&token);
|
||||
|
||||
|
|
@ -58,11 +48,8 @@ async fn main() {
|
|||
.delimiter(" ")
|
||||
.owners(owners)
|
||||
})
|
||||
.normal_message(normal_message)
|
||||
.help(&MY_HELP)
|
||||
.group(&GENERAL_GROUP)
|
||||
.group(&MEME_GROUP)
|
||||
.group(&ADMIN_GROUP);
|
||||
.group(&AUTOROLE_GROUP);
|
||||
|
||||
let mut client = Client::builder(&token)
|
||||
.event_handler(Handler)
|
||||
|
|
@ -72,7 +59,7 @@ async fn main() {
|
|||
|
||||
{
|
||||
let mut data = client.data.write().await;
|
||||
data.insert::<LastMessageInChannel>(HashMap::default());
|
||||
data.insert::<AutoRoleDataKey>(AutoRoleData::default());
|
||||
}
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue