~phate/rsPhate

ref: 364573b69ce4452cbdd4881f29926f429a9adcac rsPhate/src/commands/git.rs -rw-r--r-- 1.6 KiB
364573b6 — Ash support sourcehut in git command and add Cargo.lock to .gitignore 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use log::{error, info};
use serenity::{
    framework::standard::{macros::command, Args, CommandResult},
    model::channel::Message,
    prelude::*,
    utils::MessageBuilder,
};

#[command]
#[description = "Bot will parse the input and output the correct full link to the repo."]
#[usage = "site,user/repo"]
#[example = "github,rsfetch/rsfetch"]
#[example = "gitlab,ArcticTheRogue/asgl"]
#[example = "codeberg,Phate6660/musinfo"]
#[example = "sourcehut,phate/rsPhate"]
#[num_args(2)]
fn git(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
    let site = args.single::<String>()?;
    let repo = args.single::<String>()?;
    let match_site = site.as_str();

    // Log what was supplied
    info!("site: {}, owner/repo: {}", site, repo);

    // Match for site to create message.
    let message: String = match match_site {
        "github" => MessageBuilder::new()
            .push("https://github.com/")
            .push(repo)
            .build(),
        "gitlab" => MessageBuilder::new()
            .push("https://gitlab.com/")
            .push(repo)
            .build(),
        "codeberg" => MessageBuilder::new()
            .push("https://codeberg.org/")
            .push(repo)
            .build(),
        "sourcehut" => MessageBuilder::new()
            .push("https://sr.ht/~")
            .push(repo)
            .build(),
        _ => "Could not generate a full link, please try again.".to_string(),
    };

    if let Err(why) = msg.channel_id.say(&ctx.http, &message) {
        error!("Could not push full Git repo link because: {}", why);
    }

    Ok(())
}