Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
modifying commands and removing reductant ones
Browse files Browse the repository at this point in the history
  • Loading branch information
orzklv committed Dec 10, 2023
1 parent 4a21e46 commit 2b52c9e
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 313 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.idea
.DS_Store
target/
24 changes: 0 additions & 24 deletions data/roadmap.md

This file was deleted.

7 changes: 4 additions & 3 deletions src/functions/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use teloxide::{
};

static TEXT: &str = r#"
<b>Hurmatli foydalanuvchi!</b>
<b>Hello fellow (rustacean|rustina|evangelist)!</b>
Bizning botimiz aktiv tarzda shakllantirib boriladi. Buning ustida esa bir necha avtor va dasturchilar turadi, ushbu havolalar orqali bizning sinovchilarimizdan biriga aylaning va biz bilan botimiz, hamda guruhimiz ishlatish qulayligini oshiring.
This is a telegram bot created by a rustacean to help people interact with various Rust APIs way more conveniently.
"#;

pub async fn command(bot: &Bot, msg: &Message) -> ResponseResult<()> {
Expand All @@ -29,5 +29,6 @@ pub async fn command(bot: &Bot, msg: &Message) -> ResponseResult<()> {

pub fn keyboard() -> InlineKeyboardMarkup {
let mut keyboard = Keyboard::new();
keyboard.url("Ochiq Havolalar", "https://github.com/rust-lang-uz/rustina")
keyboard.url("Source Code", "https://github.com/rust-lang-uz/telegram");
keyboard.url("Author", "https://github.com/orzklv")
}
24 changes: 0 additions & 24 deletions src/functions/check.rs

This file was deleted.

12 changes: 6 additions & 6 deletions src/functions/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use teloxide::{
types::{InlineKeyboardMarkup, ParseMode},
};

static TEXT: &str = "<b>Telegramdagi Rust Hamjamiyatlari yoki Guruhlari:</b>\nAgar o'zingizni guruhingizni qo'shmoqchi bo'lsangiz, bizni <a href='https://github.com/rust-lang-uz/rustina/blob/main/data/communities.json'>community.json</a> ni yangilang!";
static TEXT: &str = "<b>List of Rust Language communities on Telegram:</b>\nIf you want to add your own community to our list, update our <a href='https://github.com/rust-lang-uz/telegram/blob/main/communities.json'>community.json</a>";

pub async fn command(bot: &Bot, msg: &Message, groups: &Groups) -> ResponseResult<()> {
bot.send_message_tf(msg.chat.id, TEXT, msg)
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn view_detail(data: &Option<Group>) -> String {
d.name, d.about
)
}
None => "<b>Ushbu guruh mavjud emas!</b>".to_string(),
None => "<b>The following group doesn't seem like exist!</b>".to_string(),
}
}

Expand All @@ -90,11 +90,11 @@ pub fn keyboard_list(groups: &Groups, page: i32) -> InlineKeyboardMarkup {
}

if !groups.get_groups(page + 1, 5).is_empty() {
keyboard.text("Keyingi ➡️", &format!("group_{}", page + 1));
keyboard.text("Next ➡️", &format!("group_{}", page + 1));
}

if page > 1 {
keyboard.text("⬅️ Oldingi", &format!("group_{}", page - 1));
keyboard.text("🔙 Back", &format!("group_{}", page - 1));
}

keyboard.get()
Expand All @@ -112,9 +112,9 @@ pub fn keyboard_detail(page: i32, data: &Option<Group>) -> InlineKeyboardMarkup

keyboard.row();

keyboard.text("🔙 Orqaga", &format!("group_{}", page));
keyboard.text("🔙 Back", &format!("group_{}", page));
} else {
keyboard.text("🔙 Orqaga", &format!("group_{}", page));
keyboard.text("🔙 Back", &format!("group_{}", page));
}

keyboard.get()
Expand Down
22 changes: 9 additions & 13 deletions src/functions/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ use crate::{utils::message::Rustina, Command};
use teloxide::{payloads::SendMessageSetters, prelude::*, types::ParseMode};

static TEXT: &[(&str, &str)] = &[
("help", "ushbu xabarni qayta ko'rsatish"),
("rules", "qoidalarni aks ettirish"),
("about", "ushbu botimizning rivojlantirish qismi"),
("group", "rust ga oid guruh va hamjamiyatlar"),
("roadmap", "boshlang'ich o'rganuvchilar uchun"),
("useful", "rust haqida foydali yoki kerakli ma'lumotlar"),
("latest", "eng oxirgi reliz haqida qisqacha ma'lumot"),
("version", "biron anniq reliz haqida to'liq ma'lumot"),
(
"off",
"reply qilingan odamga offtop borligi haqida eslatish",
),
("help", "show this message"),
("about", "briefly about this bot"),
("latest", "get short info about latest version"),
("version", "get information about specific version"),
("group", "rust communities"),
("run &lt;code&gt;", "run code and show stout & sterr"),
("roadmap", "roadmap for newbies"),
("useful", "useful resources"),
];

