-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise
331 lines (267 loc) · 12.6 KB
/
noise
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
from flask import Flask, request
import logging
from telegram import Update, Bot
from telegram.ext import Application, CommandHandler, MessageHandler, filters
from dotenv import load_dotenv
import os
import logging
import asyncio
from quart import Quart, request
app = Quart(__name__)
# app = Flask(__name__)
# Initialize logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO,
handlers=[
logging.StreamHandler() # This ensures logs are sent to the console (stdout)
]
)
logger = logging.getLogger(__name__)
# import requests
# import random
# import string
# from datetime import datetime
# from urllib.parse import urlencode
# Load environment variables from .env file
load_dotenv()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
# Initialize the bot application
application = Application.builder().token(BOT_TOKEN).build()
# Define command handlers
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome to the bot! How can I help you today?")
def play(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Let's play a game!")
def referral(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Refer your friends and earn rewards!")
# Define a message handler for text messages
def handle_text(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="hello")
# Add handlers
application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('play', play))
application.add_handler(CommandHandler('referral', referral))
application.add_handler(MessageHandler(filters.Text, handle_text))
# application.add_handler(MessageHandler(filters.Text & ~filters.Command, handle_text))
# @app.route('/webhook', methods=['POST'])
# def webhook():
# try:
# json_data = request.get_json(force=True)
# logger.info(f"Received JSON: {json_data}")
# update = Update.de_json(json_data, application.bot)
# application.update_queue.put(update)
# return "ok", 200
# except Exception as e:
# logger.error(f"Error processing webhook: {e}")
# return "error", 500
# # Flask route for receiving webhooks
@app.route('/webhook', methods=['POST'])
async def webhook():
try:
json_data = await request.get_json(force=True)
logger.info(f"Received JSON: {json_data}")
# Initialize the bot application
application = Application.builder().token(BOT_TOKEN).build()
# Transform JSON data into Telegram Update object
update = Update.de_json(json_data, application.bot)
# Dispatch the update to the bot's dispatcher
# application.updater()
# application.dispatcher.process_update(update)
# Handle the update through the dispatcher
# application.bot.dispatcher.process_update(update)
# Handle the update through the application
await application.process_update(update)
# asyncio.run(application.process_update(update) )
# asyncio.run( application.updater(application.bot, update) )
# asyncio.run( application.update_queue.put(update) )
# asyncio.run( application.update_processor.process_update(update) )
# application.process_update
return 'ok'
except Exception as e:
logger.error(f"Error processing webhook: {e}")
return 'error', 500
# @app.route('/webhook', methods=['POST'])
# def webhook():
# try:
# # json_data = request.get_json(force=True)
# # logger.info(f"Received JSON: {json_data}")
# # update = Update.de_json(json_data, application.bot)
# # # Put the update into the queue using asyncio.run to ensure it's awaited
# # # asyncio.run(application.update_queue.put(update))
# # return "ok", 200
# # retrieve the message in JSON and then transform it to Telegram object
# update = Update.de_json(request.get_json(force=True), application.bot)
# # get the chat_id to be able to respond to the same user
# chat_id = update.message.chat.id
# # get the message id to be able to reply to this specific message
# msg_id = update.message.message_id
# # Telegram understands UTF-8, so encode text for unicode compatibility
# text = update.message.text.encode('utf-8').decode()
# print("got text message :", text)
# # Handle the update through the application
# # asyncio.run(application.process_update(update) )
# # here we call our super AI
# # response = get_response(text)
# response = "hello made..."
# # now just send the message back
# # notice how we specify the chat and the msg we reply to
# asyncio.run(application.bot.send_message(chat_id=chat_id, text=response, reply_to_message_id=msg_id) )
# # bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)
# return 'ok'
# except Exception as e:
# logger.error(f"Error processing webhook: {e}")
if __name__ == '__main__':
app.run(port=8000)
"""import os
import logging
from flask import Flask, request
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Application, CommandHandler, ContextTypes
from dotenv import load_dotenv
import requests
import random
import string
from datetime import datetime
from urllib.parse import urlencode
# Load environment variables from .env file
load_dotenv()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
app = Flask(__name__)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s', level=logging.INFO)
logger = logging.getLogger(__name__)
# Initialize the bot application
application = Application.builder().token(BOT_TOKEN).build()
# Add handlers
application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('play', play))
application.add_handler(CommandHandler('referral', referral))
async def generate_strong_password(length=12):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for i in range(length))
return password
async def the_main(update: Update, context: ContextTypes.DEFAULT_TYPE, command="start"):
user = update.message.from_user
user_id = user.id
username = user.username
first_name = user.first_name
last_name = user.last_name
referrer_id = context.args[0] if context.args else None
now = datetime.now()
formattedDate = now.strftime('%Y-%m-%d')
formattedTime = now.strftime('%I:%M:%S %p')
url_plug = "https://roynek.com/alltrenders/codes/Telegram_Bot/Roynek%20Grows%20Bot"
game_url = f'{url_plug}/pre_game.html'
calendar_url = "https://docs.google.com/document/d/1lfuj6zKsNyK16RrOSvDD2AmgFedJAaR-2b5xTJwX6iw/edit?usp=sharing"
telegram_channel_url = "https://t.me/roynek_grows"
telegram_community = "https://t.me/roynek_grows_coin"
response = requests.post(f'{url_plug}/check_user.php', data={
'username': username,
'tele_id': user_id,
'referrer_id': referrer_id,
'first_name': first_name,
'last_name': last_name
})
result = response.json()
if result["status"]:
query_params = {
'hash': result["hash"],
'tele_id': user_id,
'username': username,
'first_name': first_name,
'last_name': last_name
}
game_url_with_params = f"{game_url}?{urlencode(query_params)}"
keyboard = [
[InlineKeyboardButton("Play Now", url=game_url_with_params)],
[InlineKeyboardButton("View Our Calendar", url=calendar_url)],
[InlineKeyboardButton("Join Our Telegram Channel", url=telegram_channel_url)],
[InlineKeyboardButton("Join Our Community", url=telegram_community)]
]
reply_markup = InlineKeyboardMarkup(keyboard)
welcome_message = (
f"🎉 Welcome {username}! 🎉 You are now a Roynekian with Grows Powers \n\n"
"We're thrilled to have you here. Unlike other Telegram token games, "
"we are committed and sure of our launch date.\n\n"
"Click the button below to start playing the game: You can only use this button once. \n\n"
"To enjoy another session, give the /play command again \n\n"
"Stay updated with our proposed calendar below.\n\n"
"Join our Telegram channel for the latest updates and community discussions."
) if (command == "start") else (
"Click the button below to start playing the game: It is a one time button, you can not use it again. \n\n "
"We have improved the security of telegram games. To enjoy another session, give the /play command again \n\n"
"Stay updated with our proposed calendar below.\n\n"
"Join our Telegram channel for the latest updates and community discussions."
)
await update.message.reply_text(welcome_message, reply_markup=reply_markup)
else:
response = requests.post(f'{url_plug}/register_user.php', data={
'username': username,
'tele_id': user_id,
'referrer_id': referrer_id,
'first_name': first_name,
'last_name': last_name,
'email': None,
'password': await generate_strong_password(),
'third_party_id': user_id,
'signup_date': formattedDate,
'signup_time': formattedTime,
})
result = response.json()
if result["status"]:
query_params = {
'hash': result["hash"],
'tele_id': user_id,
'username': username,
'first_name': first_name,
'last_name': last_name
}
game_url_with_params = f"{game_url}?{urlencode(query_params)}"
keyboard = [
[InlineKeyboardButton("Play Now", url=game_url_with_params)],
[InlineKeyboardButton("View Our Calendar", url=calendar_url)],
[InlineKeyboardButton("Join Our Telegram Channel", url=telegram_channel_url)],
[InlineKeyboardButton("Join Our Community", url=telegram_community)]
]
reply_markup = InlineKeyboardMarkup(keyboard)
welcome_message = (
f"🎉 Welcome {username}! 🎉 You are now a Roynekian with Grows Powers \n\n"
"We're thrilled to have you here. Unlike other Telegram token games, "
"we are committed and sure of our launch date.\n\n"
"Click the button below to start playing the game:\n\n"
"Stay updated with our proposed calendar by clicking the link below.\n\n"
"Join our Telegram channel for the latest updates and community discussions."
) if (command == "start") else (
"Click the button below to start playing the game:\n\n"
"Stay updated with our proposed calendar by clicking the link below.\n\n"
"Join our Telegram channel for the latest updates and community discussions."
)
await update.message.reply_text(welcome_message, reply_markup=reply_markup)
else:
await update.message.reply_text('We are having some issues. We are working on fixing it, Hope to see you around.')
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await the_main(update=update, context=context, command="start")
async def play(update: Update, context: ContextTypes.DEFAULT_TYPE):
await the_main(update=update, context=context, command="play")
async def referral(update: Update, context: ContextTypes.DEFAULT_TYPE):
user = update.message.from_user
user_id = user.id
referral_link = f"https://t.me/RoynekGrowsBot?start={user_id}"
await update.message.reply_text(f'Your referral link is: {referral_link}')
# Add handlers
application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('play', play))
application.add_handler(CommandHandler('referral', referral))
# Set the webhook
# application.bot.set_webhook(WEBHOOK_URL)
@app.route('/webhook', methods=['POST'])
def webhook():
update = Update.de_json(request.get_json(force=True), application.bot)
application.update_queue.put(update)
return "ok", 200
if __name__ == '__main__':
app.run(port=8000)"""
# http://rnyws-105-112-226-122.a.free.pinggy.link
# https://rnyws-105-112-226-122.a.free.pinggy.link