Skip to content

Commit

Permalink
Add shadowsocks support
Browse files Browse the repository at this point in the history
  • Loading branch information
zolagonano committed Apr 23, 2024
1 parent be1a053 commit a2d88eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 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
Expand Up @@ -16,6 +16,6 @@ serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
url = "2.5.0"
worker = "0.0.15"
proxy-scraper = { git = "https://github.com/zolagonano/proxy-scraper.git", rev = "24cc0b6" , default_features = false, features = ["scraper"] }
proxy-scraper = { git = "https://github.com/zolagonano/proxy-scraper.git", rev = "10f0569" , default_features = false, features = ["scraper"] }
reqwest = "0.12.3"

23 changes: 18 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ use worker::*;

// TODO: Read Sources from config file
const MTPROTO_SOURCES: &[&str] = &["https://t.me/s/NextGenProxy", "https://t.me/s/MTP_roto"];
const SHADOWSOCKS_SOURCES: &[&str] =
&["https://raw.githubusercontent.com/barry-far/V2ray-Configs/main/All_Configs_Sub.txt"];

const HELP_MESSAGE: &str = "Fire Ninja Bot allows you to access proxies to bypass firewalls and access blocked content. Currently, only the following commands are available:
- /help: Shows this message.
- /mtproxy: Fetches and provides a list of MTProto proxies.
- /shadowsocks: Fetches and provides a list of Shadowsocks proxies.
";

async fn fetch_source(source: &str) -> core::result::Result<String, &'static str> {
Expand Down Expand Up @@ -60,16 +63,26 @@ async fn main(mut req: Request, _env: Env, _ctx: Context) -> Result<Response> {
if let Ok(raw_proxies) = fetch_source(source).await {
let proxies = proxy_scraper::Scraper::scrape_mtproxy(&raw_proxies);
for proxy in proxies {
proxy_list.insert(format!(
"https://t.me/proxy?server={}&port={}&secret={}",
proxy.host, proxy.port, proxy.secret
));
proxy_list.insert(proxy.to_url());
}
}
}
proxy_list.into_iter().collect::<Vec<_>>().join("\n***\n")
}
"/help" => HELP_MESSAGE.to_string(),
"/ss" | "/shadowsocks" => {
let mut proxy_list = HashSet::new();

for source in SHADOWSOCKS_SOURCES {
if let Ok(raw_proxies) = fetch_source(source).await {
let proxies = proxy_scraper::Scraper::scrape_shadowsocks(&raw_proxies);
for proxy in proxies {
proxy_list.insert(proxy.to_url());
}
}
}
proxy_list.into_iter().collect::<Vec<_>>().join("\n***\n")
}
"/help" | "/start" => HELP_MESSAGE.to_string(),
_ => "Invalid command, use /help to get list of available commands.".to_string(),
};

Expand Down

0 comments on commit a2d88eb

Please sign in to comment.