Initial commit
This commit is contained in:
commit
94526fd8df
5 changed files with 1899 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
**/*.rs.bk
|
1808
Cargo.lock
generated
Normal file
1808
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "fishy"
|
||||
version = "0.1.0"
|
||||
authors = ["Skye Bleed <skyebleed@mailfence.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serenity = "0.7.0"
|
BIN
fishy
Executable file
BIN
fishy
Executable file
Binary file not shown.
79
src/main.rs
Normal file
79
src/main.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
use serenity::client::Client;
|
||||
use serenity::framework::standard::{
|
||||
StandardFramework,
|
||||
CommandResult,
|
||||
macros::{
|
||||
command,
|
||||
group
|
||||
}
|
||||
};
|
||||
|
||||
group!({
|
||||
name: "general",
|
||||
options: {},
|
||||
commands: [hello],
|
||||
});
|
||||
|
||||
use std::env;
|
||||
|
||||
use serenity::{
|
||||
model::{channel::Message, gateway::Ready},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
struct Handler;
|
||||
|
||||
impl EventHandler for Handler {
|
||||
// Set a handler for the `message` event - so that whenever a new message
|
||||
// is received - the closure (or function) passed will be called.
|
||||
//
|
||||
// Event handlers are dispatched through a threadpool, and so multiple
|
||||
// events can be dispatched simultaneously.
|
||||
fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.content == "!ping" {
|
||||
// Sending a message can fail, due to a network error, an
|
||||
// authentication error, or lack of permissions to post in the
|
||||
// channel, so log to stdout when some error happens, with a
|
||||
// description of it.
|
||||
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!") {
|
||||
println!("Error sending message: {:?}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set a handler to be called on the `ready` event. This is called when a
|
||||
// shard is booted, and a READY payload is sent by Discord. This payload
|
||||
// contains data like the current user's guild Ids, current user data,
|
||||
// private channels, and more.
|
||||
//
|
||||
// In this case, just print what the current user's username is.
|
||||
fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// get token from args
|
||||
let args: Vec<_> = env::args().collect();
|
||||
let token = &args[1];
|
||||
let mut client = Client::new(token, Handler)
|
||||
.expect("Error creating client");
|
||||
client.with_framework(StandardFramework::new()
|
||||
.configure(|c| c.prefix("fishy ")) // set the bot's prefix
|
||||
.group(&GENERAL_GROUP));
|
||||
|
||||
println!("Starting client...");
|
||||
// start listening for events by starting a single shard
|
||||
if let Err(why) = client.start() {
|
||||
println!("An error occurred while running the client: {:?}", why);
|
||||
}
|
||||
}
|
||||
|
||||
#[command]
|
||||
fn hello(ctx: &mut Context, msg: &Message) -> CommandResult {
|
||||
println!("Executing HELLO...");
|
||||
msg.reply(ctx, "Hello!")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in a new issue