-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
178 lines (160 loc) · 7.09 KB
/
main.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
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
from ast import And
import re
from pyrogram import Client, filters
from pyrogram.types import ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import (InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardMarkup, InlineKeyboardButton)
from lib_dev import SolEnd
### CBXTEvYqLZtBGSWwJcD7w7oCPGdR38TGmv8yAM3gQ1qL devnet1
### 9Rfo6MyLtpka9SzxqbQEWYEyaRvXRMJzt9Npo1mg9skX devnet2
### H2hFezqB6JNVUixUMttJogFr3KvhTDX4bLvT8Rq4eJwW mainnet1
### AddjSTX6VdJCgp2B36ioVnyHw57sSjqfewiBXYywwEoc mainnet2
API_ID = 10187665
API_HASH = "f8113bc0748601e3989acd415971b259"
BOT_TOKEN = ""
App = Client("SolgramWalletBot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
back = SolEnd()
Solana_Client = back.connect()
@App.on_message(filters.command('start'))
def start(client, message):
back.users_profile[message.from_user.username] = {'reg_flag': False}
text = f'Hey! Welcome to IZZY NFTS bot. ' \
f'We allow you to view and buy NFTs conveniently and quickly right on Telegram.' \
f'You need to connect your wallet to make the most use out of our application.' \
f' Please, share your public key and we’ll connect it to your Telegram ID.'
message.reply(text, reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
'Registration',
callback_data='registration'
),
InlineKeyboardButton(
'Skip',
callback_data='menu'
)
]
]
))
@App.on_callback_query()
def start(client, query):
if query['data'] == 'menu':
App.send_message(query.from_user.username, 'Selection function', reply_markup=ReplyKeyboardMarkup(
[
["/my_collection", "/my_balance", "/my_bids"],
["/show_collection", "/show_balance"]
],
resize_keyboard=True # Make the keyboard smaller
))
elif query['data'] == 'registration':
back.users_profile[query.from_user.username]['reg_flag'] = True
back.users_profile[query.from_user.username]['func_data'] = 'registration'
App.send_message(query.from_user.username, 'Please input public key')
elif query['data'] == 'bind':
back.bind(query['data']['binder'],query['data']['holder'], query['data']['token_address'])
@App.on_message(filters.command('my_balance'))
def raw(client, message):
bal = back.balance(back.addr_to_nick[message.from_user.username], back.connect())
new_bal = bal["result"]["value"]
new_bal = round(new_bal / 1000000000, 2)
sol_bal = round((new_bal * back.price_in_usdt()), 2)
print(f'{new_bal} SOL / {sol_bal} USDT')
message.reply(f'{new_bal} SOL = {sol_bal} USD')
@App.on_message(filters.command('my_collection'))
def drop(client, message):
wallet = back.addr_to_nick[message.from_user.username]
print(wallet)
for address in back.get_tokens(wallet):
try:
metadata = back.get_nft_metadata(address)
uri = back.get_uri_token(metadata)
App.send_photo(message.from_user.username, back.request_img(uri), caption=back.request_data(uri))
except:
print(address)
@App.on_message(filters.command('show_balance'))
def raw(client, message):
back.users_profile[message.from_user.username]['reg_flag'] = True
back.users_profile[message.from_user.username]['func_data'] = {
'func_name':"show_balance",
'chat_id': str(message.chat.id)
}
print(message.chat.id)
message.reply("Please input public key:")
@App.on_message(filters.command('show_collection'))
def drop(client, message):
back.users_profile[message.from_user.username]['reg_flag'] = True
back.users_profile[message.from_user.username]['func_data'] = {
'func_name':"show_collection",
'chat_id': str(message.chat.id)
}
print(message.chat.id)
message.reply("Please input your public key:")
@App.on_message(filters.command('help'))
def helper(client, message):
message.reply(
"This bot helps you to surf and trade Solana NFTs:\n"\
"/reg + publicKey - registrate your public address, so you dont need to paste it later\n"\
"/my_collection - shows your NFTs with names and descriptions\n"\
"/my_balance - shows your SOL balance\n"\
"/show_collection + user_publicKey - shows user NFTs with names and descriptions\n"\
"/show_balance + user_publicKey - shows user SOL balance"
)
# @App.on_message(filters.command('buy'))
@App.on_callback_query()
def bind(client, query):
data = query["data"]
back.bind(query.from_user.username,data[1]["holder"],data[1]["nft_address"])
App.send_message("Offer your price (bid). It will be shared with the owner. "\
"If approved, you will be charged and become the owner.")
@App.on_message()
def other(client, message):
user = message.from_user.username
# chat_id = back.users_profile[user]['func_data']['chat_id']
chat_id = user
if back.users_profile[user]['reg_flag'] and back.users_profile[user]['func_data'] == "registration":
back.users_profile[user]['reg_flag'] = False
back.addr_to_nick[user] = message.text
print(back.addr_to_nick)
App.send_message(chat_id,"Registration succesful. Now you can use bot functions."\
"Use /help for more information")
elif back.users_profile[user]['reg_flag'] and back.users_profile[user]['func_data']['func_name'] == "show_collection" :
back.users_profile[user]['reg_flag'] = False
wallet = message.text
print(wallet)
holder = "@Okari1n"
for address in back.get_tokens(wallet):
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
'Buy',
callback_data='buy'
),
InlineKeyboardButton(
'Bid',
callback_data = 'bid',
# 'function_name': 'bind',
# 'binder' : 'message.from_user.user',
# 'token_address': address,
# 'holder': holder}
)
]
]
)
try:
metadata = back.get_nft_metadata(address)
uri = back.get_uri_token(metadata)
print(user)
App.send_photo(user,
back.request_img(uri),
caption=back.request_data(uri),
reply_markup = keyboard)
except:
print(address)
elif back.users_profile[user]['reg_flag'] and back.users_profile[user]['func_data']['func_name'] == "show_balance" :
bal = back.balance(message.text, back.connect())
new_bal = bal["result"]["value"]
new_bal = round(new_bal / 1000000000, 2)
sol_bal = round((new_bal * back.price_in_usdt()), 2)
print(f'{new_bal} SOL / {sol_bal} USDT')
message.reply(f'{new_bal} SOL = {sol_bal} USD') #
App.run()