public void ShouldFailUsersWhenApiUnavailable() { var rc = new RecentChange("1.2.3.4"); // act, assert Assert.Throws <InvalidOperationException>(() => rc.GetUserGroups()); }
public static string GetMessage(RecentChange change, string format, string lang) { // Parse length of the diff string strLength = ""; int length = (change.LengthNew - change.LengthOld); strLength = length.ToString(); if (length > 0) { strLength = "+" + strLength; } strLength = $"({strLength})"; if (length > 500 || length < -500) { strLength = $"**{strLength}**"; } // Markdownify link string link = format.Replace("/wiki/$1", string.Format("/?{0}{1}", (change.OldID != 0 ? "diff=" : "oldid="), change.RevID)); link = string.Format("([{0}]({1}))", Locale.GetMessage("eventstreams-diff", lang), link); // Markdownify user string user = "******" + change.User; string talk = "User_talk:" + change.User; string contribs = "Special:Contributions/" + change.User; user = Linking.GetLink(user, format, true); talk = Linking.GetLink(talk, format, true); contribs = Linking.GetLink(contribs, format, true); talk = string.Format("[{0}]({1})", Locale.GetMessage("eventstreams-talk", lang), talk); IPAddress address; if (IPAddress.TryParse(change.User, out address)) { user = $"[{change.User}]({contribs}) ({talk})"; } else { contribs = string.Format("[{0}]({1})", Locale.GetMessage("eventstreams-contribs", lang), contribs); user = $"[{change.User}]({user}) ({talk} | {contribs})"; } // Parse comment, adjusting for its length string comment = ParseComment(change.Summary, format); string msg = $"{link} . . {strLength} . . {user}"; if (msg.Length + comment.Length > 2000) { comment = ParseComment(change.Summary, format, false); } msg += comment; return(msg); }
public void ShouldFailCategoriesWhenApiUnavailable() { var rc = new RecentChange("1.2.3.4") { Page = "Foo" }; // act, assert Assert.Throws <InvalidOperationException>(() => rc.PageIsInCategory("Bar")); }
/// <summary> /// Gets all the changes, sorted by date/time ascending. /// </summary> public static RecentChange[] GetAllChanges( ) { RecentChange[] changes = Settings.Provider.GetRecentChanges( ); RecentChange[] myCopy = new RecentChange[changes.Length]; Array.Copy(changes, myCopy, changes.Length); Array.Sort(myCopy, (x, y) => { return(x.DateTime.CompareTo(y.DateTime)); }); return(myCopy); }
public void ShouldFailCategoriesWhenPageUnavailable() { var rc = new RecentChange("1.2.3.4"); var mwapi = new Mock <IMediaWikiApi>(); rc.MediaWikiApi = mwapi.Object; // act var pageIsInCategory = rc.PageIsInCategory("Bar"); // assert Assert.IsFalse(pageIsInCategory); mwapi.Verify(x => x.PageIsInCategory(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public static DiscordEmbedBuilder GetEmbed(RecentChange change, string format, string lang) { DiscordEmbedBuilder embed = new DiscordEmbedBuilder() .WithTimestamp(change.Timestamp); DiscordColor embedColor = new DiscordColor(0x72777d); string embedIcon = "2/25/MobileFrontend_bytes-neutral.svg/512px-MobileFrontend_bytes-neutral.svg.png"; // Parse statuses from the diff string status = ""; if (change.Type == RecentChange.ChangeType.New) { status += Locale.GetMessage("eventstreams-new", lang); } if (change.Minor == true) { status += Locale.GetMessage("eventstreams-minor", lang); } if (status != "") { embed.WithFooter(status); } // Parse length of the diff int length = (change.LengthNew - change.LengthOld); if (length > 0) { embedColor = new DiscordColor(0x00af89); embedIcon = "a/ab/MobileFrontend_bytes-added.svg/512px-MobileFrontend_bytes-added.svg.png"; } else if (length < 0) { embedIcon = "7/7c/MobileFrontend_bytes-removed.svg/512px-MobileFrontend_bytes-removed.svg.png"; embedColor = new DiscordColor(0xdd3333); } embed .WithAuthor( change.Title, Linking.GetLink(change.Title, format, true), string.Format("https://upload.wikimedia.org/wikipedia/commons/thumb/{0}", embedIcon) ) .WithColor(embedColor) .WithDescription(GetMessage(change, format, lang)); return(embed); }
public void ShouldGetIpGroups() { var rc = new RecentChange("1.2.3.4"); var mwapi = new Mock <IMediaWikiApi>(); rc.MediaWikiApi = mwapi.Object; var expected = new[] { "*" }; mwapi.Setup(x => x.GetUserGroups("1.2.3.4")).Returns(expected); // act var result = rc.GetUserGroups(); // assert Assert.AreEqual(expected, result); mwapi.Verify(x => x.GetUserGroups(It.IsAny <string>()), Times.Once()); }
/// <summary> /// Adds a new change. /// </summary> /// <param name="wiki">The wiki.</param> /// <param name="page">The page name.</param> /// <param name="title">The page title.</param> /// <param name="messageSubject">The message subject.</param> /// <param name="dateTime">The date/time.</param> /// <param name="user">The user.</param> /// <param name="change">The change.</param> /// <param name="descr">The description (optional).</param> public static void AddChange(string wiki, string page, string title, string messageSubject, DateTime dateTime, string user, Change change, string descr) { RecentChange[] allChanges = GetAllChanges(wiki); if (allChanges.Length > 0) { RecentChange lastChange = allChanges[allChanges.Length - 1]; if (lastChange.Page == page && lastChange.Title == title && lastChange.MessageSubject == messageSubject + "" && lastChange.User == user && lastChange.Change == change && (dateTime - lastChange.DateTime).TotalMinutes <= 60) { // Skip this change return; } } Settings.GetProvider(wiki).AddRecentChange(page, title, messageSubject, dateTime, user, change, descr); }
public static async Task React(JArray data, RecentChange change) { DiscordClient client = Program.Client; for (int i = 0; i < data.Count; i++) { // Setup basic info string[] info = data[i].ToString().Split('|'); ulong channelId = ulong.Parse(info[0]); DiscordChannel channel = await client.GetChannelAsync(channelId); int minLength = (info.Length > 1 ? Convert.ToInt32(info[1]) : -1); // Check if domain is the same string domain = Config.GetDomain(); if (channel != null) { domain = Config.GetDomain(channel.Guild.Id.ToString()); if (domain != change.ServerName) { continue; } } // Set up domain for future usage for link formatting domain = $"https://{domain}/wiki/$1"; // Check if the diff is above required length if it is set if (minLength > -1) { int revLength = (change.LengthNew - change.LengthOld); bool isMinLength = (revLength > minLength); if (isMinLength == false) { continue; } } // Send the message string lang = Config.GetLang(channel.Guild.Id.ToString()); await client.SendMessageAsync(channel, embed : GetEmbed(change, domain, lang)); } }
public void ShouldConstructObjectCorrectly() { var foo = new RecentChange("def") { Page = "abc", Url = "ghi", EditSummary = "jkl", EditFlags = "mno", SizeDiff = 123, Log = "pqr" }; Assert.AreEqual("abc", foo.Page); Assert.AreEqual("def", foo.User); Assert.AreEqual("ghi", foo.Url); Assert.AreEqual("jkl", foo.EditSummary); Assert.AreEqual("mno", foo.EditFlags); Assert.AreEqual(123, foo.SizeDiff); Assert.AreEqual("pqr", foo.Log); }
public void AddRecentChange_NullMessageSubject_NullDescription() { ISettingsStorageProviderV30 prov = GetProvider(); Collectors.SettingsProvider = prov; DateTime dt = DateTime.Now; Assert.IsTrue(prov.AddRecentChange("Page", "Title", null, dt, "User", ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, null), "AddRecentChange should return true"); RecentChange c = prov.GetRecentChanges()[0]; Assert.AreEqual("Page", c.Page, "Wrong page"); Assert.AreEqual("Title", c.Title, "Wrong title"); Assert.AreEqual("", c.MessageSubject, "Wrong message subject"); Tools.AssertDateTimesAreEqual(dt, c.DateTime); Assert.AreEqual("User", c.User, "Wrong user"); Assert.AreEqual(ScrewTurn.Wiki.PluginFramework.Change.PageUpdated, c.Change, "Wrong change"); Assert.AreEqual("", c.Description, "Wrong description"); }
public void ShouldGetPageInCat() { var rc = new RecentChange("1.2.3.4") { Page = "Foo" }; var mwapi = new Mock <IMediaWikiApi>(); rc.MediaWikiApi = mwapi.Object; var expected = new[] { "*" }; mwapi.Setup(x => x.PageIsInCategory("Foo", "Category:Bar")).Returns(true); // act var pageIsInCategory = rc.PageIsInCategory("Bar"); // assert Assert.IsTrue(pageIsInCategory); mwapi.Verify(x => x.PageIsInCategory("Foo", "Category:Bar"), Times.Once); }
public override bool match(RecentChange rc) { return expression.Match(rc.User).Success; }
public override bool match(RecentChange rc) { return true; }
public abstract bool match(RecentChange rc);
public override bool match(RecentChange rc) { return !this.ChildNode.match(rc); }
public override bool match(RecentChange rc) { return (LeftChildNode.match(rc) ^ RightChildNode.match(rc)); }
public override bool match(RecentChange rc) { return expression.Match(rc.EditSummary).Success; }