Is there anyway to get Telegram Group Admins without joining channel Telethon? - telethon

async def get_group_admins(self):
dialogs = await self.get_dialogs()
for dialog in dialogs:
if type(dialog.entity) == Channel:
if dialog.entity.megagroup:
async for user in self.client.iter_participants(
dialog.name, filter=ChannelParticipantsAdmins
):
if not user.bot:
participant = await self.client(
GetParticipantRequest(dialog.id, user.id)
)
if type(participant.participant) == ChannelParticipantCreator:
item = {
"Group Name": dialog.name,
"Name": user.first_name,
"Lastname": user.last_name,
"Telegram Address": "https://web.telegram.org/k/#"
+ str(user.id),
"type" : "creator",
}
else:
item = {
"Group Name": dialog.name,
"Name": user.first_name,
"Lastname": user.last_name,
"Telegram Address": "https://web.telegram.org/k/#"
+ str(user.id),
"type" : "admin",
}
self.listed.append(item)
self.conversations[dialog.name].append(item)
This is the way how i am getting chat admins. But to reach that I need to join that group. Is there any way to get public group admins without joining?

Related

Karate filtering json response

In my Karate tests (0.9.4), I have a json response like the following:
[
{
"id": "id_number_1",
"name": "name"
},
{
"id": "id_number_2",
"name": "name 2",
"nestedThing" {
"id": "another_id",
"name": object2_name"
}
},
{
"id": "id_number_3",
"name": "name 3"
}
]
Some of the objects in the response will have a nestedThing and others will not. First, I want to get rid of all the items in the list that do not have nestedThing. Second, once that's done, I want to def a list that only contains the first-level id fields. So, it would look like:
["id_number_1", "id_number_3"]
This can be done in one line:
* def ids = response.filter(x => !x.nestedThing).map(x => x.id)
Refer: https://github.com/karatelabs/karate#json-transforms
EDIT: the below works in versions 0.9.X
* def temp = karate.filter(response, function(x){ return !x.nestedThing })
* def ids = karate.map(temp, function(x){ return x.id })
* match ids == ['id_number_1', 'id_number_3']

Symfony Doctrine createQuery

Suppose I have an entity "events" and "users". Users entity is the owing side of a ManyToMany relation to events. My user can book an event which works fine. Now I try to fetch all events and a "identifier" if a user has booked the event. I try to add the user id to the array if the user has booked. Now I try to get these in one query
$em = $this->getDoctrine()->getManager();
$this->token = $tokenStorage->getToken();
$user = $this->token->getUser()->getId();
$query = $em->createQuery("SELECT e, u.id FROM App\Entity\Events e LEFT JOIN e.users u WITH u.id = :id WHERE e.date >= :dateFirstDay and e.date <= :dateLastDay and e.date > :dateNow ")
->setParameter('dateFirstDay',$dateStartDay->format('Y-m-d'))
->setParameter('dateLastDay',$dateEndDay->format('Y-m-d'))
->setParameter('dateNow',$now->format('Y-m-d'))
->setParameter('id', $user);
$events = $query->getArrayResult();
return new JsonResponse($events);
This gives me the booked event twice. One with id "null" and the other with the (right) user id. How can I avoid to get the event with id "null"? I tried with "GROUP BY e" but that don't work.
Here is my postman output:
{
"0": {
"id": 1,
"name": "Event 1 ",
"date": {
"date": "2021-03-10 15:32:37.000000",
"timezone_type": 3,
"timezone": "Europe/Berlin"
},
"description": "Beschreibungstext",
"duration": "45"
},
"id": null
},
{
"0": {
"id": 1,
"name": "Event 1 ",
"date": {
"date": "2021-03-10 15:32:37.000000",
"timezone_type": 3,
"timezone": "Europe/Berlin"
},
"description": "Beschreibungstext",
"duration": "45"
},
"id": 4
},
Thanks
try adding "AND e.users IS NOT NULL"
anyway I suggest you to consider alternative ways to do this query if you can; think that it's common that a query to a Repository (eg. "Events") should return only instances of Events entity, and not "Events entity + user id" as you are doing with ""SELECT e, u.id"
you could do just just "SELECT e", you will have a list of Events, and then on each entity you should be able to call "$even->getUsers()" if I understood well

How to filter flask-marshmallow nested field?

