User Control Panel
Advertisements

HELP US, HELP YOU!

VB Bot

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Visual Basic
View unanswered posts
Author Message
TrUz
Newbie
Newbie


Joined: 24 Sep 2005
Posts: 14
Location: Peterborough, UK
Reputation: 13.6

PostPosted: Sun Oct 02, 2005 9:14 am    Post subject: VB Bot Reply with quote

This a slight adjustment to Riot's bot tutorial. I have amended it so it looks to a text file for it's replies.

You can also set the bot status with commands.

Ok so on your main form add this code:

Code:

Option Explicit

Public WithEvents msn As MsgrObject
Dim lp As Integer

Private Sub msn_OnTextReceived(ByVal pIMSession As Messenger.IMsgrIMSession, ByVal User As Messenger.IMsgrUser, ByVal bstrMsgHeader As String, ByVal bstrMsgText As String, pfEnableDefault As Boolean)

    If bstrMsgText = "!setaway" Then
        msn.LocalState = MSTATE_AWAY
    ElseIf bstrMsgText = "!setbusy" Then
        msn.LocalState = MSTATE_BUSY
    ElseIf bstrMsgText = "!setonline" Then
        msn.LocalState = MSTATE_ONLINE
    ElseIf bstrMsgText = "!setonphone" Then
        msn.LocalState = MISTATUS_ON_THE_PHONE
    ElseIf bstrMsgText = "!setoutlunch" Then
        msn.LocalState = MISTATUS_OUT_TO_LUNCH
    ElseIf bstrMsgText = "!setbrb" Then
        msn.LocalState = MISTATUS_BE_RIGHT_BACK
    End If
   
    For lp = 1 To NoInputs
        If bstrMsgText = MSNInput(lp) Then
            User.SendText bstrMsgHeader, MSNOutput(lp), MMSGTYPE_ALL_RESULTS
        End If
    Next lp

End Sub

