Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvement about supergroup and channel #61

Merged
merged 8 commits into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pytg/argument_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ def parse(self, value):
return super(User, self).parse(value)


class Channel(Peer):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of line 100...?

Will fix this.

type="str"
def parse(self, value):
return super(User, self).parse(value)


class SecretChat(Peer):
type="str"
def parse(self, value):
Expand Down
18 changes: 13 additions & 5 deletions pytg/fix_msg_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
TGL_PEER_USER = u("user")
TGL_PEER_ENCR_CHAT = u("encr_chat")
TGL_PEER_GEO_CHAT = u("geo_chat") #todo: does this even exists?
TGL_PEER_CHANNEL = u("channel")

def fix_message(message):
# skip if not has message typical elements
Expand All @@ -32,21 +33,28 @@ def fix_message(message):
# create the peer, thats where to reply to.
if message["own"]:
message["peer"] = None
elif message["receiver"]["type"] == TGL_PEER_CHAT or message["receiver"]["type"] == TGL_PEER_GEO_CHAT:
elif message["receiver"]["type"] in [TGL_PEER_CHAT, TGL_PEER_GEO_CHAT, TGL_PEER_CHANNEL]:
message["peer"] = message["receiver"]
elif message["receiver"]["type"] == TGL_PEER_USER or message["receiver"]["type"] == TGL_PEER_ENCR_CHAT:
elif message["receiver"]["type"] in [TGL_PEER_USER, TGL_PEER_ENCR_CHAT]:
message["peer"] = message["sender"]
# return it
return message


def fix_peer(peer):
# rename peer_type => type
if "peer_type" in peer and peer["peer_type"]:
peer["type"] = peer["peer_type"]
del peer["peer_type"]

# add cmd field
if peer["type"] == TGL_PEER_ENCR_CHAT:
assert peer["print_name"].startswith(ENCR_CHAT_PREFIX)
peer["cmd"] = peer["print_name"]
elif peer["type"] == TGL_PEER_CHANNEL:
peer["cmd"] = u("%s#id%d") % (peer["type"], peer["peer_id"])
else:
peer["cmd"] = peer["type"] + u("#") + u(str(peer["id"]))
peer["cmd"] = u("%s#%d") % (peer["type"], peer["peer_id"])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more happy if you could use

u("{type}#{id}").format(type=peer["type"], id=peer["peer_id"])

instead of "%s#%d" % (.. , ..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is a problem here. In test branch, what used to be "id" is renamed with "peer_id" and "id" now is something else. But I'm not sure whether it's OK for master branch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if you are confusing the id used in format with the peer's id.
In case, this version of my line above might help you to see what I mean:

u("{foo}#{bar}").format(foo=peer["type"], bar=peer["peer_id"])

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind. I saw the "id" in the diff.

u("{type}#{id}").format(type=peer["type"], id=peer["id"])

(You currently have more insight to the code then me 😄 You can decide)


#remove print_name field
#create name field
Expand All @@ -62,7 +70,7 @@ def fix_peer(peer):
peer["name"] = peer["first_name"]
elif "username" in peer and peer["username"]:
peer["name"] = peer["username"]
elif peer["type"] == TGL_PEER_CHAT:
elif peer["type"] in [TGL_PEER_CHAT, TGL_PEER_CHANNEL]:
if "title" in peer and peer["title"]:
peer["name"] = peer["title"]
elif peer["type"] == TGL_PEER_ENCR_CHAT:
Expand All @@ -75,4 +83,4 @@ def fix_peer(peer):
peer["name"] = peer["username"] # there are no other choices.
else:
logger.error("Unknown peer type: {type}".format(type={peer["type"]}))
return peer
return peer
1 change: 1 addition & 0 deletions pytg/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
# functions["channel_set_admin"] = ("channel_set_admin", <channel> <admin> <type> Sets channel admin. 0 - not admin, 1 - moderator, 2 - editor
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can have a look at this old line here, while your on it.
I wonder why channel_set_admin is not implemented.

functions["channel_set_username"] = ("channel_set_username", [args.Channel("channel"), args.UnicodeString("name")], res.success_fail, None, "Sets channel username info.")
functions["channel_set_photo"] = ("channel_set_photo", [args.Channel("channel"), args.File("file")], res.something, 120.0, "Sets channel photo. Photo will be cropped to square")
functions["channel_rename"] = ("rename_channel", [args.Channel("channel"), args.UnicodeString("new_name")], res.success_fail, None, "Renames channel")

# own profile
functions["set_profile_name"] = ("set_profile_name", [args.UnicodeString("first_name"), args.UnicodeString("last_name")], res.something, 60.0, "Sets profile name.")
Expand Down