Skip to content

Commit

Permalink
added telegram connection constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
alimaktabi committed Oct 17, 2024
1 parent d62fad8 commit 1cc33ba
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
IsFollowingTwitterUser,
)
from core.constraints.zora import DidMintZoraNFT
from core.constraints.telegram import HasTelegramConnection


def get_constraint(constraint_label: str) -> ConstraintVerification:
Expand Down
23 changes: 23 additions & 0 deletions core/constraints/telegram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging

from core.constraints.abstract import (
ConstraintApp,
ConstraintVerification,
)


logger = logging.getLogger(__name__)


class HasTelegramConnection(ConstraintVerification):
_param_keys = []
app_name = ConstraintApp.GENERAL.value

def is_observed(self, *args, **kwargs) -> bool:
from telegram.models import TelegramConnection

try:
twitter = TelegramConnection.get_connection(self.user_profile)
except TelegramConnection.DoesNotExist:
return False
return twitter.is_connected()
4 changes: 3 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
IsFollowingLensUser,
IsFollowingTwitterBatch,
IsFollowingTwitterUser,
HasTelegramConnection,
)
from .utils import SolanaWeb3Utils, Web3Utils

Expand Down Expand Up @@ -160,7 +161,8 @@ class Type(models.TextChoices):
IsFollowingFarcasterBatch,
HasVerifiedCloudflareCaptcha,
DidMintZoraNFT,
HasVerifiedHCaptcha
HasVerifiedHCaptcha,
HasTelegramConnection,
]

name = models.CharField(
Expand Down
7 changes: 0 additions & 7 deletions core/thirdpartyapp/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,3 @@ def __init__(self) -> None:

def verify_login(self, telegram_data):
return verify_telegram_auth(self.bot_token, telegram_data)

def create_telegram_widget(self, redirect_url):
telegram_login_widget = create_redirect_login_widget(
redirect_url, self.bot_username
)

return telegram_login_widget
Empty file modified prizetap/migrations/0067_alter_constraint_name.py
100644 → 100755
Empty file.
93 changes: 93 additions & 0 deletions prizetap/migrations/0081_alter_constraint_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Generated by Django 5.1.2 on 2024-10-17 11:39

from django.db import migrations, models


def create_prizetap_constraint(apps, schema_editor):
Constraint = apps.get_model("prizetap", "Constraint")

Constraint.objects.create(
name="core.HasTelegramConnection",
description="HasTelegramConnection",
title="Connect Telegram",
type="VER",
)


class Migration(migrations.Migration):

dependencies = [
("prizetap", "0080_alter_constraint_name"),
]

operations = [
migrations.AlterField(
model_name="constraint",
name="name",
field=models.CharField(
choices=[
("core.BrightIDMeetVerification", "BrightIDMeetVerification"),
("core.BrightIDAuraVerification", "BrightIDAuraVerification"),
("core.HasNFTVerification", "HasNFTVerification"),
("core.HasTokenVerification", "HasTokenVerification"),
(
"core.HasTokenTransferVerification",
"HasTokenTransferVerification",
),
("core.AllowListVerification", "AllowListVerification"),
("core.HasENSVerification", "HasENSVerification"),
("core.HasLensProfile", "HasLensProfile"),
("core.IsFollowingLensUser", "IsFollowingLensUser"),
("core.BeFollowedByLensUser", "BeFollowedByLensUser"),
("core.DidMirrorOnLensPublication", "DidMirrorOnLensPublication"),
("core.DidCollectLensPublication", "DidCollectLensPublication"),
("core.HasMinimumLensPost", "HasMinimumLensPost"),
("core.HasMinimumLensFollower", "HasMinimumLensFollower"),
("core.BeFollowedByFarcasterUser", "BeFollowedByFarcasterUser"),
("core.HasMinimumFarcasterFollower", "HasMinimumFarcasterFollower"),
("core.DidLikedFarcasterCast", "DidLikedFarcasterCast"),
("core.DidRecastFarcasterCast", "DidRecastFarcasterCast"),
("core.IsFollowingFarcasterUser", "IsFollowingFarcasterUser"),
("core.HasFarcasterProfile", "HasFarcasterProfile"),
("core.BeAttestedBy", "BeAttestedBy"),
("core.Attest", "Attest"),
("core.HasDonatedOnGitcoin", "HasDonatedOnGitcoin"),
("core.HasMinimumHumanityScore", "HasMinimumHumanityScore"),
("core.HasGitcoinPassportProfile", "HasGitcoinPassportProfile"),
("core.IsFollowingFarcasterChannel", "IsFollowingFarcasterChannel"),
("core.BridgeEthToArb", "BridgeEthToArb"),
("core.IsFollowingTwitterUser", "IsFollowingTwitterUser"),
("core.BeFollowedByTwitterUser", "BeFollowedByTwitterUser"),
("core.DidRetweetTweet", "DidRetweetTweet"),
("core.DidQuoteTweet", "DidQuoteTweet"),
("core.HasMuonNode", "HasMuonNode"),
("core.DelegateArb", "DelegateArb"),
("core.DelegateOP", "DelegateOP"),
("core.DidDelegateArbToAddress", "DidDelegateArbToAddress"),
("core.DidDelegateOPToAddress", "DidDelegateOPToAddress"),
("core.GLMStakingVerification", "GLMStakingVerification"),
("core.IsFollowingTwitterBatch", "IsFollowingTwitterBatch"),
("core.IsFollowingFarcasterBatch", "IsFollowingFarcasterBatch"),
(
"core.HasVerifiedCloudflareCaptcha",
"HasVerifiedCloudflareCaptcha",
),
("core.DidMintZoraNFT", "DidMintZoraNFT"),
("core.HasVerifiedHCaptcha", "HasVerifiedHCaptcha"),
("core.HasTelegramConnection", "HasTelegramConnection"),
("prizetap.HaveUnitapPass", "HaveUnitapPass"),
("prizetap.NotHaveUnitapPass", "NotHaveUnitapPass"),
("faucet.OptimismDonationConstraint", "OptimismDonationConstraint"),
(
"faucet.OptimismClaimingGasConstraint",
"OptimismClaimingGasConstraint",
),
],
max_length=255,
unique=True,
),
),
migrations.RunPython(
create_prizetap_constraint, reverse_code=migrations.RunPython.noop
),
]
95 changes: 95 additions & 0 deletions tokenTap/migrations/0067_alter_constraint_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Generated by Django 5.1.2 on 2024-10-17 11:39

from django.db import migrations, models


def create_tokentap_constraint(apps, schema_editor):
Constraint = apps.get_model("tokenTap", "Constraint")

Constraint.objects.create(
name="core.HasTelegramConnection",
description="HasTelegramConnection",
title="Connect Telegram",
type="VER",
)


class Migration(migrations.Migration):

dependencies = [
("tokenTap", "0066_alter_constraint_name"),
]

operations = [
migrations.AlterField(
model_name="constraint",
name="name",
field=models.CharField(
choices=[
("core.BrightIDMeetVerification", "BrightIDMeetVerification"),
("core.BrightIDAuraVerification", "BrightIDAuraVerification"),
("core.HasNFTVerification", "HasNFTVerification"),
("core.HasTokenVerification", "HasTokenVerification"),
(
"core.HasTokenTransferVerification",
"HasTokenTransferVerification",
),
("core.AllowListVerification", "AllowListVerification"),
("core.HasENSVerification", "HasENSVerification"),
("core.HasLensProfile", "HasLensProfile"),
("core.IsFollowingLensUser", "IsFollowingLensUser"),
("core.BeFollowedByLensUser", "BeFollowedByLensUser"),
("core.DidMirrorOnLensPublication", "DidMirrorOnLensPublication"),
("core.DidCollectLensPublication", "DidCollectLensPublication"),
("core.HasMinimumLensPost", "HasMinimumLensPost"),
("core.HasMinimumLensFollower", "HasMinimumLensFollower"),
("core.BeFollowedByFarcasterUser", "BeFollowedByFarcasterUser"),
("core.HasMinimumFarcasterFollower", "HasMinimumFarcasterFollower"),
("core.DidLikedFarcasterCast", "DidLikedFarcasterCast"),
("core.DidRecastFarcasterCast", "DidRecastFarcasterCast"),
("core.IsFollowingFarcasterUser", "IsFollowingFarcasterUser"),
("core.HasFarcasterProfile", "HasFarcasterProfile"),
("core.BeAttestedBy", "BeAttestedBy"),
("core.Attest", "Attest"),
("core.HasDonatedOnGitcoin", "HasDonatedOnGitcoin"),
("core.HasMinimumHumanityScore", "HasMinimumHumanityScore"),
("core.HasGitcoinPassportProfile", "HasGitcoinPassportProfile"),
("core.IsFollowingFarcasterChannel", "IsFollowingFarcasterChannel"),
("core.BridgeEthToArb", "BridgeEthToArb"),
("core.IsFollowingTwitterUser", "IsFollowingTwitterUser"),
("core.BeFollowedByTwitterUser", "BeFollowedByTwitterUser"),
("core.DidRetweetTweet", "DidRetweetTweet"),
("core.DidQuoteTweet", "DidQuoteTweet"),
("core.HasMuonNode", "HasMuonNode"),
("core.DelegateArb", "DelegateArb"),
("core.DelegateOP", "DelegateOP"),
("core.DidDelegateArbToAddress", "DidDelegateArbToAddress"),
("core.DidDelegateOPToAddress", "DidDelegateOPToAddress"),
("core.GLMStakingVerification", "GLMStakingVerification"),
("core.IsFollowingTwitterBatch", "IsFollowingTwitterBatch"),
("core.IsFollowingFarcasterBatch", "IsFollowingFarcasterBatch"),
(
"core.HasVerifiedCloudflareCaptcha",
"HasVerifiedCloudflareCaptcha",
),
("core.DidMintZoraNFT", "DidMintZoraNFT"),
("core.HasVerifiedHCaptcha", "HasVerifiedHCaptcha"),
("core.HasTelegramConnection", "HasTelegramConnection"),
("tokenTap.OncePerMonthVerification", "OncePerMonthVerification"),
(
"tokenTap.OnceInALifeTimeVerification",
"OnceInALifeTimeVerification",
),
(
"faucet.OptimismHasClaimedGasConstraint",
"OptimismHasClaimedGasConstraint",
),
],
max_length=255,
unique=True,
),
),
migrations.RunPython(
create_tokentap_constraint, reverse_code=migrations.RunPython.noop
),
]

0 comments on commit 1cc33ba

Please sign in to comment.