80 lines
2.3 KiB
Rust
80 lines
2.3 KiB
Rust
use serenity::client::Client;
|
|
use serenity::framework::standard::{
|
|
macros::{command, group},
|
|
CommandResult, StandardFramework,
|
|
};
|
|
use serenity::model::{
|
|
channel::Message,
|
|
id::{ChannelId, GuildId},
|
|
prelude::User,
|
|
};
|
|
use serenity::prelude::*;
|
|
use std::fs::File;
|
|
use std::io::{self, BufRead, BufReader};
|
|
use time::Duration;
|
|
|
|
#[group]
|
|
#[commands(name)]
|
|
struct Fluff;
|
|
struct Handler;
|
|
impl EventHandler for Handler {
|
|
fn guild_ban_addition(&self, ctx: Context, guild_id: GuildId, _: User) {
|
|
if guild_id == 427456811973738498 {
|
|
if let Err(e) =
|
|
ChannelId(562731470423064587).say(&ctx, "Das hier ist eine flauschige Diktatur!")
|
|
{
|
|
eprintln!("Couldn’t send message because {:?}", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn read_token() -> io::Result<String> {
|
|
let reader = BufReader::new(File::open("secret")?);
|
|
reader.lines().next().unwrap()
|
|
}
|
|
|
|
fn main() {
|
|
let mut client = Client::new(&read_token().expect("no secret file"), Handler)
|
|
.expect("Error creating client");
|
|
client.with_framework(
|
|
StandardFramework::new()
|
|
.configure(|c| c.prefix("!"))
|
|
.group(&FLUFF_GROUP),
|
|
);
|
|
|
|
if let Err(why) = client.start() {
|
|
println!("An error occurred while running the client: {:?}", why);
|
|
}
|
|
}
|
|
|
|
#[command]
|
|
fn name(ctx: &mut Context, msg: &Message) -> CommandResult {
|
|
if let Some((_, name)) = msg.content.split_once(' ') {
|
|
let (name, adjustment) = name.split_once(" -").unwrap_or((name, "0"));
|
|
let adjustment = adjustment.strip_suffix("h").unwrap_or(adjustment);
|
|
msg.guild(&ctx)
|
|
.unwrap()
|
|
.read()
|
|
.edit_member(&ctx, msg.author.id, |m| m.nickname(name))?;
|
|
let now = time::OffsetDateTime::now_utc()
|
|
- adjustment
|
|
.parse::<f32>()
|
|
.map(|a| (a * 3600.0) as i64)
|
|
.map(Duration::seconds)
|
|
.ok()
|
|
.unwrap_or_else(Duration::zero);
|
|
println!(
|
|
"{},{},{},{},{}",
|
|
now.format("%d.%m.%Y %H:%M"),
|
|
name,
|
|
now.format("%y%m"),
|
|
msg.author.id,
|
|
now.unix_timestamp()
|
|
);
|
|
} else {
|
|
msg.reply(&ctx, "Please specify a new name.")?;
|
|
}
|
|
Ok(())
|
|
}
|