AddQ function

From StealthBot Wiki Backup
(Redirected from AddQ)
Jump to: navigation, search

The AddQ SSC function adds text to the message queue.

Development

The AddQ function was added to StealthBot with the addition of the Scripting system. In version 2.7, the optional Tag argument was added, and the return value was added.

Documentation

'// ADDQ (ADD QUEUE)
'// Adds a string to the message send queue.
'// Nonzero priority messages will be sent with precedence over 0-priority messages.
Public Function AddQ(ByVal sText As String, Optional ByVal msg_priority As Integer = -1, Optional ByVal _
    Tag As String = vbNullString) As Integer
    
    '// Disabled while in Clan SBs.
    If ((StrComp(g_Channel.Name, "Clan SBs", vbTextCompare) = 0) And _
        (IsStealthBotTech() = False)) Then Exit Function
    
    '// priority zero reserved for internal usage only
    'If (msg_priority = 0) Then
    '    msg_priority = 1
    'End If

    '// ...
    AddQ = frmChat.AddQ(sText, msg_priority, g_lastQueueUser, Tag)
    
    '// ...
    'If (g_lastQueueUser <> vbNullString) Then
    '    g_lastQueueUser = vbNullString
    'End If
End Function

Summary

Call this subroutine to add text to the message queue.

Syntax

[SSC.]AddQ sText, [msg_priority], [Tag]
LineSent = [SSC.]AddQ(sText, [msg_priority], [Tag])

(Optional parts are enclosed in [ ]s.)

Arguments

  • sText is the text you want to send.
  • msg_priority is an integer that you can optionally provide that specifies the priority of the message. Numerically lower priorities will be sent before numerically higher priorities.
  • Tag is an optional value that will be passed with the queue item so that scripts can keep track of it. It is supplied in Event_MessageQueued and Event_MessageSent.

Returns

This function will return the number of items that were added to the queue. Long messages are split into multiple queue items and the " [more]" string is appended automatically.

Examples

  • Output "Hi, I'm a bot." to the channel.
  • AddQ "Hi, I'm a bot."
    
  • Respond to the message "myping" with the user's ping.
  • Sub Event_UserTalk(Username, Flags, Message, Ping)
        If Message = "myping" Then
            AddQ Username & ", your ping is " & Ping & "ms!"
        End If
    End Sub
    
  • This will send the messages in the opposite order!
  • AddQ "1", 3
    AddQ "2", 2
    AddQ "3", 1
    
  • Here, we'll use the Queue object to remove messages without the specified tag after they are added (note: if you use this script, all messages you send out without the correct tag will be removed).
  • Sub Event_PressedEnter(Text)
        If Text = "/test" Then
            AddQ "test a", , "Simon says AddQ"
            AddQ "test 2"
            AddQ "test x", , "AddQ"
        End If
    End Sub
    
    Sub Event_MessageQueued(ID, Message, Tag)
        If Tag <> "Simon says AddQ" Then Queue.RemoveItemByID(ID)
    End Sub
    

See also