initial?
This commit is contained in:
commit
a6dc08df80
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "namebot"
|
||||
version = "0.1.0"
|
||||
authors = ["kageru <kageru@encode.moe>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serenity = "0.8.6"
|
||||
time = "0.2.10"
|
|
@ -0,0 +1,79 @@
|
|||
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(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user