mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-08 13:04:06 +00:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
30d9d470cd | |||
3236131377 |
@ -4,7 +4,7 @@ use html_escape::encode_text;
|
|||||||
use markov::Chain;
|
use markov::Chain;
|
||||||
use mystem::Gender::Feminine;
|
use mystem::Gender::Feminine;
|
||||||
use mystem::MyStem;
|
use mystem::MyStem;
|
||||||
use mystem::Tense::{Past, Inpresent};
|
use mystem::Tense::{Inpresent, Past};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@ -117,9 +117,15 @@ pub(crate) async fn omedeto(api: Api, message: Message, mystem: &mut MyStem) ->
|
|||||||
.map(|m| m.split(' ').map(|s| s.to_string()).collect::<Vec<String>>()[1].clone())
|
.map(|m| m.split(' ').map(|s| s.to_string()).collect::<Vec<String>>()[1].clone())
|
||||||
.filter(|m| {
|
.filter(|m| {
|
||||||
let stem = mystem.stemming(m.clone()).unwrap_or_default();
|
let stem = mystem.stemming(m.clone()).unwrap_or_default();
|
||||||
match stem[0].lex[0].grammem.part_of_speech {
|
if stem.is_empty() {
|
||||||
mystem::PartOfSpeech::Noun => true,
|
false
|
||||||
_ => false,
|
} else if stem[0].lex.is_empty() {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
match stem[0].lex[0].grammem.part_of_speech {
|
||||||
|
mystem::PartOfSpeech::Noun => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -134,12 +140,18 @@ pub(crate) async fn omedeto(api: Api, message: Message, mystem: &mut MyStem) ->
|
|||||||
.map(|m| m.split(' ').map(|s| s.to_string()).collect::<Vec<String>>()[1].clone())
|
.map(|m| m.split(' ').map(|s| s.to_string()).collect::<Vec<String>>()[1].clone())
|
||||||
.filter(|m| {
|
.filter(|m| {
|
||||||
let stem = mystem.stemming(m.clone()).unwrap_or_default();
|
let stem = mystem.stemming(m.clone()).unwrap_or_default();
|
||||||
match stem[0].lex[0].grammem.part_of_speech {
|
if stem.is_empty() {
|
||||||
mystem::PartOfSpeech::Verb => stem[0].lex[0]
|
false
|
||||||
.grammem
|
} else if stem[0].lex.is_empty() {
|
||||||
.facts
|
false
|
||||||
.contains(&mystem::Fact::Tense(Past)),
|
} else {
|
||||||
_ => false,
|
match stem[0].lex[0].grammem.part_of_speech {
|
||||||
|
mystem::PartOfSpeech::Verb => stem[0].lex[0]
|
||||||
|
.grammem
|
||||||
|
.facts
|
||||||
|
.contains(&mystem::Fact::Tense(Past)),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -154,12 +166,18 @@ pub(crate) async fn omedeto(api: Api, message: Message, mystem: &mut MyStem) ->
|
|||||||
.map(|m| m.split(' ').map(|s| s.to_string()).collect::<Vec<String>>()[1].clone())
|
.map(|m| m.split(' ').map(|s| s.to_string()).collect::<Vec<String>>()[1].clone())
|
||||||
.filter(|m| {
|
.filter(|m| {
|
||||||
let stem = mystem.stemming(m.clone()).unwrap_or_default();
|
let stem = mystem.stemming(m.clone()).unwrap_or_default();
|
||||||
match stem[0].lex[0].grammem.part_of_speech {
|
if stem.is_empty() {
|
||||||
mystem::PartOfSpeech::Verb => stem[0].lex[0]
|
false
|
||||||
.grammem
|
} else if stem[0].lex.is_empty() {
|
||||||
.facts
|
false
|
||||||
.contains(&mystem::Fact::Tense(Inpresent)),
|
} else {
|
||||||
_ => false,
|
match stem[0].lex[0].grammem.part_of_speech {
|
||||||
|
mystem::PartOfSpeech::Verb => stem[0].lex[0]
|
||||||
|
.grammem
|
||||||
|
.facts
|
||||||
|
.contains(&mystem::Fact::Tense(Inpresent)),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -179,25 +197,25 @@ pub(crate) async fn omedeto(api: Api, message: Message, mystem: &mut MyStem) ->
|
|||||||
//debug!("Nouns: {:#?}", nouns);
|
//debug!("Nouns: {:#?}", nouns);
|
||||||
//debug!("Verbs: {:#?}", verbs);
|
//debug!("Verbs: {:#?}", verbs);
|
||||||
|
|
||||||
let fem = if mystem
|
let fem = {
|
||||||
.stemming(message.from.first_name.to_string())
|
let z = mystem
|
||||||
.unwrap()[0]
|
|
||||||
.lex
|
|
||||||
.is_empty()
|
|
||||||
{
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
if mystem
|
|
||||||
.stemming(message.from.first_name.to_string())
|
.stemming(message.from.first_name.to_string())
|
||||||
.unwrap()[0]
|
.unwrap();
|
||||||
.lex[0]
|
|
||||||
.grammem
|
if z.is_empty() {
|
||||||
.facts
|
|
||||||
.contains(&mystem::Fact::Gender(Feminine))
|
|
||||||
{
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
false
|
||||||
|
} else if z[0].lex.is_empty() {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
if z[0].lex[0]
|
||||||
|
.grammem
|
||||||
|
.facts
|
||||||
|
.contains(&mystem::Fact::Gender(Feminine))
|
||||||
|
{
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let result = format!(
|
let result = format!(
|
||||||
@ -219,6 +237,18 @@ pub(crate) async fn omedeto(api: Api, message: Message, mystem: &mut MyStem) ->
|
|||||||
|
|
||||||
);
|
);
|
||||||
debug!("{:?}", result);
|
debug!("{:?}", result);
|
||||||
|
match api
|
||||||
|
.send(
|
||||||
|
message
|
||||||
|
.text_reply(result.trim())
|
||||||
|
.parse_mode(ParseMode::Html),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => debug!("/omedeto command sent to {}", message.chat.id()),
|
||||||
|
Err(_) => warn!("/omedeto command sent failed to {}", message.chat.id()),
|
||||||
|
}
|
||||||
|
|
||||||
// '^я [а-яА-Я]+(-[а-яА-Я]+(_[а-яА-Я]+)*)*$'
|
// '^я [а-яА-Я]+(-[а-яА-Я]+(_[а-яА-Я]+)*)*$'
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user