Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

3 876 Posts in 868 Topics- by 723 Members - Latest Member: tablarock

23 May 2012, 06:34
Select Language English | Russian ru | German
Main PageIRC Client KVIrc forumKVIrc discussionKVIrc scriptingUsing config store file
Pages: [1]
Print
Author Topic: Using config store file  (Read 337 times)
0 Members and 1 Guest are viewing this topic.
organisedmess
Новичок
*

Репутация: 1
Posts: 4


View Profile
« on: 9 December 2011, 15:55 »

Firstly, congratulations on creating such a wonderful irc client.

I am trying to use the client as a bot to manage my clans channel.
What I would really like the bot to do is store matches we play and have played and be able to configure these matches from inside the channelw ithout editting the bots source code.

I have read the whole help file and played around with most examples for a while, but can't quite figure it out. I assume that I will need the following commands: $config.open, $config.read, $config.section, $config.id, $config.readonly, config.close, config.setsection and config.write.

What I would like to do is make it so that any user that has op rights in my channel cannel can use ie:
"!set nextmatch 11/12/2011 21:00 vs =LOW=" to set this match on a new line in the config file.

And then for users to be able to use: "!nextmatch" for the bot to tell what has been set as the next match.

Alternatively perhaps it could tell the users the last match by using: "!lastmatch" or "!previousmatch".


Unfortunately, my coding skills are limited. I know how to use simple evenet triggers, but have no idea where to start writing a script like this, even after reading the readme. Can anyone help?
Logged
ambossarm
Постоялец
***

Репутация: 11
Gender: Male
Posts: 113



View Profile
« Reply #1 on: 10 December 2011, 00:11 »

Hi, sounds not hard.

For the parsing of the message you need to create an eventhandler for "OnChanneLMessage"

for reading a file $file.read or $file.readLines
$file.localdir or .homedir are good places to save the file

For the parsed config a hash or so could be a good idea, the time format could be a little problematic. If you are a bit advaned a look into the SQL class would be perfect! Wink


If you need help scripting: best join one of the international IRC Channels and have some patience, there is always one who helps if asked nicely.
Logged
organisedmess
Новичок
*

Репутация: 1
Posts: 4


View Profile
« Reply #2 on: 11 December 2011, 01:06 »

Hmm, I'm a coding noob to be honest. I'll read the manuals some more and try somethings out. I'm pretty sure SQL is probably outside of my skills though. Cheesy

I'm doornroosje on irc.
Logged
organisedmess
Новичок
*

Репутация: 1
Posts: 4


View Profile
« Reply #3 on: 11 December 2011, 21:48 »

Okay, I have read some more and played around with some things, and I think I'm going to need quite a bit of help. I have tried to make a simplified version of what my ideal script should do first, with a textfile having 1 line that gets overwritten by a '!set xxxxx' command and read with '!nextmatch'.


I have created two Event triggers: OnchannelMessage
I created an empty file in my kvirc folder (home/username/.config/kvirc/matches.txt)

The event triggers currently read:
Code:
if ($3 == "!set" && $chan.name == "#doorn" ) {
$file.writeLines <filename:$file.localdir/matches.txt> <lines:1> "$3";
}

Code:
if ($3 == "!nextmatch" && $chan.name == "#doorn" ) {
<array> $file.readLines(<filename:$file.localdir/matches.txt>[,<startline:1>,[<count:1>]])
echo $file.readLines(/proc/cpuinfo);
}


Obviously, this doesn't work. I know of a few things that I do wrong.

1. '!set' is not the parameter I want the code to respond to. It should be respond to: '!set xxxxxxxxxxxxxxxxx' where x is a wildcard.
2. I'm not really sure if I use $file.write correctly.
3. The message I want to write to line 1 of the file is not '$3'. It's $3 where the !set is stripped out.

4. I am unsure whether I use the $file.readLines command right.
5. I obviously do not get the desired endresult because of all points mentioned above.



the problem is that everything I do at the moment is a guessing game. I simply don't understand what I'm doing, or should be doing.
Logged
Fiber
Новичок
*

Репутация: 1
Posts: 1


View Profile
« Reply #4 on: 11 December 2011, 23:42 »

After some bit-shifting:

KVIrc KVS:
Scripting -> Events -> OnChannelMessage -> create a new Handler, name it to: MatchScript (or any suitable name, it doesn't really matter) and paste this:
Code:
%channame="#testmatch"

//its obvious, _if_ the chan name is the specified one, we do something
if ($chan.name == %channame){
if ($str.match("!set",$3)){
%message = $str.split(" ",$3)
if (%message[0] == "!set"){
if (%message[1] == nextmatch){
%c = $config.open("matches.kvc",w);
// replacing the "!set nextmatch blabla" to "blabla" by removing the first two word from it
%cleanedMessage = $str.replace("$3","!set nextmatch ","");
//not neccessary, but easier to read the kvc for humans
config.setsection %c Matches
config.write %c NextMatch %cleanedMessage
config.close %c
// inform the looser about the change:
msg %channame Next match set to: %cleanedMessage
}
}
}
if ($str.match("!nextmatch","$3")){
//opening the config file
%c = $config.open("matches.kvc",r);
config.setsection %c Matches
//read the stuff what we need
%nextmatch = $config.read(%c,NextMatch);
// post it to the looser who is too lazy to check the league's web site:
msg %channame Next match set to: %nextmatch
config.close %c
}
}

Maybe it will be usefull for someone in the future Smiley

Usage:
!set nextmatch anything you want to display with !nextmatch
!nextmatch

Be aware it is not safe to use this script on public channel due to lack of flood-protection, etc.
Logged
organisedmess
Новичок
*

Репутация: 1
Posts: 4


View Profile
« Reply #5 on: 12 December 2011, 14:34 »

Thank you so much for your help last night, Fiber!

Unfortunately I got a powercut when we spoke, so I never had the time to thank you properly, but your help is really appreciated!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic