How to prevent the bot from responding to the admin in Pyrogram - pyrogram

#app.on_message(filters.private & filters.user != ADMIN)
def something(app, message):
doSomething()

I Expect ADMIN is the chat_id of Admin
ADMIN=849816969
#app.on_message(filters.private & ~filters.user(ADMIN))
def something(app, message):
doSomething()
If More than one admin
ADMIN=[849816969, 599815969, 488681569]
#app.on_message(filters.private & ~filters.user(ADMIN))
def something(app, message):
doSomething()
here ~ work as not operator
you can find it in Pyrogram Docs: https://docs.pyrogram.org/topics/use-filters#combining-filters
Use ~ to invert a filter (behaves like the not operator).
Use & and | to merge two filters (behave like and, or operators respectively).

Related

Why any Geb page method or module method can not be accessed in Where block

I have a Page class and having some method which extract the Web page. Now I want to call these method into the Where block of Spock to pass as data provider. But when I call the method then it throws an error as it did not find it. But the same is accessible from out of Where block. Why is it so?
Example
def "Validate all article has its id"(){
when:"I am at Overview page"
at OverviewPage
then:"I should the article id of all article"
getAllCountOf(articleInfo).size() == actualCount
where:
articleInfo |actualCount
TopArticleListInfo.ARTICLE_THUMBNAIL |filter.getCount()
}
In the above code 'filter.getCount()' can not be accessed from Where block, But the same method is accessible in when or then block.
i want to understand the logic behind the scene It looks like , Where block is not able to find this method statically, need to create an object to call this.
When I tried the solution provided by erdi, But that also not solving the issue
when:"I am at Overview page"
at OverviewPage
then:"I should the article id of all article"
getAllCountOf(articleInfo).size() == page."$actualCount"
where:
articleInfo |actualCount
TopArticleListInfo.ARTICLE_THUMBNAIL |'getRowCount().size()'
Here getRowCount().size() substitute in "$actualCount". But still it throwing the error
Error Message
getAllCountOf(articleInfo).size() == page."$actualCount"
| | | | |
| | 10 | groovy.lang.MissingPropertyException: Unable to resolve getRowCount().size() as content for inca.sundashboard.pageobject.OverviewPage, or as a property on its Navigator context. Is getRowCount().size() a class you forgot to import?
|
I'm using Dynamic Method Names in my tests, here is a small example:
def "Validate all article has its id"(){
when: "I am at Overview page"
at OverviewPage
then: "I should the article id of all article"
getAllCountOf(articleInfo).size() == "$actualCountMethod"().getCount()
where:
articleInfo | actualCountMethod
TopArticleListInfo.ARTICLE_THUMBNAIL | filter
}

Function overlapping specs

I have a simple function like this:
def extract_text({_, _, [text]}) when is_binary(text), do: text
def extract_text(_), do: nil
and the spec I added for it was:
#spec extract_text(any) :: nil
#spec extract_text({any, any, [text]}) :: text when text: String.t
but when I run dializer, I get the following error:
lib/foo/bar.ex:1: Overloaded contract for
'Elixir.Foo.Bar':extract_text/1 has overlapping domains;
such contracts are currently unsupported and are simply ignored
I think I understand the reason for it but I can't really come up with a solution. What would be the right spec for this function?
You should be aware of that, even if you define multiple functions of the same arity (accept the same number of arguments), from outside world this is considered only one function. That means, you need to define function signature, and only this one should have type spec defined.
Try the following:
#spec extract_text(any) :: String.t | nil
def extract_text(arg)
def extract_text({_, _, [text]}) when is_binary(text), do: text
def extract_text(_), do: nil

What sign -> means in spock framework?

Could anyone explain me what means sign -> in spock framework?
For exaple we have code like below:
given:
UserService service = Stub()
service.save({ User user -> 'Michael' == user.name }) >> {
throw new IllegalArgumentException("We don't want you here, Micheal!")
}
I know what this code do, but I dont know how role have sign -> in this code.
The Spock Framework assumes a basic level of understanding of the Groovy language and sometimes the more intricate parts of Groovy show up (like in your example).
The -> denotes a closure as described in the Groovy documentation.
For instance, a closure in Groovy could look like this:
def greeting = "Hello"
def sayHiTo = { name -> greeting + " " + name }
println sayHiTo("user3664097")

How to avoid null field errors in spock for Grails domain mock

Using grails 2.2.0 given this simple Domain
class Order {
static mapping = {table "ticket_order"}
String foo
}
And associated spock test
#TestFor(Order)
class OrderSpec extends Specification {
def "sensible constraints for order class"() {
setup:
mockForConstraintsTests(Order)
when:
def order = new Order(
foo : foo
)
order.validate()
then:
!order.errors.hasFieldErrors("foo")
where:
foo = "bar"
}
}
I get this output
grails> test-app unit: Order -echoOut
| Running 1 spock test... 1 of 1
--Output from sensible constraints for order class--
| Failure: sensible constraints for order class(uk.co.seoss.presscm.OrderSpec)
| Condition not satisfied:
!order.errors.hasFieldErrors("foo")
|| | |
|| | true
|| org.codehaus.groovy.grails.plugins.testing.GrailsMockErrors: 1 errors
|| Field error in object 'uk.co.seoss.presscm.Order' on field 'foo': rejected value [null];
Could someone please explain why I'm getting that null, have I not set the property correctly? I've tried a few simpler formulations of this with no joy. It works fine in a standard unit test.
It looks to me like your mixing the data-driven and interaction based testing styles.
The where block is mentioned only in the context of data-driven, and the when/then combo in the context of interaction testing.
Try put def foo = "bar" at the top of the test.

Grails validate a password

In a controller how can i validate a password so it contains at least 1 letter, 1 number, 1 special character and is at least 8 digits long. The code i am trying to use is as follows:
boolean validatePassword(String password) {
System.out.println("In validate")
def pattern = /^.*(?=.{7,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[!##$%*&+()]).*$/
def matcher = password =~ pattern
System.out.println("HERERERE")
return matcher.getCount() ? true : false
}
This does not work if says everything is invalid.
I have spring security ui plug in installed. Is there a way I can use its validation features?
I know i can use it to encode the password.
Rather than trying to do everything in one regex I'd split up the tests. Since in Groovy a Matcher coerces to boolean by calling find(), the following should work, and makes the intent clearer.
boolean validatePassword(String pass) {
return (pass) && (pass.length() > 7) && (pass =~ /\p{Alpha}/) &&
(pass =~ /\p{Digit}/) && (pass =~ /[!##$%*&+()]/)
}
There is also a nice java library called vtpassword for this purpose if you need something more sophisticated
http://code.google.com/p/vt-middleware/wiki/vtpassword

Resources