Autor Beitrag
Sauger Chris
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Do 17.05.07 07:59 
moin

hab mal ne frage code hier gerade bissle mit den socks komp. rum
(so ne art wetter irc bot)

was mein porb ist wie müßte der code aus sehen wen ein user zum beispiel

!wetter Stuttgart eingibt das es mir wen der 1 string !wetter ist der
2 string in ner edit komp oder ähnliches aus gibt.



edit: warum funktioniert das so nicht ?


ausblenden Delphi-Quelltext
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:
i,c :integer;
filterstring: array[1..4of string;
begin

filterstring[1] := '!wetter';                     // strings die gesucht werden sollen
filterstring[2] := '!lotto';             
filterstring[3] := '!poker';
filterstring[4] := '!quiz';


sData := Socket.ReceiveText;                      // socket text in memo schreiben
memo1.Lines.add(sData);

for i:=0 to memo2.Lines.count -1 do              // routine zum checken ob der sting im memo1 text vorhanden ist
for c:=1 to 10 do                                // filter string durch checken
    begin
      s:=memo2.Lines[i];
      iPos := pos(filterstring[c],s);
      if iPos <> 0 then
      begin
         sergebnis := s;
         delete(sergebnis, 1, iPos + length(filterstring[c]) - 1);
         Memo3.Lines.Add(sergebnis);              // gefundenen strings in memo 3 schreiben
         memo2.Clear; 
      end;
end;


////// ohne dem array of string geht es aber warum nicht mit ??? * kopf kraz




mfg saugi
LexXis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 170
Erhaltene Danke: 3



BeitragVerfasst: Do 17.05.07 12:46 
Moisen!

Ich hätte das Problem jetzt ganz anderst angepackt. Für denn Fall, dass dich mein Ansatz irgendwie weiterbringt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var
sData: String;
begin

  sData := ClientSocket1.ReceiveText;
  memo1.Lines.Add(sData);
  sData := LowerCase(sData);

  if pos(' :!wetter', sData) <> 0 then
    DeinEdit.Text := copy(sData, pos('!wetter')+7, length(sData)-pos('!wetter')-7);
  else
  if pos(' :!lotto', sData) <> 0 then
    DeinEdit.Text := copy(sData, pos('!lotto')+6, length(sData)-pos('!lotto')-6);
  else
  if pos(' :!poker', sData) <> 0 then
    DeinEdit.Text := copy(sData, pos('!poker')+6, length(sData)-pos('!poker')-6);
  else
  if pos(' :!quiz', sData) <> 0 then
    DeinEdit.Text := copy(sData, pos('!quiz')+5, length(sData)-pos('!quiz')-5);


Mag sein dass der Code nich funktioniert, is nur schnell hingeklatscht. Aber das Prinzip sollte ersichtlich sein.
Ansonsten rat ich dir dringenst dazu, die empfangenen Daten aufzuschlüsseln, damit du immer weist, ob es sich jetz um ne PRIVMSG, ne NOTICE oda irgendwas anderes handelt, was du da empfängst.
Mir haben dabei die jeweiligen RFC's immer geholfen: RFC
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 19.05.07 22:51 
Moin!

Auch wenn es möglicherweise nicht dem eigentlichen Problem zuträglich ist: du hast hier einen versteckten "Denkfehler", denn du gehst möglicherweise davon aus, das ein .ReceiveText-Aufruf "vollständige" Datenpakete liefert:
user profile iconSauger Chris hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
i,c :integer;
filterstring: array[1..4of string;
begin
//...
sData := Socket.ReceiveText// socket text in memo schreiben
memo1.Lines.add(sData);
//...

Für nähere Infos siehe FAQ. :les: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.