smol bot
Diffstat (limited to 'src/bot/data.rs')
| -rw-r--r-- | src/bot/data.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/bot/data.rs b/src/bot/data.rs new file mode 100644 index 0000000..4f3e205 --- /dev/null +++ b/src/bot/data.rs @@ -0,0 +1,23 @@ +use serde_json::json; +use serenity::json::Value; + +use crate::bot::Context; + +#[implicit_fn::implicit_fn] +pub fn log(c: &Context<'_>) { + let v = json! {{ + "locale": c.author().locale.as_deref().unwrap_or("unknown".into()), + "name": c.author().name.clone(), + "id": c.author().id, + "cname": &*c.command().name, + "guild": c.guild().map_or(0, |x|x.id.get()), + "channel": c.channel_id() + }}; + push_j(v); +} + +pub fn push_j(j: Value) { + let mut f = std::fs::File::options().append(true).open("data").unwrap(); + use std::io::Write; + writeln!(f, "{}", serde_json::to_string(&j).unwrap()).unwrap(); +} |