Author Topic: HOW-TO: Write your own bot = Lesson 4  (Read 10446 times)

0 Members and 1 Guest are viewing this topic.

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
HOW-TO: Write your own bot = Lesson 4
« on: 25 October, 2003, 14:55:06 »
Using timers
---------------

First of all here is the code we had from lesson 3

Code: [Select]

Bot = "Keiko"

version = "0.4"
NEWCON = 1
prefix = "!"

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
if user.iProfile == 0 then
user:SendData(Bot,"Hello Master "..user.sName.." How are you")
return 1
else
SendToAll(Bot,"A Op has entered")
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end

Now we are going to add a timed advert, its very simple

You first of all have to set the timer
Code: [Select]

SetTimer(60000)

but also have something to show on the timer

we are going to use:

Code: [Select]
function OnTimer()
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

and now you need to also start the timer:

Code: [Select]
StartTimer()

so now we have so far :

Code: [Select]
Bot = "Keiko"

version = "0.4"
NEWCON = 1
prefix = "!"

function Main()
frmHub:RegBot(Bot)
SetTimer(60000)
StartTimer() --In the main function because it starts the timer on hub start or restart
end

function OnTimer() --This is what will be sent on the timer
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
if user.iProfile == 0 then
user:SendData(Bot,"Hello Master "..user.sName.." How are you")
return 1
else
SendToAll(Bot,"A Op has entered")
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end

now also dont forget to use tabs, scripters always use tabs when scripting, it helps then find errors, in there script for example:

Code: [Select]
Bot = "Keiko"

version = "0.4"
NEWCON = 1
prefix = "!"

function Main()
frmHub:RegBot(Bot)
SetTimer(60000)
StartTimer() --In the main function because it starts the timer on hub start or restart
end

function OnTimer() --This is what will be sent on the timer
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
if user.iProfile == 0 then
user:SendData(Bot,"Hello Master "..user.sName.." How are you")
return 1
else
SendToAll(Bot,"A Op has entered")
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end
end

in this example you will not really notice the problem
but if you use tabs:

Code: [Select]
Bot = "Keiko"

version = "0.4"
NEWCON = 1
prefix = "!"

function Main()
frmHub:RegBot(Bot)
SetTimer(60000)
StartTimer() --In the main function because it starts the timer on hub start or restart
end

function OnTimer() --This is what will be sent on the timer
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
if user.iProfile == 0 then
user:SendData(Bot,"Hello Master "..user.sName.." How are you")
return 1
else
SendToAll(Bot,"A Op has entered")
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end
end -- now we can see there is 1 to many ends


so for each if there is an end

so this is the working version, this lesson has tought you to use tabs when scripting, why, and a little on timers, remember this is still the basic lessons, advanced will come when you have the basic bot

Code: [Select]
Bot = "Keiko"

version = "0.4"
NEWCON = 1
prefix = "!"

function Main()
frmHub:RegBot(Bot)
SetTimer(60000)
StartTimer() --In the main function because it starts the timer on hub start or restart
end

function OnTimer() --This is what will be sent on the timer
SendToAll(Bot,"-------------------------------")
SendToAll(Bot,"--Write your own bot lesson 4--")
SendToAll(Bot,"-------------------------------")
end

function NewUserConnected(user)
if NEWCON == 1 then
user:SendData (Bot,"A User has connected")
end
end

function OpConnected(user)
if user.iProfile == 0 then
user:SendData(Bot,"Hello Master "..user.sName.." How are you")
return 1
else
SendToAll(Bot,"A Op has entered")
end
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == prefix.."version" then
user:SendData(Bot,"This bot is Learn to write a bot version: "..version)
return 1
elseif cmd == prefix.."help" then
user:SendData(Bot,"This is where the help text wud go, bt im not gonna waste my time :P")
return 1
end
end
end

l8rr,,

-phatty
Resistance is futile!

PtokaX forum

HOW-TO: Write your own bot = Lesson 4
« on: 25 October, 2003, 14:55:06 »

Offline raz

  • Triple Ace
  • **
  • Posts: 176
  • Karma: +4/-0
