Skip to content

Commit

Permalink
chore: adopting 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
orzklv committed Dec 23, 2024
1 parent 91bb4f0 commit 485696a
Show file tree
Hide file tree
Showing 26 changed files with 868 additions and 338 deletions.
307 changes: 246 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/rust-lang-uz/telegram"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
teloxide = { version = "0.12", features = [
teloxide = { version = "0.13", features = [
"macros",
"webhooks",
"webhooks-axum",
Expand All @@ -24,6 +24,7 @@ serde_json = "1.0.108"
serde = { version = "1.0.192", features = ["derive"] }
octocrab = { version = "0.32.0" }
clap = { version = "4.5.23", features = ["derive"] }
orzklv = { version = "0.1.8", features = ["full"] }

[profile.release]
strip = true
Expand Down
49 changes: 38 additions & 11 deletions data/topics.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
{
"asosiy": 1,
"learning": 26210,
"offtopic": 9400,
"yordam": 146749,
"explore": 26603,
"showroom": 26382,
"livestreams": 22577,
"jobs": 27940,
"l10n": 22990
}
[
{
"name": "asosiy",
"id": 1
},
{
"name": "learning",
"id": 26210
},
{
"name": "yordam",
"id": 146749
},
{
"name": "explore",
"id": 26603
},
{
"name": "showroom",
"id": 26382
},
{
"name": "livestreams",
"id": 22577
},
{
"name": "jobs",
"id": 27940
},
{
"name": "l10n",
"id": 22990
},
{
"name": "offtopic",
"id": 0
}
]
2 changes: 1 addition & 1 deletion src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Command {
Version,

/// Report offtopic
Off,
Warn,

/// Useful resources
Useful,
Expand Down
10 changes: 5 additions & 5 deletions src/functions/about.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
hooks,
utils::{keyboard::Keyboard, message::Rustina},
};
use crate::hooks;
use orzklv::telegram::{keyboard::Keyboard, topic::Topics};
use teloxide::{
payloads::SendMessageSetters,
prelude::*,
Expand Down Expand Up @@ -29,5 +27,7 @@ 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("Ochiq Havolalar", "https://github.com/rust-lang-uz/rustina")
.unwrap()
}
2 changes: 1 addition & 1 deletion src/functions/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::message::Rustina;
use orzklv::telegram::topic::Topics;
use teloxide::{payloads::SendMessageSetters, prelude::*, types::ParseMode};

pub async fn command(bot: &Bot, msg: &Message) -> ResponseResult<()> {
Expand Down
53 changes: 35 additions & 18 deletions src/functions/groups.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use crate::utils::{
groups::{Group, Groups},
keyboard::Keyboard,
message::Rustina,
};
use teloxide::{
payloads::{EditMessageTextSetters, SendMessageSetters},
prelude::*,
types::{InlineKeyboardMarkup, ParseMode},
};
use crate::utils::groups::{Group, Groups};
use orzklv::telegram::{keyboard::Keyboard, topic::Topics};
use teloxide::{payloads::EditMessageTextSetters, prelude::*, types::*};

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!";

pub async fn command(bot: &Bot, msg: &Message, groups: &Groups) -> ResponseResult<()> {
bot.send_message_tf(msg.chat.id, TEXT, msg)
.parse_mode(ParseMode::Html)
.reply_markup(keyboard_list(groups, 1))
.disable_web_page_preview(true)
.link_preview_options(LinkPreviewOptions {
is_disabled: true,
url: None,
prefer_small_media: false,
prefer_large_media: false,
show_above_text: false,
})
.await?;

Ok(())
Expand All @@ -28,11 +27,22 @@ pub async fn callback_list(
groups: &Groups,
) -> ResponseResult<()> {
if !args.is_empty() {
if let Some(Message { id, chat, .. }) = q.message.clone() {
bot.edit_message_text(chat.id, id, TEXT)
let om = match q.message.clone() {
Some(m) => m,
None => return Ok(()),
};

if let Some(Message { id, chat, .. }) = om.regular_message() {
bot.edit_message_text(chat.id, *id, TEXT)
.parse_mode(ParseMode::Html)
.reply_markup(keyboard_list(groups, args[0].parse().unwrap_or(1)))
.disable_web_page_preview(true)
.link_preview_options(LinkPreviewOptions {
is_disabled: true,
url: None,
prefer_small_media: false,
prefer_large_media: false,
show_above_text: false,
})
.await?;
} else if let Some(id) = q.inline_message_id.clone() {
bot.edit_message_text_inline(id, "Oopsie, something went wrong...")
Expand All @@ -48,8 +58,13 @@ pub async fn callback_detail(bot: &Bot, q: &CallbackQuery, args: &[&str]) -> Res
let find = groups.find_group(args[1..].join("_").to_string());

if !args.is_empty() {
if let Some(Message { id, chat, .. }) = q.message.clone() {
bot.edit_message_text(chat.id, id, view_detail(&find))
let om = match q.message.clone() {
Some(m) => m,
None => return Ok(()),
};

if let Some(Message { id, chat, .. }) = om.regular_message() {
bot.edit_message_text(chat.id, *id, view_detail(&find))
.parse_mode(ParseMode::Html)
.reply_markup(keyboard_detail(args[0].parse().unwrap_or(1), &find))
.await?;
Expand Down Expand Up @@ -104,10 +119,12 @@ pub fn keyboard_detail(page: i32, data: &Option<Group>) -> InlineKeyboardMarkup
let mut keyboard = Keyboard::new();

if let Some(group) = data {
keyboard.url("Telegram", &format!("https://t.me/{}", group.telegram));
keyboard
.url("Telegram", &format!("https://t.me/{}", group.telegram))
.unwrap();

if group.link.is_some() {
keyboard.url("Web", &group.link.clone().unwrap());
keyboard.url("Web", &group.link.clone().unwrap()).unwrap();
}

keyboard.row();
Expand Down
5 changes: 3 additions & 2 deletions src/functions/help.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::start::keyboard;
use crate::{bot::Command, utils::message::Rustina};
use teloxide::{payloads::SendMessageSetters, prelude::*, types::ParseMode};
use crate::bot::Command;
use orzklv::telegram::topic::Topics;
use teloxide::{prelude::*, types::ParseMode};

static TEXT: &[(&str, &str)] = &[
("help", "ushbu xabarni qayta ko'rsatish"),
Expand Down
26 changes: 22 additions & 4 deletions src/functions/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ pub async fn inline(
InputMessageContent::Text(
InputMessageContentText::new(NO_INPUT)
.parse_mode(ParseMode::Html)
.disable_web_page_preview(true),
.link_preview_options(LinkPreviewOptions {
is_disabled: true,
url: None,
prefer_small_media: false,
prefer_large_media: false,
show_above_text: false,
}),
),
)
.reply_markup(err_keyboard())
Expand Down Expand Up @@ -47,11 +53,17 @@ pub async fn inline(
"Xatolik yuz berdi!",
InputMessageContent::Text(
InputMessageContentText::new(
format!("<b>{} ga oid natija mavjud emas!</b>\nIltimos, boshqattan ushbu qidirmoqchi bo'lgan paketingiz yozib qidirib ko'ring!",
format!("<b>{} ga oid natija mavjud emas!</b>\nIltimos, boshqattan ushbu qidirmoqchi bo'lgan paketingiz yozib qidirib ko'ring!",
q.query.clone())
)
.parse_mode(ParseMode::Html)
.disable_web_page_preview(true),
.link_preview_options(LinkPreviewOptions {
is_disabled: true,
url: None,
prefer_small_media: false,
prefer_large_media: false,
show_above_text: false,
}),
),
)
.reply_markup(err_keyboard())
Expand All @@ -72,7 +84,13 @@ pub async fn inline(
InputMessageContent::Text(
InputMessageContentText::new(view_generate(c))
.parse_mode(ParseMode::Html)
.disable_web_page_preview(true),
.link_preview_options(LinkPreviewOptions {
is_disabled: true,
url: None,
prefer_small_media: false,
prefer_large_media: false,
show_above_text: false,
}),
),
)
.description(c.description.clone().unwrap())
Expand Down
7 changes: 4 additions & 3 deletions src/functions/joined.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use orzklv::telegram::{timer::Timer, topic::Topics};
use teloxide::{prelude::*, types::*};

use crate::utils::message::{delete_timer, Rustina};

static TEXT: &str = "<b>Salom bo'lajak Rustacean!</b>\n\n\
Sizlarni bu guruhda ko'rib turganimizdan mamnunmiz. Bu guruh Rust dasturlash tiliga qaratilgan hisoblanib, \
bu yerda ushbu til haqida gaplashish, savollar berish yoki o'z fikrlaringiz bilan bo'lishishingiz mumkin. \
Expand All @@ -15,7 +14,9 @@ pub async fn trigger(bot: &Bot, msg: &Message) -> ResponseResult<()> {
.parse_mode(ParseMode::Html)
.await?;

delete_timer(bot, &message, 60 * 5).await?;
bot.delete_timer(message.chat.id, message.id, 60 * 5)
.await
.await?;

Ok(())
}
8 changes: 5 additions & 3 deletions src/functions/latest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::{github::GitHub, keyboard::Keyboard, message::Rustina};
use crate::utils::github::GitHub;
use octocrab::models::repos::Release;
use orzklv::telegram::{keyboard::Keyboard, topic::Topics};
use teloxide::{
payloads::SendMessageSetters,
prelude::*,
types::{InlineKeyboardMarkup, ParseMode},
};
Expand Down Expand Up @@ -34,5 +34,7 @@ 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("Ko'proq ma'lumotlar", release.html_url.as_str())
.unwrap()
}
13 changes: 9 additions & 4 deletions src/functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#![allow(clippy::too_many_arguments)]

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;
pub mod warn;

pub use inline::inline;

use crate::bot::Command;
use crate::utils::{github::GitHub, groups::Groups, resources::Resources};
use crate::utils::{github::GitHub, groups::Groups, resources::Resources, topics::Topics};
use std::error::Error;
use teloxide::{prelude::*, types::*};

Expand All @@ -26,6 +28,7 @@ pub async fn commands(
cmd: Command,
github: GitHub,
groups: Groups,
topics: Topics,
resources: Resources,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let _ = match cmd {
Expand All @@ -36,7 +39,7 @@ pub async fn commands(
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::Warn => crate::functions::warn::command(&bot, &msg, &me, &topics).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,
Expand All @@ -50,6 +53,7 @@ pub async fn callback(
q: CallbackQuery,
github: GitHub,
groups: Groups,
topics: Topics,
resources: Resources,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let mut args: Vec<&str> = Vec::new();
Expand All @@ -76,6 +80,7 @@ pub async fn callback(
crate::functions::useful::callback_material_detail(&bot, &q, &args, &resources)
.await
}
"warn" => warn::callback(&bot, &q, &args, &topics).await,
_ => Ok(()),
};
}
Expand All @@ -84,7 +89,7 @@ pub async fn callback(
}

pub async fn triggers(bot: Bot, msg: Message) -> Result<(), Box<dyn Error + Send + Sync>> {
if let Some(user) = msg.from() {
if let Some(ref user) = msg.from {
if let Some(username) = user.username.clone() {
if username == "Channel_Bot" {
// Try to delete message and ignore error
Expand Down
Loading

0 comments on commit 485696a

Please sign in to comment.