Help - Search - Members - Calendar
Full Version: DQD Project
StealthBot.net > StealthBot > Scripting and Plugins > Plugin Projects
Snap
The Dynamic Queue Delegator Plugin for Beta R31+

Previously scripts to share a queue used some sort of 'SharedQueue' sub or an addq-replacement.
Avoiding both of these methods DQD interfaces with the queue object using Event_MessageQueued.
By doing this I introduce a shared-queue system globally which affects built-in commands as well as plugins, and regular chat. (You can even paste multi-lined text).

When a bot has nothing in it's queue - and hasn't sent a message in [x]ms it checks the database to see if it can pick up a message.
All "/" commands except for whispers aren't shared. This prevents any issues with plugin-reliant /whois requests & etc.

This will be a fairly light-weight plugin as the amount of code needed is small - however getting everything just right is taking some time.
QUOTE
[02:40:28 AM] <SCSF> Test 1
[02:40:29 AM] <Snapit> Test 2
[02:40:30 AM] <SCSF> Test 3
[02:40:32 AM] <Snapit> Test 3
[02:40:33 AM] <SCSF> Test 4
[02:40:34 AM] <Snapit> Test 5
[02:40:35 AM] <SCSF> Test 6
[02:40:38 AM] <SCSF> Test 7


52's helping me with the Race Conditions (What's causing that duplicate to exist) - after that's done there's some fine-tuning.
I'll probably have a usable version this weekend.
AwaKening
Nice, I planned on doing something like this myself, but hadn't gotten around to it. How's it coming along?
The-Black-Ninja
Still don't see why you didn't just go with what I gave you tongue.gif You could've avoided this race issue all together. All my free time is spent doing the AGP, so I can't bounce ideas to you anymore sad.gif
Jack
CODE
'sq
'0.1

Private Const sq_bots = "Tech-Jack), Tech-Jack(, Tech-Jack-"
Private FSO

Sub sq_Event_Load()
  
   Set FSO = CreateObject("Scripting.FileSystemObject")
End Sub

Sub sq_Event_UserTalk(Username, Flags, Message, Ping)
  
   bots = Split(sq_bots, ", ")
  
   For i = 0 To UBound(bots)
      If myUsername = bots(i) Then
         t = i
         If t = 0 Then t = UBound(bots) + 1
         If Username = bots(t-1) Then
            If GetVirtualQueueSize > 0 And Message = getLastMessage Then
               setLastMessage(FirstVirtualMessage())
               AddQ getLastMessage
               Call DeleteFirstVirtualMessage()
               Exit For
            End If
         End If
      End If
   Next
End Sub

Sub sq_Event_PressedEnter(Text)
  
   If Text = "/wtfhax" Then
      VetoThisMessage
      For i = 1 To 30
         sq_AddQ i & " wtf hax lawl"
      Next
      Exit Sub
   End If
   If Left(Text, 1) <> "/" Then
      VetoThisMessage
      Call sq_AddQ(Text)
   End If
End Sub

' ///
Sub sq_AddQ(Text)
  
   If Text = "" Then Exit Sub
   If GetQueueSize = 0 And GetVirtualQueueSize = 0 Then
      Call setLastMessage(Text)
      AddQ Text
   Else
      Set f = FSO.OpenTextFile("bqqhax.txt", 8, True)
      f.WriteLine Text
      f.Close
   End If
End Sub

Sub DeleteFirstVirtualMessage()
  
   Set f = FSO.OpenTextFile("bqqhax.txt", 1, True)
   msgs = Split(f.ReadAll, vbCrLf)
   f.Close
  
   Set f = FSO.OpenTextFile("bqqhax.txt", 2, True)
   For i = 1 To UBound(msgs)
      If msgs(i) <> "" Then f.WriteLine msgs(i)
   Next
   f.Close
End Sub

Sub setLastMessage(Text)
  
   Call SetSetting("sq", "LastMessage", Text, "", True)
