fix poles
This commit is contained in:
parent
24a4624c9d
commit
493dfcbb10
@ -7,7 +7,11 @@ use crate::telegram_utils::*;
|
|||||||
mod database;
|
mod database;
|
||||||
|
|
||||||
fn change_day(last_day: &str) -> bool{
|
fn change_day(last_day: &str) -> bool{
|
||||||
last_day.cmp(&Local::now().add(chrono::TimeDelta::hours(2)).format("%Y-%m-%d").to_string()) != Equal
|
last_day.cmp(&get_actual_day()) != Equal
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_actual_day() -> String {
|
||||||
|
Local::now().add(chrono::TimeDelta::hours(2)).format("%Y-%m-%d").to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pole(group_id: &str) -> bool {
|
fn check_pole(group_id: &str) -> bool {
|
||||||
@ -21,24 +25,24 @@ fn check_pole(group_id: &str) -> bool {
|
|||||||
|
|
||||||
fn do_pole(group_id: &str, user_id: &str, user_name: &str){
|
fn do_pole(group_id: &str, user_id: &str, user_name: &str){
|
||||||
let data: database::DatabasePole = database::DatabasePole::get_database();
|
let data: database::DatabasePole = database::DatabasePole::get_database();
|
||||||
data.write_points(group_id, user_id, user_name, &Local::now().format("%Y-%m-%d").to_string(),Rewards::POLE as i64);
|
data.write_points(group_id, user_id, user_name, &get_actual_day(),Rewards::POLE as i64);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_plata(group_id: &str, user_id: &str, user_name: &str){
|
fn do_plata(group_id: &str, user_id: &str, user_name: &str){
|
||||||
let data: database::DatabasePole = database::DatabasePole::get_database();
|
let data: database::DatabasePole = database::DatabasePole::get_database();
|
||||||
data.write_points(group_id, user_id, user_name, &Local::now().format("%Y-%m-%d").to_string(),Rewards::PLATA as i64);
|
data.write_points(group_id, user_id, user_name, &get_actual_day(),Rewards::PLATA as i64);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_fail(group_id: &str, user_id: &str, user_name: &str){
|
fn do_fail(group_id: &str, user_id: &str, user_name: &str){
|
||||||
let data: database::DatabasePole = database::DatabasePole::get_database();
|
let data: database::DatabasePole = database::DatabasePole::get_database();
|
||||||
data.write_points(group_id, user_id, user_name, &Local::now().format("%Y-%m-%d").to_string(),Rewards::FAIL as i64);
|
data.write_points(group_id, user_id, user_name, &get_actual_day(),Rewards::FAIL as i64);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_user_points(msg: &teloxide::prelude::Message, rw: Rewards) -> bool{
|
fn check_user_points(msg: &teloxide::prelude::Message, rw: Rewards) -> bool{
|
||||||
let data: database::DatabasePole = database::DatabasePole::get_database();
|
let data: database::DatabasePole = database::DatabasePole::get_database();
|
||||||
let ret = data.check_user_pole(&msg.chat.id.to_string(),
|
let ret = data.check_user_pole(&msg.chat.id.to_string(),
|
||||||
&msg.from().unwrap().id.to_string(),
|
&msg.from().unwrap().id.to_string(),
|
||||||
&Local::now().format("%Y-%m-%d").to_string());
|
&get_actual_day());
|
||||||
check_group_points(msg, rw) && (ret == 0)
|
check_group_points(msg, rw) && (ret == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +55,7 @@ enum Rewards {
|
|||||||
fn check_group_points(msg: &teloxide::prelude::Message, rw: Rewards) -> bool {
|
fn check_group_points(msg: &teloxide::prelude::Message, rw: Rewards) -> bool {
|
||||||
let data: database::DatabasePole = database::DatabasePole::get_database();
|
let data: database::DatabasePole = database::DatabasePole::get_database();
|
||||||
let ret = data.check_group_points(&msg.chat.id.to_string(),
|
let ret = data.check_group_points(&msg.chat.id.to_string(),
|
||||||
&Local::now().format("%Y-%m-%d").to_string());
|
&get_actual_day());
|
||||||
match rw {
|
match rw {
|
||||||
Rewards::PLATA => ret == (Rewards::POLE as i64),
|
Rewards::PLATA => ret == (Rewards::POLE as i64),
|
||||||
Rewards::FAIL => ret == (Rewards::PLATA as i64 + Rewards::POLE as i64),
|
Rewards::FAIL => ret == (Rewards::PLATA as i64 + Rewards::POLE as i64),
|
||||||
|
Loading…
Reference in New Issue
Block a user