public SocialTip(string socialPlatform, ISocialUser fromUser, int amount, params ISocialUser[] users) { SocialPlatform = socialPlatform ?? throw new ArgumentNullException(nameof(socialPlatform)); FromUser = fromUser ?? throw new ArgumentNullException(nameof(fromUser)); Amount = amount; ToUsers = users ?? throw new ArgumentNullException(nameof(users)); }
public virtual TokenIdentity Authenticate( ISocialUser socialUser, DeviceType?deviceType = null, string deviceRegistrationID = null) { using (var usersRepo = new UsersRepository()) { var user = usersRepo.GetUserBySocialID(socialUser.SocialUserID, socialUser.SocialNetwork); user = (user ?? new User()).CopyFrom(socialUser); user.AuthToken = System.Guid.NewGuid().ToString(); if (user.ID == default(int)) { usersRepo.Add(user); } usersRepo.SaveChanges(); return(new TokenIdentity { AuthToken = user.AuthToken, SocialUser = user, UserID = user.ID }); } }
protected async Task <SocialTipResponse[]> SendTip(TContext context) { if (!await IsTip(context).ConfigureAwait(false)) { return(new SocialTipResponse[0]); } ISocialUser fromUser = await GetFromUser(context).ConfigureAwait(false); string messageId = await GetMessageId(context).ConfigureAwait(false); ISocialUser[] mentionedUsers = await GetMessageMentionedUsers(context).ConfigureAwait(false); if (mentionedUsers.Length == 0) { throw new NoUserMentionedException("Learn about Kinny here (https://telegram.me/kinnytip_bot?start=kinny) \r\nHow to tip Kin using Kinny:\r\n1. For (new message) direct tips: @username +amount /kinnytips\r\n2. For direct reply tips: +amount /kinnytips"); } string messageText = await GetMessageText(context).ConfigureAwait(false); double tipAmount = _tipParser.GetTipAmount(messageText); List <SocialTipResponse> listOfResponses = new List <SocialTipResponse>(); foreach (ISocialUser mentionedUser in mentionedUsers) { SocialTipRequest socialTipRequest = new SocialTipRequest { From = fromUser.UserId, To = mentionedUser.UserId, Amount = tipAmount, Provider = Platform, OfferParticipantsData = new OfferParticipantsData { From = new OfferData { Description = $"You sent {tipAmount} KIN to {mentionedUser.Username}", Title = $"Sent Tip ({Platform})", Username = fromUser.Username }, To = new OfferData { Description = $"{fromUser.Username} sent you {tipAmount} KIN", Title = $"Received Tip ({Platform})", Username = mentionedUser.Username } }, MessageId = messageId + mentionedUser.UserId }; listOfResponses.Add( await Tip(await GetSocialQueueItem(socialTipRequest, context).ConfigureAwait(false))); } return(listOfResponses.ToArray()); }
protected override Task <ISocialUser[]> GetMessageMentionedUsers(SocketCommandContext context) { SocketUser[] mentionedUsers = context.Message.MentionedUsers.Where(u => u.Username != _client.CurrentUser.Username && u.Username != context.User.Username) .ToArray(); ISocialUser[] users = new ISocialUser[mentionedUsers.Length]; for (int i = 0; i < mentionedUsers.Length; i++) { users[i] = new SocialUser(mentionedUsers[i].Username, mentionedUsers[i].Id.ToString()); } return(Task.FromResult(users)); }
public override TokenIdentity Authenticate( ISocialUser socialUser, DeviceType?deviceType = null, string deviceRegistrationID = null) { if (socialUser == null) { throw new ArgumentNullException("socialUser"); } var identity = base.Authenticate(socialUser, deviceType, deviceRegistrationID); HttpRuntime.Cache.Add( identity.AuthToken, identity, null, DateTime.Now.AddDays(7), Cache.NoSlidingExpiration, CacheItemPriority.Default, null); return(identity); }