End Sub

Function GetVirtualQueueSize()
  
   Set f = FSO.OpenTextFile("bqqhax.txt", 1, True)
   Do While Not f.AtEndOfStream
      l = f.ReadLine
      GetVirtualQueueSize = GetVirtualQueueSize + 1
   Loop
   f.Close
End Function

Function FirstVirtualMessage()
  
   Set f = FSO.OpenTextFile("bqqhax.txt", 1, True)
   FirstVirtualMessage = Split(f.ReadAll, vbCrLf)(0)
   f.Close
End Function

Function getLastMessage()
  
   getLastMessage = GetSetting("sq", "LastMessage")
End Function

Here's mine. I made it before all the dev releases and I think this was back in 2.697 or around there.

I loaded about 4 bots and then had someone spam "gamble; bet 50; roll; bet 50; roll" over and over again and it worked fine.








QUOTE
[13:35:33.330] <IdleBoT> We're no strangers to love
[13:35:34.759] <IdleSpamOne> You know the rules and so do I
[13:35:35.466] <IdleSpamTwo> A full commitment's what I'm thinking of
[13:35:36.378] <IdleSpamThree> You wouldn't get this from any other guy
[13:35:36.781] <IdleSpamFour> I just wanna tell you how I'm feeling
[13:35:37.322] <IdleBoT> Gotta make you understand
[13:35:38.457] <IdleSpamOne> Never gonna give you up
[13:35:39.049] <IdleSpamTwo> Never gonna let you down
[13:35:40.111] <IdleSpamThree> Never gonna run around and desert you
[13:35:41.460] <IdleSpamFour> Never gonna make you cry
[13:35:42.463] <IdleBoT> Never gonna say goodbye
[13:35:43.151] <IdleSpamOne> Never gonna tell a lie and hurt you
[13:35:44.112] <IdleSpamTwo> We've known each other for so long
[13:35:45.214] <IdleSpamThree> Your heart's been aching, but
[13:35:45.905] <IdleSpamFour> You're too shy to say it
[13:35:46.873] <IdleBoT> Inside we both know what's been going on
[13:35:47.776] <IdleSpamOne> We know the game and we're gonna play it
[13:35:48.978] <IdleSpamTwo> And if you ask me how I'm feeling
[13:35:49.927] <IdleSpamThree> Don't tell me you're too blind to see
[13:35:50.909] <IdleSpamFour> Never gonna give you up
[13:35:51.928] <IdleBoT> Never gonna let you down
[13:35:53.077] <Ribose[BoT]> holy shit win. ohmy.gif
[13:35:53.505] <IdleSpamOne> Never gonna run around and desert you
[13:35:54.642] <IdleSpamTwo> Never gonna make you cry
[13:35:55.417] <IdleSpamThree> Never gonna say goodbye
[13:35:55.990] <IdleSpamFour> Never gonna tell a lie and hurt you
[13:35:56.517] <IdleBoT> Never gonna give you up
[13:35:57.576] <IdleSpamOne> Never gonna let you down
[13:35:58.341] <IdleSpamTwo> Never gonna run around and desert you
[13:35:59.790] <IdleSpamThree> Never gonna make you cry
[13:36:00.583] <IdleSpamFour> Never gonna say goodbye
[13:36:01.423] <IdleBoT> Never gonna tell a lie and hurt you
[13:36:02.705] <IdleSpamOne> (Oooooooh, Give you up)
[13:36:03.328] <IdleSpamTwo> (Oooooooh, Give you UP)
[13:36:04.238] <IdleSpamThree> Never gonna give, never gonna give
[13:36:05.710] <IdleSpamFour> (Give you up)
[13:36:06.751] <IdleBoT> Never gonna give, never gonna give
[13:36:07.660] <IdleSpamOne> (Give you up)
[13:36:08.524] <IdleSpamTwo> We've known each other for so long
[13:36:09.152] <IdleSpamThree> Your heart's been aching, but
[13:36:10.127] <IdleSpamFour> You're too shy to say it
[13:36:11.144] <IdleBoT> Inside we both know what's been going on
[13:36:12.008] <IdleSpamOne> We know the game and we're gonna play it
[13:36:12.723] <IdleSpamTwo> I just wanna tell you how I'm feeling
[13:36:13.444] <IdleSpamThree> Gotta make you understand
[13:36:14.500] <IdleSpamFour> Never gonna give you up
[13:36:15.681] <IdleBoT> Never gonna let you down
[13:36:16.785] <IdleSpamOne> Never gonna run around and desert you
[13:36:17.694] <IdleSpamTwo> Never gonna make you cry
[13:36:18.603] <IdleSpamThree> Never gonna say goodbye
[13:36:19.165] <IdleSpamFour> Never gonna tell a lie and hurt you
[13:36:21.252] <IdleBoT> Never gonna give you up
[13:36:22.144] <IdleSpamOne> Never gonna let you down
[13:36:22.818] <IdleSpamTwo> Never gonna run around and desert you
[13:36:23.933] <IdleSpamThree> Never gonna make you cry
[13:36:24.996] <IdleSpamFour> Never gonna say goodbye
[13:36:25.522] <IdleBoT> Never gonna tell a lie and hurt you
[13:36:27.751] <IdleSpamOne> Never gonna give you up
[13:36:28.812] <IdleSpamTwo> Never gonna let you down
[13:36:29.912] <IdleSpamThree> Never gonna run around and desert you
[13:36:30.621] <IdleSpamFour> Never gonna make you cry
[13:36:34.600] <IdleBoT> Never gonna say goodbye
[13:36:35.937] <IdleSpamOne> Never gonna tell a lie and hurt you


