StealthBot.net: Resolved: How do you create databases? - StealthBot.net

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Resolved: How do you create databases? And read them, and pull information off of them...

#1 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 01, 2010 - 09:46 PM

Basically, I'm thinking about writing a script but there's a few things I need to know before I can start:

First off, how do I make a script create a database, be able to open and read it, and perform commands based off whats in the database (Kind of like the CRS members database)

Poking through the CRS script didn't really give me any information that helped me much, and searching didn't yield any results that I could find.

Ideally, I'd be able to type in a command with a few arguments that would place the given arguments into the file.

I.E:

[command Word1 Word2 Word3

Then it's saved in the database with those three words.

Also, is there a way to have it write to a .txt file in a way that's readable and editable by notepad?

#2 User is offline   Shnougle Icon

  • The Other King of TBR
  • PipPipPip
  • Group: Members
  • Posts: 107
  • Joined: September-13 09

Posted March 01, 2010 - 09:55 PM

Well you can very easily write info to a text file or an ini file. It just depends on what information will be stored, how much of it, and how it will be read. If you just want to type the command and have it store a line in a text file:

Sub Event_Load()
FileName = "Whatever you want your filename to be.txt"
End Sub

Sub Event_Usertalk(Username, Flags, Message, Ping)
If Left(Message, Len(Split(Message)(0))) = "whatever" '\\Your command
X = Split(Message, Split(Message)(0) & " ")(1) '\\What will be written to the file.
Set fso = CreateObject("Scripting.FileSystemObject") 
Set File = FSO.OpenTextFile(BotPath & FileName, 8, True) '\\Open The text file so that you can write to it.
File.WriteLine X        '\\Write to the file
AddQ X & " has been written to " & FileName
File.Close  '\\Close the file
End if
End Sub


That would write whatever you said into the text file as a new line which could be read using the .ReadLine method. But this is a super simple way of doing it. If you outline more of what your trying to do maybe i can give you a better example.

This post has been edited by Shnougle: March 01, 2010 - 10:01 PM

Posted Image

TBR Official Website
Visit us at Channel 'Clan TBR' on USWest, USEast, or Europe.

#3 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 01, 2010 - 10:01 PM

Use the FSO, File System Object
-Tuck

#4 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted March 01, 2010 - 10:43 PM

What specifically were you looking for in the CRS that you weren't able to find? I could write you a very basic template where it creates the db if it isn't there, automatically adds an entry, then reads that entry back to you on event_load.

#5 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 01, 2010 - 11:03 PM

In the CRS script, basically I was looking for a line that would say something about writing to or reading a file (Other than writing to or reading from settings) that would clue me in on how to do it myself. That strategy worked with quite a few things, but not in this instance.

I was aiming to set up a personal list of known hackers and what not that can easily be accessed through my bot, and added to in the same manner. The reason I want it in a text file I can open read and edit, is so I can open the file and use CTRL+F to quickly search through for certain usernames, though if there's a way to get the bot to search it for me that would be a plus.

What i'm looking at so far is 4 variables that I want to use, two of which would be given in the command
The username of whoever is 'reported'
A description (In the form of a string, after the first variable) that gives the offense
The username of the person that added him to the list
And a timestamp of when he was added

P.S. I know I could've just requested this script be done, but I wouldn't learn that way. I'll read through the link Tuck gave. This post was mostly for TBN to get what she asked for.

#6 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 01, 2010 - 11:08 PM

If this is first time your trying to store values, i would suggest using

WriteSettingsEntry EntryName, EntryValue
GetSettingsEntry(EntryName)


would just save/load the values into/from Script.ini

This post has been edited by Tuck: March 01, 2010 - 11:08 PM

-Tuck

#7 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 01, 2010 - 11:37 PM

The WriteSettingsEntry and GetSettingsEntry are one of the things I got from poking through scripts (In particular, the CRS script.) Though, I'm wondering what from my concept can be considered a value that would be put in the scripts.ini file. With what I'm trying to do with the entries, it could easily come to a hundred lines in a couple weeks since I'm using BWHF to find hacks >.>

ALSO: Thanks to the posts here, I might be able to find what I need to find in the CRS script. The problem was that I just didn't know what to look for. We'll see shortly.

#8 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted March 02, 2010 - 12:27 AM

So you don't want me to give you a basic example so you're not looking through hundreds of line of code?

#9 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 12:37 AM

Oh, didn't mean that XD

The basic example would help out alot. I'm still not quit getting whats in the CRS Script. For example:
   crsDatabasePath = BotPath() & "MemberData.mdb"
   Set crsFSO = CreateObject("Scripting.FileSystemObject")
   If Not crsFSO.FileExists(crsDatabasePath) Then
      AddChat 16759296, "Welcome to the Clan Rank Script! You can customize the number and names of existing ranks inside crsClanRankScript.txt"
      AddChat 16759296, "Please note that all changes to the ", vbRed, "NUMBER OF EXISTING RANKS", vbCyan, " should be made ", vbRed, "BEFORE", vbCyan, " you start adding members!"
      AddChat 16759296, "You may customize the access level for each rank inside crsClanRankScript.txt"
      AddChat 10682112, "For help on common CRS questions and issues, visit:"
      AddChat 10682112, "http://www.stealthbot.net/forum/index.php?/topic/368-clan-rank-script-faqs-crs/"
	  AddChat 10682112, "Remember to state that this is the CRS edited by Sierra.Komodo when asking for help"
      crs_create_database '// Create the database
   Else
      crs_connect '// Connect to database
   End If


I don't quite know what the create database and connect ones do and how to get them to do what they do - I can give a guess on the former, but the latter I just can't figure out >.>

#10 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 02, 2010 - 12:43 AM

View PostSierraKomodo, on 02 March 2010 - 01:37 AM, said:

Oh, didn't mean that XD

The basic example would help out alot. I'm still not quit getting whats in the CRS Script. For example:
   crsDatabasePath = BotPath() & "MemberData.mdb"
   Set crsFSO = CreateObject("Scripting.FileSystemObject")
   If Not crsFSO.FileExists(crsDatabasePath) Then
      AddChat 16759296, "Welcome to the Clan Rank Script! You can customize the number and names of existing ranks inside crsClanRankScript.txt"
      AddChat 16759296, "Please note that all changes to the ", vbRed, "NUMBER OF EXISTING RANKS", vbCyan, " should be made ", vbRed, "BEFORE", vbCyan, " you start adding members!"
      AddChat 16759296, "You may customize the access level for each rank inside crsClanRankScript.txt"
      AddChat 10682112, "For help on common CRS questions and issues, visit:"
      AddChat 10682112, "http://www.stealthbot.net/forum/index.php?/topic/368-clan-rank-script-faqs-crs/"
	  AddChat 10682112, "Remember to state that this is the CRS edited by Sierra.Komodo when asking for help"
      crs_create_database '// Create the database
   Else
      crs_connect '// Connect to database
   End If


I don't quite know what the create database and connect ones do and how to get them to do what they do - I can give a guess on the former, but the latter I just can't figure out >.>


Uses FSO (File System Object) to check if the sql database file exists if not it will create it.
-Tuck

#11 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted March 02, 2010 - 12:45 AM

Okay, I'll write you something fast right now.

#12 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 01:00 AM

Alright, thanks. I should go experiment with the code, see what happens if I change something >.>

#13 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted March 02, 2010 - 01:32 AM

On reload, the bot will get reported. On the next reload, the bot will already be in the database, so it will retrieve the comments instead:
Script("Name") = "DBTest"
Script("Major") = 1
Script("Minor") = 4


Public dbConn, dbPath

     
Sub Event_Load()

   
   dbPath = BotPath() & "Data.mdb"
   
   '// Check if file exists with a FSO
   Set dbSO = CreateObject("Scripting.FileSystemObject")
   If NOT dbSO.FileExists(dbPath) Then
      AddChat vbGreen, "Database does not exist at: " & dbPath & " - Creating database"
      Call Create_DB() '// Create the database
   End If
      
   AddChat vbGreen, "Zomg!! Hacker found!"
   Call AddHacker(BotVars.Username, "Hacking n00b!")
End Sub


Public Sub Create_DB()

   '// Create the database using ADOX and a connection string
   Set Catalog = CreateObject("ADOX.Catalog")
   Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & dbPath

   Call DB_Connect()

   '// Create colums and format them for data entry
   dbConn.Execute("CREATE TABLE `users` (`name` varchar(30), `comments` Text)")
   
   dbConn.Close
   Set Catalog = Nothing
End Sub


Public Sub DB_Connect()
   
   Set dbConn = CreateObject("ADODB.connection")
   dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & dbPath
   dbConn.ConnectionString = dsn
   
   dbConn.Open
End Sub


Private Sub AddHacker(name, sComments)

   '// Connect to the database
   Call DB_Connect()
   
   '// Check if the user is in the database. 0 means they aren't in there.
   Set userExists = dbConn.Execute("SELECT COUNT(`name`) FROM `users` WHERE `name` ='" & name & "'")
   If userExists.Fields(0) > 0 Then
      AddChat vbGreen, name & " is already reported as a hacker. Retrieving info..."
      dbConn.Close
      Call GetHackerInfo(name)
   Else
      '// Add user to database. Since the comments colum is mainly accepting text, convert the variable to a string so the ' before the quotations won't error if someone decides to input all numbers.
      dbConn.Execute("INSERT INTO `users` (`name`, `comments`) VALUES ('" & name & "', '" & CStr(sComments) & "')")
      AddChat vbGreen, name & " reported as: " & sComments
   End If
   
   '// Close the connection
   Set userExists = Nothing
   
   '// Check if the connection is still open, if it's not already closed, close it
   If dbConn.State <> 0 Then dbConn.Close
End Sub


Private Sub GetHackerInfo(name)

   Call DB_Connect()
   
   Set userExists = dbConn.Execute("SELECT COUNT(`name`) FROM `users` WHERE `name` ='" & name & "'")
   If userExists.Fields(0) > 0 Then
      Set rs = dbConn.Execute("SELECT COUNT(`comments`) FROM `users` WHERE `name` ='" & name & "'")
      If LenB(rs.Fields(0)) = 0 Then    
         AddChat vbGreen, name & " is reported as a hacker without a reason."
      Else
         AddChat vbGreen, name & " is reported as a hacker with the reason: " & dbConn.Execute("SELECT `comments` FROM `users` WHERE `name` ='" & name & "'").Fields(0)
      End If
   End If
   
   Set userExists = Nothing
   Set rs = Nothing
   If dbConn.State <> 0 Then dbConn.Close
End Sub


#14 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 02, 2010 - 01:39 AM

I actually made something like ninjas example (might help you to)

Script("Name") = "rp"
Script("Author") = "Tuck"
Script("Major") = 1
Script("Minor") = 0
Script("Revision") = 0
Script("Description") = "Report People."

private dbPath, Conn

Sub Event_Load()
    dbPath = BotPath() & "scripts\rp.mdb"
    If (CreateObject("Scripting.FileSystemObject").FileExists(dbPath)) Then
        Call Connect()
    Else
        CreateObject("ADOX.Catalog").Create "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & dbPath
        Call Connect()
        Conn.Execute("Create Table `Data` (`Account` Varchar(25) Not Null, `Reason` Text, `Time` Timestamp Not Null, `Username` Varchar(25) Not Null)")
    End If
    If (OpenCommand("report") Is Nothing) Then
        With CreateCommand("report")
            .RequiredRank = 200
            .Description = "Report <Username> [Reason]"
            .Parameters.Add .NewParameter("Username", False, "Word")
            .Parameters.Add .NewParameter("Reason", False, "String")
            .Save
        End With
    End If
    If (OpenCommand("reports") Is Nothing) Then
        With CreateCommand("reports")
            .RequiredRank = -1
            .Description = "List all reports"
            .Save
        End With
    End If
    If (OpenCommand("delreports") Is Nothing) Then
        With CreateCommand("delreports")
            .RequiredRank = -1
            .Description = "Delete all reports"
            .Save
        End With
    End If
End Sub

Private Sub Connect()
   Set Conn = CreateObject("ADODB.connection")
   Conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & dbPath
   Conn.Open
End Sub

Sub Event_Close()
    On Error Resume Next
    Conn.Close
    Set Conn = Nothing
End Sub

Sub Event_Command(Command)
    If Not (Command.HasAccess And Command.IsValid) Then Exit Sub
    If (Command.IsLocal And Not IsOnline()) Then Command.Username = BotVars.Username
    If LCase(Command.Name) = "report" Then
        If Not LCase(Command.Argument("Username")) = LCase(Command.Username) Then
            Conn.Execute("Insert Into `Data` (`Account`, `Reason`, `Time`, `Username`) Values ('" & Command.Argument("Username") & "', '" & Command.Argument("Reason") & "', '" & Now() & "', '" & Command.Username & "')")
            Command.Respond(Command.Argument("Username") & " has been reported.")
        End If
    ElseIf LCase(Command.Name) = "reports" Then
        'Show all database entrys inside bot
        Set Data = Conn.Execute("Select * From `Data`")
        AddChat RGB(0, 204, 153), "Account | Reason | Time | Username"
        If (Not (Data.BOF Or Data.EOF)) Then
            Do Until Data.EOF
                AddChat RGB(0, 204, 153), Data.Fields(0) & " | " & Data.Fields(1) & " | " & Data.Fields(2) & " | " & Data.Fields(3)
                Data.MoveNext
            Loop
        Else
            AddChat RGB(0, 204, 153), "No reports."
        End If
    ElseIf LCase(Command.Name) = "delreports" Then
        Conn.Execute("Delete * From `Data`")
        Command.Respond("Deleted reports.")
    End If
End Sub

-Tuck

#15 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 01:40 AM

Thanks TBN. I'll look through the script, see if I can't figure out how you did it now and put it to test :D

#16 User is offline   7thAce Icon

  • Find me elsewhere (Inactive)
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,292
  • Joined: August-18 09

Posted March 02, 2010 - 01:49 AM

You mentioned something with BWHF. I have actually made a BWHF script that you may find useful. It uses a text file (with FSO), so you can learn from that.
I'll add comments too, let me edit my post.
Spoiler

Edit: Haha, it's all trying to make you a better scripter.
Posted Image
7thAce.no-ip.org: Posted Image
Official SB Tech @ Clan SBs USEast
Just a note to all you people who want to give Tech Support: Post with correct info (only - no info is better than wrong info), contribute to the topic, and be clear (the more explanation, the better).

#17 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 02:02 AM

Thx, Ace. I'll take a look at that one too XD

And I didn't even see Tucks >.>

Good god I'm being overwhelmed! XD

TBN:

Quote

[06:01:36 PM] Scripting runtime error '450' in DBTest.txt: (line 1; column 0)
[06:01:36 PM] Wrong number of arguments or invalid property assignment: 'Scripts'
[06:01:36 PM] Offending line: >>
[06:01:36 PM] Scripts loaded.
[06:01:36 PM] Zomg!! Hacker found!
[06:01:36 PM] Scripting runtime error '-2147217865' in DBTest: (line 57; column 0)
[06:01:36 PM] [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'users'. Make sure it exists and that its name is spelled correctly.
[06:01:36 PM] Offending line: >>
[06:01:36 PM] Scripting runtime error '-2147217865' in DBTest: (line 57; column 0)
[06:01:36 PM] [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'users'. Make sure it exists and that its name is spelled correctly.
[06:01:36 PM] Offending line: >>


#18 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 02, 2010 - 02:05 AM

View PostSierraKomodo, on 02 March 2010 - 03:02 AM, said:

Thx, Ace. I'll take a look at that one too XD

And I didn't even see Tucks >.>

Good god I'm being overwhelmed! XD

TBN:


change

Scripts("Name") = "DBTest"
Scripts("Major") = 1
Scripts("Minor") = 0


to

Script("Name") = "DBTest"
Script("Major") = 1
Script("Minor") = 0


And

dbConn.Execute("CREATE TABLE `users` (`name` varchar(30), `comments` Text")


To

dbConn.Execute("CREATE TABLE `users` (`name` varchar(30), `comments` Text)")

This post has been edited by Tuck: March 02, 2010 - 02:08 AM

-Tuck

#19 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 02:11 AM

Ace: What are the commands for your script? There's nothing showing up in the command manager

#20 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 02, 2010 - 02:12 AM

View PostSierraKomodo, on 02 March 2010 - 03:11 AM, said:

Ace: What are the commands for your script? There's nothing showing up in the command manager


If left(lcase(message), 6) = botvars.trigger & "scan " Then


.scan <arg>
-Tuck

#21 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 02:15 AM

Tuck: Error still comes up. Might be different from before, not sure but I'll copy it again anyway.

Quote

[06:12:22 PM] Scripting runtime error '-2147217865' in DBTest: (line 57; column 0)
[06:12:22 PM] [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'users'. Make sure it exists and that its name is spelled correctly.
[06:12:22 PM] Offending line: >>
[06:12:22 PM] Scripting runtime error '-2147217865' in DBTest: (line 57; column 0)
[06:12:22 PM] [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'users'. Make sure it exists and that its name is spelled correctly.
[06:12:22 PM] Offending line: >>


And I feel like an idiot there. Should've seen that one in his script >.>

ADD: /scan username comes up as an invalid command

#22 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted March 02, 2010 - 02:15 AM

Updated. It shouldn't be not finding that table because it's getting created in the event_load...

#23 User is offline   SierraKomodo Icon

  • Warn Status: 99.9%
  • PipPipPip
  • Group: Members
  • Posts: 192
  • Joined: January-01 10

Posted March 02, 2010 - 02:16 AM

And, it seems the command works when another user uses it but wont work in console

Ok so, I'm over here poking through and testing three scripts at once now.. XD

I'm just gonna focus on one at a time, starting with TBN's

#24 User is offline   Tuck Icon

  • Full Member
  • PipPipPip
  • Group: Banned
  • Posts: 587
  • Joined: August-31 09

Posted March 02, 2010 - 02:19 AM

View PostSierraKomodo, on 02 March 2010 - 03:16 AM, said:

And, it seems the command works when another user uses it but wont work in console

Ok so, I'm over here poking through and testing three scripts at once now.. XD

I'm just gonna focus on one at a time, starting with TBN's


You need to delete the "Data.mdb" inside bot folder and do the 2 fixes i posted and reload scripts. (might need to disable the script to delete the file)
-Tuck

#25 User is offline   7thAce Icon

  • Find me elsewhere (Inactive)
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,292
  • Joined: August-18 09

Posted March 02, 2010 - 02:24 AM

It's not an internal command. I'll edit it real quick.
Fixed. Use it in your bot like an external command (.scan test)
Posted Image
7thAce.no-ip.org: Posted Image
Official SB Tech @ Clan SBs USEast
Just a note to all you people who want to give Tech Support: Post with correct info (only - no info is better than wrong info), contribute to the topic, and be clear (the more explanation, the better).

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users