{Escriba v2.7
Grava log do canal sem códigos de cor. Mude o valor da variável
$diretorio para o local onde deseja fazer os logs
Eventos:
ON TEXT:*:#:/runscript [log] # $nick $gravarlog texto *1
ON TEXT:*:?:/runscript [log] $nick $nick $gravarlog texto *1
ON ACTION:*:#:/runscript [log] # $nick $gravarlog action *1
ON JOIN:#:/runscript [log] # $nick $gravarlog action [ $+ $address $+ ] entrou no #
ON JOINED:#:/runscript [log] # $me $gravarlog action [ $+ $address $+ ] entrou no #
ON PART:#:/runscript [log] # $nick $gravarlog action [ $+ $address $+ ] saiu do #
ON INPUT:*:*:/runscript [log] $activewin $me $gravarlog texto *1
function strsearch(texto1, texto2: string; apartir: value): value;
var
cont, achou: value;
begin
texto1 := strupper(texto1);
texto2 := strupper(texto2);
achou := 0;
if apartir > strlen(texto2) then
apartir := strlen(texto2)
else if apartir < 1 then
apartir := 1;
cont := apartir;
while not (achou) and (cont <= strlen(texto2)) and (strlen(texto2) > 0) do
begin
if strcopy(texto2, cont, strlen(texto1)) = texto1 then
achou := 1
else
cont := cont + 1;
breathe;
end;
if achou then
strsearch := cont
else
strsearch := 0;
end;
function isnumber(texto: string): value;
var
cont: value;
valido: value;
begin
valido := 1;
cont := 1;
if (strcopy(texto, 1, 1) = '+') or (strcopy(texto, 1, 1) = '-') then
strdel(texto, 1, 1);
if strlen(texto) <= 0 then
valido := 0
else
begin
while (cont <= strlen(texto)) and (valido) do
begin
if (strcopy(texto, cont, 1) <> '0') and (strcopy(texto, cont, 1) <> '1') and
(strcopy(texto, cont, 1) <> '2') and (strcopy(texto, cont, 1) <> '3') and
(strcopy(texto, cont, 1) <> '4') and (strcopy(texto, cont, 1) <> '5') and
(strcopy(texto, cont, 1) <> '6') and (strcopy(texto, cont, 1) <> '7') and
(strcopy(texto, cont, 1) <> '8') and (strcopy(texto, cont, 1) <> '9') then
valido := 0;
cont := cont + 1;
breathe;
end;
end;
isnumber := valido;
end;
function strtrim(texto: string): string;
var
cont, cont2, postexto: value;
begin
cont := 1;
while cont <= strlen(texto) do
begin
if strcopy(texto, cont, 1) = '' then {ctrl+k}
begin
postexto := strsearch(',', texto, cont);
if (postexto > 0) and (isnumber(strcopy(texto, cont + 1, postexto - 1 - cont))) then
strdel(texto, cont, (postexto - cont) + 1)
else
strdel(texto, cont, 1);
for cont2 := 1 to 2 do
begin
if isnumber(strcopy(texto, cont, 1)) then
strdel(texto, cont, 1);
breathe;
end;
end
else if (strcopy(texto, cont, 1) = '') or (strcopy(texto, cont, 1) = '') or (strcopy(texto, cont, 1) = '') or
(strcopy(texto, cont, 1) = '') or (strcopy(texto, cont, 1) = '') or
(strcopy(texto, cont, 1) = '') then {ctrl b,i,u,s,f,}
strdel(texto, cont, 1)
else
cont := cont + 1;
breathe;
end;
while strcopy(texto, strlen(texto), 1) = ' ' do
begin
strdel(texto, strlen(texto), 1);
breathe;
end;
while strcopy(texto, 1, 1) = ' ' do
begin
strdel(texto, 1, 1);
breathe;
end;
strtrim := texto;
end;
function convertcolor(cor: value): string;
begin
if cor > 15 then
cor := cor mod 16;
if cor = 00 then
convertcolor := '#FFFFFF'
else if cor = 01 then
convertcolor := '#000000'
else if cor = 02 then
convertcolor := '#000080'
else if cor = 03 then
convertcolor := '#009900'
else if cor = 04 then
convertcolor := '#FF0000'
else if cor = 05 then
convertcolor := '#993300'
else if cor = 06 then
convertcolor := '#990099'
else if cor = 07 then
convertcolor := '#919100'
else if cor = 08 then
convertcolor := '#FFFF00'
else if cor = 09 then
convertcolor := '#99FF33'
else if cor = 10 then
convertcolor := '#669999'
else if cor = 11 then
convertcolor := '#66FFFF'
else if cor = 12 then
convertcolor := '#0066FF'
else if cor = 13 then
convertcolor := '#FF00FF'
else if cor = 14 then
convertcolor := '#666666'
else if cor = 15 then
convertcolor := '#CCCCCC';
end;
function converttohtml(texto: string): string;
var
corfonte, corbackground, cont, cont2, posvirgula, postexto: value;
caracteres, caractere, taganterior, tagatual, auxcor: string;
begin
taganterior := '';
tagatual := '';
corfonte := -1;
corbackground := -1;
caracteres := ''; {ctrl k,b,i,u,s,f, (asccii 15)}
for cont := 1 to 7 do
begin
breathe;
caractere := strcopy(caracteres, cont, 1);
postexto := strpos(caractere, texto);
while postexto > 0 do
begin
if caractere = '' then {ctrl k}
begin
if postexto > 0 then
begin
auxcor := '';
cont2 := 1;
while (cont2 <= 2) and (isnumber(strcopy(texto, postexto + cont2, 1))) do
begin
if isnumber(strcopy(texto, postexto + cont2, 1)) then
begin
auxcor := auxcor + strcopy(texto, postexto + cont2, 1);
cont2 := cont2 + 1;
end;
breathe;
end;
if auxcor <> '' then
corfonte := strtoint(auxcor)
else
corfonte := -1;
strdel(texto, postexto, strlen(auxcor) + 1);
auxcor := '';
if strcopy(texto, postexto, 1) = ',' then
begin
cont2 := 1;
while (cont2 <= 2) and (isnumber(strcopy(texto, postexto + cont2, 1))) do
begin
if isnumber(strcopy(texto, postexto + cont2, 1)) then
begin
auxcor := auxcor + strcopy(texto, postexto + cont2, 1);
cont2 := cont2 + 1;
end;
breathe;
end;
strdel(texto, postexto, strlen(auxcor) + 1)
end;
if auxcor <> '' then
corbackground := strtoint(auxcor)
else
corbackground := -1;
end;
end
else if postexto > 0 then
strdel(texto, postexto, 1);
if taganterior <> '' then
begin
if taganterior = '' then
taganterior := ''
else if taganterior = '' then
taganterior := ''
else if taganterior = '' then
taganterior := ''
else if taganterior = '' then
taganterior := ''
else
taganterior := '';
end;
if (caractere = '') and (taganterior = '') then {ctrl b}
tagatual := ''
else if (caractere = '') and (taganterior = '') then {ctrl i}
tagatual := ''
else if (caractere = '') and (taganterior = '') then {ctrl u}
tagatual := ''
else if (caractere = '') and (taganterior = '') then {ctrl s}
tagatual := ''
else if (caractere = '') and (taganterior = '') then {ctrl f}
tagatual := ''
else if (caractere = '') and (taganterior = '') then {}
tagatual := ''
else if (caractere = '') and ((corbackground <> -1) or (corfonte <> -1)) then {ctrl k}
begin
tagatual := '';
end;
if (taganterior <> '') or (tagatual <> '') then
strins(taganterior + tagatual, texto, postexto);
if (caractere = '') and ((corbackground <> -1) or (corfonte <> -1)) then {ctrl k}
taganterior := ''
else
taganterior := tagatual;
tagatual := '';
postexto := strpos(caractere, texto);
breathe;
end;
if taganterior = '' then
texto := texto + ''
else if taganterior = '' then
texto := texto + ''
else if taganterior = '' then
texto := texto + ''
else if (corbackground <> -1) or (corfonte <> -1) then
texto := texto + ''
else if taganterior <> '' then
texto := texto + '';
taganterior := '';
tagatual := '';
corfonte := -1;
corbackground := -1;
end;
converttohtml := texto;
end;
function replace(texto, antigo, novo: string): string;
var
posicao: value;
begin
posicao := strpos(antigo, texto);
while posicao > 0 do
begin
strdel(texto, posicao, 1);
strins(novo, texto, posicao);
posicao := strpos(antigo, texto);
breathe;
end;
replace := texto;
end;
procedure escrevearquivo(arq, frase: string; linha, formatohtml, substituir: value);
begin
if not formatohtml then
frase := strtrim(frase)
else
begin
if substituir then
begin
frase := replace(frase, '<', '<');
frase := replace(frase, '>', '>');
end;
frase := converttohtml(frase);
end;
if not filewrite(arq, linha, frase) then
begin
command('/newwindow Erro');
command('/display > Erro Não foi possível escrever o texto "', frase, '" no arquivo ', arq);
end;
end;
$canal := $1;
$log := $3;
$action := $4;
$texto := *5;
if (strpos('/me ', $texto) = 1) or (strupper($action) = 'ACTION') then
begin
$nick := $2 + ' ';
if strpos('/me ', $texto) = 1 then
strdel($texto, 1, 4);
end
else
$nick := '<' + $2 + '> ';
$diretorio := 'D:\ShinRyuu\_dungeon\RPG\campanha\notas\logs\'; {deve ter barra invertida no final}
$canal := replace($canal, '#', '');
$arquivo := $diretorio + $canal + unixtimetostr('.yy.mm.dd', unixtime) + '.txt';
$arqhtml := $diretorio + $canal + unixtimetostr('.yy.mm.dd', unixtime) + '.htm';
if $log = 'iniciar' then
begin
command('/define gravarlog=gravar');
$log := 'gravar';
$inicio := '===== SESSÃO INICIADA ' + $date + ' ' + $time + ' =====';
command('/write -I ', $arquivo, ' ', $inicio);
$inicio := converttohtml('4===== SESSÃO INICIADA ' + $date + ' ' + $time + ' =====
');
command('/write -I ', $arqhtml, ' ', $inicio);
end;
if $log = 'gravar' then
begin
escrevearquivo($arquivo, '[' + $time + '] ' + $nick + $texto, 0, 0, 0);
escrevearquivo($arqhtml, ' ' + '[' + $time + '] ' + $nick + $texto, 0, 1, 1);
escrevearquivo($arqhtml, '
', 0, 1, 0);
end
else if $log = 'parar' then
begin
escrevearquivo($arquivo, $texto, 0, 0, 0);
escrevearquivo($arqhtml, '', 1, 1, 0);
escrevearquivo($arqhtml, ' ', 2, 1, 0);
escrevearquivo($arqhtml, ' Log de jogo: #' + $canal + ' - ' + $date + '', 3, 1, 0);
escrevearquivo($arqhtml, ' ', 4, 1, 0);
escrevearquivo($arqhtml, ' ', 5, 1, 0);
escrevearquivo($arqhtml, ' ', 6, 1, 0);
escrevearquivo($arqhtml, ' ' + $texto, 0, 1, 0);
escrevearquivo($arqhtml, '', 0, 1, 0);
end;