New script:

CODE
Private FSO
Private followBot

Sub Data()
  
   Script("Name") = "SplitQueue"
   Script("Author") = "Jack"
   Script("Major") = 0           ' script major version
   Script("Minor") = 1           ' script minor version
   Script("Revision") = 0        ' script version revision
End Sub

Sub Event_Load()
  
   Set FSO = CreateObject("Scripting.FileSystemObject")
   bots = Split("IdleBoT, IdleSpamOne, IdleSpamTwo, IdleSpamThree, IdleSpamFour", ", ")
   For i = 0 To UBound(bots)
      If bots(i) = myUsername Then
         If i = 0 Then i = UBound(bots) + 1
         followBot = bots(i - 1)
         Exit For
      End If
   Next
  
   AddChat vbCyan, "I am following bot [" & followBot & "]"
End Sub

Sub Event_UserTalk(Username, Flags, Message, Ping)
  
   If Username = followBot Then
      If GetVirtualQueueSize() > 0 Then
         msg = FirstVirtualMessageAndDelete()
         REM AddChat vbMagenta, followBot & " SPEAKED! - " & msg
         AddQ msg, , "SplitQueue"
      End If
   End If
End Sub

Sub Event_UserEmote(Username, Flags, Message)
  
   If Username = followBot Then
      If GetVirtualQueueSize() > 0 Then
         msg = FirstVirtualMessageAndDelete()
         REM AddChat vbMagenta, followBot & " SPEAKED! - " & msg
         AddQ msg, , "SplitQueue"
      End If
   End If
End Sub

Sub Event_MessageQueued(MessageID, Message, Tag)
  
   If Left(Message, 1) = "/" And Not Left(Message, 4) = "/me " Then Exit Sub
  
   If (GetVirtualQueueSize() > 0 Or Queue.Count > 1) And Not Tag = "SplitQueue" Then
      Queue.RemoveItemByID(MessageID)
      AddToVirtualQueue(Message)
   End If
End Sub

Sub AddToVirtualQueue(msg)

   Set f = FSO.OpenTextFile("queue.txt", 8, True)
   f.WriteLine msg
   f.Close
