Esempio n. 1
0
 def _track_metric(self, metric: Gauge, value: bool) -> None:
     if self._metric_value[metric] != value:
         if value:
             metric.inc(1)
         else:
             metric.dec(1)
         self._metric_value[metric] = value
Esempio n. 2
0
import shutil

from mausignald.types import Account, Address, Contact, Group, GroupV2, ListenEvent, ListenAction
from mautrix.bridge import BaseUser
from mautrix.types import UserID, RoomID
from mautrix.appservice import AppService
from mautrix.util.opt_prometheus import Gauge

from .db import User as DBUser
from .config import Config
from . import puppet as pu, portal as po

if TYPE_CHECKING:
    from .__main__ import SignalBridge

METRIC_CONNECTED = Gauge('bridge_connected',
                         'Bridge users connected to Signal')


class User(DBUser, BaseUser):
    by_mxid: Dict[UserID, 'User'] = {}
    by_username: Dict[str, 'User'] = {}
    config: Config
    az: AppService
    loop: asyncio.AbstractEventLoop
    bridge: 'SignalBridge'

    is_admin: bool
    permission_level: str

    _notice_room_lock: asyncio.Lock
Esempio n. 3
0
METRIC_SYNC_THREADS = Summary('bridge_sync_threads', 'calls to sync_threads')
METRIC_RESYNC = Summary('bridge_on_resync', 'calls to on_resync')
METRIC_UNKNOWN_EVENT = Summary('bridge_on_unknown_event', 'calls to on_unknown_event')
METRIC_MEMBERS_ADDED = Summary('bridge_on_members_added', 'calls to on_members_added')
METRIC_MEMBER_REMOVED = Summary('bridge_on_member_removed', 'calls to on_member_removed')
METRIC_TYPING = Summary('bridge_on_typing', 'calls to on_typing')
METRIC_PRESENCE = Summary('bridge_on_presence', 'calls to on_presence')
METRIC_REACTION = Summary('bridge_on_reaction', 'calls to on_reaction')
METRIC_MESSAGE_UNSENT = Summary('bridge_on_unsent', 'calls to on_unsent')
METRIC_MESSAGE_SEEN = Summary('bridge_on_message_seen', 'calls to on_message_seen')
METRIC_TITLE_CHANGE = Summary('bridge_on_title_change', 'calls to on_title_change')
METRIC_AVATAR_CHANGE = Summary('bridge_on_avatar_change', 'calls to on_avatar_change')
METRIC_THREAD_CHANGE = Summary('bridge_on_thread_change', 'calls to on_thread_change')
METRIC_MESSAGE = Summary('bridge_on_message', 'calls to on_message')
METRIC_LOGGED_IN = Gauge('bridge_logged_in', 'Users logged into the bridge')
METRIC_CONNECTED = Gauge('bridge_connected', 'Bridge users connected to Facebook')

if TYPE_CHECKING:
    from .__main__ import MessengerBridge

try:
    from aiohttp_socks import ProxyError, ProxyConnectionError, ProxyTimeoutError
except ImportError:
    class ProxyError(Exception):
        pass


    ProxyConnectionError = ProxyTimeoutError = ProxyError

T = TypeVar('T')
Esempio n. 4
0
from mautrix.util.opt_prometheus import Summary, Gauge, async_time

from .db import User as DBUser, Portal as DBPortal
from .config import Config
from . import puppet as pu, portal as po

if TYPE_CHECKING:
    from .__main__ import TwitterBridge

METRIC_CONVERSATION_UPDATE = Summary("bridge_on_conversation_update",
                                     "calls to handle_conversation_update")
METRIC_USER_UPDATE = Summary("bridge_on_user_update", "calls to handle_user_update")
METRIC_MESSAGE = Summary("bridge_on_message", "calls to handle_message")
METRIC_REACTION = Summary("bridge_on_reaction", "calls to handle_reaction")
METRIC_RECEIPT = Summary("bridge_on_receipt", "calls to handle_receipt")
METRIC_LOGGED_IN = Gauge("bridge_logged_in", "Users logged into the bridge")
METRIC_CONNECTED = Gauge("bridge_connected", "Bridged users connected to Twitter")


class User(DBUser, BaseUser):
    by_mxid: Dict[UserID, 'User'] = {}
    by_twid: Dict[int, 'User'] = {}
    config: Config
    az: AppService
    loop: asyncio.AbstractEventLoop

    client: Optional[TwitterAPI]

    is_admin: bool
    permission_level: str
    username: Optional[str]
Esempio n. 5
0
from mautrix.util.opt_prometheus import Gauge

from .types import TelegramID
from .db import User as DBUser, Portal as DBPortal, Message as DBMessage
from .abstract_user import AbstractUser
from . import portal as po, puppet as pu

if TYPE_CHECKING:
    from .config import Config
    from .context import Context

config: Optional['Config'] = None

SearchResult = NamedTuple('SearchResult', puppet='pu.Puppet', similarity=int)

METRIC_LOGGED_IN = Gauge('bridge_logged_in', 'Users logged into bridge')
METRIC_CONNECTED = Gauge('bridge_connected', 'Users connected to Telegram')


