P5J5K557OJ5TDY5GLKE74QGCIVI34FI2ANAIBVVRW7NJG5I76VWAC
fn parse() -> HashMap<String, i64> {
let mut hash: HashMap<String, i64> = HashMap::default();
let path = Path::new("/tmp/hello.txt");
let mut file = match File::open(&path) {
Err(why) => panic!("couldn't open file {}", why),
Ok(file) => file,
};
let mut s = String::new();
file.read_to_string(&mut s).unwrap();
for line in s.split("\n") {
if line == "" {
break;
}
let mut split = line.split(" ");
let name = split
.next()
.unwrap_or_else(|| panic!(format!("can't parse this line: {}", line)));
let nb: i64 = split
.next()
.unwrap_or_else(|| panic!(format!("need a score: {}", line)))
.parse()
.unwrap_or_else(|_| panic!(format!("can't parse this score: {}", line)));
hash.insert(name.to_string(), nb);
}
return hash;
}
let mut s = String::new();
match file.read_to_string(&mut s) {
Err(why) => panic!("couldn't read {}: {}", display, why.description()),
Ok(_) => print!("{} contains:\n{}", display, s),
fn get_user_id(user: String) -> Result<String, String> {
println!("user: {}", user);
let mut start = 0;
if !user.starts_with("<@") || !user.ends_with(">") {
return Err("Le nom est mal formé !".to_string());
println!("{}", s);
let user_id: u64 = match user[start..user.len() - 1].parse() {
Err(_) => return Err("Le nom est mal formé !".to_string()),
Ok(n) => n,
};
let user = serenity::model::id::UserId(user_id);
return match user.to_user() {
Err(_) => Err("Utilisateur inconnu".to_string()),
Ok(u) => Ok(u.to_string()),
};
if !user.starts_with("<@") || !user.ends_with(">") {
msg.reply("Le nom est malformé !");
return Ok(());
}
let user_id: u64 = match user[2..user.len() - 1].parse::<u64>() {
Err(_) => {
msg.reply("Le nom est malformé !");
let user = match get_user_id(user) {
Err(e) => {
let _ = msg.reply(&e);
let _ = msg.react('❎');
// println!("{:?}", ctx);
let user = serenity::model::id::UserId(user_id);
let user = match user.get() {
Err(_) => {
msg.reply("Utilisateur inconnu");
command!(nul(ctx, msg, args) {
if args.len() != 1 {
let _ = msg.reply("Donne moi **un** nom !");
let _ = msg.react('❎');
return Ok(());
}
let user: String = args.iter().next().unwrap().unwrap();
let user = match get_user_id(user) {
Err(e) => {
let _ = msg.reply(&e);
let _ = msg.react('❎');
if let Err(why) = msg.channel_id.say(format!("Shame {}!", user)) {
println!("Error sending message: {:?}", why);
}
let mut data = ctx.data.lock();
let score = data
.get_mut::<Score>()
.expect("Expected Score in ShareMap.");
let entry = score.entry(user.to_string()).or_insert(0);
*entry -= 1;
let _ = msg.react('👌');
println!("Error sending message: {:?}", why);
}
});
command!(say(_ctx, msg, args) {
let mut settings = if let Some(guild_id) = msg.guild_id {
ContentSafeOptions::default()
.clean_channel(false)
.display_as_member_from(guild_id)
} else {
ContentSafeOptions::default()
.clean_channel(false)
.clean_role(false)
};
let mut content = content_safe(&args.full(), &settings);
if let Err(why) = msg.channel_id.say(&content) {