Help - Search - Members - Calendar
Full Version: Custom Commands?
StealthBot.net > StealthBot > Scripting and Plugins > Script Creation Requests
AENEMA
Hello,

It's been a while since I used any chat bots, about 5 years, so bare with me please.

I'm working on setting up a channel for Diablo 2. Its going to be a private dueling community. I want to add a command so that people with enough access can post new games to the bot and so others can get the list of current games that are up. Is this possible?

Please help point me in the right direction. Thanks!
Spiritless
To make sure I understand correctly:

Someone adds a game to a list...
Someone else can view a list of current games...
When a game ends they take the game off the list...

Correct?
AENEMA
QUOTE(Spiritless @ Sep 26 2009, 02:10 AM) *

To make sure I understand correctly:

Someone adds a game to a list...
Someone else can view a list of current games...
When a game ends they take the game off the list...

Correct?


100%

Any ideas?
The-Black-Ninja
Please don't bump. Someone will get to this when they have the time. If no one can, or no one has the time, you're outta luck sad.gif
Fallen-God
How will the bot detect when the game has ended?
I could make it so it is on a timer and/or a gamedel command.
If that's okay then I can make this script.

I have made a script which achieves this, but for some reason it errors in the way described below:

Things that should happen are in green, things that shouldn't are in red


When someone tries to add a game to the list:
QUOTE
<Fallen-God[LcR]> !gameadd hio
<ClanBoT[LcR]> The game [hio] has been added to the game list.

UserTalk Call Error On File> C:\Program Files\StealthBot\plugins\Gamelist.txt
Error Number: 13 Description: Type mismatch

<Fallen-God[LcR]> !gameadd hio
<ClanBoT[LcR]> A game with that name is already on the list.



A similar story with the !gemedel command. It says it has deleted the entry/there is no entry by that name, but it errors when it tries to do anything to the dictionary.

When someone tries to list the games:
QUOTE
<Fallen-God[LcR]> !listgames
UserTalk Call Error On File> C:\Program Files\StealthBot\plugins\Gamelist.txt
Error Number: 13 Description: Type mismatch

Once again; anything to do with the dictionary errors.



If someone could tell me why this happens that'd be great.
Thanks.

Oh, here is the script:
CODE
'GLS
'1.0
'Game List Script:Fallen-God

Private Const gls_Gameadd = "Gameadd"         'Command to add a game to the list
Private Const gls_Gamedel = "Gamedel"         'Command to remove a game to the list
Private Const gls_Gamelist = "Listgames"      'Command to list all of the added games
Private Const glsInterval = 60                'Time (minutes) before a game is removed from the list

Private gls_gameDic                 'Declare dictionary variable
Private gls_GameArr                 'Declare the Gamelist Array
Private gls_Output                  'Declare the bot output for the Gamelist

Sub GLS_Event_Load()
   Set gls_gameDic = CreateObject("Scripting.Dictionary")
End Sub

Sub GLS_Event_Usertalk(Username, Flags, Message, Ping)
   GLS_ProcessInput Username, Message, 1
End Sub

Sub GLS_Event_WhisperFromUser(Username, Flags, Message)
   GLS_ProcessInput Username, Message, 3
End Sub

Sub GLS_ProcessInput(Username, Message, DspId)
   If Left(LCase(Message),Len(gls_Gameadd)+1) = BotVars.Trigger & LCase(gls_Gameadd) Then
      gls_Inputsplit = Split(Message, " ", 2)(1)
      If gls_gameDic.Exists(gls_Inputsplit) Then
         AddQ "A game with that name is already on the list."
         Exit Sub
      End If
      gls_gameDic.Add gls_Inputsplit, Now
      AddQ "The game [" & gls_Inputsplit & "] has been added to the game list."
   End If
  
   If Left(LCase(Message),Len(gls_Gamedel)+1) = BotVars.Trigger & LCase(gls_Gamedel) Then
      gls_Inputsplit = Split(Message, " ", 2)(1)
      If Not gls_gameDic.Exists(gls_Inputsplit) Then
         AddQ "That game does not appear on the list."
         Exit Sub
      End If
      gls_gameDic.Remove(gls_Inputsplit)
      AddQ "The game [" & gls_Inputsplit & "] has been removed from the game list."
   End If
  
   If Left(LCase(Message),gls_Gamelist+1) = BotVars.Trigger & LCase(gls_Gamelist) Then
      gls_Output = "Current games"
      gls_GameArr = gls_gameDic.Keys
      
      If UBound(gls_GameArr) < 0 Then
         AddQ "There are currently no games on the list."
         Exit Sub
      End If
      
      For i = 0 to UBound(gls_GameArr)  
         If DateDiff("n", gls_gameDic.Item(gls_GameArr(i)), Now) > glsInterval Then gls_gameDic.Remove(gls_GameArr(i))
      Next
      
      gls_GameArr = gls_gameDic.Keys
      
      For i = 0 to UBound(gls_GameArr)
         gls_Output = gls_Output & ": Game( " & i+1 & "): " & gls_GameArr(i) & ":"
      Next
      AddQ gls_Output
   End If
