Thema: [Tutorial][#3] Chatverlauf
-
27.11.2011, 17:42 #1
[Tutorial][#3] Chatverlauf
Nabend, mein letztes Tutorial habe ich vor fast einer Woche gepostet, verzeiht mir diese lange Wartezeit
In diesem Tutorial geht es darum den Chatverlauf etwas schöner darzustellen.
Ich möchte allerdings, dass ihr lernt selbstständig zu arbeiten, deswegen werde ich nur einfache Codes posten, die ihr dann erweitern könnt, damit euer Bot nicht zu einem C&P Projekt wird
Momentan könnte euer Chatverlauf so aussehen:
Wir möchten diesen allerings in etwa so haben:
Dann fangen wir mal an, das ist nicht wirklich schwer,
wir schreiben eine Methode und ändern den restlichen Code etwas.
Zuerst erstellen wir diese Methode:
Code:Private Sub WriteText(ByVal Absender As String, ByVal AbsenderFarbe As Color, ByVal Text As String, ByVal TextFarbe As Color) RichTextBox1.SelectionColor = AbsenderFarbe RichTextBox1.AppendText(Absender & ": ") RichTextBox1.SelectionColor = TextFarbe RichTextBox1.AppendText(Text & vbLf) End Sub
Anschließend passen wir den restlichen Code noch an, d.h. wir ersetzen z.b. im PublicMessage Event:
Code:RichTextBox1.AppendText(Nick & ": " & Message & vbLf)
Code:WriteText(Nick, Color.Red, Message, Color.Black)
Früher war es noch möglich den Chatverlauf schön sauber zu halten, mittlerweile gibt es aber schon so viele verschiedene Sonderzeichen (sind es eigentlich nicht aber ich weiß nicht, wie man das nennt, also z.b. dieses °serverpp oder so in der Art) , dass es nicht möglich ist den Chatverlauf davon 100% zu befreien, zumindest würde es viel zu lange dauern...Geändert von Snees (27.11.2011 um 17:44 Uhr)
-
The Following 2 Users Say Thank You to Snees For This Useful Post:
-
27.11.2011, 17:49 #2
AW: [Tutorial][#3] Chatverlauf
Code:Message = Message.Replace("°>_hi", "").Replace("|/serverpp ", "").Replace("|/w ", "").Replace("<°", "").Replace("""", "")
Und wer will, kann sich die hier die Zeichen raussuchen und diese dann ebenfalls replacen
Code:°>CENTER°+9030°°>{table|w2|588|w2 °>{tc}°>left<12°#°>abo/abo_textlink-2011-11_001_bg...w_588.h_193.png#°+9208° #°>abo/abo_textlink-2011-11_002_over_2d...w_588.h_193.gif#°+9151° #°3° #°11° # # # °>sm_abo_11-11_rudolph...b.h_10.mx_45.my_-1.w_110.gif °>sm_abo_11-11_xmas-boot...b.h_10.w_69.gif °>sm_abo_11-11_giftgiving-ani...b.h_10.my_1.w_77.gif °>sm_abo_11-11_lollipop-ani...b.h_10.w_73.gif °>sm_abo_11-11_baby-girl-ani...b.h_10.my_4.w_77.gif °>abo/abo_textlink-2011-11_001_feature-vamp_001...b.h_10.my_48.w_81.gif °>abo/abo_textlink-2011-11_001_feature-wwolf_001...b.h_10.my_41.gif#°+9117>abo/abo_textlink-2011-07_001_trans...b.w_588.h_193.gif|abo/abo_textlink-2011-11_001_hover...b.w_588.h_193.gif<>|/mobpay smileyabo°>{tc} °>{endtable}°>left#°r°#
-
-
27.11.2011, 18:14 #3
- Registriert seit
- 09.11.2011
- Beiträge
- 121
Thanked 129 Times in 46 PostsAW: [Tutorial][#3] Chatverlauf
Warum replacest du °>_hi, wenn es doch immer °>_hNICK|/serverpp "|/w "<° ist?
Ich würde nicht die ganzen Codes ersetzen, sondern den Text per Schleife durchgehen, das was zwischen ° ist filtern und dann erstmal schauen, um was es sich handelt (Farbcodes: R, G, B, O, M, [R,G,B] (z.B. [12,100,203]) oder Links >SHOWTEXT|LINKSKLICK|RECHTSKLICK OPTIONAL<, nicht unterstrichene Links (_h) wie bei >_hNICK|/serverpp "|/w "< und ob davor noch ein Farbcode ist like BB>...|...|...<).
Dann die nötigen Informationen filtern mit String.IndexOf/Regex/whatever und (mit Highlighting) anzeigen.
MfG
-
-
27.11.2011, 18:25 #4
-
18.12.2011, 01:28 #5
- Registriert seit
- 17.12.2011
- Beiträge
- 151
Thanked 24 Times in 23 PostsAW: [Tutorial][#3] Chatverlauf
Hiii ich hab mal ne frage wenn man so ein normalen Stayonlinebot macht könnte man wenn ein CM im channel kommt, kann der bot das CM zeichen (<PIC>) auch machen, also so da neben den nick machen, oder kann ein onlinebot das nicht? oder gibt es kein code dafür :o?
-
18.12.2011, 01:53 #6
AW: [Tutorial][#3] Chatverlauf
-
18.12.2011, 02:36 #7
AW: [Tutorial][#3] Chatverlauf
Hallo,
das ist gar nicht so schwer einfach im OnTokenReceived Sub
das cm icon auslesen.
Code:Dim WithEvents c As New KNClient(New Applet()) Private Sub c_OnTokenReceived(ByVal sender As Object, ByVal token As String) Handles c.OnTokenReceived Dim tokens As String() = token.Split(vbNullChar) Select Case (tokens(0)) Case "u" ' Userlist" If tokens(5).Contains("pics/cm.png") Then ' CM hat den Channel betreten. End If End Select End Sub
Geändert von uncopyable (18.12.2011 um 02:43 Uhr) Grund: Split
while( behappy() ) { code(); }
-
18.12.2011, 02:38 #8
AW: [Tutorial][#3] Chatverlauf
Split ist eine veraltete VB6 Funktion, die äquivalente Funktion im .NET Framework lautet STRING.Split.
-
18.12.2011, 02:48 #9
AW: [Tutorial][#3] Chatverlauf
geht auch damit (ist jetzt für html-code ausgelegt, mit ein paar änderungen kann man damit aber auch machen was man will...):
PHP-Code:private class KCodeItem
{
private int id;
private string code;
private string html;
//Eine Sammlung von Regular-Expressions für die Identifizierung der Knuddels-Links
private Dictionary<string, string> regExCollection = new Dictionary<string, string>();
/// <summary>
/// Konstruktor
/// </summary>
/// <param name="id">Die Nummer des Code-Elements</param>
/// <param name="code">Der Inhalt des Code-Elements</param>
/// <param name="channel">Channelobjekt mit Styleeinstellungen des Channels</param>
public KCodeItem(int id, string code, Channel c)
{
this.id = id;
this.code = code;
#region regexCollection erstellen
//Reihenfolge ist Wichtig!!!
//Bild + Text + WebLink
regExCollection.Add("ImageTextWebLink", "BB>(.+?)\\.(gif)<>(.*?)\\|((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s\"]*))<");
//Text + WebLink
regExCollection.Add("TextLink", "BB>(.*?)(\\|)((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s\"]*))<");
//Bild + Text + Befehlssatz1 + Linktext + Befehlssatz2
regExCollection.Add("ParameterizedImageChatLink", "BB >(.*?)< >--< >\\|(.*?)\\|(.*?)< >--< >(.*?)\\|(.*?)\\|(.*?)< r");
//Reihenfolge ist Wichtig!!!
//Links ohne Parameter
regExCollection.Add("LinkWithoutParams", ">_h(.*?)\\|(.*?)\\|(.*?)<");
//Links mit Parametern
regExCollection.Add("ParameterizedChatLink", ".*?>_h(.*?)\\|(.*?)\"\\|(.*?)\"<");
//Links mit selbem Parameter auf beiden Maustasten
regExCollection.Add("SimpleParamLink", ">(.*?)\\|(.*?) \\\"<");
//Formatierter Link mit Text = Funktion und nur einer Funktion
regExCollection.Add("SingleParamLink", "(.*?)>(.*?)\\|\"<(.*?)");
//Pics (doppelte)
regExCollection.Add("DoublePicture", ">sm_(.*?)<>sm_(.*?)<");
//Pics (einzelne)
regExCollection.Add("SimplePicture", ">(.+?)<");
#endregion
if (code.Length > 0 && code[0] == '>' || code.StartsWith("BB >") || code.StartsWith("BB>") && code[1] != '{')
{
foreach (KeyValuePair<string, string> kvp in regExCollection)
{
Match m = new Regex(kvp.Value, RegexOptions.IgnoreCase | RegexOptions.Singleline).Match(code);
string fileName = null;
string text = null;
string url = null;
string commandLeftClick = null;
string commandRightClick = null;
string imageName = null;
if (m.Success)
{
switch (kvp.Key)
{
#region LinkWithoutParams
case "LinkWithoutParams":
text = m.Groups[1].ToString();
text = text.Replace("\\<", "<");
text = text.Replace("\\>", ">");
commandLeftClick = m.Groups[2].ToString().Replace("\"", text);
commandRightClick = m.Groups[3].ToString().Replace("\"", text);
this.html = "<a hidefocus=\"hidefocus\" class=\"leading\" href=\"#\" name=\"" + commandLeftClick + "|" + commandRightClick + "\">" + text + "</a>";
break;
#endregion
#region TextLink
case "TextLink":
text = m.Groups[1].ToString();
text = text.Replace("\\<", "<");
text = text.Replace("\\>", ">");
url = m.Groups[3].ToString();
this.html = "<a hidefocus=\"hidefocus\" href=\"#\" name=\"\0" + url + "|\0" + url + "\">" + text + "</a>";
break;
#endregion
#region ParameterizedImageChatLink
case "ParameterizedImageChatLink":
/* <------ NOT USED! ------>
string str = "";
for (int i = 0; i <= m.Groups.Count; i++)
{
str += "[" + i.ToString() + "]" + m.Groups[i].ToString() + "\r\n";
}
MessageBox.Show(str);*/
fileName = m.Groups[1].ToString();
string command1Left = m.Groups[2].ToString();
string command1Right = m.Groups[3].ToString();
text = m.Groups[4].ToString();
text = text.Replace("\\<", "<");
text = text.Replace("\\>", ">");
string command2Left = m.Groups[5].ToString();
string command2Right = m.Groups[6].ToString();
//ClientHelper.imageLoader(fileName, ClientHelper.standartPicsDirectory + '/' + ClientHelper.standartPicsDirectory, rootDomain);
//filePath = new FileInfo(ClientHelper.imageDirectory + @"\" + fileName);
this.html = "<img src=\"" + "http://chat.knuddels.de/" + fileName + "\">" + "<a hidefocus=\"hidefocus\" href=\"#\" name=\"" + command2Left + "|" + command2Right + "\">" + text + "</a>";
break;
#endregion
#region ImageTextWebLink
case "ImageTextWebLink":
imageName = m.Groups[1].ToString();
if (imageName.Contains("..."))
imageName = imageName.Substring(0, imageName.IndexOf("...")) + ".png";
imageName = imageName + "." + m.Groups[2];
text = m.Groups[3].ToString();
text = text.Replace("\\<", "<");
text = text.Replace("\\>", ">");
url = m.Groups[4].ToString();
fileName = imageName;
//ClientHelper.imageLoader(fileName, ClientHelper.standartPicsDirectory + '/' + ClientHelper.standartPicsDirectory, rootDomain);
//filePath = new FileInfo(ClientHelper.imageDirectory + @"\" + fileName);
this.html = "<img src=\"" + "http://chat.knuddels.de/" + url + "\">" + "<a hidefocus=\"hidefocus\" href=\"#\" name=\"\0" + url + "|\0" + url + "\">" + text + "</a>";
break;
#endregion
#region ParameterizedChatLink
case "ParameterizedChatLink":
string param = m.Groups[1].ToString();
commandLeftClick = m.Groups[2].ToString();
commandRightClick = m.Groups[3].ToString();
param = param.Replace("<", "<");
param = param.Replace(">", ">");
this.html = "<a hidefocus=\"hidefocus\" href=\"#\" name=\"" + commandLeftClick + param + "|" + commandRightClick + param + "\">" + param + "</a>";
break;
#endregion
#region SimpleParamLink
case "SimpleParamLink":
text = m.Groups[1].ToString();
text = text.Replace("\\<", "<");
text = text.Replace("\\>", ">");
commandLeftClick = m.Groups[2].ToString();
commandRightClick = m.Groups[2].ToString();
this.html = "<a style=\"text-decoration:underline;\" hidefocus=\"hidefocus\" class=\"leading\" href=\"#\" name=\"" + commandLeftClick + "|" + commandRightClick + "\">" + text + "</a>";
break;
#endregion
#region SingleParamLink
case "SingleParamLink":
//regExCollection.Add("SingleParamLink", "(.*?)>(.*?)\\|\"<(.*?)");
text = m.Groups[2].ToString();
text = text.Replace("\\<", "<");
text = text.Replace("\\>", ">");
commandLeftClick = m.Groups[2].ToString();
commandRightClick = m.Groups[2].ToString();
string add = "";
if (m.Groups[1].ToString() == "BB")
add = "color: " + ColorTranslator.ToHtml(c.blue).Replace("#", "") + ";";
this.html = "<a style=\"text-decoration:underline; font-weight:bold; " + add + "\" hidefocus=\"hidefocus\" class=\"leading\" href=\"#\" name=\"" + commandLeftClick + "|" + commandRightClick + "\">" + text + "</a>";
break;
#endregion
#region DoublePicture
case "DoublePicture":
//ForeGround
string pic1 = "sm_" + m.Groups[1];
//Background
string pic2 = "sm_" + m.Groups[2];
this.html = "<img style =\"background-image:url(file:///" + ImageHandler.LoadImage(pic1).ImagePath + ");\" src=\"file:///" + ImageHandler.LoadImage(pic2).ImagePath + "\">";
break;
#endregion
#region SimplePicture
case "SimplePicture":
fileName = m.Groups[1].ToString();
try
{
this.html = "<img src=\"file:///" + ImageHandler.LoadImage(fileName).ImagePath + "\">";
}
catch
{
this.html = "[RegExNotImplemented]";
File.AppendAllText("unparsed.txt", code + Environment.NewLine);
}
break;
#endregion
}
break;
}
}
if (this.html == null || this.html == "" || this.html == string.Empty)
this.html = code + "\n";
}
else if (code.Length > 3 && code[2] == '{')
{
File.AppendAllText("unparsed.txt", code + Environment.NewLine);
}
#region RGB Color
else if (code.Length != 0 && code[0] == '[')
{
try
{
code = code.Substring(1);
code = code.Remove(code.Length - 1);
string[] rgb = code.Split(new char[] { ',' });
Color color = Color.FromArgb(
int.Parse(rgb[0]),
int.Parse(rgb[1]),
int.Parse(rgb[2]));
this.html =
"<span style=\"color: " +
ColorTranslator.ToHtml(color) +
";\">";
}
catch
{
}
}
#endregion
#region ColorLetter, Size, Fehler
else
{ //ColorLetter / Size
string[] ChatColors = { "W", "E", "R", "O", "P", "A", "D", "G", "K", "Y", "C", "B", "N", "M", "BB", "RR" };
string[] ChatSizes = new string[31];
for (int i = 1; i <= 30; i++)
ChatSizes[i] = i.ToString();
string[] HTMLColors = { "#FFFFFF", "#00AC00", "#FF0000", "#FFC800", "#FFAFAF", "#808080", "#404040", "#00FF00", "#000000", "#FFFF00", "#00FFFF", "#0000FF", "#964A00", "#FF00FF", ColorTranslator.ToHtml(c.blue).Replace("#", ""), ColorTranslator.ToHtml(c.red).Replace("#", "") };
#region Check Colors
for (int i = 1; i <= 16; i++)
if (code == ChatColors[i - 1])
{
this.html = "<span style=\"color: " + HTMLColors[i - 1] + ";\">";
return;
}
#endregion
#region CheckFormatReset
if (code == "r")
{
this.html = "</span></b></i><span style=\"font-size:" + c.fontSize + "px; color: " + ColorTranslator.ToHtml(c.foreColor) + ";\">";
return;
}
#endregion
#region Check Points
if (code == "!")
{
this.html = "<span style=\"letter-spacing: 2px; color: " + ColorTranslator.ToHtml(c.foreColor) + "; font-size:7px;\">.........</span>";
return;
}
#endregion
#region Check Sizes
try
{
int.Parse(code);
this.html = "<span style=\"font-size:" + code + "px\">";
return;
}
catch { }
#endregion
#region Size&Color
try
{
string re1 = "(\\d+)"; // Integer Number 1
string re2 = "([a-z])"; // Any Single Character 1
string size = new Regex(re1, RegexOptions.IgnoreCase | RegexOptions.Singleline).Match(code).Groups[1].ToString();
string color = new Regex(re2, RegexOptions.IgnoreCase | RegexOptions.Singleline).Match(code).Groups[1].ToString();
for (int i = 1; i <= 16; i++)
if (color == ChatColors[i - 1])
color = HTMLColors[i - 1];
this.html = "<span style=\"font-size:" + size + "px; color: " + color + ";\">";
return;
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
#endregion
this.html = code;
//Konnte nichts mit anfangen, also erstmal zurück,
//damit man sieht, wenn Fehler auftauchen.
}
#endregion
}
public int Id
{
get { return this.id; }
}
public string Code
{
get { return this.code; }
}
public string HTML
{
get { return this.html; }
}
}
-
The Following 3 Users Say Thank You to Sky.NET For This Useful Post:
DnL (07.02.2012), Snees (18.12.2011), uncopyable (18.12.2011)
-
18.12.2011, 14:50 #10
AW: [Tutorial][#3] Chatverlauf
Anschließend passen wir den restlichen Code noch an, d.h. wir ersetzen z.b. im PublicMessage Event:
Welches PublicMessage Event?
Ähnliche Themen
-
GFX Tutorial's Basic uvm.
Von Ricardo1337 im Forum TutorialsAntworten: 5Letzter Beitrag: 28.08.2013, 17:56 -
Chatverlauf faken
Von UnReal im Forum Fragen & ProblemeAntworten: 5Letzter Beitrag: 29.07.2013, 08:36 -
C++ Tutorial: Hello World
Von x failstar im Forum C++Antworten: 11Letzter Beitrag: 04.07.2012, 14:48 -
(.bat) Batch Tutorial
Von MC Phlegmatisch im Forum TutorialsAntworten: 0Letzter Beitrag: 31.03.2012, 13:35 -
[VB] - Chatverlauf farbig gestalten - Problem
Von Pyromane im Forum SourcecodeAntworten: 1Letzter Beitrag: 26.03.2012, 14:12
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.