Compare commits
No commits in common. "master" and "patch/use-once-cell" have entirely different histories.
master
...
patch/use-
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler32"
|
||||
version = "1.0.4"
|
||||
|
@ -871,9 +873,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.4.1"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
|
||||
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
|
@ -1274,7 +1276,7 @@ version = "2.0.0"
|
|||
dependencies = [
|
||||
"brainfrick",
|
||||
"colored",
|
||||
"lazy_static 1.4.0",
|
||||
"once_cell",
|
||||
"owoify",
|
||||
"percent-encoding 2.1.0",
|
||||
"rand 0.8.4",
|
||||
|
|
|
@ -13,11 +13,11 @@ toml = "0.5.8"
|
|||
sys-info = "0.9.0"
|
||||
urbandict = "0.2.0"
|
||||
owoify = "0.1.5"
|
||||
lazy_static = "1.4.0"
|
||||
colored = "2.0.0"
|
||||
brainfrick = "1.1.2"
|
||||
percent-encoding = "2.1.0"
|
||||
regex = "1.5.4"
|
||||
once_cell = "1.8.0"
|
||||
|
||||
[patch.crates-io]
|
||||
openssl = { git = "https://github.com/ishitatsuyuki/rust-openssl", branch = "0.9.x" }
|
||||
|
@ -33,4 +33,4 @@ features = ["blocking", "json"]
|
|||
|
||||
[dependencies.tokio]
|
||||
version = "1.7.1"
|
||||
features = ["macros", "rt-multi-thread"]
|
||||
features = ["macros", "rt-multi-thread"]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use serenity::{
|
||||
framework::standard::{macros::command, Args, CommandError, CommandResult},
|
||||
framework::standard::{macros::command, Args, CommandResult},
|
||||
model::channel::Message,
|
||||
prelude::*,
|
||||
};
|
||||
|
@ -8,32 +8,36 @@ use serenity::{
|
|||
#[command]
|
||||
#[aliases("what's this")]
|
||||
async fn define(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||
if args.is_empty() {
|
||||
return Err("No arguments!".into());
|
||||
}
|
||||
|
||||
let text: String = args.rest().trim().to_string();
|
||||
let defs =
|
||||
urbandict::get_definitions(&text).map_err(|_| CommandError::from("Invalid query >w<"))?;
|
||||
|
||||
let def = defs
|
||||
.first()
|
||||
.ok_or_else(|| CommandError::from("No results!"))?;
|
||||
|
||||
let _ = message
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!("Query: {}, Author: {}", text, def.author))
|
||||
.field(
|
||||
"Definition: ",
|
||||
def.definition.replace(|c| c == '[' || c == ']', ""),
|
||||
false,
|
||||
)
|
||||
.color(0xffd1dc)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
let defs = &urbandict::get_definitions(&text);
|
||||
if !args.is_empty() {
|
||||
match defs {
|
||||
Err(_e) => {
|
||||
return Err("Invalid query >w<".into());
|
||||
}
|
||||
Ok(v) => {
|
||||
if !v.is_empty() {
|
||||
let def = &v[0];
|
||||
let _ = message
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!("Query: {}, Author: {}", text, def.author))
|
||||
.field(
|
||||
"Definition: ",
|
||||
def.definition.replace(|c| c == '[' || c == ']', ""),
|
||||
false,
|
||||
)
|
||||
.color(0xffd1dc)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
} else {
|
||||
return Err("No results!".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
|
||||
use serde::Deserialize;
|
||||
use serenity::{
|
||||
framework::standard::{macros::command, Args, CommandError, CommandResult},
|
||||
framework::standard::{macros::command, Args, CommandResult},
|
||||
model::channel::Message,
|
||||
prelude::*,
|
||||
};
|
||||
|
@ -24,19 +24,24 @@ async fn lyrics(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
|||
// TODO: use https://orion.apiseeds.com/api/music/lyric/:artist/:track instead
|
||||
let mut url = String::from("https://mourits.xyz:2096/?q=");
|
||||
// check if input is not empty
|
||||
let input = args.rest().trim();
|
||||
if input.is_empty() {
|
||||
return Err("Called without input!".into());
|
||||
}
|
||||
let input = match args.rest().trim() {
|
||||
"" => {
|
||||
return Err("Called without input!".into());
|
||||
}
|
||||
v => v,
|
||||
};
|
||||
// encode into url
|
||||
url += &s!(percent_encode(input.as_bytes(), NON_ALPHANUMERIC));
|
||||
|
||||
let request = reqwest::get(&url).await?;
|
||||
let request = match reqwest::get(&url).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
|
||||
let resp: Response = request
|
||||
.json()
|
||||
.await
|
||||
.map_err(|_| CommandError::from("Could not find lyrics"))?;
|
||||
let resp: Response = match request.json().await {
|
||||
Ok(v) => v,
|
||||
Err(_) => return Err("Could not find lyrics".into()),
|
||||
};
|
||||
let _ = message
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use serenity::{
|
||||
framework::standard::{macros::command, Args, CommandError, CommandResult},
|
||||
framework::standard::{macros::command, Args, CommandResult},
|
||||
model::{channel::Message, id::ChannelId},
|
||||
prelude::*,
|
||||
};
|
||||
|
@ -19,10 +19,12 @@ async fn pinned(ctx: &Context, message: &Message, mut args: Args) -> CommandResu
|
|||
Ok(v) => v,
|
||||
Err(_) => message.channel_id,
|
||||
};
|
||||
let pinned = target_channel
|
||||
.pins(&ctx.http)
|
||||
.await
|
||||
.map_err(|e| CommandError::from(format!("Could not get pinned messages! Error: {}", e)))?;
|
||||
let pinned = match target_channel.pins(&ctx.http).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
return Err(format!("Could not get pinned messages! Error: {}", e).into());
|
||||
}
|
||||
};
|
||||
if pinned.is_empty() {
|
||||
return Err("No pinned messages found!".into());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use serenity::{
|
||||
builder::CreateMessage,
|
||||
framework::standard::{macros::command, Args, CommandError, CommandResult},
|
||||
framework::standard::{macros::command, Args, CommandResult},
|
||||
http::AttachmentType,
|
||||
model::channel::Message,
|
||||
prelude::*,
|
||||
|
@ -10,11 +10,11 @@ use serenity::{
|
|||
#[command]
|
||||
async fn spoiler(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||
// check if the message has any attachments
|
||||
|
||||
let attachments = if message.attachments.is_empty() {
|
||||
return Err("No images were attached!".into());
|
||||
} else {
|
||||
&message.attachments
|
||||
let attachments = match message.attachments.is_empty() {
|
||||
true => {
|
||||
return Err("No images were attached!".into());
|
||||
}
|
||||
false => &message.attachments,
|
||||
};
|
||||
|
||||
// get the author's nick in the server, otherwise default to global username later
|
||||
|
@ -42,10 +42,10 @@ async fn spoiler(ctx: &Context, message: &Message, args: Args) -> CommandResult
|
|||
|
||||
for a in attachments {
|
||||
// download each attachment
|
||||
let content = a
|
||||
.download()
|
||||
.await
|
||||
.map_err(|_| CommandError::from("Error downloading attachment"))?;
|
||||
let content = match a.download().await {
|
||||
Ok(content) => content,
|
||||
Err(_) => return Err("Error downloading attachment".into()),
|
||||
};
|
||||
|
||||
let content: &[u8] = content.as_slice();
|
||||
|
||||
|
|
177
src/main.rs
177
src/main.rs
|
@ -1,10 +1,8 @@
|
|||
#![allow(clippy::unreadable_literal)]
|
||||
#![allow(clippy::cmp_owned)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use colored::*;
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::Rng;
|
||||
use serenity::{
|
||||
async_trait,
|
||||
|
@ -14,8 +12,7 @@ use serenity::{
|
|||
},
|
||||
framework::standard::{
|
||||
macros::{check, command, group, hook},
|
||||
Args, CommandError, CommandOptions, CommandResult, DispatchError, Reason,
|
||||
StandardFramework,
|
||||
Args, CommandOptions, CommandResult, DispatchError, Reason, StandardFramework,
|
||||
},
|
||||
model::{
|
||||
channel::{Message, ReactionType},
|
||||
|
@ -92,27 +89,30 @@ async fn dispatch_error(ctx: &Context, msg: &Message, error: DispatchError) {
|
|||
#[hook]
|
||||
async fn after(ctx: &Context, msg: &Message, command_name: &str, command_result: CommandResult) {
|
||||
// prints error in chat
|
||||
if let Err(why) = command_result {
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!("Error in **{}**", command_name))
|
||||
.description(&why.to_string())
|
||||
/*.thumbnail("https://i.imgur.com/VzOEz2E.png") oh no */
|
||||
.colour(0xff6961)
|
||||
match command_result {
|
||||
Ok(()) => (),
|
||||
Err(why) => {
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!("Error in **{}**", command_name))
|
||||
.description(&why.to_string())
|
||||
/*.thumbnail("https://i.imgur.com/VzOEz2E.png") oh no */
|
||||
.colour(0xff6961)
|
||||
})
|
||||
})
|
||||
})
|
||||
.await;
|
||||
// prints error in console
|
||||
eprintln!(
|
||||
"{}",
|
||||
format!(
|
||||
"Error in {}: {}",
|
||||
command_name.purple(),
|
||||
&why.to_string().red().bold()
|
||||
)
|
||||
);
|
||||
.await;
|
||||
// prints error in console
|
||||
eprintln!(
|
||||
"{}",
|
||||
format!(
|
||||
"Error in {}: {}",
|
||||
command_name.purple(),
|
||||
&why.to_string().red().bold()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,18 +123,15 @@ async fn after(ctx: &Context, msg: &Message, command_name: &str, command_result:
|
|||
)]
|
||||
struct General;
|
||||
|
||||
lazy_static! {
|
||||
static ref OWNERS: std::vec::Vec<serenity::model::id::UserId> =
|
||||
/* Agatha's Id Julia's Id */
|
||||
vec![UserId(254310746450690048), UserId(687740609703706630)];
|
||||
}
|
||||
static OWNERS: Lazy<Vec<serenity::model::id::UserId>> =
|
||||
Lazy::new(|| vec![UserId(254310746450690048), UserId(687740609703706630)]);
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let framework = StandardFramework::new()
|
||||
.configure(|c| {
|
||||
c.with_whitespace(true)
|
||||
.owners(OWNERS.clone().into_iter().collect())
|
||||
.owners(OWNERS.iter().cloned().collect())
|
||||
.prefixes(vec!["owo!", "OwO!", "aga"])
|
||||
.no_dm_prefix(true)
|
||||
.case_insensitivity(true)
|
||||
|
@ -171,7 +168,7 @@ async fn main() {
|
|||
async fn owner_check(
|
||||
_: &Context, msg: &Message, _: &mut Args, _: &CommandOptions,
|
||||
) -> Result<(), Reason> {
|
||||
if OWNERS.clone().contains(&msg.author.id) {
|
||||
if OWNERS.contains(&msg.author.id) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Reason::Unknown)
|
||||
|
@ -207,21 +204,23 @@ async fn ping(ctx: &Context, message: &Message) -> CommandResult {
|
|||
// I have no idea if this works but its 5æm and I need to sleep help
|
||||
let data = ctx.data.read().await;
|
||||
|
||||
let shard_manager = data
|
||||
.get::<ShardManagerContainer>()
|
||||
.ok_or_else(|| CommandError::from("There was a problem getting the shard manager!"))?;
|
||||
let shard_manager = match data.get::<ShardManagerContainer>() {
|
||||
Some(v) => v,
|
||||
None => return Err("There was a problem getting the shard manager!".into()),
|
||||
};
|
||||
|
||||
let manager = shard_manager.lock().await;
|
||||
let runners = manager.runners.lock().await;
|
||||
|
||||
let runner = runners
|
||||
.get(&ShardId(ctx.shard_id))
|
||||
.ok_or_else(|| CommandError::from("No shard found!"))?;
|
||||
let runner = match runners.get(&ShardId(ctx.shard_id)) {
|
||||
Some(v) => v,
|
||||
None => return Err("No shard found!".into()),
|
||||
};
|
||||
|
||||
let ping = runner
|
||||
.latency
|
||||
.ok_or_else(|| CommandError::from("Could not get latency!"))?
|
||||
.as_millis();
|
||||
let ping = match runner.latency {
|
||||
Some(v) => v.as_millis(),
|
||||
None => return Err("Could not get latency!".into()),
|
||||
};
|
||||
|
||||
let _ = message
|
||||
.channel_id
|
||||
|
@ -343,29 +342,32 @@ async fn bottom_rng(ctx: &Context, message: &Message, mut args: Args) -> Command
|
|||
|
||||
// get N last messages, otherwise 10
|
||||
let num = args.single::<u64>().unwrap_or(10);
|
||||
let mut messages = message
|
||||
let messages = message
|
||||
.channel_id
|
||||
.messages(&ctx.http, |get| get.before(message.id).limit(num))
|
||||
.await
|
||||
.map_err(|e| CommandError::from(format!("Error: {}", e)))?;
|
||||
|
||||
// remove all messages by other users
|
||||
messages.retain(|v| v.author != message.mentions[0]);
|
||||
let mut input = String::new();
|
||||
for msg in messages {
|
||||
input += &format!("{} ", msg.content);
|
||||
}
|
||||
let result: u64 = StdRng::seed_from_u64(calculate_hash(&input)).gen_range(0..100);
|
||||
let _ = message
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title("Bottom RNG")
|
||||
.description(format!("Result: {}", result))
|
||||
.color(0x800869)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
if let Err(e) = messages {
|
||||
return Err(format!("Error: {}", e).into());
|
||||
} else {
|
||||
let mut messages = messages?;
|
||||
// remove all messages by other users
|
||||
messages.retain(|v| v.author != message.mentions[0]);
|
||||
let mut input = String::new();
|
||||
for msg in messages {
|
||||
input += &format!("{} ", msg.content);
|
||||
}
|
||||
let result: u64 = StdRng::seed_from_u64(calculate_hash(&input)).gen_range(0..100);
|
||||
let _ = message
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
e.title("Bottom RNG")
|
||||
.description(format!("Result: {}", result))
|
||||
.color(0x800869)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -385,7 +387,7 @@ async fn headpat(ctx: &Context, message: &Message, args: Args) -> CommandResult
|
|||
_ => message.mentions[0].name.as_str(),
|
||||
};
|
||||
|
||||
message
|
||||
if let Err(e) = message
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |m| {
|
||||
m.embed(|e| {
|
||||
|
@ -396,7 +398,10 @@ async fn headpat(ctx: &Context, message: &Message, args: Args) -> CommandResult
|
|||
.description("[Source](https://www.pinterest.com/pin/377809856242075277/)")
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
.await
|
||||
{
|
||||
let _ = message.channel_id.say(&ctx.http, format!("{:?}", e)).await;
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -475,7 +480,7 @@ async fn info(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
|||
|
||||
let num = ctx.cache.guilds().await.len();
|
||||
// get developer's username
|
||||
let aganame = OWNERS.clone()[0].to_user(ctx.http.clone()).await?.tag();
|
||||
let aganame = OWNERS[0].to_user(ctx.http.clone()).await?.tag();
|
||||
let _ = message.channel_id.send_message(&ctx.http, |m| m
|
||||
.embed(|e| e
|
||||
.title("Discordinator9000's info:")
|
||||
|
@ -523,18 +528,20 @@ async fn pfp(ctx: &Context, message: &Message) -> CommandResult {
|
|||
async fn owo(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||
use owoify::OwOifiable;
|
||||
|
||||
let messages = message
|
||||
let lastmsg = match message
|
||||
.channel_id
|
||||
.messages(&ctx.http, |get| get.before(message.id).limit(1))
|
||||
.await
|
||||
.map_err(|_| CommandError::from("Could not get last message!"))?;
|
||||
{
|
||||
Ok(v) => v,
|
||||
Err(_) => return Err("Could not get last message!".into()),
|
||||
};
|
||||
|
||||
let lastmsg = &messages[0].content;
|
||||
let lastmsg = &lastmsg[0].content;
|
||||
|
||||
let input: String = if args.is_empty() {
|
||||
s!(lastmsg)
|
||||
} else {
|
||||
args.rest().trim().to_string()
|
||||
let input: String = match args.is_empty() {
|
||||
true => s!(lastmsg),
|
||||
false => args.rest().trim().to_string(),
|
||||
};
|
||||
let _ = message.channel_id.say(&ctx.http, input.owoify()).await;
|
||||
|
||||
|
@ -546,17 +553,23 @@ async fn owo(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
|||
#[only_in(guilds)]
|
||||
#[aliases("description", "topic")]
|
||||
async fn desc(ctx: &Context, message: &Message) -> CommandResult {
|
||||
let channel = message
|
||||
.channel(&ctx)
|
||||
.await
|
||||
.ok_or_else(|| CommandError::from("Could not get channel!"))?;
|
||||
let channel = channel
|
||||
.guild()
|
||||
.ok_or_else(|| CommandError::from("Could not get guild channel!"))?;
|
||||
let channel = match message.channel(&ctx).await {
|
||||
Some(ch) => ch,
|
||||
None => {
|
||||
return Err("Could not get channel!".into());
|
||||
}
|
||||
};
|
||||
let channel = match channel.guild() {
|
||||
Some(g) => g,
|
||||
None => {
|
||||
return Err("Could not get guild channel!".into());
|
||||
}
|
||||
};
|
||||
|
||||
let topic = match channel.topic.as_deref() {
|
||||
Some("") | None => String::from("No channel topic found"),
|
||||
Some(topic) => topic.to_string(),
|
||||
let topic = if channel.topic.clone().unwrap() != "" {
|
||||
channel.topic.clone().unwrap()
|
||||
} else {
|
||||
String::from("No channel topic found")
|
||||
};
|
||||
|
||||
let _ = message
|
||||
|
|
Loading…
Reference in New Issue