Jump to content
UBot Underground

Macros / Tokens to replace data - Whats the best way to do it?


Recommended Posts

I have a folder called Macros. Inside the macro folders are text files like "Greetings.txt", "FirstName.txt" "ZipCodes.txt" "Colors.txt"...etc

 

Now i also have a text file called Messages.txt

 

Inside Messages.txt There are items like:

%Greetings% My name is %FirstName%

My Favorite color is %Colors%

My ZipCode is %ZipCodes.txt

 

ETC

 

What i want to do is grab the first Message from Messages.txt And have it replace the macro with a random item from the text file. Like for example if the message contains %Greetings% it should pick a random item from Greetings.txt.

 

I am trying to figure out the best way to do this. Does anyone already have an example how this can be done?

 

I'm guessing that first i will need to load up all the text file names from the macro folder and make it add "%" to the front and end of it. Then make it scan through the message and the filenames and if it finds a match then do a replace.

Hopefully that will work.

 

I also want to be able to create new macro text file anytime i want and not have to change any code in the program that is why i want it to load up the file names of the text files.

 

 

If anyone knows the best way to do this, please let me know.

 

Thanks

Link to post
Share on other sites

I actually figured it out.

 

here is the code in case anyone needs it.

 

im still new to ubot, is there anyway to optimize this code?

 

Just copy and paste this into the code view then save and then create a folder called "Data" and inside that make a folder called "Macros" and create text files called "City.txt" "Female.txt" "State.txt" and "Zipcodes.txt" and put some data in there.

 

Then just take a look at the debugger and you can see the values keep changing for the macros everytime you run this.

 

 

set(#AppFolder, $special folder("Application"), "Global")
clear list(%MacroFileNames)
clear list(%MacroFileNamesReplaced)
add list to list(%MacroFileNames, $get files("{#AppFolder}\\Data\\Macros", "No"), "Delete", "Global")
set(#Position, 0, "Global")
loop($list total(%MacroFileNames)) {
   set(#MacroFileName, $list item(%MacroFileNames, #Position), "Global")
   set(#NewMacroFileName, "%{$replace(#MacroFileName, ".txt", "")}%", "Global")
   add item to list(%MacroFileNamesReplaced, #NewMacroFileName, "Delete", "Global")
   increment(#Position)
}
set(#Position, 0, "Global")
set(#Message, "Hello My First name is %Female%. I live in the state of %State% and the city is %City% the zipcode here is %Zipcodes%", "Global")
loop($list total(%MacroFileNamesReplaced)) {
   set(#SearchMacro, $list item(%MacroFileNamesReplaced, #Position), "Global")
   set(#ReplaceMacro, $replace(#Message, #SearchMacro, $random list item($list from file("{#AppFolder}\\Data\\Macros\\{$replace(#SearchMacro, "%", "")}.txt"))), "Global")
   set(#Message, #ReplaceMacro, "Global")
   increment(#Position)
}

Link to post
Share on other sites

one thing i noticed is if i create a macro %RandomNumber% and a text file RandomNumber.txt with the values from 0-9 and in the message i put

My phone number is %RandomNumber%%RandomNumber%%RandomNumber%-%RandomNumber%%RandomNumber%%RandomNumber%-%RandomNumber%%RandomNumber%%RandomNumber%%RandomNumber%

 

Then all of the %RandomNumber% have the same value

like the result would be 111-111-1111 or 666-666-666 etc

 

So i am thinking i might need to make some hard coded macros like %RandomNumbers/4% then this would give me random 4 numbers or like %RandomString/6% which would give me random 6 alphanumeric characters. I would have to make the script look for "%RandomString/6%" But i am having a hard time figuring this one out. Can you use wild cards in the replace function in ubot 4.0? i know that in ubot 3.0 it didnt support it. Or if anyone knows a solution how i can do the hard coded macros that would be great.

 

thanks

Link to post
Share on other sites

replace randonnumber with $rand(1,999)

 

will give a random number 3 digits long for each instance.

 

however i it seems it multiple times at once it might release all at once.

what you would have to do is add it to a list, of the number of times in format that your wanting it in there, then change it per line so its called numerous times to replace rather then just 1 time.

Link to post
Share on other sites

Careful, that would also give 1-99 which are not three digits. You have to start with 100,999 or add padding logic to the number.

Link to post
Share on other sites

replace randonnumber with $rand(1,999)

 

will give a random number 3 digits long for each instance.

 

however i it seems it multiple times at once it might release all at once.

what you would have to do is add it to a list, of the number of times in format that your wanting it in there, then change it per line so its called numerous times to replace rather then just 1 time.

 

 

sorry im a bit confused. To avoid it generating the same number, i would have to add what to the list? is it possible to give an example for that.

 

thanks

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...