End Sub

The-Black-Ninja
Use:
CODE
gls_gameDic.Item(gls_Inputsplit) = Now

Also, don't use brackets in your .Remove stuff:
CODE
gls_gameDic.Remove gls_Inputsplit
In the list games sub, you should be checking if there are any games left AFTER the for loop because that loop is removing games as well.
Fallen-God
Thanks and thanks.
Why can't I use brackets? Because after seeing you use the Dictionary for the anti-spam I read up about it and their examples used brackets.
The-Black-Ninja
You can't use brackets for when you remove an item.
Fallen-God
Still doesn't work.
I think I changed it all right.

CODE
'GLS
'1.0
'Game List Script:Fallen-God

Private Const gls_Gameadd = "Gameadd"         'Command to add a game to the list
Private Const gls_Gamedel = "Gamedel"         'Command to remove a game to the list
Private Const gls_Gamelist = "Listgames"      'Command to list all of the added games
Private Const glsInterval = 60                'Time (minutes) before a game is removed from the list

Private gls_gameDic                 'Declare dictionary variable
Private gls_GameArr                 'Declare the Gamelist Array
Private gls_Output                  'Declare the bot output for the Gamelist

Sub GLS_Event_Load()
   Set gls_gameDic = CreateObject("Scripting.Dictionary")
End Sub

Sub GLS_Event_Usertalk(Username, Flags, Message, Ping)
   GLS_ProcessInput Username, Message, 1
End Sub

Sub GLS_Event_WhisperFromUser(Username, Flags, Message)
   GLS_ProcessInput Username, Message, 3
End Sub

Sub GLS_ProcessInput(Username, Message, DspId)
   If Left(LCase(Message),Len(gls_Gameadd)+1) = BotVars.Trigger & LCase(gls_Gameadd) Then
      gls_Inputsplit = Split(Message, " ", 2)(1)
      If gls_gameDic.Exists(gls_Inputsplit) Then
         AddQ "A game with that name is already on the list."
         Exit Sub
      End If
      gls_gameDic.Item(gls_Inputsplit) = Now
      AddQ "The game [" & gls_Inputsplit & "] has been added to the game list."
   End If
  
   If Left(LCase(Message),Len(gls_Gamedel)+1) = BotVars.Trigger & LCase(gls_Gamedel) Then
      gls_Inputsplit = Split(Message, " ", 2)(1)
      If Not gls_gameDic.Exists(gls_Inputsplit) Then
         AddQ "That game does not appear on the list."
         Exit Sub
      End If
      gls_gameDic.Remove gls_Inputsplit
      AddQ "The game [" & gls_Inputsplit & "] has been removed from the game list."
   End If
  
   If Left(LCase(Message),gls_Gamelist+1) = BotVars.Trigger & LCase(gls_Gamelist) Then
      gls_Output = "Current games"
      gls_GameArr = gls_gameDic.Keys
      
      For i = 0 to UBound(gls_GameArr)  
         If DateDiff("n", gls_gameDic.Item(gls_GameArr(i)), Now) > glsInterval Then gls_gameDic.Remove gls_GameArr(i)
      Next
      
      If UBound(gls_GameArr) < 0 Then
         AddQ "There are currently no games on the list."
         Exit Sub
      End If
      
      gls_GameArr = gls_gameDic.Keys
      
      For i = 0 to UBound(gls_GameArr)
         gls_Output = gls_Output & ": Game( " & i+1 & "): " & gls_GameArr(i) & ":"
      Next
      
      AddQ gls_Output
   End If
