Skip to content

Commit

Permalink
Merge pull request #117 from dvilelaf/fix/filter-banned
Browse files Browse the repository at this point in the history
Fix/filter banned
  • Loading branch information
dvilelaf authored Dec 20, 2024
2 parents 6ad3ef1 + 18c1294 commit ae4bfbd
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 33 deletions.
8 changes: 4 additions & 4 deletions packages/dvilela/agents/memeooorr/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ connections:
- valory/http_client:0.23.0:bafybeihi772xgzpqeipp3fhmvpct4y6e6tpjp4sogwqrnf3wqspgeilg4u
- valory/ledger:0.19.0:bafybeigntoericenpzvwejqfuc3kqzo2pscs76qoygg5dbj6f4zxusru5e
- valory/p2p_libp2p_client:0.1.0:bafybeid3xg5k2ol5adflqloy75ibgljmol6xsvzvezebsg7oudxeeolz7e
- dvilela/twikit:0.1.0:bafybeibglc42u6krxzzhdsnixhdwblefcolhulzckyfmek4hg4chvgpwza
- dvilela/twikit:0.1.0:bafybeig2rrxb4v56r7oo3vb5ahgryb7aw6n2i6wreackeamlhndwoldawm
- dvilela/kv_store:0.1.0:bafybeiekugvb2kan4342hliluxl3h5och3fjwqoafdyttpcn57evvyztq4
- valory/http_server:0.22.0:bafybeihpgu56ovmq4npazdbh6y6ru5i7zuv6wvdglpxavsckyih56smu7m
- dvilela/genai:0.1.0:bafybeifcrrfz6jwp437zutmrhtjjkruflauoa4go627c47haiv2r2ej2uq
contracts:
- valory/gnosis_safe:0.1.0:bafybeiaw4yr7ubqlp63iz5wxqep3a5fokqs3kqva7sp2nsqg355zzucqgm
- valory/gnosis_safe_proxy_factory:0.1.0:bafybeidkqhw7smq4kbqryodom6maj7gubc5nbxwm4vi343xbkqxx3brjtm
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- dvilela/meme_factory:0.1.0:bafybeigdnngracdis2shkn5hua3ufrnqo5qettmuvqbviculbsimwa4lzi
- dvilela/meme_factory:0.1.0:bafybeifwx7zcrj7fi4nkfdcucomn3ph7jlr3ac364ilayzcnh4sqjma3vu
- dvilela/service_registry:0.1.0:bafybeie2rrgzcjehlp2feff6bhkuindxzrnuwxe2jcrsy2thcdtrsp2o24
protocols:
- open_aea/signing:1.0.0:bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi
Expand All @@ -41,8 +41,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeigh2vkt74jrad5gtsczrgqcuhcqe7jkgjy7jdw56yamlzwwnaymjy
- valory/registration_abci:0.1.0:bafybeib3n6vqkfbrcubcbliebjnuwyywdinxkbzt76n6gbn2kg7ace47dq
- valory/reset_pause_abci:0.1.0:bafybeihkj6lmaypspyxe5qqrjgnolyck62pyvqoylr24ab6ue4steqcw7e
- dvilela/memeooorr_abci:0.1.0:bafybeic6iw6x7rcbnueptuols5notwwnojfnuoduwtqjq6j2r435ukct7m
- dvilela/memeooorr_chained_abci:0.1.0:bafybeic7cs5xfbevl6wjvbw5ok6u5pfzhjso46gg5k6y57re5zmy7etmju
- dvilela/memeooorr_abci:0.1.0:bafybeidcqpydciwahw5f56k4hlqm5gbcaqvqolbhbbv2ogljecqa5a7rvm
- dvilela/memeooorr_chained_abci:0.1.0:bafybeibytcdn746izbyeosfz4sidkcbdk4h6dytmnjvbqtnonitosochx4
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
12 changes: 12 additions & 0 deletions packages/dvilela/connections/twikit/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ async def _get_response(
"like_tweet",
"retweet",
"follow_user",
"filter_suspended_users",
]

if not all(i in payload for i in REQUIRED_PROPERTIES):
Expand Down Expand Up @@ -416,6 +417,17 @@ async def retweet(self, tweet_id: str) -> Dict:
response = await self.client.retweet(tweet_id)
return {"success": response.status_code == HTTP_OK}

async def filter_suspended_users(self, user_names: List[str]) -> List[str]:
"""Retweet"""
not_suspendend_users = []
for user_name in user_names:
try:
await self.client.get_user_by_screen_name(user_name)
not_suspendend_users.append(user_name)
except twikit.errors.TwitterException:
continue
return not_suspendend_users


def tweet_to_json(tweet: Any) -> Dict:
"""Tweet to json"""
Expand Down
2 changes: 1 addition & 1 deletion packages/dvilela/connections/twikit/connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeiaism4qxp36o6dflr3emtu4hk37dw7evimcoqkvlvt5s42af5lr5m
connection.py: bafybeie6vkyda3ewwrq3nfg5qdvt735bmu5eatmtsgww6ecu6yxi3wumre
connection.py: bafybeigjg54pbuspjqceoqhuxtpri4vk66pgjsm4h3iy3cuscrghiaieju
readme.md: bafybeihl7k3yi3twtvlkjntaknmib6hnhmyjurn25c4nksffcagrwkx5t4
fingerprint_ignore_patterns: []
connections: []
Expand Down
19 changes: 7 additions & 12 deletions packages/dvilela/contracts/meme_factory/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,24 @@ def get_events( # pylint: disable=too-many-arguments
) -> JSONLike:
"""Get events."""
contract_instance = cls.get_instance(ledger_api, contract_address)
current_block = ledger_api.api.eth.get_block_number()

if from_block is None:
from_block = (
ledger_api.api.eth.get_block_number() - 86400 * 2
) # approx 48h ago (2s per block)
from_block = current_block - 86400 # approx 48h ago (2s per block)

# Avoid parsing too many blocks at a time. This might take too long and
# the connection could time out.
MAX_BLOCKS = 5000
MAX_BATCH_BLOCKS = 5000

to_block = (
ledger_api.api.eth.get_block_number() - 1
if to_block == "latest"
else to_block
)
to_block = current_block - 1 if to_block == "latest" else to_block

_logger.info(
f"Getting {event_name} events from block {from_block} to {to_block} ({int(to_block) - int(from_block)} blocks)"
)

ranges: List[int] = list(range(from_block, cast(int, to_block), MAX_BLOCKS)) + [
cast(int, to_block)
]
ranges: List[int] = list(
range(from_block, cast(int, to_block), MAX_BATCH_BLOCKS)
) + [cast(int, to_block)]

event = getattr(contract_instance.events, event_name)
events = []
Expand Down
2 changes: 1 addition & 1 deletion packages/dvilela/contracts/meme_factory/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
README.md: bafybeies3iafkjwo4xvqtqpdxvood7pf2wgto4t76dqswy55rya7vl5zgu
__init__.py: bafybeiddslgyschgiuwsfiovqgxqqbkazdy6h3d4swwnq3tvpqaxzy37si
build/MemeBase.json: bafybeibr3pkkofhukwqjuqxuxsb52g2xlquzhu5uv6xqo527s2zzmp3cq4
contract.py: bafybeiaussmgr2ffnget7jnibl5rdqcx5h7mmlc2zh3ku6tgiaioibjccu
contract.py: bafybeibx6clkjoixakvzqc2p7cnzeypm333ceuwm3cpekrzwldwwr2wx7e
fingerprint_ignore_patterns: []
contracts: []
class_name: MemeFactoryContract
Expand Down
2 changes: 1 addition & 1 deletion packages/dvilela/services/memeooorr/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeiaekcmielp6mb4qvmo2twwkpmoun36bqajrh7wnnkcpdnia45ycl4
fingerprint_ignore_patterns: []
agent: dvilela/memeooorr:0.1.0:bafybeihvhv6jbq7b6r2eyi7ez3vdr4omf4ocqmsz36vv4zhz2o6qnry7ya
agent: dvilela/memeooorr:0.1.0:bafybeihmrflznbs4zzkw4cqgkvw5clfor7mzop3vkdou653tbbnuc3442m
number_of_agents: 1
deployment:
agent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ def get_meme_coins_from_chain(self) -> Generator[None, None, Optional[List]]:
contract_address=self.get_meme_factory_address(),
contract_id=str(MemeFactoryContract.contract_id),
contract_callable="get_summon_data",
from_block=self.get_meme_factory_deployment_block(),
chain_id=self.get_chain_id(),
)

Expand All @@ -492,7 +491,6 @@ def get_meme_coins_from_chain(self) -> Generator[None, None, Optional[List]]:
contract_id=str(MemeFactoryContract.contract_id),
contract_callable="get_events",
event_name="Unleashed",
from_block=self.get_meme_factory_deployment_block(),
chain_id=self.get_chain_id(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ def get_event(self) -> Generator[None, None, str]:
# Get other memeooorr handles
agent_handles = yield from self.get_memeooorr_handles_from_subgraph()

# Filter out suspended accounts
agent_handles = yield from self._call_twikit(
method="filter_suspended_users",
user_names=agent_handles,
)
self.context.logger.info(f"Not suspended users: {agent_handles}")

# Load previously responded tweets
db_data = yield from self._read_kv(keys=("interacted_tweet_ids",))

Expand Down
8 changes: 4 additions & 4 deletions packages/dvilela/skills/memeooorr_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeidorrnxjv4n4ngovxnu4mzod46kyrdncfmli4hapqeqnzp7imq7hm
behaviour_classes/__init__.py: bafybeicjks4kxsb2r6a4armmaqxyxngwm3pouegq3fycm37rbe7otiwsre
behaviour_classes/base.py: bafybeib26og4iiwb322svawmmaiqytvkrdv6nelcbpiqyia3nlwxaj5vpi
behaviour_classes/base.py: bafybeidrog7oqe6cdrbx66mgsiqfu7ybuuexkruqhwmmoz3bu34p2f56nq
behaviour_classes/chain.py: bafybeigxfwko3rofqlzyjjhgeo6yabxseqngo2uz5muyfk3f2jjpgdrsli
behaviour_classes/db.py: bafybeieuhjes2gsiidepjxcojgnn3swx2znem5uwvz7rwkxpwls3dmlxf4
behaviour_classes/llm.py: bafybeifdhipccrdtfx5vay2sfd7vss4iovwtyeefuz5vrjewjbyatk35c4
behaviour_classes/twitter.py: bafybeiaepletyjiqy6z7y2nmsuxtmpfs4fgfqswyihf4o27vhyodxcuvx4
behaviour_classes/twitter.py: bafybeidmon7e55izpbzj7u4jiziyfelh6akdfkyixkhdaulwjbk66xeayi
behaviours.py: bafybeibdbimezloiomvsv3zgfdug4tw276gt7tb5agnezl2nuqcfcplscu
dialogues.py: bafybeiaygigeleloplgrsg2sovv463uvzk3zc2tupgazn4ak2vqcangksu
fsm_specification.yaml: bafybeif4kr2lnj4ppaaxveej2a3gq2gul6gicu2rar2yeyhg4mspqsikxy
Expand All @@ -25,12 +25,12 @@ fingerprint:
fingerprint_ignore_patterns: []
connections:
- dvilela/kv_store:0.1.0:bafybeiekugvb2kan4342hliluxl3h5och3fjwqoafdyttpcn57evvyztq4
- dvilela/twikit:0.1.0:bafybeibglc42u6krxzzhdsnixhdwblefcolhulzckyfmek4hg4chvgpwza
- dvilela/twikit:0.1.0:bafybeig2rrxb4v56r7oo3vb5ahgryb7aw6n2i6wreackeamlhndwoldawm
- dvilela/genai:0.1.0:bafybeifcrrfz6jwp437zutmrhtjjkruflauoa4go627c47haiv2r2ej2uq
- valory/http_server:0.22.0:bafybeihpgu56ovmq4npazdbh6y6ru5i7zuv6wvdglpxavsckyih56smu7m
contracts:
- valory/gnosis_safe:0.1.0:bafybeiaw4yr7ubqlp63iz5wxqep3a5fokqs3kqva7sp2nsqg355zzucqgm
- dvilela/meme_factory:0.1.0:bafybeigdnngracdis2shkn5hua3ufrnqo5qettmuvqbviculbsimwa4lzi
- dvilela/meme_factory:0.1.0:bafybeifwx7zcrj7fi4nkfdcucomn3ph7jlr3ac364ilayzcnh4sqjma3vu
- dvilela/service_registry:0.1.0:bafybeie2rrgzcjehlp2feff6bhkuindxzrnuwxe2jcrsy2thcdtrsp2o24
protocols:
- valory/srr:0.1.0:bafybeihrixgptxuqpf2s4nujypwlv5aed2nboozq5kl4c26cxw6r7si2x4
Expand Down
2 changes: 1 addition & 1 deletion packages/dvilela/skills/memeooorr_chained_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeihkj6lmaypspyxe5qqrjgnolyck62pyvqoylr24ab6ue4steqcw7e
- valory/transaction_settlement_abci:0.1.0:bafybeigh2vkt74jrad5gtsczrgqcuhcqe7jkgjy7jdw56yamlzwwnaymjy
- valory/termination_abci:0.1.0:bafybeifi2uodnrjsrivj53g3sjutocmyusbx6mlsb6oanqdyt2mfbyvusy
- dvilela/memeooorr_abci:0.1.0:bafybeic6iw6x7rcbnueptuols5notwwnojfnuoduwtqjq6j2r435ukct7m
- dvilela/memeooorr_abci:0.1.0:bafybeidcqpydciwahw5f56k4hlqm5gbcaqvqolbhbbv2ogljecqa5a7rvm
behaviours:
main:
args: {}
Expand Down
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dev": {
"contract/dvilela/meme_factory/0.1.0": "bafybeigdnngracdis2shkn5hua3ufrnqo5qettmuvqbviculbsimwa4lzi",
"contract/dvilela/meme_factory/0.1.0": "bafybeifwx7zcrj7fi4nkfdcucomn3ph7jlr3ac364ilayzcnh4sqjma3vu",
"contract/dvilela/service_registry/0.1.0": "bafybeie2rrgzcjehlp2feff6bhkuindxzrnuwxe2jcrsy2thcdtrsp2o24",
"connection/dvilela/twikit/0.1.0": "bafybeibglc42u6krxzzhdsnixhdwblefcolhulzckyfmek4hg4chvgpwza",
"skill/dvilela/memeooorr_abci/0.1.0": "bafybeic6iw6x7rcbnueptuols5notwwnojfnuoduwtqjq6j2r435ukct7m",
"skill/dvilela/memeooorr_chained_abci/0.1.0": "bafybeic7cs5xfbevl6wjvbw5ok6u5pfzhjso46gg5k6y57re5zmy7etmju",
"agent/dvilela/memeooorr/0.1.0": "bafybeihvhv6jbq7b6r2eyi7ez3vdr4omf4ocqmsz36vv4zhz2o6qnry7ya",
"service/dvilela/memeooorr/0.1.0": "bafybeiamfoix3qumef6nyl67fobb5bi2y3mun2lxedah3cj2k37qqlhbwm"
"connection/dvilela/twikit/0.1.0": "bafybeig2rrxb4v56r7oo3vb5ahgryb7aw6n2i6wreackeamlhndwoldawm",
"skill/dvilela/memeooorr_abci/0.1.0": "bafybeidcqpydciwahw5f56k4hlqm5gbcaqvqolbhbbv2ogljecqa5a7rvm",
"skill/dvilela/memeooorr_chained_abci/0.1.0": "bafybeibytcdn746izbyeosfz4sidkcbdk4h6dytmnjvbqtnonitosochx4",
"agent/dvilela/memeooorr/0.1.0": "bafybeihmrflznbs4zzkw4cqgkvw5clfor7mzop3vkdou653tbbnuc3442m",
"service/dvilela/memeooorr/0.1.0": "bafybeida3qb2cuqcyanpfkf6do7ttyzi6erq54t4y3dz7fcfhy2yo3iw5y"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
12 changes: 11 additions & 1 deletion scripts/test_twikit.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ async def like_tweet() -> None:
await client.favorite_tweet("1868952161427882053")


asyncio.run(like_tweet())
async def is_suspended() -> None:
"""Is suspended"""
client = await cookie_login()
try:
await client.get_user_by_screen_name("autonolas")
return False
except twikit.errors.UserUnavailable:
return True


print(asyncio.run(is_suspended()))

0 comments on commit ae4bfbd

Please sign in to comment.