-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::utils::{keyboard::Keyboard, resources::Resources}; | ||
use teloxide::{ | ||
payloads::SendMessageSetters, | ||
prelude::*, | ||
types::{InlineKeyboardMarkup, ParseMode}, | ||
}; | ||
|
||
static TEXT: &str = "<b>Rustga oid foydali materiallar:</b>\n\ | ||
Agar o'zingizdan material qo'shmoqchi bo'lsangiz, bizni \ | ||
<a href='https://github.com/rust-lang-uz/rustina/blob/main/source.json'>\ | ||
source.json</a> ni yangilang!"; | ||
|
||
pub async fn command(bot: &Bot, msg: &Message, resources: &Resources) -> ResponseResult<()> { | ||
let categories = resources.get_keys(); | ||
|
||
bot.send_message(msg.chat.id, TEXT) | ||
.parse_mode(ParseMode::Html) | ||
.reply_markup(keyboard_list(1, categories)) | ||
.disable_web_page_preview(true) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn keyboard_list(page: u32, categories: Vec<String>) -> InlineKeyboardMarkup { | ||
let mut keyboard = Keyboard::new(); | ||
|
||
for category in categories { | ||
keyboard.text( | ||
&format!( | ||
"{}{}", | ||
&category[0..1].to_uppercase(), | ||
&category[1..].replace("_", " ") | ||
), | ||
&format!("useful_{}_{}", page, category), | ||
); | ||
keyboard.row(); | ||
} | ||
|
||
keyboard.get() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod github; | ||
pub mod group_manager; | ||
pub mod inline_manager; | ||
pub mod keyboard_manager; | ||
pub mod groups; | ||
pub mod inlines; | ||
pub mod keyboard; | ||
pub mod resources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
|
||
static RESOURCE: &'static str = include_str!("../../source.json"); | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct Resource { | ||
pub name: String, | ||
pub desc: String, | ||
pub link: String, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Resources { | ||
materials: HashMap<String, Vec<Resource>>, | ||
} | ||
|
||
impl Resources { | ||
pub fn new() -> Self { | ||
Resources { | ||
materials: serde_json::from_str(RESOURCE).unwrap(), | ||
} | ||
} | ||
|
||
pub fn get_keys(&self) -> Vec<String> { | ||
self.materials.keys().map(|k| k.to_string()).collect() | ||
} | ||
|
||
pub fn get_materials(&self, key: &str) -> Option<&Vec<Resource>> { | ||
self.materials.get(key) | ||
} | ||
|
||
pub fn get_material(&self, key: &str, index: usize) -> Option<&Resource> { | ||
self.materials.get(key).and_then(|v| v.get(index)) | ||
} | ||
} |