End Sub
The-Black-Ninja
Is this what you're more/less trying to do?
CODE
'GLS
'1.0
'Game List Script:Fallen-God

Private Const gls_Gameadd = "Gameadd"         'Command to add a game to the list
Private Const gls_Gamedel = "Gamedel"         'Command to remove a game to the list
Private Const gls_Gamelist = "Listgames"      'Command to list all of the added games
Private Const glsInterval = 60                'Time (minutes) before a game is removed from the list

Private gls_gameDic                 'Declare dictionary variable
Private gls_GameArr                 'Declare the Gamelist Array
Private gls_Output                  'Declare the bot output for the Gamelist

Sub GLS_Event_Load()
   Set gls_gameDic = CreateObject("Scripting.Dictionary")
End Sub

Sub GLS_Event_Usertalk(Username, Flags, Message, Ping)
   GLS_ProcessInput Username, Message, 1
End Sub

Sub GLS_Event_WhisperFromUser(Username, Flags, Message)
   GLS_ProcessInput Username, Message, 3
End Sub

Sub GLS_Event_PressedEnter(Text)
   GLS_ProcessInput BotVars.Username, Text, 4
End Sub

Sub GLS_ProcessInput(Username, Message, DspId)

   If dspId = 4 Then
      If Left(Message, 1) <> "/" Then Exit Sub
   Else
      If Left(LCase(Message), Len(BotVars.Trigger)) <> BotVars.Trigger Then Exit Sub
   End If
  
   msg = Mid(Message, Len(BotVars.Trigger)+1)
   cmd = Split(Lcase(msg))(0)
    
   If cmd = LCase(gls_Gameadd) Then
      gls_Inputsplit = Split(msg, " ", 2)(1)
      If gls_gameDic.Exists(gls_Inputsplit) Then
         AddQ "A game with that name is already on the list."
         Exit Sub
      End If
      gls_gameDic.Item(gls_Inputsplit) = Now
      AddQ "The game [" & gls_Inputsplit & "] has been added to the game list."
   End If
  
   If cmd = LCase(gls_Gamedel) Then
      gls_Inputsplit = Split(msg, " ", 2)(1)
      If Not gls_gameDic.Exists(gls_Inputsplit) Then
         AddQ "That game does not appear on the list."
         Exit Sub
      End If
      gls_gameDic.Remove gls_Inputsplit
      AddQ "The game [" & gls_Inputsplit & "] has been removed from the game list."
   End If
  
   If cmd = LCase(gls_Gamelist) Then
      gls_Output = "Current games: "
      gls_GameArr = gls_gameDic.Keys
            
      If UBound(gls_GameArr) < 0 Then
         AddQ "There are currently no games on the list."
         Exit Sub
      End If      
      
      For i = 0 to UBound(gls_GameArr)
         If DateDiff("n", gls_gameDic.Item(gls_GameArr(i)), Now) > glsInterval Then
            gls_gameDic.Remove gls_GameArr(i)
         Else
            text = text & "Game(" & i+1 & "): " & gls_GameArr(i) & ":"
         End If
      Next
        
      If text <> vbNullString Then
         AddQ gls_Output & Left(text, Len(text) -1)
      Else
         AddQ "There are currently no games on the list."
      End If
   End If
End Sub
AENEMA
Thanks for the help guys! I'll have to give the script a try tomorrow. Been a long day. Sorry for the bump! wasn't sure if there was a bump rule or not.

I appreciate all the help guys. Awesome.
Fallen-God
Thanks Ninja.
I have edited the script to do the following commands (names can be changed):

!gameadd <Name> Add a game with <Name>

!gamedel <Name/Number> - Delete a game by name or by game number

!getgame <Number/Name> - Returns the name of the game and the amount of time passed since the game was added to the script (to the nearest minute)

!listgames - Lists the names and numbers of all games

!clearlist - Clears the whole list of games.


I have also change it to have 3 access requirements:
Access to view games
Access to add games
Access to delete games

If you want I will also change it to record the maker of the game, but I will wait to see if you actually want this before I go ahead.

Oh and also I have changed the AddQ's to Dsp DspIds so it supports effectively adding/deleting/viewing games view whisper.
(It did this before but people not in the channel would not be able to see the reply)
Neco
Any chance of someone adapting this script for Warcraft III? Or will it work already?
The-Black-Ninja
What I posted will work for WC3 as is.
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-2014 Invision Power Services, Inc.