Private Sub Form_Load()

    Set msn = New MsgrObject

    Open "C:\Replies.txt" For Input As #1
        If Not EOF(1) Then
            FileIn = Input(LOF(1), #1)
        End If
    Close #1

    IOMode = "Input"
    NoInputs = 0
    NoOutputs = 0
    LastLine = 0

    For lp = 1 To Len(FileIn)
        If Mid(FileIn, lp, 1) = "|" And IOMode = "Input" Then
            NoInputs = NoInputs + 1
            ReDim Preserve MSNInput(1 To NoInputs)
            MSNInput(NoInputs) = Mid(FileIn, LastLine + 1, lp - LastLine - 1)
            LastLine = lp
        End If
        If Mid(FileIn, lp, 1) = "|" And IOMode = "Output" Then
            NoOutputs = NoOutputs + 1
            ReDim Preserve MSNOutput(1 To NoOutputs)
            MSNOutput(NoOutputs) = Mid(FileIn, LastLine + 1, lp - LastLine - 1)
            LastLine = lp
        End If
        If Mid(FileIn, lp, 1) = "#" Then
            IOMode = "Output"
            NoInputs = NoInputs + 1
            ReDim Preserve MSNInput(1 To NoInputs)
            MSNInput(NoInputs) = Mid(FileIn, LastLine + 1, lp - LastLine - 1)
            LastLine = lp
        End If
        If Mid(FileIn, lp, 1) = Chr(13) Then
            NoOutputs = NoOutputs + 1
            ReDim Preserve MSNOutput(1 To NoOutputs)
            MSNOutput(NoOutputs) = Mid(FileIn, LastLine + 1, lp - LastLine)
            IOMode = "Input"
            LastLine = lp + 1
        End If
        If lp = Len(FileIn) Then
            NoOutputs = NoOutputs + 1
            ReDim Preserve MSNOutput(1 To NoOutputs)
            MSNOutput(NoOutputs) = Mid(FileIn, LastLine + 1, lp - LastLine)
        End If
    Next lp

End Sub


Now on a module add this code:

Code:

Option Explicit

Public MSNInput() As String
Public MSNOutput() As String
Public IOMode As String
Public LastLine As Integer
Public NoInputs As Integer
Public NoOutputs As Integer
Public FileIn As String


Now create a text file on your C drive call Replies.txt

The replies file works like this:

how are you#I am fine yourself?
hello#Hello there!

You cannot use the | (pipe) to create a random reply, I am unsure of how to do this. If you know then you can add this code yourself, even let us know here so I can add it to mine! Smile

Many Thanks,

TrUz
Back to top
trotter
Newbie
Newbie


Joined: 09 Oct 2005
Posts: 6

Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1

PostPosted: Sun Oct 09, 2005 1:22 pm    Post subject: Reply with quote

Hi, i have change the way to look in a txt file (i think it's more simple, see below)

And now you can use the pipe to create a random reply :]

In addition, it convert the words in lower case.
Here it is :
(you must have a file named replies.txt in the program path)

Code:
Option Explicit
Public WithEvents msn As MsgrObject
Dim test As Integer
Private Sub Form_Load()
Set msn = New MsgrObject
End Sub

Private Sub msn_OnTextReceived(ByVal pIMSession As Messenger.IMsgrIMSession, ByVal User As Messenger.IMsgrUser, ByVal bstrMsgHeader As String, ByVal Usersay As String, pfEnableDefault As Boolean)
Dim replystring As String
Dim question() As String
Dim replies() As String
Dim nbrrep As Integer
Dim randomnbr As Integer
'convert in lower case
Usersay = LCase(Usersay)
'open file
Open App.Path & "\Replies.txt" For Input As #1
Do Until EOF(1) 'do until the file end
'read line and put in reply string
Line Input #1, replystring
question = Split(replystring, "#")
'test if There is Usersay in question
test = InStr(Usersay, question(0))
If test > 0 Then
  'get the number of "|" (=replies) after #
replies = Split(question(1), "|")
nbrrep = UBound(replies)
  'make a random number between 0 to nbrrep
Randomize
randomnbr = Int(Rnd() * (nbrrep - 0 + 1)) + 0
  'replie with the random number
User.SendText bstrMsgHeader, replies(randomnbr), MMSGTYPE_ALL_RESULTS
End If
Loop
Close #1
End Sub


replies.txt exemple :

Code:

hello#hi|hello|hey !|Hi|hi there
bye#c u|Bye|You already leave me ?


This is just an exemple, to show the basics (i'll maybe post a complete .exe later).
Maybe it looks like a "beginner work" for u : it is. Smile

(and thanks a lot to Riot :p)


Last edited by trotter on Sun Oct 09, 2005 1:49 pm; edited 1 time in total
Back to top
trotter
Newbie
Newbie


Joined: 09 Oct 2005
Posts: 6

Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1

PostPosted: Sun Oct 09, 2005 1:43 pm    Post subject: Reply with quote

I forgot to say that this code check if *one part* of the sentence match with the Replies.txt

For instance :
Code:
hello#hi|hello|hey !|Hi|hi there
means that the bot will reply at "hello" "hello there" and "rgthtrehellorger".

:]
Back to top
TrUz
Newbie
Newbie


Joined: 24 Sep 2005
Posts: 14
Location: Peterborough, UK
Reputation: 13.6

PostPosted: Tue Oct 11, 2005 9:25 pm    Post subject: Reply with quote

Nice one, I will have a play about with that. Smile
Back to top
Database
Newbie
Newbie


Joined: 28 Oct 2005
Posts: 1

Reputation: 6.4Reputation: 6.4Reputation: 6.4Reputation: 6.4Reputation: 6.4Reputation: 6.4

PostPosted: Fri Oct 28, 2005 6:24 pm    Post subject: Reply with quote

Visual Basic 6.0 working model feedback: user defined type not defined
Back to top
zero_kool
Newbie
Newbie


Joined: 17 Feb 2005
Posts: 6

Reputation: 14.9

PostPosted: Mon Nov 07, 2005 6:19 am    Post subject: ? Reply with quote

hmm not working at all
Back to top
trotter
Newbie
Newbie


Joined: 09 Oct 2005
Posts: 6

Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1Reputation: 7.1

PostPosted: Tue Dec 20, 2005 12:56 am    Post subject: Reply with quote

Database wrote:
Visual Basic 6.0 working model feedback: user defined type not defined


You don't have the reference :
OLE automation
Messenger type library
Messenger API type library
Messenger AddIns type library
Messenger Private type library

See Riot's tutorial :
http://bot-depot.com/phpBB2/viewtopic.php?t=2022
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Tue Dec 20, 2005 5:54 pm    Post subject: Reply with quote

If anyone has a working VB Bot that you'd like to release, Botworld currently doesn't have any. Feel free to post it there.
_________________
Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Visual Basic All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group