/me and other stuff
This commit is contained in:
parent
65086a3b3c
commit
13dab47532
1 changed files with 46 additions and 9 deletions
55
src/main.rs
55
src/main.rs
|
@ -37,6 +37,7 @@ struct Message {
|
|||
sender: User,
|
||||
contents: String,
|
||||
timestamp: time::OffsetDateTime,
|
||||
me_message: bool
|
||||
}
|
||||
|
||||
type Channel = Arc<Mutex<UnwrappedChannel>>;
|
||||
|
@ -134,14 +135,25 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
|||
if current_message_count != new_message_count {
|
||||
let new_messages = &channel.lock().unwrap().messages[current_message_count..];
|
||||
for msg in new_messages {
|
||||
stream
|
||||
.write_fmt(format_args!(
|
||||
"\x1b[0m\x1b[34m[{}]\x1b[0m \x1b[1m{}\x1b[0m \x1b[31m⇛\x1b[0m \x1b[35m{}\x1b[0m\n",
|
||||
msg.timestamp.format(&time_format).unwrap(),
|
||||
msg.sender.name,
|
||||
msg.contents
|
||||
))
|
||||
.unwrap();
|
||||
if !msg.me_message {
|
||||
stream
|
||||
.write_fmt(format_args!(
|
||||
"\x1b[0m\x1b[34m[{}]\x1b[0m \x1b[1m{}\x1b[0m \x1b[31m⇛\x1b[0m \x1b[35m{}\x1b[0m\n",
|
||||
msg.timestamp.format(&time_format).unwrap(),
|
||||
msg.sender.name,
|
||||
msg.contents
|
||||
))
|
||||
.unwrap();
|
||||
} else {
|
||||
stream
|
||||
.write_fmt(format_args!(
|
||||
"\x1b[0m\x1b[34m[{}]\x1b[0m \x1b[1;3m{}\x1b[0m \x1b[3m{}\x1b[0m\n",
|
||||
msg.timestamp.format(&time_format).unwrap(),
|
||||
msg.sender.name,
|
||||
msg.contents
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
current_message_count = new_message_count;
|
||||
|
@ -154,6 +166,13 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
|||
});
|
||||
}
|
||||
|
||||
channel.lock().unwrap().messages.push(Message {
|
||||
sender: netbot.clone(),
|
||||
contents: format!("User {} has joined!", user.name),
|
||||
timestamp: time::OffsetDateTime::now_local().unwrap(),
|
||||
me_message: false
|
||||
});
|
||||
|
||||
let mut buf = Vec::<u8>::new();
|
||||
let mut buf1 = [0u8];
|
||||
|
||||
|
@ -171,6 +190,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
|||
sender: netbot.clone(),
|
||||
contents: format!("User {} has left.", user.name),
|
||||
timestamp: time::OffsetDateTime::now_local().unwrap(),
|
||||
me_message: false
|
||||
});
|
||||
|
||||
recieve_terminate_send.send(()).unwrap();
|
||||
|
@ -191,6 +211,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
|||
sender: user.clone(),
|
||||
contents,
|
||||
timestamp: time::OffsetDateTime::now_local().unwrap(),
|
||||
me_message: false
|
||||
});
|
||||
} else {
|
||||
if contents.split(" ").collect::<Vec<&str>>()[0] == "/help" || contents.split(" ").collect::<Vec<&str>>()[0] == "/?" {
|
||||
|
@ -201,9 +222,25 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
|||
/status [online|idle|disconnected|(any value)]: Set your status.\n \
|
||||
/user [nick]: Get information about a user.\n \
|
||||
/server [new name]: Get or set the server name.\n \
|
||||
/users: List users.\x1b[0m\n",
|
||||
/users: List users.\n \
|
||||
/me x: Say that you are doing x(for example, \"Netbot purrs\").\x1b[0m\n",
|
||||
)
|
||||
.unwrap();
|
||||
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/me" {
|
||||
if contents.split(" ").collect::<Vec<&str>>().len() < 2 || contents.split(" ").collect::<Vec<&str>>()[1] == "" {
|
||||
stream
|
||||
.write_fmt(format_args!(
|
||||
"\x1b[0m\x1b[31mYou need to provide at least one argument to /me!\n\x1b[0m",
|
||||
))
|
||||
.unwrap();
|
||||
} else {
|
||||
channel.lock().unwrap().messages.push(Message {
|
||||
sender: user.clone(),
|
||||
contents: contents.replace("/me ", ""),
|
||||
timestamp: time::OffsetDateTime::now_local().unwrap(),
|
||||
me_message: true
|
||||
});
|
||||
}
|
||||
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/status" || contents == "/user" {
|
||||
let contents = contents.split(" ").collect::<Vec<&str>>();
|
||||
if contents.len() == 1 {
|
||||
|
|
Loading…
Add table
Reference in a new issue