End Sub

Function GetVirtualQueueSize()
  
   Set f = FSO.OpenTextFile("queue.txt", 1, True)
   Do While Not f.AtEndOfStream
      l = f.ReadLine
      GetVirtualQueueSize = GetVirtualQueueSize + 1
   Loop
   f.Close
End Function

Function FirstVirtualMessageAndDelete() ' // also known as "pop" :D
  
   Set f = FSO.OpenTextFile("queue.txt", 1, True)
   msgs = Split(f.ReadAll, vbCrLf)
   f.Close
  
   Set f = FSO.OpenTextFile("queue.txt", 2, True)
   For i = 1 To UBound(msgs)
      If msgs(i) <> "" Then f.WriteLine msgs(i)
   Next
   f.Close
  
   FirstVirtualMessageAndDelete = msgs(0)
End Function
AbsoluteMSTR
Jack, your new one is better, fixes a lot of my problems

What about /cq and /scq?
AwaKening
Added scq and cq functionality

CODE


Private FSO
Private followBot

Sub Data()
  
   Script("Name") = "SplitQueue"
   Script("Author") = "Jack"
   Script("Major") = 0           ' script major version
   Script("Minor") = 1           ' script minor version
   Script("Revision") = 1        ' script version revision
End Sub

Sub Event_Load()
  
   Set FSO = CreateObject("Scripting.FileSystemObject")
   bots = Split("IdleBoT, IdleSpamOne, IdleSpamTwo, IdleSpamThree, IdleSpamFour", ", ")
   For i = 0 To UBound(bots)
      If bots(i) = BotVars.Username Then
         If i = 0 Then i = UBound(bots) + 1
         followBot = bots(i - 1)
         Exit For
      End If
   Next
  
   AddChat vbCyan, "I am following bot [" & followBot & "]"
End Sub

Sub Event_PressedEnter(Text)
   If Text = "/cq" OR Text = "/scq" Then
         ClearVirtualQueue
   End If
End Sub

Sub Event_UserEmote(Username, Flags, Message)
   Event_UserTalk Username, Flags, Message, 0
End Sub

Sub Event_UserTalk(Username, Flags, Message, Ping)
  
   If Username = followBot Then
      If GetVirtualQueueSize() > 0 Then
         msg = FirstVirtualMessageAndDelete()
         REM AddChat vbMagenta, followBot & " SPEAKED! - " & msg
         AddQ msg, , "SplitQueue"
      End If
   ElseIf Message = BotVars.Trigger& "cq" OR Message = BotVars.Trigger& "scq" Then
          If HasAccess(Username, "cq") Then
                 ClearVirtualQueue
          End If
   End If
End Sub

Sub Event_MessageQueued(MessageID, Message, Tag)
  
   If Left(Message, 1) = "/" And Not Left(Message, 4) = "/me " Then Exit Sub
  
   If (GetVirtualQueueSize() > 0 Or Queue.Count > 1) And Not Tag = "SplitQueue" Then
      Queue.RemoveItemByID(MessageID)
      AddToVirtualQueue(Message)
   End If
End Sub

Sub ClearVirtualQueue()
   Set f = FSO.OpenTextFile("queue.txt", 2, True)
   f.Close
   Set f = Nothing
End Sub

Sub AddToVirtualQueue(msg)

   Set f = FSO.OpenTextFile("queue.txt", 8, True)
   f.WriteLine msg
   f.Close
End Sub

Function GetVirtualQueueSize()
  
   Set f = FSO.OpenTextFile("queue.txt", 1, True)
   Do While Not f.AtEndOfStream
      l = f.ReadLine
      GetVirtualQueueSize = GetVirtualQueueSize + 1
   Loop
   f.Close
End Function