pub async fn command(bot: &Bot, msg: &Message, _cmd: &Command) -> ResponseResult<()> {
let mut text = String::new();

text.push_str("<b>Mavjud komandalar ro'yxati:</b>\n\n");
text.push_str("<b>List of available commands:</b>\n\n");

for cmd in TEXT {
text.push('/');
Expand Down
21 changes: 0 additions & 21 deletions src/functions/joined.rs

This file was deleted.

9 changes: 5 additions & 4 deletions src/functions/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ pub async fn command(bot: &Bot, github: GitHub, msg: &Message) -> ResponseResult

pub fn view(release: &Release) -> String {
format!(
"<b>Hozirgi eng oxirgi versiya bu <a href=\"https://releases.rs/docs/{}\">\
{}</a> va ushbu reliz </b> <code>{}</code> da e'lon qilingan <a href=\"{}\">\
{}</a> tomonidan.\
"<b>Latest version is <a href=\"https://releases.rs/docs/{}\">\
{}</a> released at </b> <code>{}</code> by <a href=\"{}\">\
{}</a>.\
\n\n\
<b>In order to install latest update, execute</b> <code>rustup update</code> <b>on your terminal!</b>
",
release.tag_name,
release.tag_name,
Expand All @@ -34,5 +35,5 @@ pub fn view(release: &Release) -> String {

pub fn keyboard(release: &Release) -> InlineKeyboardMarkup {
let mut keyboard = Keyboard::new();
keyboard.url("Ko'proq ma'lumotlar", release.html_url.as_str())
keyboard.url("More Information", release.html_url.as_str())
}
51 changes: 8 additions & 43 deletions src/functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
pub mod about;
pub mod check;
pub mod groups;
pub mod help;
pub mod inline;
pub mod joined;
pub mod latest;
pub mod offtop;
pub mod roadmap;
pub mod rules;
pub mod start;
pub mod useful;
pub mod version;
Expand All @@ -21,25 +16,21 @@ use teloxide::{prelude::*, types::*};

pub async fn commands(
bot: Bot,
me: Me,
_me: Me,
msg: Message,
cmd: Command,
github: GitHub,
groups: Groups,
resources: Resources,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let _ = match cmd {
Command::Start => crate::functions::start::command(&bot, &msg).await,
Command::Help => crate::functions::help::command(&bot, &msg, &cmd).await,
Command::Rules => crate::functions::rules::command(&bot, &msg).await,
Command::About => crate::functions::about::command(&bot, &msg).await,
Command::Group => crate::functions::groups::command(&bot, &msg, &groups).await,
Command::Latest => crate::functions::latest::command(&bot, github, &msg).await,
Command::Version => crate::functions::version::command(&bot, github, &msg).await,
Command::Off => crate::functions::offtop::command(&bot, &msg, &me).await,
Command::Useful => crate::functions::useful::command(&bot, &msg, &resources).await,
Command::Roadmap => crate::functions::roadmap::command(&bot, &msg).await,
Command::Check => crate::functions::check::command(&bot, &msg).await,
Command::Start => crate::functions::start::command(&bot, &msg).await, // done
Command::Help => crate::functions::help::command(&bot, &msg, &cmd).await, // partially done
Command::About => crate::functions::about::command(&bot, &msg).await, // done
Command::Group => crate::functions::groups::command(&bot, &msg, &groups).await, // done
Command::Latest => crate::functions::latest::command(&bot, github, &msg).await, // done
Command::Version => crate::functions::version::command(&bot, github, &msg).await, // done
Command::Useful => crate::functions::useful::command(&bot, &msg, &resources).await, // done
};

Ok(())
Expand Down Expand Up @@ -82,29 +73,3 @@ pub async fn callback(

Ok(())
}

pub async fn triggers(bot: Bot, msg: Message) -> Result<(), Box<dyn Error + Send + Sync>> {
if let Some(user) = msg.from() {
if let Some(username) = user.username.clone() {
if username == "Channel_Bot" {
// Try to delete message and ignore error
match bot.delete_message(msg.chat.id, msg.id).await {
Ok(_) => {}
Err(_) => {}
}
}
}
}

if let Some(new_chat_members) = msg.new_chat_members() {
let bot_id = bot.get_me().send().await?.id;

if !new_chat_members.iter().any(|user| user.id == bot_id)
&& (msg.chat.is_supergroup() || msg.chat.is_group())
{
crate::functions::joined::trigger(&bot, &msg).await?;
}
}

Ok(())
}
55 changes: 0 additions & 55 deletions src/functions/offtop.rs

This file was deleted.

46 changes: 0 additions & 46 deletions src/functions/roadmap.rs

This file was deleted.

Loading

0 comments on commit 2b52c9e

Please sign in to comment.