[SVN] Release 0.4.1

[UPD] [BROKE] New config to database is added, please, re-create it, it is broken!
[UPD] `Long time ago` contacts now is offline instead of XA
[ADD] Contacts last seen later than `status_xa_interval` (configurable via !configure) hours now have XA status
This commit is contained in:
annelin
2018-07-03 01:26:45 +00:00
parent 2f2d534f09
commit 0db8c90169
2 changed files with 17 additions and 28 deletions

View File

@@ -1,27 +1,20 @@
import sqlite3
import re
import sys
import os
import io
import time
import hashlib
import sleekxmpp
from sleekxmpp.componentxmpp import ComponentXMPP
import re, sys, os, io, sqlite3, hashlib, time, datetime
import xml.etree.ElementTree as ET
from sleekxmpp.componentxmpp import ComponentXMPP
from sleekxmpp import Presence, Message
from telethon.tl.functions.messages import GetDialogsRequest, SendMessageRequest, SendMediaRequest, EditMessageRequest, DeleteMessagesRequest, ImportChatInviteRequest, GetFullChatRequest, AddChatUserRequest, DeleteChatUserRequest, CreateChatRequest, DeleteHistoryRequest
from telethon.tl.functions.account import UpdateStatusRequest, GetAuthorizationsRequest, UpdateProfileRequest, UpdateUsernameRequest
from telethon.tl.functions.contacts import DeleteContactRequest, BlockRequest, UnblockRequest, ImportContactsRequest
from telethon.tl.functions.channels import JoinChannelRequest, LeaveChannelRequest, InviteToChannelRequest, EditBannedRequest, CreateChannelRequest, DeleteMessagesRequest as DeleteMessagesChannel
from telethon.tl.types import InputPeerEmpty, InputPeerUser, InputPeerChat, InputPeerChannel, InputPhoneContact
from telethon.tl.types import InputPeerEmpty, InputPeerUser, InputPeerChat, InputPeerChannel, InputPhoneContact, InputMediaPhotoExternal
from telethon.tl.types import User, Chat, Channel
from telethon.tl.types import PeerChannel, PeerChat, PeerUser, Chat, ChatForbidden, Channel, ChannelForbidden
from telethon.tl.types import PeerChannel, PeerChat, PeerUser, Chat, ChatForbidden, Channel, ChannelForbidden, ChannelBannedRights
from telethon.tl.types import UserStatusOnline, UserStatusRecently, UserStatusOffline
from telethon.tl.types import Updates, UpdateShortSentMessage, UpdateMessageID
from telethon.tl.types import ChannelBannedRights
from telethon.tl.types import InputMediaPhotoExternal
from telethon.tl.types.messages import Dialogs, DialogsSlice
from telethon.helpers import generate_random_long
@@ -585,7 +578,7 @@ class XMPPTelegram(ComponentXMPP):
def roster_exchange(self, tojid, contacts):
message = sleekxmpp.Message()
message = Message()
message['from'] = self.boundjid.bare
message['to'] = tojid
rawxml = "<x xmlns='http://jabber.org/protocol/rosterx'>"
@@ -601,7 +594,7 @@ class XMPPTelegram(ComponentXMPP):
def roster_fill(self, tojid, contacts):
for jid, nick in contacts.items():
presence = sleekxmpp.Presence()
presence = Presence()
presence['from'] = jid
presence['to'] = tojid
presence['type'] = 'subscribe'
@@ -694,9 +687,10 @@ class XMPPTelegram(ComponentXMPP):
elif type(usr.status) is UserStatusRecently:
self.send_presence(pto=jid, pfrom=u_jid, pshow='dnd', pstatus='Last seen recently')
elif type(usr.status) is UserStatusOffline:
self.send_presence(pto=jid, pfrom=u_jid, pshow='away', pstatus=localtime(usr.status.was_online).strftime('Last seen at %H:%M %d/%m/%Y') )
phow = 'away' if datetime.datetime.utcnow() - usr.status.was_online < datetime.timedelta(hours = self.accounts[jid]['status_xa_interval'] ) else 'xa'
self.send_presence(pto=jid, pfrom=u_jid, pshow=phow, pstatus=localtime(usr.status.was_online).strftime('Last seen at %H:%M %d/%m/%Y') )
else:
self.send_presence(pto=jid, pfrom=u_jid, pshow='xa', pstatus='Last seen a long time ago')
self.send_presence(pto=jid, pfrom=u_jid, ptype='unavailable', pstatus='Last seen a long time ago')
if type(dlg.peer) in [PeerChat, PeerChannel]:
cht = None
@@ -799,7 +793,7 @@ class XMPPTelegram(ComponentXMPP):
return (msg_id, edited)
def publish_photo(self, jid, fromjid, photo):
presence = sleekxmpp.Presence()
presence = Presence()
presence['to'] = jid
presence['from'] = fromjid
presence.appendxml(ET.fromstring("<x xmlns='vcard-temp:x:update'><photo>%s</photo></x>" % photo))
@@ -820,6 +814,6 @@ class XMPPTelegram(ComponentXMPP):
conn = sqlite3.connect(self.config['db_connect'], isolation_level=None, check_same_thread=False)
conn.row_factory = dict_factory
conn.execute("CREATE TABLE IF NOT EXISTS accounts(jid VARCHAR(255), tg_phone VARCHAR(25), use_roster_exchange BOOLEAN default false, keep_online BOOLEAN default false, status_update_interval INTEGER default 30, enable_avatars BOOLEAN default false)")
conn.execute("CREATE TABLE IF NOT EXISTS accounts(jid VARCHAR(255), tg_phone VARCHAR(25), use_roster_exchange BOOLEAN default false, keep_online BOOLEAN default false, status_update_interval INTEGER default 30, status_xa_interval INTEGER default 24, enable_avatars BOOLEAN default false)")
return conn