mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
fix(tweety): new api with spam protection
This commit is contained in:
@@ -11,6 +11,8 @@ import aiohttp
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import pytz
|
import pytz
|
||||||
|
import time
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
def break_long_words(text: str, max_word_length: int = 50) -> str:
|
def break_long_words(text: str, max_word_length: int = 50) -> str:
|
||||||
@@ -132,6 +134,8 @@ class TweetyView(discord.ui.View):
|
|||||||
self.is_dark = tweet_data.get("dark", False)
|
self.is_dark = tweet_data.get("dark", False)
|
||||||
self.is_verified = tweet_data.get("verified", False)
|
self.is_verified = tweet_data.get("verified", False)
|
||||||
self.image_message = image_message
|
self.image_message = image_message
|
||||||
|
self.last_regenerate_time = 0
|
||||||
|
self.click_count = 0
|
||||||
|
|
||||||
self.update_button_styles()
|
self.update_button_styles()
|
||||||
|
|
||||||
@@ -158,8 +162,28 @@ class TweetyView(discord.ui.View):
|
|||||||
|
|
||||||
async def regenerate_tweet(self, interaction: discord.Interaction):
|
async def regenerate_tweet(self, interaction: discord.Interaction):
|
||||||
"""Regenerate only the image message with current settings"""
|
"""Regenerate only the image message with current settings"""
|
||||||
|
if self.click_count >= 10:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Error",
|
||||||
|
description="Stop spamming! You've reached the maximum number of changes for this tweet.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
|
|
||||||
|
current_time = time.time()
|
||||||
|
time_since_last = current_time - self.last_regenerate_time
|
||||||
|
|
||||||
|
if time_since_last < 3 and self.last_regenerate_time > 0:
|
||||||
|
wait_time = 3 - time_since_last
|
||||||
|
await asyncio.sleep(wait_time)
|
||||||
|
|
||||||
|
self.click_count += 1
|
||||||
|
self.last_regenerate_time = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(
|
async with session.post(
|
||||||
@@ -332,7 +356,7 @@ def tweety_command():
|
|||||||
"dark": False
|
"dark": False
|
||||||
}
|
}
|
||||||
|
|
||||||
API_BASE_URL = "https://tweety-api.vercel.app"
|
API_BASE_URL = "http://tweet.6969.pro"
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user