/// <summary> /// </summary> /// <param name="fromType">Used to set which members messages must be processed.</param> public Task <Message> ReadMessageAsync( ReadCallbackFromType fromType = ReadCallbackFromType.CurrentUser, CancellationToken cancellationToken = default(CancellationToken) ) { return(_botExtSingleton.ReadMessageAsync(_updateContext, fromType, cancellationToken)); }
/// <summary> /// </summary> /// <param name="updateContext">Current command context. Needed to find TaskCompletionSource of current command.</param> /// <param name="fromType">Used to set which members messages must be processed.</param> public async Task <Message> ReadMessageAsync( UpdateContext updateContext, ReadCallbackFromType fromType, CancellationToken cancellationToken ) { UpdateValidatorDelegate updateValidator = async(newCtx, origCtx) => { return(CheckFromType(newCtx, origCtx, fromType)); }; return(await ReadMessageAsync(updateContext, updateValidator, cancellationToken)); }
public static bool Check(UpdateContext newCtx, UpdateContext origCtx, ReadCallbackFromType fromType) { var upd = newCtx.Update; try { origCtx.Logger().LogTrace("Default CheckFromType for {0}.", fromType); if (fromType == ReadCallbackFromType.CurrentUser) { return(newCtx.FromId.Identifier == origCtx.FromId.Identifier); } else if (fromType == ReadCallbackFromType.CurrentUserReply) { if (newCtx.FromId.Identifier == origCtx.FromId.Identifier) { return(false); } if (upd.Message.ReplyToMessage?.From.Id != origCtx.Bot.BotId) { return(false); } return(true); } else if (fromType == ReadCallbackFromType.AnyUserReply) { if (upd.Message.ReplyToMessage?.From.Id != origCtx.Bot.BotId) { return(false); } return(true); } else if (fromType == ReadCallbackFromType.AnyUser) { //I know that current expression can be removed, but it make code more readable. return(true); } return(true); } catch { return(false); } }
UpdateValidatorResult CheckFromType(UpdateContext newCtx, UpdateContext origCtx, ReadCallbackFromType fromType) { var res = ReadCallbackFromDefaultValidator.Check(newCtx, origCtx, fromType); return(res ? UpdateValidatorResult.Valid : UpdateValidatorResult.ContinueWaiting); }