Skip to content

Commit

Permalink
fix @Contribute, add url content into bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlett authored and Skarlett committed Feb 11, 2023
1 parent 9cd20f6 commit 3a3a30b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coggiebot"
version = "1.3.6"
version = "1.3.7"
edition = "2021"

[dependencies]
Expand Down
57 changes: 32 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ async fn rev_cmd(ctx: &Context, msg: &Message) -> CommandResult {

#[command]
async fn contribute(ctx: &Context, msg: &Message) -> CommandResult {
msg
.channel_id
.send_message(&ctx.http, |m| {
m.reference_message(msg)
.embed(|e| {
e.title("Coggie Bot");
e.description("Coggie Bot is an open source bot written in Rust. It is licensed under the BSD2 license.");
e.url(REPO);
e.field("License", LICENSE, false);
e.field("Contribute", format!("{}#contribute", REPO), false);
e
})
.content(include_str!("../tickets.md"))
})
.await?;
msg.channel_id
.send_message(&ctx.http, |m|
m
.add_embed(|e|
e.title("Coggie Bot")
.description("Coggie Bot is an open source \"Discord\" (discord.com) bot.")
.url(REPO)
.fields(vec![
("License", "BSD2", false),
("Version", VERSION, false),
("Revision", get_rev(), false),
("Contribute", &format!("{}/contribute.md", REPO), false),
])
)
).await?;
Ok(())
}

Expand Down Expand Up @@ -123,10 +123,21 @@ impl EventHandler for Handler {

let m = msg.attachments
.iter()
.map(|a| (a, a.filename.rsplit_once('.').unwrap().1) )
.map(|c| c.url.clone())
.chain(
msg.content
.split_whitespace()
.filter(|x| x.starts_with("http"))
.map(|x| x.to_string())
)

.filter_map(|a| if let Some((_prefix, suffix)) = &a.rsplit_once('.') {
Some((a.clone(), suffix.to_string()))
} else { None })

.fold(m, |msg, (atch, ext)|
match ext {
"png" | "jpg" | "jpeg" | "gif" => { msg.add_embed(|e| e.image(&atch.url)); msg},
match ext.as_str() {
"png" | "jpg" | "jpeg" | "gif" => { msg.add_embed(|e| e.image(&atch)); msg},
_ => msg
}
);
Expand Down Expand Up @@ -167,7 +178,6 @@ struct CLI {
async fn main() -> Result<(), Box<dyn std::error::Error>>
{
let cli = CLI::from_args();

if cli.version {
println!("{VERSION}");
return Ok(());
Expand All @@ -181,24 +191,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>>

println!("{}", LICENSE);

let intents = GatewayIntents::GUILD_MESSAGES
| GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::MESSAGE_CONTENT
| GatewayIntents::GUILD_MESSAGE_REACTIONS;

let http = Http::new(&cli.token);
let bot_id = http.get_current_user().await?.id;

let framework = StandardFramework::new()
.configure(|c| {
c.with_whitespace(true)
.ignore_bots(true)
.prefix(".")
.on_mention(Some(bot_id))
.delimiters(vec![", ", ","])
.owners(std::collections::HashSet::new())
})
.group(&COMMANDS_GROUP);

let mut client = Client::builder(&cli.token, intents)
let mut client = Client::builder(&cli.token, GatewayIntents::non_privileged())
.framework(framework)
.event_handler(Handler)
.await
Expand Down

0 comments on commit 3a3a30b

Please sign in to comment.