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
|
/target
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
token
|
config.json
|
||||||
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -465,7 +465,6 @@ dependencies = [
|
||||||
name = "killjoy_turret"
|
name = "killjoy_turret"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,9 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0.126", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0.64"
|
||||||
regex = "1.5.4"
|
regex = "1.5.4"
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,6 @@ use serenity::framework::standard::{
|
||||||
};
|
};
|
||||||
use serenity::model::prelude::*;
|
use serenity::model::prelude::*;
|
||||||
use serenity::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::collections::HashMap;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
@ -26,15 +17,15 @@ impl TypeMapKey for AutoRoleDataKey {
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(autorole)]
|
#[commands(autorole)]
|
||||||
#[description = "Auto role related commands"]
|
#[description = "Auto role related commands"]
|
||||||
struct AutoRole;
|
struct _AutoRole;
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[description = "Add auto assign roles"]
|
#[description = "Add auto assign roles"]
|
||||||
#[usage = "sdakhnfj"]
|
#[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 http = &ctx.http;
|
||||||
let mut data = ctx.data.write().await;
|
//let mut data = ctx.data.write().await;
|
||||||
let mut auto_roles = data.get_mut::<AutoRoleDataKey>();
|
//let mut auto_roles = data.get_mut::<AutoRoleDataKey>();
|
||||||
|
|
||||||
msg.channel_id
|
msg.channel_id
|
||||||
.send_message(http, |m| {
|
.send_message(http, |m| {
|
||||||
|
|
@ -58,10 +49,6 @@ async fn autorole(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
if let Some(emote) = answer.content.split(' ').next() {
|
if let Some(emote) = answer.content.split(' ').next() {
|
||||||
lazy_static! {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("should add emote: {}", emote);
|
println!("should add emote: {}", emote);
|
||||||
answer.react(http, '☑').await?;
|
answer.react(http, '☑').await?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,10 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::framework::standard::{
|
use serenity::framework::standard::{
|
||||||
help_commands,
|
help_commands, macros::help, Args, CommandGroup, CommandResult, HelpOptions,
|
||||||
macros::{command, group, help},
|
|
||||||
Args, CommandGroup, CommandResult, HelpOptions,
|
|
||||||
};
|
};
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::model::id::UserId;
|
use serenity::model::id::UserId;
|
||||||
use serenity::utils::{content_safe, ContentSafeOptions};
|
|
||||||
|
|
||||||
#[help]
|
#[help]
|
||||||
#[individual_command_tip = "Killjoy Turret Command Info"]
|
#[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 commands;
|
||||||
mod general;
|
mod general;
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
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::client::Context;
|
||||||
use serenity::framework::StandardFramework;
|
use serenity::framework::StandardFramework;
|
||||||
use serenity::http::Http;
|
use serenity::http::Http;
|
||||||
use serenity::model::id::{ChannelId, UserId};
|
use serenity::model::id::UserId;
|
||||||
use serenity::{async_trait, model::gateway::Ready, prelude::*};
|
use serenity::{async_trait, model::gateway::Ready, prelude::*};
|
||||||
use crate::autorole::{AUTOROLE_GROUP, AutoRoleDataKey, AutoRoleData};
|
|
||||||
use crate::commands::MY_HELP;
|
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
|
||||||
|
|
@ -24,9 +25,12 @@ impl EventHandler for Handler {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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 {
|
let (owners, bot_id) = match http.get_current_application_info().await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|
@ -49,7 +53,8 @@ async fn main() {
|
||||||
.owners(owners)
|
.owners(owners)
|
||||||
})
|
})
|
||||||
.help(&MY_HELP)
|
.help(&MY_HELP)
|
||||||
.group(&AUTOROLE_GROUP);
|
.normal_message(normal_message);
|
||||||
|
// .group(&AUTOROLE_GROUP);
|
||||||
|
|
||||||
let mut client = Client::builder(&token)
|
let mut client = Client::builder(&token)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
|
|
@ -60,6 +65,7 @@ async fn main() {
|
||||||
{
|
{
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
data.insert::<AutoRoleDataKey>(AutoRoleData::default());
|
data.insert::<AutoRoleDataKey>(AutoRoleData::default());
|
||||||
|
data.insert::<ConfigFile>(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue