예제 #1
0
        internal override Task SendMessage(Channel channel, string text, Attachment[] attachments)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(text);
            if (attachments != null && attachments.Any())
            {
                foreach (var attachment in attachments)
                {
                    if (!string.IsNullOrEmpty(attachment.Pretext))
                        Console.WriteLine(attachment.Pretext);
                    if (!string.IsNullOrEmpty(attachment.AuthorName))
                        Console.WriteLine(attachment.AuthorName);
                    Console.WriteLine($"{attachment.Title} <{attachment.TitleLink}>");
                    if (!string.IsNullOrEmpty(attachment.Text))
                        Console.WriteLine(attachment.Text);
                    foreach (var field in attachment.Fields)
                        Console.WriteLine($"{field.Title}: {field.Value}");
                    Console.WriteLine();
                }
            }
            Console.ResetColor();

            // TODO: .CompletedTask (4.6).
            return Task.FromResult(true);
        }
예제 #2
0
		public async override Task OnMessage(Channel channel, User user, string text, bool botIsMentioned)
		{
			// Check the message for a case reference.
			var match = Regex.Match(text, @"(?:fogbugz|fb|case|bug|feature|issue) (\d+)", RegexOptions.IgnoreCase);

			// Extract the case number.
			int caseNumber;
			if (!match.Success || !int.TryParse(match.Groups[1].Captures[0].Value, out caseNumber))
				return;

			// Make it clear we're doing something.
			await SendTypingIndicator(channel);

			// Attempt to fetch the case from the FogBugz API.
			var c = GetCase(caseNumber);
			if (c == null)
				await SendMessage(channel, $"_(Unable to retrieve info from FogBugz for Case {caseNumber})_");
			else
			{
				var att = new Attachment
				{
					Pretext = c.ParentBug != null ? $"Child case of {c.ParentBug}" : null,
					Fallback = $"{caseNumber}: {c.Title}",
					Title = $"{caseNumber}: {c.Title}",
					TitleLink = c.Url.AbsoluteUri,
					Text = c.LatestText,
					AuthorName = c.IsOpen ? c.AssignedTo : null,
					AuthorIcon = new Uri(url, $"default.asp?ixPerson={c.ixAssignedTo}&pg=pgAvatar&pxSize=16").AbsoluteUri,
					Colour = c.ixPriority <= 2 ? "danger" : "warning",
					Fields = new[]
					{
						new Field(c.Status, c.Category),
						new Field($"{c.Project} {c.Area}", "FixFor: " + c.Milestone)
					}
				};

				await SendMessage(channel, null, new[] { att });
			}
		}
예제 #3
0
		/// <summary>
		/// Used by the bot to send a message.
		/// </summary>
		abstract internal Task SendMessage(Channel channel, string text, Attachment[] attachments = null);
예제 #4
0
		protected async Task SendMessage(Channel channel, string text, Attachment[] attachments = null)
		{
			await bot.SendMessage(channel, text, attachments);
		}