Skip to content

Commit

Permalink
Init with example ping pong code
Browse files Browse the repository at this point in the history
  • Loading branch information
xNul committed Sep 12, 2020
0 parents commit 208a8f4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Irrelevant macOS meta file
.DS_Store

# Config file for private bot information
src/config.rs
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "among-us-discord-bot"
version = "0.1.0"
authors = ["Blake Wyatt <blakewy@live.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serenity = "0.9.0-rc.1"
tokio = "0.2.22"
51 changes: 51 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use tokio::net::TcpListener;
use tokio::prelude::*;
use serenity::async_trait;
use serenity::client::{Client, Context, EventHandler};
use serenity::model::channel::Message;
use serenity::framework::standard::{
StandardFramework,
CommandResult,
macros::{
command,
group
}
};

mod config;

use std::env;

#[group]
#[commands(ping)]
struct General;

struct Handler;

#[async_trait]
impl EventHandler for Handler {}

#[tokio::main]
async fn main() {
let framework = StandardFramework::new()
.configure(|c| c.prefix("!")) // set the bot's prefix to "~"
.group(&GENERAL_GROUP);

let mut client = Client::new(config::token)
.event_handler(Handler)
.framework(framework)
.await
.expect("Error creating client");

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

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

Ok(())
}

0 comments on commit 208a8f4

Please sign in to comment.