Resolved: How do you create databases? And read them, and pull information off of them...
#1
Posted March 01, 2010 - 09:46 PM
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
Posted March 01, 2010 - 09:55 PM
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
#4
Posted March 01, 2010 - 10:43 PM
#5
Posted March 01, 2010 - 11:03 PM
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
Posted March 01, 2010 - 11:08 PM
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
#7
Posted March 01, 2010 - 11:37 PM
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
Posted March 02, 2010 - 12:27 AM
#9
Posted March 02, 2010 - 12:37 AM
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
Posted March 02, 2010 - 12:43 AM
SierraKomodo, on 02 March 2010 - 01:37 AM, said:
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.
#11
Posted March 02, 2010 - 12:45 AM
#12
Posted March 02, 2010 - 01:00 AM
#13
Posted March 02, 2010 - 01:32 AM
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
Posted March 02, 2010 - 01:39 AM
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
#15
Posted March 02, 2010 - 01:40 AM

#16
Posted March 02, 2010 - 01:49 AM
I'll add comments too, let me edit my post.
Edit: Haha, it's all trying to make you a better scripter.
#17
Posted March 02, 2010 - 02:02 AM
And I didn't even see Tucks >.>
Good god I'm being overwhelmed! XD
TBN:
Quote
[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
Posted March 02, 2010 - 02:05 AM
SierraKomodo, on 02 March 2010 - 03:02 AM, said:
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
#19
Posted March 02, 2010 - 02:11 AM
#21
Posted March 02, 2010 - 02:15 AM
Quote
[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
Posted March 02, 2010 - 02:15 AM
#23
Posted March 02, 2010 - 02:16 AM
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
Posted March 02, 2010 - 02:19 AM
SierraKomodo, on 02 March 2010 - 03:16 AM, said:
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)
#25
Posted March 02, 2010 - 02:24 AM
Fixed. Use it in your bot like an external command (.scan test)