Showing the time for each chat message

Posted by Nick Gammon on Thu 17 Apr 2003 11:18 PM — 2 posts, 14,229 views.

Australia Forum Administrator #0
The flexibility of the chat system can be demonstrated with a minor change to the supplied "chat" plugin. Say you are chatting with people and want to know *when* a particular message arrived. You can modify the OnPluginChatDisplay callback function to add the date and/or time to each message.

The example below puts the time at the start of the message, and then uses ChatNote to redisplay it with the date. However, the program would quickly go into an infinite loop without one more check. We assign a user-assigned "message type" of 1000, which represents our modified message. When ChatNote calls OnPluginChatDisplay a second time, we detect the message type of 1000, and decline to redisplay it a second time.


Function OnPluginChatDisplay (message, sText)

  OnPluginChatDisplay = vbTrue  ' display it

  If message <> 1000 Then
    ChatNote 1000,  FormatDateTime (Now, vbShortTime) & ": " & sText
    OnPluginChatDisplay = vbFalse
  End If  
  
End Function


With this modification in place, you can now see this sort of thing:


#chat bruce aha
08:09: You chat to Bruce, 'aha'


Note the time at the start of the message.

Instead of "vbShortTime" in the code you can use one of the following:


  • vbGeneralDate - General date/time, eg. 18/04/03 8:17:39
  • vbLongDate - Long date, eg. Friday, 18 April 2003
  • vbShortDate - Short date, eg. 18/04/03 (Australian format)
  • vbLongTime - Long time, eg. 8:16:55
  • vbShortTime - Short time, eg. 08:16

Amended on Thu 17 Apr 2003 11:20 PM by Nick Gammon
#1
Heh, and I was just thinking about adding times to the output this morning. I figured there was a way to do it, but didn't realize it could run that cleanly.

Thanks for the code snippet. :)