-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwitch_vip_bot.lpr
181 lines (145 loc) · 4.6 KB
/
twitch_vip_bot.lpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{ twitch vip bot
Copyright (C) 2020 Red_prig
This source is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1335, USA.
}
program twitch_vip_bot;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
FastMM4,
evpool,bufferevent_openssl,
Interfaces, // this includes the LCL widgetset
UniqueInstanceBase,
uniqueinstanceraw,
LCLIntf,
SysUtils, ExtCtrls, Classes, UAsyncQueue, ULog, Forms, printer4lazarus, main,
Uloginf, UFrmParam, UFrmAbout, UFrmVipParam, UFrmSubParam, ufrmvol,
UFrmVorRpg, ufrmexportstory;
{$R *.res}
type
TUserApp=class(TApplication)
procedure TimerIdleUpdate(Sender:TObject);
procedure CustomExceptionHandler(Sender:TObject;E:Exception);
procedure OnIdleUpdate(Sender:TObject;var Done:Boolean);
Procedure FOnLog(time_:TDateTime;type_:LogType;code_:SizeInt;Const S:String);
procedure OnIPCEvent(Sender:TObject);
end;
procedure TUserApp.TimerIdleUpdate(Sender:TObject);
begin
ProcessMessages;
if not Terminated then Idle(False);
end;
procedure TUserApp.CustomExceptionHandler(Sender:TObject;E:Exception);
begin
ULog.CatchLog;
Application.ShowException(E);
end;
procedure TUserApp.OnIdleUpdate(Sender:TObject;var Done:Boolean);
begin
Done:=True;
MainQueue.OnUpdate;
end;
Var
TFS:TFileStream;
Procedure TFSWriteln(Const S:String); inline;
Const
NL:array[0..1] of Char=#13#10;
begin
if Assigned(TFS) then
begin
TFS.Write(S[1],Length(S));
TFS.Write(NL,2);
end;
end;
Procedure TUserApp.FOnLog(time_:TDateTime;type_:LogType;code_:SizeInt;Const S:String);
Var
FS:TFormatSettings;
T:String;
begin
FS:=DefaultFormatSettings;
FS.ShortDateFormat:='yyyy/mm/dd';
FS.DateSeparator:='.';
FS.ShortTimeFormat:='hh:nn:ss.zzz';
FS.LongTimeFormat:='hh:nn:ss.zzz';
FS.TimeSeparator:=':';
T:=DateTimeToStr(time_,FS,True)+'|';
T:=T+type_.ClassName+'|';
T:=T+type_.Explain(code_)+'|'+S;
TFSWriteln(T);
{if Assigned(PageOnLog) then
begin
PageOnLog(time_,type_,code_,S);
end;}
end;
procedure TUserApp.OnIPCEvent(Sender:TObject);
begin
Application.MainForm.WindowState:=wsNormal;
Application.MainForm.Show;
end;
Var
TimerIdleUpdate:TTimer;
Const
BOM:PAnsiChar=#$EF#$BB#$BF;
function GetLocalLog:RawByteString;
begin
Result:=ParamStr(0);
Result:=ExtractFileDir(Result);
Result:=IncludeTrailingPathDelimiter(Result);
{$IFDEF UNIX}
Result:=Result+'log_'+GetEnvironmentVariable('USER')+'.txt';
{$ELSE}
Result:=Result+'log_'+UTF8Encode(GetEnvironmentVariable(UnicodeString('USERNAME')))+'.txt';
{$ENDIF}
end;
begin
if InstanceRunning('twitch_vip_bot',True,True) then
begin
Halt;
end;
UniqueInstanceBase.FIPCServer.OnMessageQueued:=@TUserApp(Application).OnIPCEvent;
RequireDerivedFormResource:=True;
UAsyncQueue.MainQueue:=TNodeQueue.Create;
UAsyncQueue.CurrQueue:=UAsyncQueue.MainQueue;
Application.OnException:=@TUserApp(Application).CustomExceptionHandler;
Application.AddOnIdleHandler(@TUserApp(Application).OnIdleUpdate,False);
try
TStream(TFS):=TFileStream.Create(GetLocalLog,fmCreate or fmShareDenyWrite);
TFS.Write(BOM^,Length(BOM));
except
TFS:=nil;
end;
ULog.OnLog:=@TUserApp(Application).FOnLog;
ULog.app_logic.LogDetail:=true;
pool:=Default(Tevpool);
pool_config:=Default(Tevpool_config);
evpool_start(@pool,1,@pool_config);
TimerIdleUpdate:=TTimer.Create(Application);
TimerIdleUpdate.Interval:=400;
TimerIdleUpdate.OnTimer:=@TUserApp(Application).TimerIdleUpdate;
TimerIdleUpdate.Enabled:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TFrmMain, FrmMain);
Application.CreateForm(TfrmLogin, frmLogin);
Application.CreateForm(TFrmParam, FrmParam);
Application.CreateForm(TFrmAbout, FrmAbout);
Application.CreateForm(TFrmVipParam, FrmVipParam);
Application.CreateForm(TFrmSubParam, FrmSubParam);
Application.CreateForm(TFrmVolParam, FrmVolParam);
Application.CreateForm(TFrmVorRpg, FrmVorRpg);
Application.CreateForm(TFrmExportStory, FrmExportStory);
Application.Run;
end.