Implement bot
parent
c5b440311c
commit
ac4f180dd8
@ -1,3 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
secret
|
||||
prod_config.toml
|
||||
|
@ -1,4 +1,22 @@
|
||||
secret = "your login secret"
|
||||
|
||||
[[command]]
|
||||
trigger = ">restart_example"
|
||||
command = "/usr/bin/restart_something"
|
||||
users = [12345, 54321]
|
||||
# The prefix (a constant in the source code)
|
||||
# does not need to be specified here.
|
||||
# It is added automatically.
|
||||
trigger = "create_file"
|
||||
# Spaces are not escaped here
|
||||
command = "touch /tmp/test-rce"
|
||||
users = [137780880344088576]
|
||||
|
||||
[[command]]
|
||||
trigger = "append_to_file"
|
||||
# Pipes and redirection are allowed
|
||||
command = "echo asd >> /tmp/test-rce"
|
||||
users = [137780880344088576]
|
||||
|
||||
[[command]]
|
||||
trigger = "delete_file"
|
||||
command = "rm /tmp/test-rce"
|
||||
# Multiple user IDs can be added here
|
||||
users = [137780880344088576, 123456789098765]
|
||||
|
@ -0,0 +1,18 @@
|
||||
use super::commands::*;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
|
||||
pub fn read_config() -> String {
|
||||
fs::read_to_string("config.toml").expect("Could not read config file. Make sure a file named config.toml exists in the current working directory.")
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Config {
|
||||
#[serde(rename = "command")]
|
||||
pub commands: Vec<Command>,
|
||||
pub secret: String,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: Config = toml::from_str(&read_config()).unwrap();
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
use std::fs::File;
|
||||
use std::io::{prelude::*, BufReader};
|
||||
|
||||
pub fn read_file(path: &'static str) -> impl Iterator<Item = String> {
|
||||
let reader = BufReader::new(File::open(path).expect("File not found"));
|
||||
reader
|
||||
.lines()
|
||||
.map(|l| l.expect(&format!("Could not read from file")))
|
||||
}
|
Loading…
Reference in new issue