(No subject)
« Reply #1 on: 25 October, 2003, 15:03:39 »
so what is the lesson. as u r explaining this. ?(

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #2 on: 25 October, 2003, 15:05:59 »
Quote
Originally posted by raz
so what is the lesson. as u r explaining this. ?(

i dont understand what you mean?
Resistance is futile!

Offline raz

  • Triple Ace
  • **
  • Posts: 176
  • Karma: +4/-0
(No subject)
« Reply #3 on: 25 October, 2003, 15:10:03 »
now that we have learnt about tabs and how to put a timer in to a bot. what is the next lesson? this lesson seems very easy to do. maybe u could put a harder 1 up. :D

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #4 on: 25 October, 2003, 15:16:03 »
No im writing the lessons, so ill write them easy to hard, im not jumping ahead, to quick, because newbies might not be able to keep up, or need to ask questions, then as i decide what next, then i will put up the next lesson ;)
And you are not supposed to just copy, its not as simple as it seems..........

you are supposed to use this data to help you think of ideas to use in a timer this is to help you understadn the basic timer
Resistance is futile!

Offline raz

  • Triple Ace
  • **
  • Posts: 176
  • Karma: +4/-0
(No subject)
« Reply #5 on: 25 October, 2003, 15:28:19 »
sorry, but i thought there was only 2 of us last time trying lesson 2. its ok if u want 2 wait 4 other ppl. i have new ideas like you do the timer thing u can have it so information about the hub comes up every 30 mins and and few commands dey can do like !news etc... :D i don't mind waiting, just i wnat 2 make my bot sooooon. :P

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #6 on: 25 October, 2003, 15:33:20 »
Well i will try and split my time up and mabbe try and get another few lessons done today, but like i sqaid earlier i got linux to sort out ;)
Resistance is futile!

Offline raz

  • Triple Ace
  • **
  • Posts: 176
  • Karma: +4/-0
(No subject)
« Reply #7 on: 25 October, 2003, 15:39:44 »
actuaaly take your time as we went some good lessons. don't do it in a hurry. if u wnat u can get ur linux done first and den come on to the lessons. :D

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #8 on: 26 October, 2003, 19:26:51 »
Nice going here... When do we get some advanced lessons.... :-D
//NL

Offline RiPOFF

  • Member
  • ***
  • Posts: 46
  • Karma: +0/-0
(No subject)
« Reply #9 on: 02 November, 2003, 07:27:51 »
what about functions that generally are used?

like if an account is idle for a while its automaticlly backed up into a txt and then deleted

or
like other hub function...

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #10 on: 02 November, 2003, 11:13:13 »
Not quite sure what you mean, i will start on lesson 5 soon, altho i am taking it easy, i am going thru all the beginners lessons, then go thru them agen, but in advanced, i also have gekko to work on too, so not to much time on my hands, if you have a requests for next lesson post em here, n can you explain what you mean, see i am not writing you a bot, i am just teaching how to write things,

so if you mean to backup something, i will randomly choose something to backup, then you can learn from it ;)

-phatty
Resistance is futile!

Offline lazyj189

  • Forum Ace
  • *****
  • Posts: 81
  • Karma: +1/-0
(No subject)
« Reply #11 on: 10 November, 2003, 02:42:10 »
I dont know about anyone else, but these lessons are sure helping me.  For the most part the basics, I've got them figured out.  Hell, I can even pull certian code out of other scripts that others have done to make smallers ones.  I am glad that phatty has taken this nice and slow because to someone who has never really understood the language, it takes a little time to absorb all this info.  I know I am ready whenever you are for lesson 5.  Otherwise some good practice is taking scripts that others have made and go through them, trying to understand al the functions, what does what, and what the results are of each.  When I get a script I try to start at the top and follow it through to see how it jumps all over the place.  Just a little insight as to how i've learned a little more about scripting.
DivX Dominion Hub Owner
3 years running
DivX Dominion Hub

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #12 on: 10 November, 2003, 12:13:04 »
i am really happy that these are helping people, i might cancel some of my projects to do some more lessons :o)
Resistance is futile!

Offline Masterload

  • Member
  • ***
  • Posts: 36
  • Karma: +0/-0
nice one !
« Reply #13 on: 16 November, 2003, 17:23:17 »
like these lessons ,
helping to understand the basics
of scripting like to learn more about this :P
good job !!
magmarnet

visit me at home....

 

