Skip to content

Commit

Permalink
set activity, log all messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Exr0n committed May 5, 2020
1 parent 49ec5de commit f24447b
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 14 deletions.
116 changes: 116 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serenity = "0.8"

[dependencies.serenity]
default-features = false
features = ["voice", "builder", "cache", "client", "framework", "gateway", "http", "model", "standard_framework", "utils", "rustls_backend"]
version = "0.8"

42 changes: 29 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// modified from [serenity-rs example](https://github.com/serenity-rs/serenity#example-bot)
use serenity::client::Client;
use serenity::model::channel::Message;
use serenity::model::gateway::Ready;
use serenity::prelude::{EventHandler, Context};
use serenity::framework::standard::{
StandardFramework,
Expand All @@ -19,7 +20,33 @@ use std::env;

struct Handler;

impl EventHandler for Handler {}
fn log(msg: &Message) {
println!("{}, {}#{}\n {}", msg.timestamp, msg.author.name, msg.author.discriminator, msg.content);
}

impl EventHandler for Handler {
fn ready(&self, ctx: Context, _data: Ready) {
// status: https://docs.rs/serenity/0.8.6/serenity/prelude/struct.Context.html#method.set_presence
use serenity::model::gateway::Activity;
use serenity::model::user::OnlineStatus;
let activity = Activity::playing("with your psyche...");
let status = OnlineStatus::DoNotDisturb; // TODO: change to Offline
ctx.set_presence(Some(activity), status);

println!("Bot ready.");
}
fn message(&self, _ctx: Context, msg: Message) {
log(&msg);
}
}

#[command]
fn ping(ctx: &mut Context, msg: &Message) -> CommandResult {
log(&msg);
msg.reply(ctx, "Pong!")?;

Ok(())
}

fn main() {
// Login with a bot token from the environment
Expand All @@ -30,20 +57,9 @@ fn main() {
.group(&GENERAL_GROUP));

// start listening for events by starting a single shard
println!("Starting bot...");
if let Err(why) = client.start() {
println!("An error occurred while running the client: {:?}", why);
}
}

fn log(msg: &Message) {
println!("{}: Message from {}#{}\n {}", msg.timestamp, msg.author.name, msg.author.discriminator, msg.content);
}

#[command]
fn ping(ctx: &mut Context, msg: &Message) -> CommandResult {
log(&msg);
msg.reply(ctx, "Pong!")?;

Ok(())
}

0 comments on commit f24447b

Please sign in to comment.