Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Bot now pms requester
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Gautier committed Apr 3, 2017
1 parent 7022b2a commit 53ab439
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,54 @@ fn main() {
match connection.recv_event() {
Ok(Event::MessageCreate(message)) => {
let content = message.content.clone();
let author_id = message.author.id;

if content.is_char_boundary(2) {
let (prefix, item) = content.split_at(2);

let item_name = item.to_string();
let item_name = item.trim().to_string();
let vending_api = vending_api.clone();
let channel_id = message.channel_id.clone();
let discord = discord.clone();


if item_name.len() < 3 {
println!("Item name less than 3 chars. Passing");
continue;
}

match prefix {
"B>" => {
println!("Look for selling {}", item);

std::thread::spawn(move || {
let private_channel_id = discord.create_private_channel(author_id).unwrap().id;
let items = look_for_sale(vending_api, item_name).wait().unwrap();

if items.len() == 0 {
discord.send_message(channel_id, "Sorry, the item you're looking for doesn't seem to be in sale", "", false);
discord.send_message(private_channel_id, "Sorry, the item you're looking for doesn't seem to be in sale", "", false);
}

for item in items.into_iter() {
let msg : String = format!("**{}** **{}** for **{}**z each. Shop name: **{}**. **{}**", item.amount(), item.name(), item.price(), item.shop_name(), item.location());
discord.send_message(channel_id, &msg, "", false);
discord.send_message(private_channel_id, &msg, "", false);
}
});
}
"S>" => {
println!("Look for buying {}", item);

std::thread::spawn(move || {
let private_channel_id = discord.create_private_channel(author_id).unwrap().id;
let items = look_for_buying(vending_api, item_name).wait().unwrap();

if items.len() == 0 {
discord.send_message(channel_id, "Sorry, the item you wanna sell doesn't seem to match any buy proposition right now", "", false);
discord.send_message(private_channel_id, "Sorry, the item you wanna sell doesn't seem to match any buy proposition right now", "", false);
}

for item in items.into_iter() {
let msg : String = format!("**{}** **{}** for **{}**z each. Shop name: **{}**. **{}**", item.amount(), item.name(), item.price(), item.shop_name(), item.location());
discord.send_message(channel_id, &msg, "", false);
discord.send_message(private_channel_id, &msg, "", false);
}
});
}
Expand Down

0 comments on commit 53ab439

Please sign in to comment.