public UserMention ParseUserMention(JObject obj) { var userMention = new UserMention { Indices = ParseIndices(obj["indices"].ToObject <JArray>()), Name = obj["name"].ToString(), ScreenNane = obj["screen_name"].ToString(), ID = obj["id"].ToObject <long>() }; return(userMention); }
internal UserMentionElement(UserMention mention, BindableMessage?context) : base(mention) { this.DefaultStyleKey = typeof(UserMentionElement); if (context is null) { return; } if (context.Users.ContainsKey(mention.UserId)) { User = context.Users[mention.UserId]; UserName = User.User.Username; } }
public long AddUserMention(UserMention userMention) { var user = _context.UserMentions.FirstOrDefault(um => um.Id == userMention.Id); if (user == null) { _context.UserMentions.Add(userMention); _context.SaveChanges(); return(userMention.Id); } else { return(user.Id); } }
private List<IMessageBlock> GenerateApproval(SlashCommand command) { return new List<IMessageBlock> { new Header("Approval request"), new Section(new MarkdownText("*From*"), new MarkdownText(UserMention.Text(command.UserId))){BlockId = "originator"}, new Section(new MarkdownText("*Request For*"), new PlainText(command.Text)){BlockId = "request"}, new Actions { Elements = new List<IMessageElement> { new Button{Text="Approve", Style = ButtonStyle.Primary, Value="approved"}, new Button{Text="Deny", Style = ButtonStyle.Danger, Value="declined"} } } }; }
public async Task ShouldSendGreetingToUserViaDmsIfNotRegisteredAndWasMentioned( string content, Snowflake userId, Snowflake botId, Snowflake channelId, [Frozen] Channel channel, [Frozen] AdapterOptions options, [Frozen] IStringLocalizer <Strings> strings, [Frozen, Substitute] IDiscordUserClient userClient, [Frozen, Substitute] IDiscordChannelClient channelClient, [Frozen, Substitute] IGatewayService gateway, [Frozen, Substitute] IMessageEmitter emitter, [Frozen, Substitute] IUserService userService, [Target] MessageCreateEventController controller ) { var cancellationToken = new CancellationToken(false); var author = new User { Id = userId }; var mention = new UserMention { Id = botId }; var message = new Message { Content = content, Author = author, ChannelId = channelId, Mentions = new[] { mention } }; var @event = new MessageCreateEvent { Message = message }; gateway.BotId = botId; userService.IsUserRegistered(Any <User>(), Any <CancellationToken>()).Returns(false); await controller.Handle(@event, cancellationToken); await userClient.Received().CreateDirectMessageChannel(Is(userId), Is(cancellationToken)); await channelClient.Received().CreateMessage(Is(channel.Id), Is <CreateMessagePayload>(payload => payload.Content == strings["RegistrationGreeting", options.RegistrationUrl] !), Is(cancellationToken)); }
public void User() { Assert.Equal("<@U1234>", UserMention.Text("U1234")); }