cleanup
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import re, sys, os, io, sqlite3, hashlib, time, datetime
|
import time
|
||||||
import xml.etree.ElementTree as ET
|
import logging, pprint
|
||||||
import logging, traceback, pprint
|
|
||||||
|
|
||||||
from xmpp_tg.mtproto import TelegramGateClient
|
|
||||||
from xmpp_tg.utils import var_dump, display_tg_name, get_contact_jid, localtime
|
from xmpp_tg.utils import var_dump, display_tg_name, get_contact_jid, localtime
|
||||||
|
|
||||||
# modified by adnidor
|
# modified by adnidor
|
||||||
@@ -85,209 +83,208 @@ class CommandHandler():
|
|||||||
class GateCommandHandler(CommandHandler):
|
class GateCommandHandler(CommandHandler):
|
||||||
_helptext = "Available Gateway commands:"
|
_helptext = "Available Gateway commands:"
|
||||||
|
|
||||||
def configure(hndl, self):
|
def configure(self, gate):
|
||||||
"""Get config/set config options"""
|
"""Get config/set config options"""
|
||||||
config_exclude = ['jid', 'tg_phone']
|
config_exclude = ['jid', 'tg_phone']
|
||||||
|
|
||||||
option = hndl.arguments[0] if len(hndl.arguments) >= 1 else None
|
option = self.arguments[0] if len(self.arguments) >= 1 else None
|
||||||
value = hndl.arguments[1] if len(hndl.arguments) == 2 else None
|
value = self.arguments[1] if len(self.arguments) == 2 else None
|
||||||
|
|
||||||
if value is not None and option not in config_exclude:
|
if value is not None and option not in config_exclude:
|
||||||
self.db_connection.execute("update accounts set {} = ? where jid = ?".format(option), (value,hndl.jid,) )
|
gate.db_connection.execute("update accounts set {} = ? where jid = ?".format(option), (value, self.jid,))
|
||||||
self.accounts[hndl.jid] = self.db_connection.execute("SELECT * FROM accounts where jid = ?", (hndl.jid,) ).fetchone()
|
gate.accounts[self.jid] = gate.db_connection.execute("SELECT * FROM accounts where jid = ?", (self.jid,)).fetchone()
|
||||||
|
|
||||||
message = "=== Your current configuration ===\n\n"
|
message = "=== Your current configuration ===\n\n"
|
||||||
for param, value in self.accounts[hndl.jid].items():
|
for param, value in gate.accounts[self.jid].items():
|
||||||
message = message + "<%s>: %s" % (param, value) + "\n"
|
message = message + "<%s>: %s" % (param, value) + "\n"
|
||||||
message = message + "\nTo modify some option, please, send !configure param value"
|
message = message + "\nTo modify some option, please, send !configure param value"
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def login(hndl, self): #1 arg
|
def login(self, gate): #1 arg
|
||||||
"""Initiates Telegram session
|
"""Initiates Telegram session
|
||||||
|
|
||||||
Usage: !login <phone number in international format>"""
|
Usage: !login <phone number in international format>"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
phone_no = hndl.arguments[0]
|
phone_no = self.arguments[0]
|
||||||
|
|
||||||
hndl._update("Please wait...")
|
self._update("Please wait...")
|
||||||
self.spawn_tg_client(hndl.jid, phone_no)
|
gate.spawn_tg_client(self.jid, phone_no)
|
||||||
|
|
||||||
if self.tg_connections[hndl.jid].is_user_authorized():
|
if gate.tg_connections[self.jid].is_user_authorized():
|
||||||
self.send_presence(pto=jid, pfrom=self.boundjid.bare, ptype='online', pstatus='connected')
|
gate.send_presence(pto=jid, pfrom=gate.boundjid.bare, ptype='online', pstatus='connected')
|
||||||
return "You are already authenticated in Telegram"
|
return "You are already authenticated in Telegram"
|
||||||
else:
|
else:
|
||||||
# remove old sessions for this JID #
|
# remove old sessions for this JID #
|
||||||
self.db_connection.execute("DELETE from accounts where jid = ?", (hndl.jid, ) )
|
gate.db_connection.execute("DELETE from accounts where jid = ?", (self.jid,))
|
||||||
self.tg_connections[hndl.jid].send_code_request(phone_no)
|
gate.tg_connections[self.jid].send_code_request(phone_no)
|
||||||
self._update('Gate is connected. Telegram should send SMS message to you.')
|
gate._update('Gate is connected. Telegram should send SMS message to you.')
|
||||||
return 'Please enter one-time code via !code 12345.'
|
return 'Please enter one-time code via !code 12345.'
|
||||||
|
|
||||||
def code(hndl, self):
|
def code(self, gate):
|
||||||
"""nolist Enter confirmation code"""
|
"""nolist Enter confirmation code"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
code = hndl.arguments[0]
|
code = self.arguments[0]
|
||||||
jid = hndl.jid
|
jid = self.jid
|
||||||
|
|
||||||
if not self.tg_connections[jid].is_user_authorized():
|
if not gate.tg_connections[jid].is_user_authorized():
|
||||||
try:
|
try:
|
||||||
hndl._update('Trying authenticate...')
|
self._update('Trying authenticate...')
|
||||||
self.tg_connections[jid].sign_in(self.tg_phones[jid], code)
|
gate.tg_connections[jid].sign_in(gate.tg_phones[jid], code)
|
||||||
except SessionPasswordNeededError:
|
except SessionPasswordNeededError:
|
||||||
self.gate_reply_message(iq, 'Two-factor authentication detected.')
|
self._update('Two-factor authentication detected.')
|
||||||
self.gate_reply_message(iq, 'Please enter your password via !password abc123.')
|
self._update('Please enter your password via !password abc123.')
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.tg_connections[jid].is_user_authorized():
|
if gate.tg_connections[jid].is_user_authorized():
|
||||||
self.send_presence(pto=jid, pfrom=self.boundjid.bare, ptype='online', pstatus='connected')
|
gate.send_presence(pto=jid, pfrom=gate.boundjid.bare, ptype='online', pstatus='connected')
|
||||||
self.gate_reply_message(iq, 'Authentication successful. Initiating Telegram...')
|
self._update('Authentication successful. Initiating Telegram...')
|
||||||
self.db_connection.execute("INSERT INTO accounts(jid, tg_phone) VALUES(?, ?)", (jid, self.tg_phones[jid],))
|
gate.db_connection.execute("INSERT INTO accounts(jid, tg_phone) VALUES(?, ?)", (jid, gate.tg_phones[jid],))
|
||||||
self.accounts[jid] = self.db_connection.execute("SELECT * FROM accounts where jid = ?", (jid,) ).fetchone()
|
gate.accounts[jid] = gate.db_connection.execute("SELECT * FROM accounts where jid = ?", (jid,)).fetchone()
|
||||||
self.init_tg(jid)
|
gate.init_tg(jid)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return 'Authentication failed.'
|
return 'Authentication failed.'
|
||||||
else:
|
else:
|
||||||
return 'You are already authenticated. Please use !logout before new login.'
|
return 'You are already authenticated. Please use !logout before new login.'
|
||||||
|
|
||||||
def password(hndl, self):
|
def password(self, gate):
|
||||||
"""nolist Enter password"""
|
"""nolist Enter password"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
password = hndl.arguments[1]
|
password = self.arguments[1]
|
||||||
jid = self.jid
|
jid = gate.jidhndl
|
||||||
|
|
||||||
if not self.tg_connections[jid].is_user_authorized():
|
if not gate.tg_connections[jid].is_user_authorized():
|
||||||
self.gate_reply_message(iq, 'Checking password...')
|
self._update('Checking password...')
|
||||||
self.tg_connections[jid].sign_in(password=password)
|
gate.tg_connections[jid].sign_in(password=password)
|
||||||
|
|
||||||
if self.tg_connections[jid].is_user_authorized():
|
if gate.tg_connections[jid].is_user_authorized():
|
||||||
self.send_presence(pto=jid, pfrom=self.boundjid.bare, ptype='online', pstatus='connected')
|
gate.send_presence(pto=jid, pfrom=gate.boundjid.bare, ptype='online', pstatus='connected')
|
||||||
self.gate_reply_message(iq, 'Authentication successful. Initiating Telegram...')
|
self._update('Authentication successful. Initiating Telegram...')
|
||||||
self.db_connection.execute("INSERT INTO accounts(jid, tg_phone) VALUES(?, ?)", (jid, self.tg_phones[jid],))
|
gate.db_connection.execute("INSERT INTO accounts(jid, tg_phone) VALUES(?, ?)", (jid, gate.tg_phones[jid],))
|
||||||
self.accounts[jid] = self.db_connection.execute("SELECT * FROM accounts where jid = ?", (jid,) ).fetchone()
|
gate.accounts[jid] = gate.db_connection.execute("SELECT * FROM accounts where jid = ?", (jid,)).fetchone()
|
||||||
self.init_tg(jid)
|
gate.init_tg(jid)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.gate_reply_message(iq, 'Authentication failed.')
|
return 'Authentication failed.'
|
||||||
else:
|
else:
|
||||||
self.gate_reply_message(iq, 'You are already authenticated. Please use !logout before new login.')
|
return 'You are already authenticated. Please use !logout before new login.'
|
||||||
|
|
||||||
def reload_dialogs(hndl, self):
|
def reload_dialogs(self, gate):
|
||||||
"""Reload Telegram dialogs"""
|
"""Reload Telegram dialogs"""
|
||||||
if not self.tg_connections[hndl.jid].is_user_authorized():
|
if not gate.tg_connections[self.jid].is_user_authorized():
|
||||||
return "Error"
|
return "Error"
|
||||||
|
|
||||||
self.tg_process_dialogs(hndl.jid)
|
gate.tg_process_dialogs(self.jid)
|
||||||
return "Dialogs reloadad"
|
return "Dialogs reloadad"
|
||||||
|
|
||||||
def logout(hndl, self):
|
def logout(self, gate):
|
||||||
"""Deletes current Telegram session at Gateway"""
|
"""Deletes current Telegram session at Gateway"""
|
||||||
self.tg_connections[hndl.jid].log_out()
|
gate.tg_connections[self.jid].log_out()
|
||||||
self.db_connection.execute("DELETE FROM accounts WHERE jid = ?", (hndl.jid,))
|
gate.db_connection.execute("DELETE FROM accounts WHERE jid = ?", (self.jid,))
|
||||||
return 'Your Telegram session was deleted'
|
return 'Your Telegram session was deleted'
|
||||||
|
|
||||||
def add(hndl, self): #1 arg
|
def add(self, gate): #1 arg
|
||||||
"""Add contact by nickname or t.me link"""
|
"""Add contact by nickname or t.me link"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
argument = hndl.arguments[0]
|
argument = self.arguments[0]
|
||||||
jid = hndl.jid
|
jid = self.jid
|
||||||
|
|
||||||
result = self.tg_connections[jid].get_entity(argument)
|
result = gate.tg_connections[jid].get_entity(argument)
|
||||||
if type(result) == User:
|
if type(result) == User:
|
||||||
tg_peer = InputPeerUser( result.id, result.access_hash )
|
tg_peer = InputPeerUser( result.id, result.access_hash )
|
||||||
result = self.tg_connections[jid].invoke( SendMessageRequest(tg_peer, 'Hello! I just want to add you in my contact list.', generate_random_long() ) )
|
result = gate.tg_connections[jid].invoke(SendMessageRequest(tg_peer, 'Hello! I just want to add you in my contact list.', generate_random_long()))
|
||||||
elif type(result) == Channel:
|
elif type(result) == Channel:
|
||||||
tg_peer = InputPeerChannel( result.id, result.access_hash )
|
tg_peer = InputPeerChannel( result.id, result.access_hash )
|
||||||
self.tg_connections[jid].invoke(JoinChannelRequest( InputPeerChannel(result.id, result.access_hash) ) )
|
gate.tg_connections[jid].invoke(JoinChannelRequest(InputPeerChannel(result.id, result.access_hash)))
|
||||||
else:
|
else:
|
||||||
self.gate_reply_message(iq, 'Sorry, nothing found.')
|
return 'Sorry, nothing found.'
|
||||||
return
|
|
||||||
|
|
||||||
self.tg_process_dialogs(jid)
|
gate.tg_process_dialogs(jid)
|
||||||
|
|
||||||
def join(hndl, self): #1 arg
|
def join(self, gate): #1 arg
|
||||||
"""Join conference via invite link"""
|
"""Join conference via invite link"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
argument = hndl.arguments[0]
|
argument = self.arguments[0]
|
||||||
jid = hndl.jid
|
jid = self.jid
|
||||||
|
|
||||||
link = argument.split('/') # https://t.me/joinchat/HrCmckx_SkMbSGFLhXCvSg
|
link = argument.split('/') # https://t.me/joinchat/HrCmckx_SkMbSGFLhXCvSg
|
||||||
self.tg_connections[jid].invoke(ImportChatInviteRequest(link[4]))
|
gate.tg_connections[jid].invoke(ImportChatInviteRequest(link[4]))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.tg_process_dialogs(jid)
|
gate.tg_process_dialogs(jid)
|
||||||
|
|
||||||
def group(hndl, self): #2 args
|
def group(self, gate): #2 args
|
||||||
"""Creat a Group"""
|
"""Creat a Group"""
|
||||||
hndl._min_args(2)
|
self._min_args(2)
|
||||||
# group name? #
|
# group name? #
|
||||||
groupname = parsed[1]
|
groupname = parsed[1]
|
||||||
|
|
||||||
# group users? #
|
# group users? #
|
||||||
groupuser = self.tg_connections[jid].get_entity(parsed[2])
|
groupuser = gate.tg_connections[jid].get_entity(parsed[2])
|
||||||
|
|
||||||
# we re ready to make group
|
# we re ready to make group
|
||||||
self.tg_connections[jid].invoke(CreateChatRequest([groupuser], groupname))
|
gate.tg_connections[jid].invoke(CreateChatRequest([groupuser], groupname))
|
||||||
self.tg_process_dialogs(jid)
|
gate.tg_process_dialogs(jid)
|
||||||
|
|
||||||
|
|
||||||
def supergroup(hndl, self): #1 arg
|
def supergroup(self, gate): #1 arg
|
||||||
"""Create a channel"""
|
"""Create a channel"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
groupname = hndl.arguments[0]
|
groupname = self.arguments[0]
|
||||||
self.tg_connections[hndl.jid].invoke(CreateChannelRequest(groupname, groupname, megagroup = True))
|
gate.tg_connections[self.jid].invoke(CreateChannelRequest(groupname, groupname, megagroup = True))
|
||||||
self.tg_process_dialogs(hndl.jid)
|
gate.tg_process_dialogs(self.jid)
|
||||||
|
|
||||||
channel = supergroup
|
channel = supergroup
|
||||||
|
|
||||||
def username(hndl, self): #1 arg
|
def username(self, gate): #1 arg
|
||||||
"""Change your Telegram nickname"""
|
"""Change your Telegram nickname"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
username = hndl.arguments[0]
|
username = self.arguments[0]
|
||||||
|
|
||||||
self.tg_connections[hndl.jid].invoke(UpdateUsernameRequest(username))
|
gate.tg_connections[self.jid].invoke(UpdateUsernameRequest(username))
|
||||||
|
|
||||||
def name(hndl, self): #1 or 2 args
|
def name(self, gate): #1 or 2 args
|
||||||
"""Change your Telegram display name"""
|
"""Change your Telegram display name"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
firstname = hndl.arguments[0]
|
firstname = self.arguments[0]
|
||||||
lastname = hndl.arguments[1] if len(hndl.arguments) > 1 else None
|
lastname = self.arguments[1] if len(self.arguments) > 1 else None
|
||||||
|
|
||||||
self.tg_connections[hndl.jid].invoke(UpdateProfileRequest(first_name = firstname, last_name = lastname))
|
gate.tg_connections[self.jid].invoke(UpdateProfileRequest(first_name = firstname, last_name = lastname))
|
||||||
|
|
||||||
def about(hndl, self): #>0 args
|
def about(self, gate): #>0 args
|
||||||
"""Change your Telegram 'about' text"""
|
"""Change your Telegram 'about' text"""
|
||||||
hndl._min_args(1)
|
self._min_args(1)
|
||||||
|
|
||||||
about = hndl.msg['body'][7:]
|
about = self.msg['body'][7:]
|
||||||
self.tg_connections[hndl.jid].invoke(UpdateProfileRequest(about = about))
|
gate.tg_connections[self.jid].invoke(UpdateProfileRequest(about = about))
|
||||||
|
|
||||||
def import_contact(hndl, self): #2 args
|
def import_contact(self, gate): #2 args
|
||||||
"""Add contact by phone number"""
|
"""Add contact by phone number"""
|
||||||
hndl._min_args(2)
|
self._min_args(2)
|
||||||
|
|
||||||
phone = hndl.arguments[0]
|
phone = self.arguments[0]
|
||||||
firstname = hndl.arguments[1]
|
firstname = self.arguments[1]
|
||||||
lastname = hndl.arguments[2] if len(hndl.arguments) > 2 else None
|
lastname = self.arguments[2] if len(self.arguments) > 2 else None
|
||||||
|
|
||||||
contact = InputPhoneContact(client_id=generate_random_long(), phone=phone, first_name=firstname, last_name=lastname)
|
contact = InputPhoneContact(client_id=generate_random_long(), phone=phone, first_name=firstname, last_name=lastname)
|
||||||
self.tg_connections[hndl.jid].invoke(ImportContactsRequest([contact]))
|
gate.tg_connections[self.jid].invoke(ImportContactsRequest([contact]))
|
||||||
self.tg_process_dialogs(jid)
|
gate.tg_process_dialogs(jid)
|
||||||
|
|
||||||
def roster(hndl, self):
|
def roster(self, gate):
|
||||||
"""Send Telegram contact list back, with JIDs"""
|
"""Send Telegram contact list back, with JIDs"""
|
||||||
response = "Telegram chats:\n"
|
response = "Telegram chats:\n"
|
||||||
for jid,tid in self.contact_list[hndl.jid].items():
|
for jid,tid in gate.contact_list[self.jid].items():
|
||||||
response += "{}: {}\n".format(tid, jid)
|
response += "{}: {}\n".format(tid, jid)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def oldhelp(hndl, self):
|
def oldhelp(self, gate):
|
||||||
"""nolist Old !help message"""
|
"""nolist Old !help message"""
|
||||||
return ('=== Available gateway commands ===:\n\n'
|
return ('=== Available gateway commands ===:\n\n'
|
||||||
'!help - Displays this text\n'
|
'!help - Displays this text\n'
|
||||||
@@ -325,43 +322,43 @@ class ChatCommandHandler(CommandHandler):
|
|||||||
self._handler = self._replace
|
self._handler = self._replace
|
||||||
self.tg_id = int(msg['to'].node[1:])
|
self.tg_id = int(msg['to'].node[1:])
|
||||||
|
|
||||||
def block(hndl, self):
|
def block(self, gate):
|
||||||
"""Block this user"""
|
"""Block this user"""
|
||||||
nickname = display_tg_name(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id])
|
nickname = display_tg_name(gate.tg_dialogs[self.jid]['users'][self.tg_id])
|
||||||
self.tg_connections[hndl.jid].invoke(BlockRequest( InputPeerUser(hndl.tg_id, self.tg_dialogs[jid]['users'][hndl.tg_id].access_hash) ) )
|
gate.tg_connections[self.jid].invoke(BlockRequest(InputPeerUser(self.tg_id, gate.tg_dialogs[self.jid]['users'][self.tg_id].access_hash)))
|
||||||
self.gate_reply_message(iq, 'User %s blacklisted!' % nickname)
|
gate.gate_reply_message(iq, 'User %s blacklisted!' % nickname)
|
||||||
|
|
||||||
def unblock(hndl, self):
|
def unblock(self, gate):
|
||||||
"""Unblock this user"""
|
"""Unblock this user"""
|
||||||
nickname = display_tg_name(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id])
|
nickname = display_tg_name(gate.tg_dialogs[self.jid]['users'][self.tg_id])
|
||||||
self.tg_connections[hndl.jid].invoke(UnblockRequest( InputPeerUser(hndl.tg_id, self.tg_dialogs[jid]['users'][hndl.tg_id].access_hash) ) )
|
gate.tg_connections[self.jid].invoke(UnblockRequest(InputPeerUser(self.tg_id, gate.tg_dialogs[self.jid]['users'][self.tg_id].access_hash)))
|
||||||
self.gate_reply_message(iq, 'User %s unblacklisted!' % nickname)
|
gate.gate_reply_message(iq, 'User %s unblacklisted!' % nickname)
|
||||||
|
|
||||||
def remove(hndl, self):
|
def remove(self, gate):
|
||||||
"""Remove User from Telegram contact list"""
|
"""Remove User from Telegram contact list"""
|
||||||
peer = InputPeerUser(hndl.tg_id, self.tg_dialogs[hndl.jid]['users'][hndl.tg_id].access_hash)
|
peer = InputPeerUser(self.tg_id, gate.tg_dialogs[self.jid]['users'][self.tg_id].access_hash)
|
||||||
c_jid = get_contact_jid(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id], self.boundjid.bare)
|
c_jid = get_contact_jid(gate.tg_dialogs[self.jid]['users'][self.tg_id], gate.boundjid.bare)
|
||||||
|
|
||||||
self.tg_connections[hndl.jid].invoke( DeleteContactRequest(peer) )
|
gate.tg_connections[self.jid].invoke(DeleteContactRequest(peer))
|
||||||
self.tg_connections[hndl.jid].invoke( DeleteHistoryRequest( peer, max_id = 0, just_clear = None ) )
|
gate.tg_connections[self.jid].invoke(DeleteHistoryRequest(peer, max_id = 0, just_clear = None))
|
||||||
|
|
||||||
self.send_presence(pto = hndl.jid, pfrom = c_jid, ptype = 'unavailable')
|
gate.send_presence(pto = self.jid, pfrom = c_jid, ptype ='unavailable')
|
||||||
self.send_presence(pto = hndl.jid, pfrom = c_jid, ptype = 'unsubscribed')
|
gate.send_presence(pto = self.jid, pfrom = c_jid, ptype ='unsubscribed')
|
||||||
self.send_presence(pto = hndl.jid, pfrom = c_jid, ptype = 'unsubscribe')
|
gate.send_presence(pto = self.jid, pfrom = c_jid, ptype ='unsubscribe')
|
||||||
|
|
||||||
def _replace(hndl, self):
|
def _replace(self, gate):
|
||||||
peer = InputPeerUser(hdnl.tg_id, self.tg_dialogs[hndl.jid]['users'][hndl.tg_id].access_hash)
|
peer = InputPeerUser(hdnl.tg_id, gate.tg_dialogs[self.jid]['users'][self.tg_id].access_hash)
|
||||||
|
|
||||||
msg_id, edited = self.edit_message(hdnl.jid, hdnl.tg_id, hndl.msg['body'])
|
msg_id, edited = gate.edit_message(hdnl.jid, hdnl.tg_id, self.msg['body'])
|
||||||
if not edited: return
|
if not edited: return
|
||||||
|
|
||||||
# and send it
|
# and send it
|
||||||
if edited != '' and edited != ' ':
|
if edited != '' and edited != ' ':
|
||||||
self.tg_dialogs[hndl.jid]['messages'][hndl.tg_id]["body"] = edited
|
gate.tg_dialogs[self.jid]['messages'][self.tg_id]["body"] = edited
|
||||||
self.tg_connections[hndl.jid].invoke( EditMessageRequest(peer, msg_id, message = edited) )
|
gate.tg_connections[self.jid].invoke(EditMessageRequest(peer, msg_id, message = edited))
|
||||||
else:
|
else:
|
||||||
del(self.tg_dialogs[hndl.jid]['messages'][hndl.tg_id])
|
del(gate.tg_dialogs[self.jid]['messages'][self.tg_id])
|
||||||
self.tg_connections[hndl.jid].invoke( DeleteMessagesRequest([msg_id], revoke = True) )
|
gate.tg_connections[self.jid].invoke(DeleteMessagesRequest([msg_id], revoke = True))
|
||||||
|
|
||||||
class GroupchatCommandHandler(CommandHandler):
|
class GroupchatCommandHandler(CommandHandler):
|
||||||
_helptext = "Available Groupchat commands:"
|
_helptext = "Available Groupchat commands:"
|
||||||
@@ -370,38 +367,43 @@ class GroupchatCommandHandler(CommandHandler):
|
|||||||
super(GroupchatCommandHandler, self).__init__(msg)
|
super(GroupchatCommandHandler, self).__init__(msg)
|
||||||
if self._command.startswith("s/"):
|
if self._command.startswith("s/"):
|
||||||
self._handler = self._replace
|
self._handler = self._replace
|
||||||
|
self.tg_id = int(self.msg['to'].node[1:])
|
||||||
|
|
||||||
def leave(hndl, self):
|
def leave(self, gate):
|
||||||
"""Leave group or channel"""
|
"""Leave group or channel"""
|
||||||
tg_id = int(hndl.msg['to'].node[1:])
|
if self.tg_id in gate.tg_dialogs[self.jid]['supergroups']:
|
||||||
if tg_id in self.tg_dialogs[hndl.jid]['supergroups']:
|
peer = InputPeerChannel(self.tg_id, gate.tg_dialogs[self.jid]['supergroups'][self.tg_id].access_hash)
|
||||||
peer = InputPeerChannel(tg_id, self.tg_dialogs[hndl.jid]['supergroups'][tg_id].access_hash)
|
gate.tg_connections[self.jid].invoke(LeaveChannelRequest(peer))
|
||||||
self.tg_connections[hndl.jid].invoke(LeaveChannelRequest(peer))
|
gate.tg_connections[self.jid].invoke(DeleteHistoryRequest(peer, max_id = 0, just_clear = None))
|
||||||
self.tg_connections[hndl.jid].invoke(DeleteHistoryRequest(peer, max_id = 0, just_clear = None))
|
c_jid = get_contact_jid(gate.tg_dialogs[self.jid]['supergroups'][self.tg_id], gate.boundjid.bare)
|
||||||
c_jid = get_contact_jid(self.tg_dialogs[hndl.jid]['supergroups'][tg_id], self.boundjid.bare)
|
|
||||||
self.send_presence(pto =hndl.jid, pfrom = c_jid, ptype ='unavailable')
|
|
||||||
self.send_presence(pto =hndl.jid, pfrom = c_jid, ptype ='unsubscribed')
|
|
||||||
self.send_presence(pto =hndl.jid, pfrom = c_jid, ptype ='unsubscribe')
|
|
||||||
if tg_id in self.tg_dialogs[hndl.jid]['groups']:
|
|
||||||
self.tg_connections[hndl.jid].invoke(DeleteChatUserRequest(tg_id, self.tg_connections[hndl.jid].me))
|
|
||||||
self.tg_connections[hndl.jid].invoke(DeleteHistoryRequest(InputPeerChat(tg_id), max_id = 0, just_clear = None))
|
|
||||||
c_jid = get_contact_jid(self.tg_dialogs[hndl.jid]['groups'][tg_id], self.boundjid.bare)
|
|
||||||
self.send_presence(pto =hndl.jid, pfrom = c_jid, ptype ='unavailable')
|
|
||||||
self.send_presence(pto =hndl.jid, pfrom = c_jid, ptype ='unsubscribed')
|
|
||||||
self.send_presence(pto =hndl.jid, pfrom = c_jid, ptype ='unsubscribe')
|
|
||||||
|
|
||||||
def invite(hndl, self):
|
gate.send_presence(pto =self.jid, pfrom = c_jid, ptype ='unavailable')
|
||||||
|
gate.send_presence(pto =self.jid, pfrom = c_jid, ptype ='unsubscribed')
|
||||||
|
gate.send_presence(pto =self.jid, pfrom = c_jid, ptype ='unsubscribe')
|
||||||
|
|
||||||
|
if self.tg_id in gate.tg_dialogs[self.jid]['groups']:
|
||||||
|
gate.tg_connections[self.jid].invoke(DeleteChatUserRequest(self.tg_id, gate.tg_connections[self.jid].me))
|
||||||
|
gate.tg_connections[self.jid].invoke(DeleteHistoryRequest(InputPeerChat(self.tg_id), max_id = 0, just_clear = None))
|
||||||
|
c_jid = get_contact_jid(gate.tg_dialogs[self.jid]['groups'][self.tg_id], gate.boundjid.bare)
|
||||||
|
|
||||||
|
gate.send_presence(pto =self.jid, pfrom = c_jid, ptype ='unavailable')
|
||||||
|
gate.send_presence(pto =self.jid, pfrom = c_jid, ptype ='unsubscribed')
|
||||||
|
gate.send_presence(pto =self.jid, pfrom = c_jid, ptype ='unsubscribe')
|
||||||
|
|
||||||
|
def invite(self, gate):
|
||||||
"""Invite user to group"""
|
"""Invite user to group"""
|
||||||
tg_id = int(hndl.msg['to'].node[1:])
|
if self.tg_id in gate.tg_dialogs[self.jid]['supergroups']:
|
||||||
if tg_id in self.tg_dialogs[hndl.jid]['supergroups']:
|
invited_user = gate.tg_connections[[self.jid]].get_entity(parsed[1])
|
||||||
invited_user = self.tg_connections[[hndl.jid]].get_entity(parsed[1])
|
|
||||||
if type(invited_user) == User:
|
if type(invited_user) == User:
|
||||||
self.tg_connections[[hndl.jid]].invoke(EditBannedRequest(InputPeerChannel(tg_id, self.tg_dialogs[[hndl.jid]]['supergroups'][tg_id].access_hash), invited_user, ChannelBannedRights(until_date=None, view_messages=False)))
|
gate.tg_connections[[self.jid]].invoke(EditBannedRequest(InputPeerChannel(self.tg_id, gate.tg_dialogs[[self.jid]]['supergroups'][
|
||||||
self.tg_connections[[hndl.jid]].invoke(InviteToChannelRequest(InputPeerChannel(tg_id, self.tg_dialogs[[hndl.jid]]['supergroups'][tg_id].access_hash), [invited_user]))
|
self.tg_id].access_hash), invited_user, ChannelBannedRights(until_date=None, view_messages=False)))
|
||||||
if tg_id in self.tg_dialogs[[hndl.jid]]['groups']:
|
gate.tg_connections[[self.jid]].invoke(InviteToChannelRequest(InputPeerChannel(self.tg_id, gate.tg_dialogs[[self.jid]]['supergroups'][
|
||||||
invited_user = self.tg_connections[[hndl.jid]].get_entity(parsed[1])
|
self.tg_id].access_hash), [invited_user]))
|
||||||
|
|
||||||
|
if self.tg_id in gate.tg_dialogs[[self.jid]]['groups']:
|
||||||
|
invited_user = gate.tg_connections[[self.jid]].get_entity(parsed[1])
|
||||||
if type(invited_user) == User:
|
if type(invited_user) == User:
|
||||||
self.tg_connections[[hndl.jid]].invoke(AddChatUserRequest(tg_id, invited_user, 0))
|
gate.tg_connections[[self.jid]].invoke(AddChatUserRequest(self.tg_id, invited_user, 0))
|
||||||
|
|
||||||
def kick(hndl, self):
|
def kick(hndl, self):
|
||||||
"""Kick user"""
|
"""Kick user"""
|
||||||
|
|||||||
Reference in New Issue
Block a user