Offline Nemesis

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
timer length
« Reply #14 on: 17 May, 2004, 14:53:04 »
Nice lessons you have here, just right for complete newbies who ar'nt afraid to mess aorund and learn, just one question....    SetTimer(60000) is 60000 set in seconds?? so i could set say 300 for 5 mins ??  

PS not yet set this last lesson up as off to work in a jiffy and dont have time to play :( so not sure how long value of 60000 will last in actual time value
 hope you understand what im asking !

i know these lessons have been up a while but im a newbie, please be patient for me  :)

 8)
We all have a photographic memory.. just some of us forget to put the film in...  

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #15 on: 17 May, 2004, 15:59:24 »
60000 = 1 min ;)
Resistance is futile!

Offline Nemesis

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
(No subject)
« Reply #16 on: 18 May, 2004, 13:54:05 »
Noticed you use
function NewUserConnected(user) - and
function OpConnected(user) for sending short message
but what if you wanted to send diff message to reg or vip too?   8o  :D  8)
We all have a photographic memory.. just some of us forget to put the film in...  

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #17 on: 18 May, 2004, 14:06:09 »
if user.iProfile == (profilenumberhere) then

vip < is newuser

op > is op of course ;)
Resistance is futile!

Offline LiqUiD~TrolL

  • Triple Ace
  • **
  • Posts: 160
  • Karma: +0/-0
(No subject)
« Reply #18 on: 12 November, 2004, 19:22:10 »
well hi ppl i was looking at these lessons but i think i saw them very late,the lessons are really nice ones
but i don t need something so complicated

what if i just wana fix a simple bot that is shows a txt file?? only this io want
can you help me????
________<>________


            -=@_ psydream-land.no-ip.org _@=-


             
http://www.psychedelicdreams.bravehost.com

Herodes

  • Guest
(No subject)
« Reply #19 on: 12 November, 2004, 20:03:00 »
for that kind of bot there is a series of posts in the :Scripting:Utilities:Central: thread located in this forum ..

also , this particular type of bots has its king ... Texter by plop..
look in http://www.plop.nl to find the complete series of this bot ...
it will give u example of what you need to do .. watch the way the script develops throught the versions .. and always expiriment .. :)

Offline LiqUiD~TrolL

  • Triple Ace
  • **
  • Posts: 160
  • Karma: +0/-0
(No subject)
« Reply #20 on: 14 November, 2004, 14:24:03 »
hello herodes ,well my firend i tried plops bot
the bot it is shown on the users list but i can t see the txt
i tried +text !text and +,! fdfolder but nothin happened
what the hell is going on with this bot ?????????
________<>________


            -=@_ psydream-land.no-ip.org _@=-


             
http://www.psychedelicdreams.bravehost.com

Offline MetalPrincess

  • Junior Member
  • **
  • Posts: 17
  • Karma: +1/-0
    • Metal Bootleg Database
Re: HOW-TO: Write your own bot = Lesson 4
« Reply #21 on: 02 July, 2006, 18:24:55 »
Coolness you rule (uk-kingdom)pH?tt? :D


MP

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO: Write your own bot = Lesson 4
« Reply #22 on: 13 November, 2006, 16:24:48 »
If I want the bot to show the +help command on main chat every 1 min thn wat shud I add in the script and where??
Thanking You,

speedX

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: HOW-TO: Write your own bot = Lesson 4
« Reply #23 on: 13 November, 2006, 16:35:32 »
You mean to show up the command itself?

Code: [Select]
Clock = 60000 --(millisec)
Bot = frmHub:GetHubBotName() --or write a nick for it in quotation marks

function Main()
SetTimer(Clock)
StartTimer()
end

OnTimer = function()
SendToAll(Bot, "Type +help for help!")
end

On Main function (upon starting the script) the timer starts ticking and on every tick (60000ms = 60 s = 1min) it sends a message to all

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: HOW-TO: Write your own bot = Lesson 4
« Reply #24 on: 13 November, 2006, 17:31:08 »
if I want to show up a text file??
I mean if I have a txt file with command +bla
And I want to display the data in tht txt file in main, thn wat to do??

Is it possible?? Please reply even if it not possible
« Last Edit: 13 November, 2006, 17:37:07 by speedX »
Thanking You,

speedX

PtokaX forum

Re: HOW-TO: Write your own bot = Lesson 4
« Reply #24 on: 13 November, 2006, 17:31:08 »