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

Group id fix #171

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions zbxtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def send_txt(self, to, text, text_name=None):

def get_uid(self, name):
uid = 0
try:
uid = int(name)
return uid
except ValueError:
pass
if sys.version_info[0] < 3:
name = name.decode("utf-8")
if self.debug:
print_message("Getting uid from /getUpdates...")
updates = self.get_updates()
Expand All @@ -188,14 +195,12 @@ def get_uid(self, name):
if "username" in chat:
if chat["username"] == name:
uid = chat["id"]
break
if (chat["type"] == "group" or chat["type"] == "supergroup") and self.type == "group":
if "title" in chat:
if sys.version_info[0] < 3:
if chat["title"] == name.decode("utf-8"):
uid = chat["id"]
else:
if chat["title"] == name:
uid = chat["id"]
if chat["title"] == name:
uid = chat["id"]
break
return uid

def error_need_to_contact(self, to):
Expand Down Expand Up @@ -806,6 +811,8 @@ def main():

if not uid:
uid = tg.get_uid(zbx_to)
if self.debug:
print_message("get_uid result = {0}".format(uid))
if uid:
tmp_need_update = True
if not uid:
Expand Down