• January 27, 2023, 10:32:09 pm

Author Topic: Bot Idle  (Read 3445 times)

LosT

  • Jr. Member
  • ***
  • Posts: 36
Bot Idle
« on: November 09, 2009, 04:12:25 am »
Okay, My first attempt ever at an idle script, Doesn't work correctly, Can anyone help me out with it?

tmrIdle's interval is set to 1000

Code: (vb) [Select]
Private Sub tmrIdle_Timer()
If GetINI(ProfileToLoad, "EnableIdle", vbNullString, App.Path & "\Profiles.ini") = "1" Then
    If (GetTickCount - IdleTime) = GetINI(ProfileToLoad, "IdleInterval", vbNullString, App.Path & "\Profiles.ini") * 60000 Then
        Select Case GetINI(ProfileToLoad, "IdleType", vbNullString, App.Path & "\Profiles.ini")
            Case "Msg"
                If Len(GetINI(ProfileToLoad, "IdleMsg", vbNullString, App.Path & "\Profiles.ini")) >= 255 Then
                    AddChat vbRed, "Your idle message is too long. Please shorten it by ", vbWhite, Len(GetINI(ProfileToLoad, "IdleMsg", vbNullString, App.Path & "\Profiles.ini")) / 255, vbRed, " character(s)."
                    IdleTime = GetTickCount()
                    Exit Sub
                Else
                    Connection.s0x0E GetINI(ProfileToLoad, "IdleMsg", vbNullString, App.Path & "\Profiles.ini")
                    IdleTime = GetTickCount()
                End If
            Case "Mp3"
                Connection.s0x0E "/me [Winamp] " & modWinamp.GetSong & " - KrewBot " & App.Major & "." & App.Minor & "." & App.Revision
                IdleTime = GetTickCount()
            Case "Version"
                Connection.s0x0E "/me KrewBot " & App.Major & "." & App.Minor & "." & App.Revision
                IdleTime = GetTickCount()
        End Select
    End If
ElseIf GetINI(ProfileToLoad, "EnableIdle", vbNullString, App.Path & "\Profiles.ini") <> "1" Then
    tmrIdle.Enabled = False
End If
End Sub
« Last Edit: November 20, 2009, 04:57:33 am by Scope »
"A man's dreams are an index to his greatness."

LosT

  • Jr. Member
  • ***
  • Posts: 36
Re: Bot Idle
« Reply #1 on: November 09, 2009, 05:49:21 am »
Thanks to Tristan I now have my idles working.

Here's the Code I used for anyone else who may have the same problem.

Code: (vb) [Select]
Private Sub tmrIdle_Timer()
If GetINI(ProfileToLoad, "EnableIdle", vbNullString, App.Path & "\Profiles.ini") = "1" And IsConnected = True Then
    Dim i As Integer
    For i = 0 To GetINI(ProfileToLoad, "IdleInterval", vbNullString, App.Path & "\Profiles.ini")
        IdleTriggers = IdleTriggers + 1
        If IdleTriggers > GetINI(ProfileToLoad, "IdleInterval", vbNullString, App.Path & "\Profiles.ini") Then
            IdleTriggers = 1
        End If
    Next i
    If IdleTriggers = GetINI(ProfileToLoad, "IdleInterval", vbNullString, App.Path & "\Profiles.ini") Then
        Select Case GetINI(ProfileToLoad, "IdleType", vbNullString, App.Path & "\Profiles.ini")
                Case "Msg"
                    If Len(GetINI(ProfileToLoad, "IdleMsg", vbNullString, App.Path & "\Profiles.ini")) >= 255 Then
                        AddChat vbRed, "Your idle message is too long. Please shorten it by ", vbWhite, Len(GetINI(ProfileToLoad, "IdleMsg", vbNullString, App.Path & "\Profiles.ini")) / 255, vbRed, " character(s)."
                        IdleTriggers = 1
                        Exit Sub
                    Else
                        Connection.s0x0E GetINI(ProfileToLoad, "IdleMsg", vbNullString, App.Path & "\Profiles.ini")
                        IdleTriggers = 1
                    End If
                Case "Mp3"
                    Connection.s0x0E "/me [Winamp] " & modWinamp.GetSong & " - KrewBot " & App.Major & "." & App.Minor & "." & App.Revision
                    IdleTriggers = 1
                Case "Version"
                    Connection.s0x0E "/me KrewBot " & App.Major & "." & App.Minor & "." & App.Revision
                    IdleTriggers = 1
            End Select
    End If
End If
End Sub

tmrIdle's Interval is set to 60,000 (One Minute)
« Last Edit: November 20, 2009, 04:57:54 am by Scope »
"A man's dreams are an index to his greatness."

pikachu

  • Administrator
  • Hero Member
  • *******
  • Posts: 3,344
Re: Bot Idle
« Reply #2 on: November 09, 2009, 01:28:29 pm »
Quick VB6 tip: don't ever use timer controls.  Actually, don't use the MSWINSCK control either.  While we're at it...just stop using VB6.  The language is dead; it takes about 10 minutes to learn VB.NET.

l2k-Shadow

  • l2k-Shadow
  • Hero Member
  • *******
  • Posts: 1,058
Re: Bot Idle
« Reply #3 on: November 10, 2009, 07:59:12 pm »
Don't use .NET, use C++.
/)  /)
( -.- )
o_(")(")
This is Bunny. Copy and paste Bunny into your signature to help him gain world domination

MyStiCaL

  • Guest
Re: Bot Idle
« Reply #4 on: November 11, 2009, 09:34:54 pm »
why is there criticism about a language in a board specified language?

Zach

  • Addict
  • *****
  • Posts: 206
  • Cell@all
Re: Bot Idle
« Reply #5 on: September 18, 2010, 05:09:49 am »
what api did you use for winamp i havnt found any publicly released for winamp 5
God my danm sig removed and cant find the link so THIS WILL DO FOR NOW

ben_fb

  • Addict
  • *****
  • Posts: 246
Re: Bot Idle
« Reply #6 on: September 19, 2010, 12:00:50 pm »
I have a few questions about your code LosT.

It looks like you are only using one profile, yet you have a loop, why I'm unsure? If you are using more than one profile I see a problem in your code where it would likely only idle for the last profile.

Another thing you should know is that the max length of a send is not 255 characters, but 220. That is unless battleNet fluctuates the max value you are allowed to send. It probably has something to correspond with packet size in general, I have not tested it. Rather than block long sends you should chop it to multiple sends. Here is one way of doing such a thing...
Code: [Select]
Private Sub chopQueue(ByRef theText As String)
Dim textPrefix As String

 'AWhisper = "/w "
 'ASpace = " "
    If AscW(theText) = 47 Then '47 /
        If Len(theText) > 4 And Left$(LCase$(theText), 3) = AWhisper Then
            textPrefix = Left$(theText, InStr(4, theText, ASpace))
            'set prefix
            theText = Mid$(theText, (Len(textPrefix) + 1))
            'cuts past the prefix
        End If
        'if string is longer than 4 chars and is a whisper store the /w name  part
    'if left is a /
    End If
     
    Do Until LenB(theText) = 0
        Add_to_Queue textPrefix & Left$(theText, (220 - Len(textPrefix)))
        'queues item
        theText = Mid$(theText, (221 - Len(textPrefix)))
        'parses next
    Loop
    'add to queue
 
End Sub
'makes sure they dont send really long strings
You could add other checks for Emotes and such but I've only found this occur in whispers.


Zach: I'm not sure if the old winamp api works for controlling winamp 5, but if you are unaware you can get the song merely by reading the winamp caption. This is pulled from my project slightly altered...works with iTunes and winamp, but it cant compile without itunes being installed unless you remove that portion of the code.

Code: [Select]
'declares
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Const WM_USER As Long = &H400
Private Const IPC_UPDTITLE As Long = &HF3
'for mp3 idle


