aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2020-11-02 16:31:17 -0800
committerFuwn <[email protected]>2020-11-02 16:31:17 -0800
commit11e768178d08d631b38703d8cc38f2aa9ff83cdb (patch)
tree858729a395e8e661bc6e425464d4dd022c95054a /src
parentchore/ fix: commit file that i forgot to commit (diff)
downloaddep-core-next-11e768178d08d631b38703d8cc38f2aa9ff83cdb.tar.xz
dep-core-next-11e768178d08d631b38703d8cc38f2aa9ff83cdb.zip
refactor, chore, feat (desc)
refactor: - `Cargo.toml` openssl patch - rename `DBOTS_TOKEN` environment variable feat: - new `wisp` command information - support server, bot invite, feature request, bot discovery sites. - use `CARGO_PKG_VERSION` environment variable to show version in presence. - `privacypolicy` command - prime more of the rocket webserver
Diffstat (limited to 'src')
-rw-r--r--src/core/api.rs4
-rw-r--r--src/core/consts.rs13
-rw-r--r--src/core/handler.rs10
-rw-r--r--src/modules/commands/general/mod.rs1
-rw-r--r--src/modules/commands/general/utilities.rs53
-rw-r--r--src/webserver/rocket.rs20
-rw-r--r--src/wisp.rs9
7 files changed, 87 insertions, 23 deletions
diff --git a/src/core/api.rs b/src/core/api.rs
index 9712ffd..71800e3 100644
--- a/src/core/api.rs
+++ b/src/core/api.rs
@@ -157,7 +157,7 @@ impl ApiClient {
pub fn stats_update(&self, bot_id: u64, server_count: usize) -> ReqwestResult<ReqwestResponse> {
let mut headers = Headers::new();
headers.set(ContentType::json());
- headers.set(Authorization(env::var("DBOTS_TOKEN").expect("Expected DiscordBots.org token in enviroment.")));
+ headers.set(Authorization(env::var("DBOTS_ORG_TOKEN").expect("Expected DiscordBots.org token in environment.")));
let mut data = HashMap::new();
data.insert("server_count", server_count);
@@ -309,7 +309,7 @@ impl ApiClient {
first.components.get("state").unwrap(),
first.components.get("country").unwrap()
);
- let ds_key = env::var("DARKSKY_KEY").expect("Expected DarkSky API Key in enviroment.");
+ let ds_key = env::var("DARKSKY_KEY").expect("Expected DarkSky API Key in environment.");
let fc_req = Some(ForecastRequestBuilder::new(ds_key.as_str(), *first.geometry.get("lat").unwrap(), *first.geometry.get("lng").unwrap())
.lang(Lang::English)
.units(units)
diff --git a/src/core/consts.rs b/src/core/consts.rs
index bc68bfc..df214c5 100644
--- a/src/core/consts.rs
+++ b/src/core/consts.rs
@@ -32,12 +32,15 @@ pub const NOW_LIVE: RoleId = RoleId(370395740406546432);
pub const SUPPORT_SERVER: GuildId = GuildId(704032355987488791); // 373561057639268352
pub const TRANSCEND: GuildId = GuildId(348660188951216129);
-pub const SUPPORT_SERV_INVITE: &str = "https://discord.gg/ASrM7p9";
-pub const BOT_INVITE: &str = "https://discordapp.com/oauth2/authorize/?permissions=335670488&scope=bot&client_id=699473263998271489";
-pub const FEATURE_REQUEST_LINK: &str = "http://mailto:[email protected]";
+pub const SUPPORT_SERV_INVITE: &str = "https://discord.gg/ASrM7p9";
+pub const BOT_INVITE: &str = "https://discordapp.com/oauth2/authorize/?permissions=335670488&scope=bot&client_id=712088369206919269";
+pub const FEATURE_REQUEST_LINK: &str = "http://mailto:[email protected]";
pub const GITHUB_ORG_LINK: &str = "https://github.com/wispgg";
-// pub const GITLAB_LINK: &str = "https://gitlab.com/fuwn/wisp";
-// pub const PATREON_LINK: &str = "https://www.patreon.com/wisp";
+pub const TOPGG_LINK: &str = "https://top.gg/bot/712088369206919269";
+pub const DBOTS_CO_LINK: &str = "https://discordbots.co/bot/712088369206919269";
+pub const BOTSOND_LINK: &str = "https://bots.ondiscord.xyz/bots/712088369206919269";
+// pub const GITLAB_LINK: &str = "https://gitlab.com/fuwn/wisp";
+// pub const PATREON_LINK: &str = "https://www.patreon.com/wisp";
pub const API_FAIL: &str = "Failed to get API";
pub const CACHE_CHANNEL_FAIL: &str = "Failed to get channel lock from CACHE";
diff --git a/src/core/handler.rs b/src/core/handler.rs
index 7d5bbfa..2074567 100644
--- a/src/core/handler.rs
+++ b/src/core/handler.rs
@@ -106,18 +106,12 @@ impl EventHandler for Handler {
// let guild_count = guilds.len();
// ctx.set_game(Game::listening(&format!("{} guilds | m!help", guild_count)));
- ctx.set_game(Game::playing("w.help | v0.1.0"));
+ // ctx.set_game(Game::playing("w.help | v0.1.0"));
+ ctx.set_game(Game::playing(&*format!("w.help | v{}", env!("CARGO_PKG_VERSION"))));
info!("Caching complete.");
}
fn message(&self, ctx: Context, message: Message) {
- // check_error!(message.guild().unwrap().read()
- // .edit_member(712088369206919269, |member| member.nickname("Wisp")));
-
- if message.content.contains("uwu!") {
- check_error!(message.channel_id.say("Uwufier has been re-branded! However, due to the current limitations in place for verified Discord bots, we are still awaiting for our username change to go through, until then, meet Wisp, your all-in-one Discord companion. For future reference, please use the new prefix; `w.`!"));
- }
-
if message.mention_everyone {
check_error!(message.react("👀"))
}
diff --git a/src/modules/commands/general/mod.rs b/src/modules/commands/general/mod.rs
index ce87755..33c97d0 100644
--- a/src/modules/commands/general/mod.rs
+++ b/src/modules/commands/general/mod.rs
@@ -112,6 +112,7 @@ pub fn init_utilities() -> CreateGroup {
.cmd("pfp", PFP)
.cmd("ping", Ping)
.cmd("prefix", Prefix)
+ .cmd("privacypolicy", PrivacyPolicy)
.cmd("remind", Reminder)
.cmd("role", RoleInfo)
.cmd("server", ServerInfo)
diff --git a/src/modules/commands/general/utilities.rs b/src/modules/commands/general/utilities.rs
index 2d974e3..daebc27 100644
--- a/src/modules/commands/general/utilities.rs
+++ b/src/modules/commands/general/utilities.rs
@@ -679,6 +679,32 @@ impl Command for Weather {
}
} */
+pub struct PrivacyPolicy;
+impl Command for PrivacyPolicy {
+ fn options(&self) -> Arc<CommandOptions> {
+ let default = CommandOptions::default();
+ let options = CommandOptions {
+ desc: Some("View my privacy policy!".to_string()),
+ aliases: vec!["privacy-policy", "privacy"].iter().map(|e| e.to_string()).collect(),
+ ..default
+ };
+ Arc::new(options)
+ }
+
+ fn execute(&self, _ctx: &mut Context, message: &Message, _args: Args) -> Result<(), CommandError> {
+ use serenity::builder::CreateEmbed;
+
+ let embed = CreateEmbed::default()
+ .field("Privacy Policy", "**Does Wisp store user/ guild data?**\nYes! We store various pieces of information which is only kept for the lifetime of the command/ feature/ module.\n\n**How can I request to have my data removed?**\nMost of the data that we keep can be retracted by disabling the command/ feature/ module, however, if you want to make *100%* sure that all your data has been erased, join our support server and we will personally make sure that your requests are satisfied.\n\n*In the future, the process of requesting the deletion of your data might be an automated or semi-automated process.*", false)
+ .colour(*colours::MAIN);
+
+ message.channel_id.send_message(|m| m
+ .embed(|_| embed))?;
+
+ Ok(())
+ }
+}
+
pub struct Wisp; // BotInfo
impl Command for Wisp {
fn options(&self) -> Arc<CommandOptions> {
@@ -686,7 +712,7 @@ impl Command for Wisp {
let options = CommandOptions {
desc: Some("Information about me!".to_string()),
usage: Some("".to_string()),
- aliases: vec!["botinfo", "bi", "binfo", "bot", "invite"].iter().map(|e| e.to_string()).collect(),
+ aliases: vec!["botinfo", "bi", "binfo", "bot", "invite", "vote", "topgg", "top.gg"].iter().map(|e| e.to_string()).collect(),
..default
};
Arc::new(options)
@@ -701,8 +727,18 @@ impl Command for Wisp {
// (cache.guilds.len(), cache.shard_count, cache.user.face())
// };
let thumbnail = CACHE.read().user.face();
- let owner = data.get::<Owner>().expect("Failed to get owner").to_user()?;
+ let owner = data.get::<Owner>().expect("Failed to get owner.").to_user()?;
let sys = System::new();
+
+ // let mut privacy_policy_message: String = "".to_string();
+ // if let Some(guild_id) = message.guild_id {
+ // if let Ok(settings) = db.get_guild(guild_id.0 as i64) {
+ // privacy_policy_message = format!("To Wisp's privacy policy, simple run `{}privacypolicy`.", settings.prefix);
+ // } else {
+ // privacy_policy_message = format!("To Wisp's privacy policy, simple run `privacypolicy`.");
+ // }
+ // }
+
let embed = CreateEmbed::default()
// .description("Hi! I'm Wisp, a general purpose bot created in [Rust](http://www.rust-lang.org/) using [Serenity](https://github.com/serenity-rs/serenity).")
.description("Hey! I'm Wisp, I was written in [Rust](https://www.rust-lang.org/) using [Serenity](https://github.com/serenity-rs/serenity).")
@@ -720,10 +756,13 @@ impl Command for Wisp {
// ,true)
.field("Useful Links", format!(
// "[Support Server]({})\n[Invite]({})\n[GitLab]({})\n[Patreon]({})"
- "[Support Server]({})\n[GitHub Organization]({})\n[Feature Request]({})\n[Invite]({})"
+ "[Support Server]({})\n[GitHub Organization]({})\n[Feature Request]({})\n[Top.gg]({}), [DiscordBots]({}), [Bots On Discord]({})\n[Invite]({})"
,SUPPORT_SERV_INVITE
,GITHUB_ORG_LINK
,FEATURE_REQUEST_LINK
+ ,TOPGG_LINK
+ ,DBOTS_CO_LINK
+ ,BOTSOND_LINK
,BOT_INVITE)
// ,GITLAB_LINK
// ,PATREON_LINK)
@@ -737,6 +776,7 @@ impl Command for Wisp {
.text("Want to request a feature? Submit one over at [email protected]!"))
.thumbnail(thumbnail)
.colour(*colours::MAIN);
+
if let Some(process) = sys.get_process(get_current_pid()) {
message.channel_id.send_message(|m| m
.embed(|_| embed
@@ -752,12 +792,17 @@ impl Command for Wisp {
,(process.cpu_usage()*100.0).round()/100.0 // round to 2 decimals
/* ,seconds_to_hrtime((sys.get_uptime() - process.start_time()) as usize) */)
,true)
+ // .field("Privacy Policy", &privacy_policy_message, false)
+ .field("Privacy Policy", "To Wisp's privacy policy, simple run `privacypolicy`.", false)
))?;
} else {
message.channel_id.send_message(|m| m
.embed(|_| embed
- ))?;
+ // .field("Privacy Policy", &privacy_policy_message, false)
+ .field("Privacy Policy", "To Wisp's privacy policy, simple run the `privacypolicy` command.", false)
+ ))?;
}
+
Ok(())
}
}
diff --git a/src/webserver/rocket.rs b/src/webserver/rocket.rs
index ac7401b..78f592a 100644
--- a/src/webserver/rocket.rs
+++ b/src/webserver/rocket.rs
@@ -1,8 +1,15 @@
use rocket::response::content;
use rocket::{State, get, post, request::Form, routes};
use rocket::response::NamedFile;
+use rocket_contrib::json::Json;
// use std::sync::Arc;
use crate::webserver::model::*;
+use sysinfo::{
+ ProcessExt,
+ SystemExt,
+ System,
+ get_current_pid
+};
pub async fn start_rocket() -> WispResult { // ctx: WispData
rocket::ignite()
@@ -22,3 +29,16 @@ pub fn icon() -> Option<NamedFile> {
pub fn index() -> content::Json<&'static str> {
content::Json("{\"message\": \"online\"}")
}
+
+#[get("/")]
+pub fn memory_usage() -> Json<&'static str> {
+ let sys = System::new();
+ let mut response;
+ if let Some(process) = sys.get_process(get_current_pid()) {
+ // response = format!("{{\"message\": \"{}\"}}", process.memory()/1000);
+ } else {
+ response = "{\"message\": \"null\"}".to_string();
+ }
+
+ Json(Json(&response))
+}
diff --git a/src/wisp.rs b/src/wisp.rs
index 28b87c7..d7f88c3 100644
--- a/src/wisp.rs
+++ b/src/wisp.rs
@@ -5,10 +5,7 @@ use crate::core::{
framework::WispFramework,
timers
};
-// use crate::webserver::{
-// model::*,
-// rocket::*
-// };
+// use crate::webserver::rocket::*;
use serenity::Error as SerenityError;
use serenity::http;
use serenity::model::id::UserId;
@@ -17,6 +14,7 @@ use serenity::prelude::{Client, Mutex};
use std::collections::HashSet;
use std::env;
use std::sync::Arc;
+// use std::thread;
pub struct WispClient(Client);
impl WispClient {
@@ -53,6 +51,9 @@ impl WispClient {
// let _ = start_rocket(bot_clone);
// });
// }
+ // thread::spawn(move || {
+ // let _ = start_rocket();
+ // });
client.with_framework(WispFramework::new(owners));
WispClient(client)