Commit f6052d6e authored by Tim54000's avatar Tim54000 💬

Add more doc and README

parent 2031ad94
......@@ -5,6 +5,6 @@ authors = ["Tim54000 <Tim54000@gmx.com>"] # For english-speakers
# For french-speakers : Tim54000@gmx.ca / Tim54000@gmx.fr
[dependencies]
serenity = "^0.5.2"
serenity = "^0.5.3"
env_logger = "^0.5.9"
log = "^0.4.1"
\ No newline at end of file
# Tim's Bot
### Dependencies
* [Serenity ^0.5.3](https://docs.rs/crate/serenity/0.5.3)
### License
This bot is currently under any open-source licenses: it is therefore protected by French laws. Tim's Bot belongs to Timothée BRILLAUD. You can just now view sources and run this bot.
\ No newline at end of file
//! Mod [`help`](#) contains only the help command
//!
//! ## Commands :
//! * -help: A custom help command
use serenity::prelude::Context;
use serenity::framework::standard::HelpOptions;
use std::collections::HashMap;
......@@ -15,7 +19,6 @@ use serenity::framework::standard::CommandError;
use serenity::framework::standard::Command;
use std::env;
/// A custom help command
pub fn help(ctx: &mut Context, msg: &Message, ho: &HelpOptions, commands: HashMap<String, Arc<CommandGroup>>, args: &Args) -> Result<(), CommandError> {
msg.channel_id.broadcast_typing(); // Send typing to Discord
bot_to_not_disturb(&ctx, Some(Game::playing("help")));
......
//! Mod [`meta`](#) contains all *"meta"* commands
//!
//! ## Commands :
//! * -ping reply Pong!
use bot_to_not_disturb;
use bot_to_idle;
use serenity::model::prelude::gateway::Game;
/// -ping reply Pong!
command!(ping(ctx, msg) {
msg.channel_id.broadcast_typing();
bot_to_not_disturb(&ctx, Some(Game::playing("Ping-Pong")));
......
//! Mod `commands` contains all commands of bot
//! Mod `meta` contains all *"meta"* commands
//! Mod `owner` contains all commands reserved to owners
//! Mod `help` contains only the help command
//! Mod `webhook` contains all commands relative to webhook
//!
//! Mod [`meta`](meta/index.html) contains all *"meta"* commands
//!
//! Mod [`owner`](owner/index.html) contains all commands reserved to owners
//!
//! Mod [`help`](help/index.html) contains only the help command
//!
//! Mod [`webhook`](webhook/index.html) contains all commands relative to webhook
pub mod meta;
pub mod owner;
......
//! Mod [`owner`](#) contains all commands reserved to owners
//!
//! ## Commands :
//! * -quit will be restart the current shard
use bot_to_not_disturb;
use serenity::model::prelude::gateway::Game;
/// -quit will be restart the current shard
command!(quit(ctx, msg, _args) {
bot_to_not_disturb(&ctx, Some(Game::playing("Shutdown")));
ctx.quit();
......
//! Mod [`webhook`](#) contains all commands relative to webhook
//!
//! ## Commands :
//! * -wh send a Webhook (id,token required)
use bot_to_idle;
use bot_to_not_disturb;
use serenity::http;
......@@ -5,7 +9,6 @@ use std::env;
use serenity::model::channel::Embed;
use serenity::model::prelude::gateway::Game;
/// Command -wh send a Webhook (id,token required)
command!(webhook(ctx, msg) {
msg.channel_id.broadcast_typing();
bot_to_not_disturb(&ctx, Some(Game::playing("Webhook")));
......
......@@ -14,14 +14,19 @@ use std::collections::HashSet;
use serenity::framework::StandardFramework;
use serenity::model::gateway::Game;
mod commands;
pub mod commands;
struct Handler;
/// It's an [EventHandler], it recieve all events
/// [EventHandler]: https://docs.rs/serenity/*/serenity/client/event_handler/trait.EventHandler.html
pub struct Handler;
/// Define the bot version displayed in the help
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
/// Its value is CARGO_PKG_VERSION
pub const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
/// Launch Client and verify env var
/// Entry point of the program
///
/// 1. Verify env var
///
/// Env variables required :
/// ```
......@@ -29,7 +34,21 @@ const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
/// WEBHOOK_ID //> Create a webhook and find it on the webhook url
/// WEBHOOK_TOKEN //> Same
/// ```
fn main() {
///
/// 2. It login the [Client]
/// with `DISCORD_TOKEN`
///
/// 3. It get the bot's owners
///
/// 4. It register [Handler] & [Commands]
///
/// 5. If not error is occured, the [Handler] will be [Ready]
///
/// [Client]: https://docs.rs/serenity/*/serenity/client/struct.Client.html
/// [Handler]: struct.Handler.html
/// [Commands]: commands/index.html
/// [Ready]: https://docs.rs/serenity/*/serenity/client/event_handler/trait.EventHandler.html#method.ready
pub fn main() {
env_logger::init();
// Load env var and verify
......@@ -81,7 +100,6 @@ fn main() {
impl EventHandler for Handler {
/// Bot connected
fn ready(&self, ctx: Context, ready: Ready) {
info!("Bot is connected as {} !", ready.user.name);
bot_to_idle(&ctx);
......@@ -92,15 +110,25 @@ impl EventHandler for Handler {
}
}
/// Set to idle and change the Presence to default
fn bot_to_idle(ctx: &Context){
/// Set to idle and change the [Presence] to default
///
/// The default presence is : `-help v{VERSION}`
/// [VERSION]'s value is CARGO_PKG_VERSION
///
/// [VERSION]: constant.VERSION.html
pub fn bot_to_idle(ctx: &Context){
let status = OnlineStatus::Idle;
let game = Game::listening(format!("-help v{}", VERSION.unwrap_or("4.0.4")).as_str());
ctx.set_presence(Some(game), status);
}
/// Set to Dnd with custom Game
fn bot_to_not_disturb(ctx: &Context, game: Option<Game>){
/// Set to Do Not Disturb with custom Game
///
/// The default Game is : `-help v{VERSION}`
/// [VERSION]'s value is CARGO_PKG_VERSION
///
/// [VERSION]: constant.VERSION.html
pub fn bot_to_not_disturb(ctx: &Context, game: Option<Game>){
let status = OnlineStatus::DoNotDisturb;
let game = game.unwrap_or(Game::listening(format!("-help v{}", VERSION.unwrap_or("4.0.4")).as_str()));
ctx.set_presence(Some(game), status);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment