44
55uses
66 { $IFDEF UNIX}
7- cthreads ,
7+ cThreads ,
88 BaseUnix,
99 { $ENDIF}
10- Classes, SysUtils, CustApp, Bot
10+ Classes, SysUtils, CustApp, IRCLogBot. Bot, IRCLogBot.Config
1111 { you can add units after this } ;
1212
1313type
1616 TPasLogBot = class (TCustomApplication)
1717 private
1818 FIRCLogBot: TIRCLogBot;
19+ FConfigFile: String;
20+ FBotConfig: TBotConfig;
1921 protected
2022 procedure DoRun ; override;
2123 public
@@ -93,7 +95,7 @@ procedure TPasLogBot.DoRun;
9395 // Signal Handling
9496 SetupSignalHandlers;
9597 // quick check parameters
96- ErrorMsg:= CheckOptions(' h ' , ' help' );
98+ ErrorMsg:= CheckOptions(' hc: ' , [ ' help' , ' config: ' ] );
9799 if ErrorMsg<>' ' then
98100 begin
99101 // ShowException(Exception.Create(ErrorMsg));
@@ -109,13 +111,50 @@ procedure TPasLogBot.DoRun;
109111 exit;
110112 end ;
111113
114+ if HasOption(' c' , ' config' ) then
115+ begin
116+ FConfigFile:= GetOptionValue(' c' , ' config' );
117+ end
118+ else
119+ begin
120+ FConfigFile:= ConcatPaths([GetUserDir, ' .pasirclogbot' ]);
121+ end ;
122+
123+ WriteLn(Format(' Attempting to read config from: "%s"...' , [FConfigFile]));
124+
125+ { #todo 100 -ogcarreno : Parse param c/config }
126+ FBotConfig:= TBotConfig.Create(FConfigFile);
127+ try
128+ FBotConfig.LoadValues;
129+ except
130+ on e:Exception do
131+ begin
132+ WriteLn(Format(' Error: %s' , [e.Message]));
133+ Terminate;
134+ exit;
135+ end ;
136+ end ;
137+
138+ { #todo 100 -ogcarreno : Use data from config }
139+ WriteLn(' Creating IRC client...' );
140+ FIRCLogBot:= TIRCLogBot.Create(
141+ FBotConfig.Host,
142+ FBotConfig.Port,
143+ FBotConfig.NickName,
144+ FBotConfig.UserName,
145+ FBotConfig.Realname,
146+ FBotConfig.Channel
147+ );
148+ WriteLn(' Successfully created IRC client.' );
112149 WriteLn(' Starting...' );
150+ { #todo 100 -ogcarreno : Read Config }
113151 FIRCLogBot.Run;
114152 while not Terminated do
115153 begin
116154 Sleep(50 );
117155 end ;
118156 FIRCLogBot.Shutdown;
157+ FIRCLogBot.Free;
119158 WriteLn(' Exiting.' );
120159 // stop program loop
121160 // Terminate;
@@ -125,26 +164,22 @@ constructor TPasLogBot.Create(TheOwner: TComponent);
125164begin
126165 inherited Create(TheOwner);
127166 StopOnException:= True;
128- FIRCLogBot:= TIRCLogBot.Create(
129- ' [PasLogBot]' ,
130- ' paslogbot' ,
131- ' Pascal channel IRC log bot' ,
132- ' localhost' ,
133- 6667 ,
134- ' #test'
135- );
136167end ;
137168
138169destructor TPasLogBot.Destroy;
139170begin
140- FIRCLogBot.Free;
141171 inherited Destroy;
142172end ;
143173
144174procedure TPasLogBot.WriteHelp ;
145175begin
146176 { add your help code here }
147- WriteLn(' Usage: ' , ExtractFileName(ExeName), ' -h' );
177+ WriteLn(' Usage:' );
178+ WriteLn(' ' , ExtractFileName(ExeName), ' [PARAMS]' );
179+ WriteLn;
180+ WriteLn(' PARAMS:' );
181+ WriteLn(' -h/--help This help message.' );
182+ WriteLn(' -c/--config=FILE Use provided FILE as config. ( default: ~/.pasirclogbot )' );
148183end ;
149184
150185begin
0 commit comments