class User(AbstractUser, BaseUser):
    log: TraceLogger = logging.getLogger("mau.user")
    by_mxid: Dict[str, 'User'] = {}
    by_tgid: Dict[int, 'User'] = {}

    phone: Optional[str]
    contacts: List['pu.Puppet']
    saved_contacts: int
    portals: Dict[Tuple[TelegramID, TelegramID], 'po.Portal']
    command_status: Optional[Dict[str, Any]]

    _db_instance: Optional[DBUser]
Esempio n. 6
0
import shutil

from mausignald.types import Account, Address, Profile, Group, GroupV2, ListenEvent, ListenAction
from mautrix.bridge import BaseUser, async_getter_lock
from mautrix.types import UserID, RoomID
from mautrix.appservice import AppService
from mautrix.util.opt_prometheus import Gauge

from .db import User as DBUser
from .config import Config
from . import puppet as pu, portal as po

if TYPE_CHECKING:
    from .__main__ import SignalBridge

METRIC_CONNECTED = Gauge('bridge_connected',
                         'Bridge users connected to Signal')
METRIC_LOGGED_IN = Gauge('bridge_logged_in', 'Bridge users logged into Signal')


class User(DBUser, BaseUser):
    by_mxid: Dict[UserID, 'User'] = {}
    by_username: Dict[str, 'User'] = {}
    by_uuid: Dict[UUID, 'User'] = {}
    config: Config
    az: AppService
    loop: asyncio.AbstractEventLoop
    bridge: 'SignalBridge'

    is_admin: bool
    permission_level: str
Esempio n. 7
0
from .config import Config
from .db import User as DBUser, UserPortal, Contact, Message as DBMessage, Portal as DBPortal
from .util.hangups_try_auth import try_auth, TryAuthResp
from . import puppet as pu, portal as po

if TYPE_CHECKING:
    from .context import Context

config: Config

METRIC_SYNC_CHATS = Summary('bridge_sync_chats', 'calls to sync_chats')
METRIC_SYNC_USERS = Summary('bridge_sync_users', 'calls to sync_users')
METRIC_TYPING = Summary('bridge_on_typing', 'calls to on_typing')
METRIC_EVENT = Summary('bridge_on_event', 'calls to on_event')
METRIC_RECEIPT = Summary('bridge_on_receipt', 'calls to on_receipt')
METRIC_LOGGED_IN = Gauge('bridge_logged_in',
                         'Number of users logged into the bridge')
METRIC_CONNECTED = Gauge('bridge_connected',
                         'Number of users connected to Hangouts')


class User(BaseUser):
    by_mxid: Dict[UserID, 'User'] = {}

    client: Optional[Client]
    is_admin: bool
    _db_instance: Optional[DBUser]

    gid: Optional[str]
    refresh_token: Optional[str]
    notice_room: Optional[RoomID]
    _notice_room_lock: asyncio.Lock
Esempio n. 8
0
from mautrix.errors import MatrixRequestError, MNotFound
from mautrix.types import PushActionType, PushRuleKind, PushRuleScope, RoomID, RoomTagInfo, UserID
from mautrix.util.bridge_state import BridgeState, BridgeStateEvent
from mautrix.util.opt_prometheus import Gauge

from . import portal as po, puppet as pu
from .abstract_user import AbstractUser
from .db import Message as DBMessage, PgSession, User as DBUser
from .types import TelegramID

if TYPE_CHECKING:
    from .__main__ import TelegramBridge

SearchResult = NamedTuple("SearchResult", puppet="pu.Puppet", similarity=int)

METRIC_LOGGED_IN = Gauge("bridge_logged_in", "Users logged into bridge")
METRIC_CONNECTED = Gauge("bridge_connected", "Users connected to Telegram")

BridgeState.human_readable_errors.update(
    {
        "tg-not-connected": "Your Telegram connection failed",
        "tg-auth-key-duplicated": "The bridge accidentally logged you out",
        "tg-not-authenticated": "The stored auth token did not work",
        "tg-no-auth": "You're not logged in",
    }
)


class User(DBUser, AbstractUser, BaseUser):
    by_mxid: dict[str, User] = {}
    by_tgid: dict[int, User] = {}
Esempio n. 9
0
from mautrix.util.opt_prometheus import Summary, Gauge, async_time

from .db import User as DBUser, Portal as DBPortal
from .config import Config
from . import puppet as pu, portal as po

if TYPE_CHECKING:
    from .__main__ import TwitterBridge

METRIC_CONVERSATION_UPDATE = Summary("bridge_on_conversation_update",
                                     "calls to handle_conversation_update")
METRIC_USER_UPDATE = Summary("bridge_on_user_update", "calls to handle_user_update")
METRIC_MESSAGE = Summary("bridge_on_message", "calls to handle_message")
METRIC_REACTION = Summary("bridge_on_reaction", "calls to handle_reaction")
METRIC_RECEIPT = Summary("bridge_on_receipt", "calls to handle_receipt")
METRIC_LOGGED_IN = Gauge("bridge_logged_in", "Bridge Users Logged in")
METRIC_CONNECTED = Gauge("bridge_connected", "Bridge Users Connected")


class User(DBUser, BaseUser):
    by_mxid: Dict[UserID, 'User'] = {}
    by_twid: Dict[int, 'User'] = {}
    config: Config
    az: AppService
    loop: asyncio.AbstractEventLoop

    client: Optional[TwitterAPI]

    is_admin: bool
    permission_level: str
    username: Optional[str]