private void NickChangeHandler(object sender, NickChangeEventArgs e) { lock (seenData) { var seenResult = seenData.SeenEntries.Where(s => s.Nick == e.OldNickname).FirstOrDefault(); if (seenResult != null) { seenResult.LastSeenTime = DateTime.Now; seenResult.LastAction = "(NICK) Nick changed to: " + e.NewNickname; seenResult.OnStatus = false; } seenResult = seenData.SeenEntries.Where(s => s.Nick == e.NewNickname).FirstOrDefault(); if (seenResult != null) { seenResult.LastSeenTime = DateTime.Now; seenResult.LastAction = "(NICK) Nick changed from: " + e.OldNickname; seenResult.OnStatus = true; } else { var seenEntry = new SeenEntry(); seenData.SeenEntries.InsertOnSubmit(seenEntry); seenEntry.Nick = e.NewNickname; seenEntry.LastSeenTime = DateTime.Now; seenEntry.LastAction = "(NICK) Nick changed from: " + e.OldNickname; seenEntry.LastMessage = "<no message yet>"; seenEntry.TimesSeen = 0; seenEntry.OnStatus = true; } var aliasResult = seenData.AliasEntries.Where(a => a.Nick == e.OldNickname && a.Alias == e.NewNickname).FirstOrDefault(); if (aliasResult == null) { var aliasEntry = new AliasEntry(); seenData.AliasEntries.InsertOnSubmit(aliasEntry); aliasEntry.Nick = e.OldNickname; aliasEntry.Alias = e.NewNickname; } aliasResult = seenData.AliasEntries.Where(a => a.Nick == e.NewNickname && a.Alias == e.OldNickname).FirstOrDefault(); if (aliasResult == null) { var aliasEntry = new AliasEntry(); seenData.AliasEntries.InsertOnSubmit(aliasEntry); aliasEntry.Nick = e.NewNickname; aliasEntry.Alias = e.OldNickname; } SaveDb(); } }
private void AliasEdit_Click(object sender, EventArgs e) { AliasEntry.Enabled = true; AliasEntry.Focus(); button2.Visible = true; }
/// <summary> /// Given an Entry object, instantiate it. Caller owns result. Return /// 0 on failure. /// <para/> /// Return a non-empty <paramref name="aliasReturn"/> value if the <paramref name="ID"/> points to an alias. /// We cannot instantiate it ourselves because the alias may contain /// filters or compounds, which we do not understand. Caller should /// make <paramref name="aliasReturn"/> empty before calling. /// <para/> /// The entry object is assumed to reside in the dynamic store. It may be /// modified. /// </summary> private Transliterator InstantiateEntry(string ID, object[] entryWrapper, StringBuffer aliasReturn) { // We actually modify the entry object in some cases. If it // is a string, we may partially parse it and turn it into a // more processed precursor. This makes the next // instantiation faster and allows sharing of immutable // components like the RuleBasedTransliterator.Data objects. // For this reason, the entry object is an Object[] of length // 1. for (; ;) { object entry = entryWrapper[0]; #pragma warning disable 612, 618 if (entry is RuleBasedTransliterator.Data) { RuleBasedTransliterator.Data data = (RuleBasedTransliterator.Data)entry; return(new RuleBasedTransliterator(ID, data, null)); #pragma warning restore 612, 618 } else if (entry is Type) { try { //return (Transliterator)((Type)entry).newInstance(); return((Transliterator)Activator.CreateInstance((Type)entry)); } catch (TargetInvocationException) { } catch (MethodAccessException) { } return(null); } else if (entry is AliasEntry) { aliasReturn.Append(((AliasEntry)entry).Alias); return(null); } else if (entry is ITransliteratorFactory) { return(((ITransliteratorFactory)entry).GetInstance(ID)); } else if (entry is CompoundRBTEntry) { return(((CompoundRBTEntry)entry).GetInstance()); } else if (entry is AnyTransliterator) { AnyTransliterator temp = (AnyTransliterator)entry; return(temp.SafeClone()); } #pragma warning disable 612, 618 else if (entry is RuleBasedTransliterator) { RuleBasedTransliterator temp = (RuleBasedTransliterator)entry; return(temp.SafeClone()); } #pragma warning restore 612, 618 else if (entry is CompoundTransliterator) { CompoundTransliterator temp = (CompoundTransliterator)entry; return(temp.SafeClone()); } else if (entry is Transliterator) { return((Transliterator)entry); } // At this point entry type must be either RULES_FORWARD or // RULES_REVERSE. We process the rule data into a // TransliteratorRuleData object, and possibly also into an // .id header and/or footer. Then we modify the registry with // the parsed data and retry. TransliteratorParser parser = new TransliteratorParser(); try { ResourceEntry re = (ResourceEntry)entry; parser.Parse(re.Resource, re.Direction); } catch (InvalidCastException) { // If we pull a rule from a locale resource bundle it will // be a LocaleEntry. LocaleEntry le = (LocaleEntry)entry; parser.Parse(le.Rule, le.Direction); } // Reset entry to something that we process at the // top of the loop, then loop back to the top. As long as we // do this, we only loop through twice at most. // NOTE: The logic here matches that in // Transliterator.createFromRules(). if (parser.IdBlockVector.Count == 0 && parser.DataVector.Count == 0) { // No idBlock, no data -- this is just an // alias for Null entryWrapper[0] = new AliasEntry(NullTransliterator._ID); } else if (parser.IdBlockVector.Count == 0 && parser.DataVector.Count == 1) { // No idBlock, data != 0 -- this is an // ordinary RBT_DATA entryWrapper[0] = parser.DataVector[0]; } else if (parser.IdBlockVector.Count == 1 && parser.DataVector.Count == 0) { // idBlock, no data -- this is an alias. The ID has // been munged from reverse into forward mode, if // necessary, so instantiate the ID in the forward // direction. if (parser.CompoundFilter != null) { entryWrapper[0] = new AliasEntry(parser.CompoundFilter.ToPattern(false) + ";" + parser.IdBlockVector[0]); } else { entryWrapper[0] = new AliasEntry(parser.IdBlockVector[0]); } } else { entryWrapper[0] = new CompoundRBTEntry(ID, parser.IdBlockVector, parser.DataVector, parser.CompoundFilter); } } }
public static void Search(string stitle, Action<AliasEntry> handler) { var c = new BasicWebCrawler("www.omdb.si", 80); var DefaultLink = new { Link = "", Title = "", Text = "" }; var ParseLink = DefaultLink.ToAnonymousConstructor( (string element) => { var Link = ""; var Title = ""; var Text = ""; element. ParseAttribute("href", value => Link = value). ParseAttribute("title", value => Title = value). ParseContent(value => Text = value). Parse(); return new { Link, Title, Text }; } ); c.DataReceived += document => { var trigger_tag = "<table width=\"100%\" class=\"fW\">"; var trigger_end_tag = "</table>"; Func<int, int> scan = offset => { var trigger_i = document.IndexOf(trigger_tag, offset); if (trigger_i < 0) return offset; var tirgger_end_i = document.IndexOf(trigger_end_tag, trigger_i); if (tirgger_end_i < 0) return offset; var data = document.Substring(trigger_i + trigger_tag.Length, tirgger_end_i - trigger_i - trigger_tag.Length); /* <tr> <td class="bTl"><img alt="" src="/images/default/Ogrodje0.gif" width="10" height="10" /></td> <td class="bT"></td><td class="bTr"></td></tr> <tr> <td class="bL"></td> <td class="bM"> <div align="left"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="5" rowspan="2"></td> <td width="444" align="left"> <div align="left"><a href="/index.php/ofilm/?i=401737">Lost <b>(2004)</b></a></div> </td> <td align="right"> <span class="forumozadje3"><b>8.9</b> <img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/d9.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellowEmpty.gif' class='slikevvrsti' /></span> </td></tr> <tr> <td align="left"> <span class="oddelki_forum_mala">Genre: <b>Drama, Adventure, Mystery, Thriller</b> Duration: <b>45 min</b></span> </td> <td align="right"><span class="oddelki_forum_mala">(174 votes)</span></td></tr> */ var title_tag = "<div align=\"left\">"; var title_end_tag = "</div>"; var title_i = data.IndexOf(title_tag); if (title_i < 0) return offset; title_i = data.IndexOf(title_tag, title_i + title_tag.Length); var title_end_i = data.IndexOf(title_end_tag, title_i); // Lost <b>(2004)</b> var title = ParseLink(data.Substring(title_i + title_tag.Length, title_end_i - title_i - title_tag.Length)); var genre_tag = "<span class=\"oddelki_forum_mala\">"; var genre_i = data.IndexOf(genre_tag, title_end_i); var genre_end_tag = "</span>"; var genre_end_i = data.IndexOf(genre_end_tag, genre_i); // Genre: <b>Drama, Adventure, Mystery, Thriller</b> Duration: <b>45 min</b> var genre = data.Substring(genre_i + genre_tag.Length, genre_end_i - genre_i - genre_tag.Length); var e = new AliasEntry { Genres = genre.Substring("Genre: <b>", "</b>").Split(new[] { ',' }).Trim(), Duration = genre.Substring("Duration: <b>", "</b>"), Link = "http://www.omdb.si" + title.Link, Title = title.Text.Substring(0, title.Text.IndexOf("<")), Year = title.Text.Substring("<b>", "</b>") }; handler(e); return tirgger_end_i + trigger_end_tag.Length; }; var start_tag = "<td align=\"right\" class=\"bM\">"; var start_offset = document.IndexOf(start_tag); start_offset = document.IndexOf(start_tag, start_offset); scan.ToChainedFunc((x, y) => y > x)(start_offset); }; // we will only look at the first result page c.Crawl("/index.php/odefault/search?sK=" + stitle.URLEncode()); }
public static string GetAlias(IrcMessage theMessage) { List <string> SplitString = new List <string>(theMessage.Message.TrimStart('!', ' ').Split(' ')); if (SplitString[0] == "alias" || SplitString[0] == "a") { SplitString.RemoveAt(0); } string thealias; using (var context = new BotContext()) { string key = SplitString[0]; AliasEntry entry = context.AliasEntries.FirstOrDefault(x => x.Key == key); if (entry != null && !String.IsNullOrEmpty(entry.Text)) { thealias = entry.Text; } else { return(String.Empty); } } for (int i = 0; thealias.Contains("$") && i < 99; i++) { if (SplitString.Count > 1) { string commandline = SplitString.Skip(1).Join(" "); thealias = thealias.Replace("$x", commandline).Replace("$X", commandline); } else { thealias = thealias.Replace("$x", "").Replace("$X", ""); } while (true) { int index = thealias.IndexOf("$" + (i + 1)); if (index == -1) { break; } thealias = thealias.Remove(index, 2); if (SplitString.Count - 1 > i) { thealias = thealias.Insert(index, SplitString[i + 1]); } else { thealias = thealias.Insert(index, ""); } } } while (thealias.Contains("encode(")) { int start = thealias.LastIndexOf("encode("); int end = thealias.Remove(0, start).IndexOf(')') + 1 + start; string second = thealias.Substring(start + 7, end - (start + 8)); second = Toolbox.UrlEncode(second); second = second.Replace("%23", "#").Replace("%3a", ":").Replace("%2f", "/").Replace("%3f", "?"); thealias = thealias.Substring(0, start) + second + thealias.Substring(end); } if (thealias[0] == '!') { StackTrace trace = new StackTrace(); StackFrame[] frames = trace.GetFrames(); int recursion = frames.Count(x => x.GetMethod() == frames[0].GetMethod()); if (recursion > 4) { theMessage.Answer("Einen moment mal... das scheint rekursiv zu sein. Ich beende das mal"); return(String.Empty); } IrcMessageData data = new IrcMessageData(theMessage.Data.Irc, theMessage.Data.From, theMessage.Data.Nick, theMessage.Data.Ident, theMessage.Data.Host, theMessage.Data.Channel, thealias, thealias, theMessage.Data.Type, theMessage.Data.ReplyCode, theMessage.Data.Tags); IrcMessage fake = new IrcMessage(data, theMessage.ServerConnetion); Program.HandleCommand(fake); theMessage.Hidden = fake.Hidden; theMessage.ProcessedByCommand = fake.ProcessedByCommand; for (int i = 0; i < fake.UnloggedMessages.Count; i++) { theMessage.UnloggedMessages.Enqueue(fake.UnloggedMessages.Dequeue()); } return(String.Empty); } return(thealias); }
public static void AliasCommand(IrcMessage theMessage) { using (var context = new BotContext()) { string key = null; if (theMessage.CommandArgs.Count > 1) { key = theMessage.CommandArgs[1]; } switch (theMessage.CommandArgs[0].ToLower()) { case "add": if (theMessage.CommandArgs.Count < 3) { theMessage.Answer("Unzureichend viele Argumente: add <key> <text ...>"); return; } if (context.AliasEntries.Any(x => x.Key == key)) { theMessage.Answer("Diesen Alias gibt es bereits"); return; } var add = new AliasEntry(); add.Key = theMessage.CommandArgs[1]; add.Text = theMessage.CommandArgs.Skip(2).Join(" "); add.Creator = context.GetUser(theMessage.Nickname); add.Created = DateTime.Now; context.AliasEntries.Add(add); context.SaveChanges(); theMessage.Answer("Der Alias wurde erfolgreich hinzugefügt"); return; case "edit": if (theMessage.CommandArgs.Count < 3) { theMessage.Answer("Unzureichend viele Argumente: edit <key> <neuer text>"); return; } AliasEntry edit = context.AliasEntries.FirstOrDefault(x => x.Key == key); if (edit != null) { edit.Text = theMessage.CommandArgs.Skip(2).Join(" "); edit.Updater = context.GetUser(theMessage.Nickname); edit.Updated = DateTime.Now; context.SaveChanges(); theMessage.Answer("Der Alias wurde erfolgreich bearbeitet"); return; } theMessage.Answer("So ein Alias wurde noch nicht definiert"); return; case "remove": if (theMessage.CommandArgs.Count < 2) { theMessage.Answer("Unzureichend viele Argumente: remove <key>"); return; } AliasEntry remove = context.AliasEntries.FirstOrDefault(x => x.Key == key); if (remove != null) { context.AliasEntries.Remove(remove); context.SaveChanges(); theMessage.Answer("Alias wurde gelöscht"); return; } theMessage.Answer("Diesen Alias gibt es nicht"); return; case "info": case "details": if (theMessage.CommandArgs.Count < 2) { theMessage.Answer("Unzureichend viele Argumente: info <key>"); return; } AliasEntry info = context.AliasEntries.Include(x => x.Creator.LastUsedName).Include(x => x.Updater.LastUsedName).FirstOrDefault(x => x.Key == key); if (info != null) { StringBuilder sb = new StringBuilder(); if (info.Creator != null) { sb.Append("Erstellt von " + info.Creator.LastUsedName); if (info.Created.HasValue) { sb.Append(" am " + info.Created.Value.ToShortDateString() + " um " + info.Created.Value.ToShortTimeString() + ". "); } else { sb.Append(". "); } } if (info.Updater != null) { sb.Append("Geändert von " + info.Updater.LastUsedName); if (info.Updated.HasValue) { sb.Append(" am " + info.Updated.Value.ToShortDateString() + " um " + info.Updated.Value.ToShortTimeString() + ". "); } else { sb.Append(". "); } } sb.Append("Definition: " + info.Text); theMessage.Answer(sb.ToString()); return; } theMessage.Answer("Wups, diesen Alias kenne ich nicht"); return; case "find": case "search": { if (theMessage.CommandArgs.Count < 2) { theMessage.Answer("Wonach soll ich denn Suchen wenn du nichts angibst ?: search <key>"); return; } key = key.ToLower(); List <AliasEntry> search = context.AliasEntries.Where(x => x.Key.ToLower().Contains(key) || x.Text.ToLower().Contains(key)).ToList(); if (search.Count == 0) { theMessage.Answer("Nichts gefunden :("); return; } if (search.Count == 1) { theMessage.Answer(search[0].Key + ": " + search[0].Text); } else { theMessage.Answer("Mögliche Aliase: " + search.Select(x => x.Key).Join(", ")); } return; } default: string theAlias = GetAlias(theMessage); if (!String.IsNullOrEmpty(theAlias)) { theMessage.Answer(theAlias); return; } if (theMessage.UnloggedMessages.Count == 0) { theMessage.Answer("Wups, diesen Alias gibt es nicht"); } return; } } }
public override bool Equals(object obj) { AliasEntry e = obj as AliasEntry; return(e != null && e.Name == this.Name); }
public static void Search(string stitle, Action <AliasEntry> handler) { var c = new BasicWebCrawler("www.omdb.si", 80); var DefaultLink = new { Link = "", Title = "", Text = "" }; var ParseLink = DefaultLink.ToAnonymousConstructor( (string element) => { var Link = ""; var Title = ""; var Text = ""; element. ParseAttribute("href", value => Link = value). ParseAttribute("title", value => Title = value). ParseContent(value => Text = value). Parse(); return(new { Link, Title, Text }); } ); c.DataReceived += document => { var trigger_tag = "<table width=\"100%\" class=\"fW\">"; var trigger_end_tag = "</table>"; Func <int, int> scan = offset => { var trigger_i = document.IndexOf(trigger_tag, offset); if (trigger_i < 0) { return(offset); } var tirgger_end_i = document.IndexOf(trigger_end_tag, trigger_i); if (tirgger_end_i < 0) { return(offset); } var data = document.Substring(trigger_i + trigger_tag.Length, tirgger_end_i - trigger_i - trigger_tag.Length); /* * <tr> * <td class="bTl"><img alt="" src="/images/default/Ogrodje0.gif" width="10" height="10" /></td> * <td class="bT"></td><td class="bTr"></td></tr> * <tr> * <td class="bL"></td> * <td class="bM"> * <div align="left"> * <table width="100%" border="0" cellspacing="0" cellpadding="0"> * <tr> * <td width="5" rowspan="2"></td> * <td width="444" align="left"> * <div align="left"><a href="/index.php/ofilm/?i=401737">Lost <b>(2004)</b></a></div> * </td> * <td align="right"> * <span class="forumozadje3"><b>8.9</b> * <img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellow.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/d9.gif' class='slikevvrsti' /><img src='/images/default/zvezdice/yellowEmpty.gif' class='slikevvrsti' /></span> * </td></tr> * <tr> * <td align="left"> * <span class="oddelki_forum_mala">Genre: <b>Drama, Adventure, Mystery, Thriller</b> Duration: <b>45 min</b></span> * </td> * <td align="right"><span class="oddelki_forum_mala">(174 votes)</span></td></tr> */ var title_tag = "<div align=\"left\">"; var title_end_tag = "</div>"; var title_i = data.IndexOf(title_tag); if (title_i < 0) { return(offset); } title_i = data.IndexOf(title_tag, title_i + title_tag.Length); var title_end_i = data.IndexOf(title_end_tag, title_i); // Lost <b>(2004)</b> var title = ParseLink(data.Substring(title_i + title_tag.Length, title_end_i - title_i - title_tag.Length)); var genre_tag = "<span class=\"oddelki_forum_mala\">"; var genre_i = data.IndexOf(genre_tag, title_end_i); var genre_end_tag = "</span>"; var genre_end_i = data.IndexOf(genre_end_tag, genre_i); // Genre: <b>Drama, Adventure, Mystery, Thriller</b> Duration: <b>45 min</b> var genre = data.Substring(genre_i + genre_tag.Length, genre_end_i - genre_i - genre_tag.Length); var e = new AliasEntry { Genres = genre.Substring("Genre: <b>", "</b>").Split(new[] { ',' }).Trim(), Duration = genre.Substring("Duration: <b>", "</b>"), Link = "http://www.omdb.si" + title.Link, Title = title.Text.Substring(0, title.Text.IndexOf("<")), Year = title.Text.Substring("<b>", "</b>") }; handler(e); return(tirgger_end_i + trigger_end_tag.Length); }; var start_tag = "<td align=\"right\" class=\"bM\">"; var start_offset = document.IndexOf(start_tag); start_offset = document.IndexOf(start_tag, start_offset); scan.ToChainedFunc((x, y) => y > x)(start_offset); }; // we will only look at the first result page c.Crawl("/index.php/odefault/search?sK=" + stitle.URLEncode()); }