Public Sub GetSong(ByRef Index As Integer, ByRef echoCommand As Boolean)
Dim iTunes_hWnd As Long, theSong As String
Dim Winamp_hWnd As Long
       
    iTunes_hWnd = FindWindow("iTunes", vbNullString)
    Winamp_hWnd = FindWindow("Winamp v1.x", vbNullString)
    If Winamp_hWnd = 0 And iTunes_hWnd = 0 Then Exit Sub
    'if 0 then winamp isnt open
    If Winamp_hWnd <> 0 Then
    'if winamp
        SendMessage Winamp_hWnd, WM_USER, 0, IPC_UPDTITLE
        'i believe this forces winamp to update its title
        'not sure if it actually works
        Dim windowText As String
        windowText = Space(256)
        GetWindowText Winamp_hWnd, windowText, 256 'len txt
        'get window caption
        windowText = Left(windowText, InStr(windowText, vbNullChar) - 1)
        If LenB(windowText) = 0 Or InStrB(windowText, " - Winamp") = 0 Then Exit Sub
        'winamp is open but no songs are selected
        theSong = windowText
        GoTo GetSong_End
    End If
    If iTunes_hWnd <> 0 Then
    'if itunes
        Set iTunes = New iTunesApp
        Dim Track As IITTrack
        '
        Set Track = iTunes.CurrentTrack
        If Track Is Nothing Then
            Set iTunes = Nothing
            Exit Sub
        End If
        'exit if nothign is playing
        theSong = Track.Index & ". " & Track.Artist & " - " & Track.Name & " - iTunes"
        GoTo GetSong_End
    End If
   
GetSong_End:

    Set iTunes = Nothing
    'unset
    QueueString theSong
   
End Sub



Also I mostly agree with Aknaip. Don't use Timer controls, use settimer api. However, I still use winsock controls because winsock api in vb6 tends to be problematic and some times can cause stability issues. I also agree that if you are starting a new bot to scrap it and switch to vbNet.  NET is very similar but way more efficient and flexible. As far as some suggesting CPP I would have to suggest against it. Unless you have a lot of spare time, a large sum of patience, and are doing something so amazingly complex its ridiculous you do not need to know CPP. You can accomplish almost anything you will ever need to do in the world of today with NET.

PS: I think it's funny every time someone post their routine used to grab INI information it has the same name as the one I wrote countless years ago (well to be fair I just ported information from api-guide).

PSS: Just noticed the original post date, someone bumped it before me so this information is probably no longer needed. Oh well.
« Last Edit: September 19, 2010, 12:12:35 pm by ben_fb »

Tagban

  • Aces Charles.. Aces.
  • Administrator
  • Addict
  • *******
  • Posts: 157
  • BNET.cc // Clan BNU@USEast
    • BNET.cc
Re: Bot Idle
« Reply #7 on: September 19, 2010, 06:57:39 pm »
Ben is correct, Winamp 5 works the same as old winamp API, so all your older code will still work. But winamp sucks, Im trying to figure out how to control iTunes from my bot. :)
BNET.cc .. Mothers.. Lock up your daughters!

ɥǝnяʎ ıן

  • Super Moderator
  • Hero Member
  • ******
  • Posts: 1,456
Re: Bot Idle
« Reply #8 on: September 19, 2010, 09:47:45 pm »
iTunes sucks unless you're on Mac or a good computer, use foobar

Edit: ask chriso how to work winamp n itunes
Quote
[09:39:13 PM] «[].[].[].[].@USEast» Do you know what the best letters of the alphabet are?
[09:39:21 PM] «DeCi@USEast» h e n r y

ben_fb

  • Addict
  • *****
  • Posts: 246
Re: Bot Idle
« Reply #9 on: September 20, 2010, 10:08:19 am »
Ben is correct, Winamp 5 works the same as old winamp API, so all your older code will still work. But winamp sucks, Im trying to figure out how to control iTunes from my bot. :)

Controlling iTunes is very easy, 20 times easier than winamp. You just set a variable like I did...
Code: [Select]
Set iTunes = New iTunesApp and then use iTunes. to control. Eg: iTunes.Pause, iTunes.Play, iTunes.Next. SIMPLE!  :)

PS: You have to reference iTunes in your project. Do so by selecting the "Project" menu, then "References" and checking (I believe) "iTunes 1.13 Type Library"


And iTunes is not suck! There may be better but itunes is definitely preferred over winamp, I hate winamp.
« Last Edit: September 20, 2010, 10:16:34 am by ben_fb »

Mike

  • Asgard Developer
  • Addict
  • *****
  • Posts: 140
    • mikeownage.com
Re: Bot Idle
« Reply #10 on: October 07, 2010, 10:09:45 am »
Checking the INI file every time the timer ticks is just bad -.-

 

newBalance by DzinerStudio