Function FirstVirtualMessageAndDelete() ' // also known as "pop" :D
  
   Set f = FSO.OpenTextFile("queue.txt", 1, True)
   msgs = Split(f.ReadAll, vbCrLf)
   f.Close
  
   Set f = FSO.OpenTextFile("queue.txt", 2, True)
   For i = 1 To UBound(msgs)
      If msgs(i) <> "" Then f.WriteLine msgs(i)
   Next
   f.Close
  
   FirstVirtualMessageAndDelete = msgs(0)
End Function


I realized though, there are a few bugs with this script.

What if one of the bots is offline. Needs to be a check. One bot missing a queue will throw it all off.
Jack
QUOTE(AwaKening @ Mar 28 2009, 09:09 PM) *


I realized though, there are a few bugs with this script.

What if one of the bots is offline. Needs to be a check. One bot missing a queue will throw it all off.


Same with the other one... it's your job to check. I guess one day I'll make it so it auto recognizes the bots.
Pyro
QUOTE(AwaKening @ Mar 28 2009, 10:09 PM) *
Added scq and cq functionality

You could've done the checking for those commands a little better.

CODE
Set cmd = IsCommand(Message)
If cmd.Name = "cq" Or cmd.Name = "scq" Then
    If HasAccess(Username, cmd.Name, cmd.Args) Then
        'do code...
    End If
End If
Set cmd = Nothing
AwaKening
QUOTE(PyroManiac @ Mar 28 2009, 08:22 PM) *

QUOTE(AwaKening @ Mar 28 2009, 10:09 PM) *
Added scq and cq functionality

You could've done the checking for those commands a little better.

CODE
Set cmd = IsCommand(Message)
If cmd.Name = "cq" Or cmd.Name = "scq" Then
    If HasAccess(Username, cmd.Name, cmd.Args) Then
        'do code...
    End If
End If
Set cmd = Nothing



How's that better? Seems like extra unnecessary steps.
Eric
QUOTE(AwaKening @ Mar 29 2009, 11:47 AM) *

QUOTE(PyroManiac @ Mar 28 2009, 08:22 PM) *

QUOTE(AwaKening @ Mar 28 2009, 10:09 PM) *
Added scq and cq functionality

You could've done the checking for those commands a little better.

CODE
Set cmd = IsCommand(Message)
If cmd.Name = "cq" Or cmd.Name = "scq" Then
    If HasAccess(Username, cmd.Name, cmd.Args) Then
        'do code...
    End If
End If
Set cmd = Nothing



How's that better? Seems like extra unnecessary steps.

While I wouldn't necessarily advocate IsCommand() in it's present stance, without it, you ignore several different trigger types and features:

ops:
ops,
all:
all,
username:
username,
& sometimes: ?, !

Your check also ignores multiple commands in a single string (i.e., when using "; "), ignores enabled/disabled command statuses, and won't adapt to changes in trigger types without recoding.
AwaKening
The multiple command string I get; although I've never checked for multiple commands in any of my scripts.

The first thing you mentioned though seems irrelevant to this particular command, but thanks for at least showing me how it works.

Edit: Removed all the updated code i posted because Jack cries that I "improved" his code.

@Jack, your code works with bots that run scripts using no padqueues and no whispers. Also assuming that all of your bots are always in the same channel with no chance of getting disconnected because then the queue will just back up and never be fixed unless you clear it and restart. Your code is basically shit. I made it better, but keep thinking otherwise because I don't give a shit.
Snap
#1. You guys totally hijacked my topic.

#2. DQD while basically employing this 'shared' concept - works a lot different. - And doesn't have the potential to 'break' like Jacks does (bot leaves the channel, disconnects etc)

#3. @Awakening - In the future I would recommend doing "Edited by Awakening" - or in the version description "Awakenings edit". - Rather than "By [user] AND Awakening".

#4. I don't have multiple non-SC keys - so until I can work around lockdown - I can't really work much on this project. -- But I do plan on releasing what I have soon non-the-less.

#5. Locked; Start your own split queue topic.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2019 Invision Power Services, Inc.