From 85ae6526907b25fb10dd7f16828e4f02fb9009e9 Mon Sep 17 00:00:00 2001 From: lalanza808 Date: Mon, 23 Mar 2020 23:02:52 -0700 Subject: [PATCH] add db init and string manipulations --- src/main.rs | 16 ++++++++++++++-- util/init_db.sql | 11 +++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 util/init_db.sql diff --git a/src/main.rs b/src/main.rs index 10327d5..a8b0848 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,8 @@ async fn main() -> Result<(), Error> { } if let Command::PRIVMSG(channel, message) = &im.command { + let src_nick = &im.source_nickname().unwrap(); + let help_msg = vec![ format!("Hey there {}, here's what you can do.", &im.source_nickname().unwrap()), "Say '!create' followed by the title of your listing to create a new one.".to_string(), @@ -51,12 +53,22 @@ async fn main() -> Result<(), Error> { println!( "[{}][{}]: {}", &im.response_target().unwrap(), - &im.source_nickname().unwrap(), + src_nick, message ); if message.starts_with("!create") { - let _ = client.send_privmsg(&channel, "This feature is still being worked on."); + let user_msg = message.split(" "); + let mut user_msg: Vec<&str> = user_msg.collect(); + user_msg.remove(0); + let user_msg = user_msg.join(" "); + println!("it looks like you said: '{:?}' - Trying to save to the DB", user_msg); + // pg_client.query( + // "INSERT INTO posts (nick, post_title) VALUES ('$1', '$2')", + // &[src_nick, &user_msg] + // ); + // let value: &str = rows2[0].get(0); + // println!("{}", value); } else if message.starts_with("!delete") { let _ = client.send_privmsg(&channel, "This feature is still being worked on."); } else if message.starts_with("!help") { diff --git a/util/init_db.sql b/util/init_db.sql new file mode 100644 index 0000000..a5e3342 --- /dev/null +++ b/util/init_db.sql @@ -0,0 +1,11 @@ +DROP TABLE posts; + +CREATE TABLE posts ( + id SERIAL PRIMARY KEY, + nick CHAR(60) NOT NULL, + date_posted TIMESTAMP DEFAULT Now(), + post_title TEXT NOT NULL +); + +INSERT INTO posts (nick, date_posted, post_title) +VALUES ('testing', '2020-03-20 21:17:00', 'Just testing this shit out');