I working on a user's public-facing profile page, where I would like to display the user's profile as well as their "published" recipes. I have the following UserSchema, but this schema displays all recipes including the one that has not been published. I want to strictly display only the published recipes. Is there a way to filter out recipes that have not been published? I looked through marshmallow documentation but could not find an answer.
class User(db.Model):
__tablename__ = 'user'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), nullable=False, unique=True)
email = db.Column(db.String(200), nullable=False, unique=True)
password = db.Column(db.String(200))
recipes = db.relationship('Recipe', backref='user')
class UserSchema(Schema):
class Meta:
ordered = True
id = fields.Int(dump_only=True)
username = fields.String(required=True)
email = fields.Email(required=True)
password = fields.Method(required=True)
recipes = fields.Nested("RecipeSchema", many=True, exclude=("author",))
Following is the RecipeModel and RecipeSchema,
class Recipe(db.Model):
__tablename__ = 'recipe'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
description = db.Column(db.String(200))
is_publish = db.Column(db.Boolean(), default=False)
user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))
class RecipeSchema(Schema):
class Meta:
ordered = True
id = fields.Integer(dump_only=True)
name = fields.String(required=True, validate=[validate.Length(max=100)])
description = fields.String(validate=[validate.Length(max=200)])
is_publish = fields.Boolean(dump_only=True)
author = fields.Nested(UserSchema, attribute='user', dump_only=True, exclude=('email', ))
Resource responsible for returning user profile data is:
from schemas.user import UserSchema
user_schema = UserSchema()
class UserResource(Resource):
#classmethod
def get(cls, _id: int):
user = User.query.filter_by(id=_id).first()
if not user:
return {"message": gettext("user_not_found")}, 404
return user_schema.dump(user), 200
Current output is
{
"id": "1",
"username": "john.doe",
"recipes": [
{
"id": "1",
"name": "cheese pizza",
"description": "yummy",
"is_publish": true
},
{
"id": "2",
"name": "Potato Salad",
"description": "tags with sepearate function",
"is_publish": false
}
]
}
I want it to be
{
"id": "1",
"username": "john.doe",
"recipes": [
{
"id": "1",
"name": "cheese pizza",
"description": "yummy",
"is_publish": true
}
]
}

Bloodhound Cypher: Negate CanRDP

To get all users who can RDP, I use the following
MATCH p=()-[r:CanRDP]->() RETURN p LIMIT 25
My question is how would I negate this to get a list of users who can not RDP and combine it to the following query to bring users who can not RDP
{
"name": "Shortest Paths to Domain Admins from Kerberoastable Users",
"queryList": [
{
"final": false,
"title": "Select a Domain Admin group...",
"query": "MATCH (n:Group) WHERE n.objectsid =~ {name} RETURN n.name ORDER BY n.name DESC",
"props": {"name": "(?i)S-1-5-.*-512"}
},
{
"final": true,
"query":"MATCH (n:User),(m:Group {name:{result}}),p=shortestPath((n)-[r:{}*1..]->(m)) WHERE n.hasspn=true RETURN p",
"allowCollapse": true,
"endNode": "{}"
}
]
}

Facebook API (javascript) getting latest school education info

I'm very new to the facebook api for my website, and I am using the javascript sdk. I want to get the users latest school information, including school name, course and year of study. This is what I have so far but it breaks the login script and returns 'response.education.school is undefined'. I'm guessing I'll need some kind of for loop to go through the education array as most users have more than one school listed?
function login() {
FB.login(function(response) {
if(response.authResponse) {
// connected
FB.api('/me', function(response) {
fbLogin(response.id, response.name, response.firstname, response.email,
response.education.school.name, response.education.concentration.name, response.education.year.name);
});
} else {
// cancelled
}
}, {scope: 'email, user_education_history, user_hometown'});
}
response.education.school is undefined
This is because responce.education is an array of objects. This would be an example for me (actual information removed)
"education": [
{
"school": {
"id": "",
"name": ""
},
"year": {
"id": "",
"name": ""
},
"concentration": [
{
"id": "",
"name": ""
}
],
"type": ""
},
...
]
You need to iterate over it and process each educaional step e.g.
for(ed in response.education) {
var school = response.education[ed].school;
var schoolName = school.name;
...
}
And so on; you are currently passing an aobject structure to your fbLogIn that can't handle it. If you want the latest school education, you simply pick the one that has the most recent year.name value.