Message Box

By Trav on Apr 12, 2008

I haven't submitted a script in AWHILE here, but now here's one! This is how it works:
Someone types !msg
It gives them instructions on what do do next, so they type
!send person's_name The message they want to send to them.
Once the person they sent it to joins any channel the bot is on, or says anything (it does this so they won't be idle when it's sent), it'll send them a message saying they have unread messages. After that, it tells them they can type !read, and it'll give them their past 3 messages. If they only have 1, it'll have 2 blanks, and the 1 message.

When you receive a message it tells you the message, who sent it, when it was sent, and in what channel it was sent!

on *:TEXT:!read*:#: { msg $nick 4Here are your last 3 messages, from the newest to oldest:
  msg $nick 4 %msg [ $+ [ $nick ] ]
  msg $nick 4 %msg2 [ $+ [ $nick ] ]
  msg $nick 4 %msg3 [ $+ [ $nick ] ]
 }
on *:TEXT:!msg*:#: { notice $nick 4To send a message to someone,  type !send name message you want to send! }
on *:TEXT:!send*:#: { set %msg3 [ $+ [ $2 ] ] %msg2 [ $+ [ $2 ] ] | set %msg2 [ $+ [ $2 ] ] %msg [ $+ [ $2 ] ] | set %msg [ $+ [ $2 ] ] $3- 12-From $nick @ $time in $chan | set %sent [ $+ [ $2 ] ] yes | notice $nick 4Your message to $2 has been sent! When they get back, they will receive the message! }
on *:TEXT:*:#: { if (%sent [ $+ [ $nick ] ] == yes) { notice $nick 4You have unread messages! To read them type !read or you can type !msg to send a message! | set %sent [ $+ [ $nick ] ] no } }
on *:JOIN:#: { if (%sent [ $+ [ $nick ] ] == yes) { notice $nick 4You have unread messages! To read them type !read or you can type !msg to send a message! | set %sent [ $+ [ $nick ] ] no } }

Comments

Sign in to comment.
Gecko321   -  Apr 12, 2008

You could also use hash tables to make it keep more than just 3 messages. You can also combine all of your on Text events to make sure there are no errors.

on *:TEXT:*:#: { 
  var %Nick = $+($Nick,.Memo)
  CheckMessages $Nick
  if ($1 = !Read) {
    if ($Hget(%Nick,Total) > 0) {
      .msg $nick You have $v1 Messages.
      var %a = 0
      While (%a != $Hget(%Nick,Total)) {
        inc %a
        .msg $Nick $HGet(%Nick,%a)
      }
    }
  }
  elseif ($1 = !msg) { .notice $nick To send a message to someone,  type !send name message you want to send! }
  elseif ($1 = !Send) {
    if (!$HGet(%Nick)) { .hmake $Nick }
    if (!$Hget(%Nick,Total)) { .hadd -m %Nick Total 0 }
    .hinc %Nick Total 1
    .hadd %Nick $HGet(%Nick,Total) $3- -From $Nick @ $Time in $Chan
    .notice $nick Your message to $2 has been sent! When they get back, they will receive the message! 
  } 
  if ($1 = !Clear) { .hdel %Nick }
}

on *:JOIN:#:CheckMessages $Nick

alias CheckMessages { 
  if ($Hget($+($2,.Memo),Total)) > 0) { 
    .notice $2 You have unread messages! To read them type !read or you can type !msg to send a message! 
  } 
} 
 Respond  
Jamiie   -  Apr 12, 2008

Sorry for the double post, meant 3/10

 Respond  
Jamiie   -  Apr 12, 2008

I don\'t really see the point of this snippet, why not use memo\'s?

2/10

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.