mirror of
https://github.com/Noratrieb/killjoy-turret.git
synced 2026-01-14 14:45:01 +01:00
breeze
This commit is contained in:
parent
120521e68b
commit
aabdacd2a6
7 changed files with 54 additions and 34 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
|||
/target
|
||||
.idea
|
||||
*.iml
|
||||
token
|
||||
config.json
|
||||
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -465,7 +465,6 @@ dependencies = [
|
|||
name = "killjoy_turret"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
|
|||
|
|
@ -8,12 +8,11 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0.126", features = ["derive"] }
|
||||
serde_json = "1.0.64"
|
||||
regex = "1.5.4"
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[dependencies.serenity]
|
||||
version = "0.10.7"
|
||||
default-features = false
|
||||
features = ["client", "gateway", "rustls_backend", "model", "framework", "standard_framework", "cache", "http", "utils", "collector"]
|
||||
features = ["client", "gateway", "rustls_backend", "model", "framework", "standard_framework", "cache", "http", "utils", "collector"]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -26,15 +17,15 @@ impl TypeMapKey for AutoRoleDataKey {
|
|||
#[group]
|
||||
#[commands(autorole)]
|
||||
#[description = "Auto role related commands"]
|
||||
struct AutoRole;
|
||||
struct _AutoRole;
|
||||
|
||||
#[command]
|
||||
#[description = "Add auto assign roles"]
|
||||
#[usage = "sdakhnfj"]
|
||||
async fn autorole(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
async fn autorole(ctx: &Context, msg: &Message, _: Args) -> CommandResult {
|
||||
let http = &ctx.http;
|
||||
let mut data = ctx.data.write().await;
|
||||
let mut auto_roles = data.get_mut::<AutoRoleDataKey>();
|
||||
//let mut data = ctx.data.write().await;
|
||||
//let mut auto_roles = data.get_mut::<AutoRoleDataKey>();
|
||||
|
||||
msg.channel_id
|
||||
.send_message(http, |m| {
|
||||
|
|
@ -58,10 +49,6 @@ async fn autorole(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||
.await
|
||||
{
|
||||
if let Some(emote) = answer.content.split(' ').next() {
|
||||
lazy_static! {
|
||||
|
||||
}
|
||||
|
||||
println!("should add emote: {}", emote);
|
||||
answer.react(http, '☑').await?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@ use std::collections::HashSet;
|
|||
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{
|
||||
help_commands,
|
||||
macros::{command, group, help},
|
||||
Args, CommandGroup, CommandResult, HelpOptions,
|
||||
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"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serenity::framework::standard::macros::hook;
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ConfigFile {
|
||||
pub token: String,
|
||||
pub auto_react: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl TypeMapKey for ConfigFile {
|
||||
type Value = Self;
|
||||
}
|
||||
|
||||
#[hook]
|
||||
pub async fn normal_message(ctx: &Context, msg: &Message) {
|
||||
let map = ctx.data.read().await;
|
||||
let reactions = map.get::<ConfigFile>().unwrap();
|
||||
|
||||
let lowercase_content = msg.content.to_lowercase();
|
||||
for (trigger, reaction) in &reactions.auto_react {
|
||||
if lowercase_content.contains(trigger) {
|
||||
if let Err(why) = msg
|
||||
.react(&ctx.http, ReactionType::Unicode(reaction.clone()))
|
||||
.await
|
||||
{
|
||||
eprintln!("Error reacting {}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/main.rs
20
src/main.rs
|
|
@ -2,16 +2,17 @@ mod autorole;
|
|||
mod commands;
|
||||
mod general;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
use crate::autorole::{AutoRoleData, AutoRoleDataKey};
|
||||
use crate::commands::MY_HELP;
|
||||
use crate::general::{normal_message, ConfigFile};
|
||||
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;
|
||||
|
||||
|
|
@ -24,9 +25,12 @@ impl EventHandler for Handler {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let token = fs::read_to_string("token").expect("Expected bot token in file 'bot_token'");
|
||||
let file = fs::read_to_string("config.json").unwrap();
|
||||
let config = serde_json::from_str::<ConfigFile>(&file).unwrap();
|
||||
|
||||
let http = Http::new_with_token(&token);
|
||||
let token = &config.token;
|
||||
|
||||
let http = Http::new_with_token(token);
|
||||
|
||||
let (owners, bot_id) = match http.get_current_application_info().await {
|
||||
Ok(_) => {
|
||||
|
|
@ -49,7 +53,8 @@ async fn main() {
|
|||
.owners(owners)
|
||||
})
|
||||
.help(&MY_HELP)
|
||||
.group(&AUTOROLE_GROUP);
|
||||
.normal_message(normal_message);
|
||||
// .group(&AUTOROLE_GROUP);
|
||||
|
||||
let mut client = Client::builder(&token)
|
||||
.event_handler(Handler)
|
||||
|
|
@ -60,6 +65,7 @@ async fn main() {
|
|||
{
|
||||
let mut data = client.data.write().await;
|
||||
data.insert::<AutoRoleDataKey>(AutoRoleData::default());
|
||||
data.insert::<ConfigFile>(config);
|
||||
}
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue