-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathads_session.py
80 lines (64 loc) · 2.16 KB
/
ads_session.py
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
import logging
logging.basicConfig(level=logging.INFO)
import requests
from io import BytesIO
from swibots import (
BotContext,
Client,
CommandEvent,
CallbackQueryEvent,
BotCommand,
InlineMarkup,
InlineKeyboardButton,
regexp,
)
from datetime import datetime
BOT_TOKEN = "TOKEN HERE"
AD_TYPE = "VIDEO_1" # or "VIDEO_2"
AD_ID = "e45206-------8516f557af"
VERIFY_HRS = 12 # verify after 12 hours
app = Client(BOT_TOKEN, is_app=True, home_callback="page")
app.set_bot_commands(
[
BotCommand("start", "Starts the bot", True),
BotCommand("unlock", "Unlock the secret", True),
]
)
approvedUsers = {}
@app.on_command("start")
async def onStart(ctx: BotContext[CommandEvent]):
await ctx.event.message.reply_text(
"Hello, You can unlock the suprise by sending `/unlock` command!"
)
@app.on_command("unlock")
async def unlockCommand(ctx: BotContext[CommandEvent]):
m = ctx.event.message
userId = m.user_id
ttime = approvedUsers.get(userId)
if ttime and (
((datetime.now() - datetime.fromtimestamp(ttime)).total_seconds() / 3600)
< VERIFY_HRS
):
await m.send("You are already approved!")
return
await m.send(
"Click below button to watch ad and unlock your reward!",
inline_markup=InlineMarkup(
[[InlineKeyboardButton("Watch 🎁", callback_data="showAD")]]
),
)
@app.on_callback_query(regexp("showAD"))
async def getRewards(ctx: BotContext[CallbackQueryEvent]):
"""Show ad and unlock rewards"""
await ctx.event.show_ad(id=AD_ID, ad_type=AD_TYPE, success_callback="watched")
@app.on_callback_query(regexp("watched"))
async def onSuccess(ctx: BotContext[CallbackQueryEvent]):
"""User watched the ad successfully"""
userId = ctx.event.action_by_id
approvedUsers[userId] = datetime.now().timestamp()
m = ctx.event.message
file = BytesIO(requests.get("https://upload.wikimedia.org/wikipedia/commons/8/8a/1000_USD_note%3B_series_of_1934%3B_obverse.jpg").content)
file.name = "reward.png"
await m.send("Thank you for watching the ad!\nHere is your reward!")
await m.send("", document=file)
app.run()